32 Commits

Author SHA1 Message Date
Timm Baeder
46ad7ff4b7
[clang][bytecode] Diagnose non-const initialiers in diagnoseUnknownDecl (#113276)
This is more similar to the diagnostic output of the current interpreter
2024-10-23 05:50:30 +02:00
Timm Bäder
1251687448 [clang][bytecode][NFC] Remove a leftover dump call 2024-10-17 12:40:14 +02:00
yronglin
8079a2c578
[clang][bytecode] Diagnose reference to non-constexpr variable of const type in C23 constexpr (#112211)
```cpp
const int V33 = 4;
const int V34 = 0;
const int V35 = 2;

constexpr int V36 = V33 / V34;
// expected-error@-1 {{constexpr variable 'V36' must be initialized by a constant expression}}
constexpr int V37 = V33 / V35;
// expected-error@-1 {{constexpr variable 'V37' must be initialized by a constant expression}}
```

---------

Signed-off-by: yronglin <yronglin777@gmail.com>
2024-10-16 00:11:12 +08:00
Timm Baeder
f93258e4ac
[clang][bytecode] Diagnose class-specific operator delete calls (#111700) 2024-10-10 08:40:14 +02:00
Timm Baeder
e637a5c9fe
[clang][bytecode] Only allow lossless ptr-to-int casts (#111669)
Only allow those casts if the bitwidth of the two types match.
2024-10-09 17:13:22 +02:00
Timm Baeder
fed8695bb8
[clang][bytecode] Emit better diagnostic for invalid shufflevector index (#111643) 2024-10-09 09:56:37 +02:00
bd1976bris
d2051919bb
[MSVC] work-around for compile time issue 102513 (#110986)
Disable optimizations when building clang/lib/AST/ByteCode/Interp.cpp
with Microsoft's compiler as it has a bug that causes excessive build
times. We do this only when NDEBUG is not defined on the assumption that
building without asserts indicates that a user is strongly invested in
runtime performance.

Partially addresses: https://github.com/llvm/llvm-project/issues/102513.

Once the bug is addressed in the Microsoft compiler this can be removed.

Co-authored-by: dyung
2024-10-04 14:59:41 +01:00
Timm Baeder
95ce78b742
[clang][bytecode] Implement fixed-point-to-int casts (#110417)
And some cleanups around overflow handling.
2024-09-29 13:31:44 +02:00
Timm Baeder
d9b377d8b1
[clang][bytecode] Don't produce a null type when checking new exprs (#110252)
getType() might give us the right type already, so use that instead of
calling getPointeeType() for all CXXNewExprs.
2024-09-27 17:48:43 +02:00
Timm Baeder
09cd5a8673
[clang][bytecode] Refuse to contruct objects with virtual bases (#110142) 2024-09-27 05:56:12 +02:00
Timm Baeder
a024a0ceed
[clang][bytecode] Override InConstantContext flag for immediate calls (#109967)
And fix the diagnostics for __builtin_is_constant_evaluated(). We can be
in a non-constant context, but calling an immediate function always
makes the context constant for the duration of that call.
2024-09-25 16:46:46 +02:00
Timm Baeder
4bd3a62cd6
[clang][bytecode] Fix diagnosing std::construct_at with wrong type (#109828)
We can't make the assumption that types are always fine in std
functions.
2024-09-25 08:00:32 +02:00
Timm Baeder
4b96400240
[clang][bytecode] Allow placement-new in std functions pre-C++26 (#109753) 2024-09-24 10:28:54 +02:00
Timm Baeder
c712ab829b
[clang][bytecode] Implement placement-new (#107033)
If we have a placement-new destination already, use that instead of
allocating a new one.
Tests are partially based on
`test/SemaCXX/cxx2c-constexpr-placement-new.cpp`.
2024-09-23 13:26:49 +02:00
Timm Baeder
f86050de73
[clang][bytecode] Don't call checkLiteralType() in visitInitializer() (#109530)
We were calling checkLiteralType() too many time and rejecting some
things we shouldn't. Add The calls manually when handling
MaterializeTemporaryExprs. Maybe we should call it in other places as
well, but adding more calls is easier than removing them from a generic
code path.
2024-09-21 20:01:21 +02:00
Timm Baeder
c57b9f5a13
[clang][bytecode] Fix reporting non-constant variables in C (#109516)
We need to call FFDiag() to get the usual "invalid subexpression"
diagnostic.
2024-09-21 09:58:56 +02:00
Timm Baeder
97aa8cc94d
[clang][bytecode] Diagnose weak reads in final load (#109515)
They aren't allowed here either.
2024-09-21 09:10:31 +02:00
Timm Baeder
d267daa9eb
[clang][bytecode] Diagnose loads from weak variables (#109256) 2024-09-19 11:59:38 +02:00
Timm Baeder
f22a8d1822
[clang][bytecode] Fix modify_global diagnostics in C++11 (#108358)
We shouldn't emit this until C++14.
2024-09-12 13:25:25 +02:00
Timm Bäder
46870175c5 [clang][bytecode][NFC] Fix CallBI function signature
This doesn't modify the PC, so pass OpPC as a copy.
2024-09-10 13:32:25 +02:00
Timm Baeder
78cf9b830c
[clang][bytecode] Implement using operator new/operator delete (#107679)
Reuse the __builtin_operator_{new,delete} implementations.
2024-09-07 12:17:54 +02:00
Timm Baeder
610b85395d
[clang][bytecode] Implement __builtin_operator{new,delete} (#107672) 2024-09-07 09:57:26 +02:00
Timm Baeder
83fea8b809
[clang][bytecode] Allow continuing when discarded MemberExpr Base fails (#107231)
We don't need the value in this case, since we're discarding it anyway.
Allow continuing the interpretation but note the side effect.
2024-09-07 09:33:27 +02:00
Timm Baeder
f70ccdaeb4
[clang][bytecode][NFC] Move Call ops into Interp.cpp (#107104)
They are quite long and not templated.
2024-09-03 16:15:58 +02:00
Timm Baeder
0f5f440f24
[clang][bytecode] Pass FPOptions to floating point ops (#107063)
So we don't have to retrieve them from the InterpFrame, which is slow.
2024-09-03 14:24:11 +02:00
Timm Baeder
e4f3b56dae
[clang][bytecode] Fix diagnosing reads from temporaries (#106868)
Fix the DeclID not being set in global temporaries and use the same
strategy for deciding if a temporary is readable as the current
interpreter.
2024-09-01 07:40:43 +02:00
Timm Baeder
e4cf0a047d
[clang][bytecode][NFC] Check for custom typechecking in call cleanup (#106826)
The comment already explains that this is only true for _some_ builtin
functions. This also brings the time it takes me to run the
builtin-functions.cpp test locally from 50s down to 47s.
2024-08-31 08:06:06 +02:00
Timm Baeder
df11ee213e
[clang][bytecode] Diagnose member calls on deleted blocks (#106529)
This requires a bit of restructuring of ctor calls when checking for a
potential constant expression.
2024-08-29 15:22:59 +02:00
Timm Baeder
cb608cc5f6
[clang][bytecode] Properly diagnose non-const reads (#106514)
If the global variable is constant (but not constexpr), we need to
diagnose, but keep evaluating.
2024-08-29 13:44:59 +02:00
yronglin
d9e7286019
[NFC][clang][bytecode] Rename clang::interp::State::getCtx to clang::interp::State::getASTContext (#106071)
The new constant interpreter's `clang::interp::InterpState` contains
both `clang::interp::Context` and `clang::ASTContext`. So using `S.Ctx`
and `S.getCtx()` was a bit confusing. This PR rename `getCtx()` to
`getASTContext` to make things more clearer.

Signed-off-by: yronglin <yronglin777@gmail.com>
2024-08-26 22:23:07 +08:00
Timm Baeder
a14c730990
[clang][bytecode] Fix diagnostic in final ltor cast (#105292)
Don't diagnose volatile reads but diagnose a few other accesses earlier.
2024-08-21 08:08:32 +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