Author: Timm Bäder
Date: 2023-07-17T14:02:04+02:00
New Revision: e6afacc0347c8f95678d56692ebc409ae85b162c
URL: 
https://github.com/llvm/llvm-project/commit/e6afacc0347c8f95678d56692ebc409ae85b162c
DIFF: 
https://github.com/llvm/llvm-project/commit/e6afacc0347c8f95678d56692ebc409ae85b162c.diff

LOG: [clang][Interp] Diagnose callsite for implicit functions

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.

Differential Revision: https://reviews.llvm.org/D154761

Added: 
    

Modified: 
    clang/lib/AST/Interp/InterpFrame.cpp
    clang/test/AST/Interp/cxx20.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index d1b6c0d68041e5..2229aa7c08f6b2 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -213,6 +213,11 @@ Pointer InterpFrame::getParamPointer(unsigned Off) {
 }
 
 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);
 }
 

diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index a7d7705c1cefa6..df08bb75199d86 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -623,3 +623,26 @@ namespace BaseAndFieldInit {
   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()'}}
+}


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to