aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/Interp.cpp
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2025-03-31 18:53:01 +0200
committerGitHub <noreply@github.com>2025-03-31 18:53:01 +0200
commit11dd7d98a6ecd2374289b6a217e358e503d4778a (patch)
tree484d99766328a2d9598fe50a0b7af9b4945f5115 /clang/lib/AST/ByteCode/Interp.cpp
parent9cdab16da99ad9fdb823853fbc634008229e284f (diff)
downloadllvm-11dd7d98a6ecd2374289b6a217e358e503d4778a.zip
llvm-11dd7d98a6ecd2374289b6a217e358e503d4778a.tar.gz
llvm-11dd7d98a6ecd2374289b6a217e358e503d4778a.tar.bz2
[clang][bytecode] Reject constexpr-unknown values from comparisons (#133701)
Diffstat (limited to 'clang/lib/AST/ByteCode/Interp.cpp')
-rw-r--r--clang/lib/AST/ByteCode/Interp.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 1874777..0acfe01 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -302,6 +302,17 @@ void cleanupAfterFunctionCall(InterpState &S, CodePtr OpPC,
TYPE_SWITCH(Ty, S.Stk.discard<T>());
}
+// FIXME: Instead of using this fairly expensive test, we should
+// just mark constexpr-unknown values when creating them.
+bool isConstexprUnknown(const Pointer &P) {
+ if (!P.isBlockPointer())
+ return false;
+ if (P.isDummy())
+ return false;
+ const VarDecl *VD = P.block()->getDescriptor()->asVarDecl();
+ return VD && VD->hasLocalStorage();
+}
+
bool CheckBCPResult(InterpState &S, const Pointer &Ptr) {
if (Ptr.isDummy())
return false;
@@ -607,11 +618,8 @@ bool CheckMutable(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
// variables in Compiler.cpp:visitDeclRef. Revisiting a so far
// unknown variable will get the same EvalID and we end up allowing
// reads from mutable members of it.
- if (!S.inConstantContext()) {
- if (const VarDecl *VD = Ptr.block()->getDescriptor()->asVarDecl();
- VD && VD->hasLocalStorage())
- return false;
- }
+ if (!S.inConstantContext() && isConstexprUnknown(Ptr))
+ return false;
return true;
}