aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/Interp.cpp
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2025-04-27 20:02:58 +0200
committerGitHub <noreply@github.com>2025-04-27 20:02:58 +0200
commite045d55dd51bfa6ee4ef29d518393cb57b4dc0c4 (patch)
treeace9dd83a21629c7f3f09bf9f34e30fae9c9f5cd /clang/lib/AST/ByteCode/Interp.cpp
parentb546baff48767d54da03049d4f30690649a5e599 (diff)
downloadllvm-e045d55dd51bfa6ee4ef29d518393cb57b4dc0c4.zip
llvm-e045d55dd51bfa6ee4ef29d518393cb57b4dc0c4.tar.gz
llvm-e045d55dd51bfa6ee4ef29d518393cb57b4dc0c4.tar.bz2
[clang][bytecode] Check for global decls in destructors (#137525)
Destructors can't be called on global variables.
Diffstat (limited to 'clang/lib/AST/ByteCode/Interp.cpp')
-rw-r--r--clang/lib/AST/ByteCode/Interp.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 3711134..080f694 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1387,9 +1387,14 @@ static bool checkConstructor(InterpState &S, CodePtr OpPC, const Function *Func,
return false;
}
-static bool checkDestructor(InterpState &S, CodePtr OpPC, const Function *Func,
- const Pointer &ThisPtr) {
- return CheckActive(S, OpPC, ThisPtr, AK_Destroy);
+bool CheckDestructor(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
+ // Can't call a dtor on a global variable.
+ if (Ptr.block()->isStatic()) {
+ const SourceInfo &E = S.Current->getSource(OpPC);
+ S.FFDiag(E, diag::note_constexpr_modify_global);
+ return false;
+ }
+ return CheckActive(S, OpPC, Ptr, AK_Destroy);
}
static void compileFunction(InterpState &S, const Function *Func) {
@@ -1486,7 +1491,7 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func,
if (Func->isConstructor() && !checkConstructor(S, OpPC, Func, ThisPtr))
return false;
- if (Func->isDestructor() && !checkDestructor(S, OpPC, Func, ThisPtr))
+ if (Func->isDestructor() && !CheckDestructor(S, OpPC, ThisPtr))
return false;
}