diff options
author | Timm Baeder <tbaeder@redhat.com> | 2025-04-27 20:02:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-27 20:02:58 +0200 |
commit | e045d55dd51bfa6ee4ef29d518393cb57b4dc0c4 (patch) | |
tree | ace9dd83a21629c7f3f09bf9f34e30fae9c9f5cd /clang/lib/AST/ByteCode/Interp.cpp | |
parent | b546baff48767d54da03049d4f30690649a5e599 (diff) | |
download | llvm-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.cpp | 13 |
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; } |