14 Commits

Author SHA1 Message Date
Timm Baeder
25ea920699
[clang][bytecode] Fix already initializing _Complex UO_Not (#181323)
We'd accidentally leave the subexpr pointer on the stack.
2026-02-13 09:17:46 +01:00
Timm Baeder
0f8d8dc5b9
[clang][bytecode] Reject composite copies on primitive pointers (#180683)
This should fail.
2026-02-10 08:45:11 +01:00
Timm Baeder
fdd9555fc0
[clang][bytecode] Fix discarded Mulc/DivC opcodes (#180537)
We need to pop the pointer in that case.
2026-02-10 05:46:16 +01:00
Timm Baeder
1c4a98f768
[clang][bytecode] Fix discarded builtin_complex (#180539)
This is the only builtin that returns a non-primitive type I think.
2026-02-10 05:21:00 +01:00
Timm Baeder
d26b035d69
[clang][bytecode] Remove an incorrect assertion (#179644)
There are situations where DiscardResult is set, but we still wish to
emit a float value, e.g. when we will discard the result of an operation
involving such a float value.
2026-02-04 14:30:10 +01:00
FYLGQ
e68eadf849
[clang][bytecode] Fix crash on discarded complex comparison (#177731)
Fixes llvm#176902: [clang][bytecode] crashes on ill-formed
_Static_assert comparing complex value

This patch resolves a crash in Clang's constant evaluation when handling
complex number comparisons in discarded expressions, such as those
involving short-circuiting logical operators. The crash occurred due to
unnecessary evaluation of the comparison in the experimental constant
interpreter.

The issue was originally observed and minimized in the following
example:

```cpp
#define EVAL(a, b) _Static_assert(a == b, "")

void foo() {
  EVAL(; + 0, 1i);
}
```

This patch ensures that such comparisons are handled correctly without
triggering assertions when the result is discarded.

Tests

A regression test has been added to verify that complex comparisons in
discarded expressions no longer cause crashes during constant
evaluation.

Local verification:


llvm-project-main/clang/lib/AST/ByteCode/constant-eval-complex-discard.c
passes.

Full ninja check-clang may fail locally due to a known GCC ICE when
building Clang unittests; this is unrelated to the change itself.
2026-01-26 07:52:17 +01:00
Timm Baeder
dc1a886fb9
[clang][bytecode] Fix CK_ToVoid casts for Complex values (#175709)
We need to remove the pointer to the local variable we've created
specifically for this complex binary operator.

Fixes https://github.com/llvm/llvm-project/issues/175670
2026-01-13 08:19:27 +01:00
Timm Baeder
4fdbe05d6e
[clang][bytecode] Fix some imag/real corner cases (#174764)
Fix real/imag when taking a primitive parameter _and_ being discarded,
and fix the case where their subexpression can't be classified.

Fixes https://github.com/llvm/llvm-project/issues/174668
2026-01-07 14:49:23 +01:00
Timm Baeder
fed6db45df
[clang][bytecode] Diagnose dereferencing a null pointer (#149330) 2025-07-19 21:39:06 +02:00
Corentin Jabot
9e5470e7d6
[Clang] Diagnose forming references to nullptr (#143667)
Per [decl.ref],

> Because a null pointer value or a pointer past the end of an object
does not point to an object, a reference in a well-defined program
cannot refer to such things.

Note this does not fixes the new bytecode interpreter.

Fixes #48665
2025-07-16 14:25:24 +02:00
Mariya Podchishchaeva
1d65c35ce1
[clang] Reject _Complex _BitInt (#119402)
The C standard doesn't require support for these types and Codegen for
these types is incorrect ATM.
See https://github.com/llvm/llvm-project/issues/119352
2024-12-12 12:19:48 +01:00
Timm Baeder
923b8eea64
[clang][bytecode] Allow ArrayElemPtr ops on null pointers (#113132)
This regresses one of the _Complex test cases a bit, but since the
diagnostic output wasn't very good here in the first place, let's ignore
it.
2024-10-21 09:52:07 +02:00
Timm Baeder
40db261551
[clang][bytecode] Fix #55390 here as well (#106395)
Ignore the multiplication overflow but report the 0 denominator.
2024-08-28 19:09:12 +02:00
Timm Baeder
a07aba5d44
[clang] Rename all AST/Interp stuff to AST/ByteCode (#104552)
"Interp" clashes with the clang interpreter and people often confuse
this.
2024-08-16 17:13:12 +02:00