22 Commits

Author SHA1 Message Date
Timm Baeder
da05208bfb
[clang][bytecode] Create temporary before discarding CXXConstructExpr (#154280)
Fixes #154110
2025-08-19 10:27:26 +02:00
Timm Baeder
376b3f7049
[clang][bytecode] Devirtualize calls during con- and destruction (#147685)
When compiliung compiling a ctor or dtor, we need to devirtualize the
virtual function calls so we always call the implementation of the
current class.
2025-07-09 14:37:10 +02:00
Timm Baeder
2e70da3fba
[clang][bytecode] Partially address string literal uniqueness (#142555)
This still leaves the case of the

constexpr auto b3 = name1() == name1();

test from cxx20.cpp broken.
2025-06-03 16:26:31 +02:00
Timm Baeder
9a26dff748
[clang][bytecode] Check dtor calls for one-past-end pointers (#140047) 2025-05-15 15:43:07 +02:00
Timm Baeder
b26adacc85
[clang][bytecode] Check destructors for temporaries (#140039)
Also, increase the EvalID in isPotentialConstantExpr(), since this is
its own evaluation.
2025-05-15 14:34:35 +02:00
Henrik G. Olsson
de1af6b727
Eval string one past end reland (#137091)
Relands #137078 after updating clang/test/AST/ByteCode/cxx20.cpp to
account for diagnostic outputs that differ between Linux and macOS.
2025-04-23 20:27:12 -07:00
Henrik G. Olsson
93705c3a76
Revert "[ConstEval] Fix crash when comparing strings past the end" (#137088)
Reverts llvm/llvm-project#137078
2025-04-23 16:48:46 -07:00
Henrik G. Olsson
55160e6a89
[ConstEval] Fix crash when comparing strings past the end (#137078)
When `ArePotentiallyOverlappingStringLiterals`, added in
https://github.com/llvm/llvm-project/pull/109208, compares string
literals it drops the front of the string with the greatest offset from
its base pointer. The number of characters dropped is equal to the
difference between the two strings' offsets from their base pointers.
This would trigger an assert when the resulting offset is past the end
of the object. Not only are one-past-the-end pointers legal constructs,
the compiler should not crash even when faced with illegal constructs.

rdar://149865910
2025-04-23 16:41:21 -07:00
Timm Baeder
e0db41615b
[clang][bytecode] Fix initializing array struct fields from an APValue (#131983)
We need to recurse once more here and move the array case into the
bigger if chain.
2025-03-19 12:43:37 +01:00
Nikita Popov
07f3388fff Revert "[clang] Implement instantiation context note for checking template parameters (#126088)"
This reverts commit a24523ac8dc07f3478311a5969184b922b520395.

This is causing significant compile-time regressions for C++ code, see:
https://github.com/llvm/llvm-project/pull/126088#issuecomment-2704874202
2025-03-10 10:32:08 +01:00
Matheus Izvekov
a24523ac8d
[clang] Implement instantiation context note for checking template parameters (#126088)
Instead of manually adding a note pointing to the relevant template
parameter to every relevant error, which is very easy to miss, this
patch adds a new instantiation context note, so that this can work using
RAII magic.

This fixes a bunch of places where these notes were missing, and is more
future-proof.

Some diagnostics are reworked to make better use of this note:
- Errors about missing template arguments now refer to the parameter
which is missing an argument.
- Template Template parameter mismatches now refer to template
parameters as parameters instead of arguments.

It's likely this will add the note to some diagnostics where the
parameter is not super relevant, but this can be reworked with time and
the decrease in maintenance burden makes up for it.

This bypasses the templight dumper for the new context entry, as the
tests are very hard to update.

This depends on #125453, which is needed to avoid losing the context
note for errors occuring during template argument deduction.
2025-03-06 14:58:42 -03:00
Timm Baeder
1760289340
[clang][bytecode] Fix three-way unordered non-pointer comparisions (#127759)
This _can_ happen with non-pointers, but we shouldn't diagnose it in
that case.
2025-02-19 10:22:37 +01:00
Timm Baeder
ee25a85ccc
[clang][bytecode] Handle CXXPseudoDestructorExprs (#125835)
Make lifetime management more explicit. We're only using this for
CXXPseudoDestructorExprs for now but we need this to handle
std::construct_at/placement-new after destructor calls later anyway.
2025-02-05 12:40:30 +01:00
Timm Baeder
16c721f2d1
[clang][bytecode] Destroy local variables in reverse order (#125727)
See the attached test case.
2025-02-05 08:09:13 +01:00
Timm Baeder
7075eee6bd
[clang][bytecode] Add InitLinkScope for toplevel Expr temporary (#123319) 2025-01-17 12:58:15 +01:00
Timm Baeder
fd6baa477f
[clang][ExprConst] Add diagnostics for invalid binary arithmetic (#118475)
... between unrelated declarations or literals.

Leaving this small (I haven't run the whole test suite locally) to get
some feedback on the wording and implementation first.

The output of the sample in
https://github.com/llvm/llvm-project/issues/117409 is now:
```console
./array.cpp:57:6: warning: expression result unused [-Wunused-value]
   57 |   am - aj.af();
      |   ~~ ^ ~~~~~~~
./array.cpp:70:8: error: call to consteval function 'L::L<bx>' is not a constant expression
   70 |   q(0, [] {
      |        ^
./array.cpp:57:6: note: arithmetic on addresses of literals has unspecified value
   57 |   am - aj.af();
      |      ^
./array.cpp:62:5: note: in call to 'al(&""[0], {&""[0]})'
   62 |     al(bp.af(), k);
      |     ^~~~~~~~~~~~~~
./array.cpp:70:8: note: in call to 'L<bx>({})'
   70 |   q(0, [] {
      |        ^~~~
   71 |     struct bx {
      |     ~~~~~~~~~~~
   72 |       constexpr operator ab<g<l<decltype(""[0])>::e>::e>() { return t(""); }
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   73 |     };
      |     ~~
   74 |     return bx();
      |     ~~~~~~~~~~~~
   75 |   }());
      |   ~~~
```

The output for 
```c++
int a, b;
constexpr int n = &b - &a
```

is now:
```console
./array.cpp:80:15: error: constexpr variable 'n' must be initialized by a constant expression
   80 | constexpr int n = &b - &a;
      |               ^   ~~~~~~~
./array.cpp:80:22: note: arithmetic involving '&b' and '&a' has unspecified value
   80 | constexpr int n = &b - &a;
      |                      ^
1 error generated.

```
2025-01-09 11:42:35 +01:00
Richard Smith
d8a2815903
[clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (#109208)
Track the identity of each string literal object produced by evaluation
with a global version number. Accept comparisons between literals of the
same version, and between literals of different versions that cannot
possibly be placed in overlapping storage. Treat the remaining
comparisons as non-constant.

---------

Co-authored-by: Timm Baeder <tbaeder@redhat.com>
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2024-09-26 15:56:33 -07:00
Timm Bäder
bad544461a [clang][bytecode][NFC] Remove an outdated comment 2024-09-23 11:54:00 +02:00
Timm Bäder
95a0b4f729 Revert "[clang][ExprConst] Allow comparisons with string literals (#106733)"
This reverts commit 5d1d2f08c4a92580e7f6b3b6b77b2b6f6184e126.

See the discussion in https://github.com/llvm/llvm-project/pull/106733
and https://github.com/llvm/llvm-project/issues/58754
2024-09-17 05:58:54 +02:00
Timm Baeder
5d1d2f08c4
[clang][ExprConst] Allow comparisons with string literals (#106733)
Don't diagnose them, but literals still have distinct addresses.

Fixes https://github.com/llvm/llvm-project/issues/58754
2024-09-13 10:30:02 +02:00
Timm Bäder
6a56f15211 [clang][bytecode][NFC] Fix a commented-out test 2024-09-10 14:05:46 +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