[PATCH] D154761: [clang][Interp] Diagnose callsite for implicit functions

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 17 05:02:53 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe6afacc0347c: [clang][Interp] Diagnose callsite for implicit functions (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154761/new/

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.540958.patch
Type: text/x-patch
Size: 1611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230717/5594cbae/attachment.bin>


More information about the cfe-commits mailing list