[PATCH] D154761: [clang][Interp] Diagnose callsite for implicit functions
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 8 01:46:57 PDT 2023
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
We don't have any code to point at here, so the diagnostics would just
point to the record declaration. Make them point to the call site
intead.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D154761
Files:
clang/lib/AST/Interp/InterpFrame.cpp
clang/test/AST/Interp/cxx20.cpp
Index: clang/test/AST/Interp/cxx20.cpp
===================================================================
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -623,3 +623,26 @@
constexpr C c = {1,2,3};
static_assert(c.a == 1 && c.b == 2 && c.c == 3);
}
+
+namespace ImplicitFunction {
+ struct A {
+ int a; // ref-note {{subobject declared here}}
+ };
+
+ constexpr int callMe() {
+ A a;
+ A b{12};
+
+ /// The operator= call here will fail and the diagnostics should be fine.
+ b = a; // ref-note {{subobject 'a' is not initialized}} \
+ // ref-note {{in call to}} \
+ // expected-note {{read of uninitialized object}} \
+ // expected-note {{in call to}}
+
+ return 1;
+ }
+ static_assert(callMe() == 1, ""); // ref-error {{not an integral constant expression}} \
+ // ref-note {{in call to 'callMe()'}} \
+ // expected-error {{not an integral constant expression}} \
+ // expected-note {{in call to 'callMe()'}}
+}
Index: clang/lib/AST/Interp/InterpFrame.cpp
===================================================================
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -213,6 +213,11 @@
}
SourceInfo InterpFrame::getSource(CodePtr PC) const {
+ // Implicitly created functions don't have any code we could point at,
+ // so return the call site.
+ if (Func && Func->getDecl()->isImplicit() && Caller)
+ return Caller->getSource(RetPC);
+
return S.getSource(Func, PC);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154761.538335.patch
Type: text/x-patch
Size: 1611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230708/276908ef/attachment.bin>
More information about the cfe-commits
mailing list