[clang] 0d26f65 - [clang][Interp] Emit diagnostics if final ltor conversion fails
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 20 01:01:47 PDT 2024
Author: Timm Bäder
Date: 2024-07-20T10:01:25+02:00
New Revision: 0d26f65414afe496b00ee803cc24722a9bf3f41d
URL: https://github.com/llvm/llvm-project/commit/0d26f65414afe496b00ee803cc24722a9bf3f41d
DIFF: https://github.com/llvm/llvm-project/commit/0d26f65414afe496b00ee803cc24722a9bf3f41d.diff
LOG: [clang][Interp] Emit diagnostics if final ltor conversion fails
Added:
Modified:
clang/lib/AST/Interp/EvalEmitter.cpp
clang/test/AST/Interp/cxx11.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp b/clang/lib/AST/Interp/EvalEmitter.cpp
index 59e78686b78ad..221bbfdc542ff 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -169,7 +169,9 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) {
return false;
// Never allow reading from a non-const pointer, unless the memory
// has been created in this evaluation.
- if (!Ptr.isConst() && Ptr.block()->getEvalID() != Ctx.getEvalID())
+ if (!Ptr.isZero() && Ptr.isBlockPointer() &&
+ Ptr.block()->getEvalID() != Ctx.getEvalID() &&
+ (!CheckLoad(S, OpPC, Ptr, AK_Read) || !Ptr.isConst()))
return false;
if (std::optional<APValue> V =
diff --git a/clang/test/AST/Interp/cxx11.cpp b/clang/test/AST/Interp/cxx11.cpp
index 92ab9b605f30d..cf2dfba079ef7 100644
--- a/clang/test/AST/Interp/cxx11.cpp
+++ b/clang/test/AST/Interp/cxx11.cpp
@@ -152,3 +152,11 @@ void A::f(SortOrder order) {
return;
}
}
+
+namespace FinalLtorDiags {
+ template<int*> struct A {}; // both-note {{template parameter is declared here}}
+ int k;
+ int *q = &k; // both-note {{declared here}}
+ A<q> c; // both-error {{non-type template argument of type 'int *' is not a constant expression}} \
+ // both-note {{read of non-constexpr variable 'q' is not allowed in a constant expression}}
+}
More information about the cfe-commits
mailing list