diff options
author | Timm Baeder <tbaeder@redhat.com> | 2025-04-17 12:50:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-17 12:50:28 +0200 |
commit | 90ddb5444030b8d7cca6e91a27994e4fa9a6525d (patch) | |
tree | 9d1e3da299aa15e28d8aa411485647c468b699df /clang/lib/AST | |
parent | d69ee885cccecb49f0b288ec634186c35c8ecfb5 (diff) | |
download | llvm-90ddb5444030b8d7cca6e91a27994e4fa9a6525d.zip llvm-90ddb5444030b8d7cca6e91a27994e4fa9a6525d.tar.gz llvm-90ddb5444030b8d7cca6e91a27994e4fa9a6525d.tar.bz2 |
[clang][bytecode] Enter a non-constant context when revisiting (#136104)
Otherwise, things like __builtin_is_constant_evaluated() return the
wrong value.
Diffstat (limited to 'clang/lib/AST')
-rw-r--r-- | clang/lib/AST/ByteCode/Compiler.cpp | 5 | ||||
-rw-r--r-- | clang/lib/AST/ByteCode/Interp.h | 9 | ||||
-rw-r--r-- | clang/lib/AST/ByteCode/InterpState.h | 2 | ||||
-rw-r--r-- | clang/lib/AST/ByteCode/Opcodes.td | 3 |
4 files changed, 18 insertions, 1 deletions
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 157e306..d3eabc5 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -6466,8 +6466,13 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) { // In case we need to re-visit a declaration. auto revisit = [&](const VarDecl *VD) -> bool { + if (!this->emitPushCC(VD->hasConstantInitialization(), E)) + return false; auto VarState = this->visitDecl(VD, /*IsConstexprUnknown=*/true); + if (!this->emitPopCC(E)) + return false; + if (VarState.notCreated()) return true; if (!VarState) diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index bd58c2a..49e2326 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -2848,6 +2848,15 @@ inline bool EndSpeculation(InterpState &S, CodePtr OpPC) { return true; } +inline bool PushCC(InterpState &S, CodePtr OpPC, bool Value) { + S.ConstantContextOverride = Value; + return true; +} +inline bool PopCC(InterpState &S, CodePtr OpPC) { + S.ConstantContextOverride = std::nullopt; + return true; +} + /// Do nothing and just abort execution. inline bool Error(InterpState &S, CodePtr OpPC) { return false; } diff --git a/clang/lib/AST/ByteCode/InterpState.h b/clang/lib/AST/ByteCode/InterpState.h index 74001b8..528c1a2 100644 --- a/clang/lib/AST/ByteCode/InterpState.h +++ b/clang/lib/AST/ByteCode/InterpState.h @@ -127,7 +127,6 @@ private: SourceMapper *M; /// Allocator used for dynamic allocations performed via the program. DynamicAllocator Alloc; - std::optional<bool> ConstantContextOverride; public: /// Reference to the module containing all bytecode. @@ -147,6 +146,7 @@ public: /// Things needed to do speculative execution. SmallVectorImpl<PartialDiagnosticAt> *PrevDiags = nullptr; unsigned SpeculationDepth = 0; + std::optional<bool> ConstantContextOverride; llvm::SmallVector< std::pair<const Expr *, const LifetimeExtendedTemporaryDecl *>> diff --git a/clang/lib/AST/ByteCode/Opcodes.td b/clang/lib/AST/ByteCode/Opcodes.td index 5a9079f..8451e54 100644 --- a/clang/lib/AST/ByteCode/Opcodes.td +++ b/clang/lib/AST/ByteCode/Opcodes.td @@ -872,3 +872,6 @@ def GetTypeidPtr : Opcode { let Args = [ArgTypePtr]; } def DiagTypeid : Opcode; def CheckDestruction : Opcode; + +def PushCC : Opcode { let Args = [ArgBool]; } +def PopCC : Opcode; |