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);
 }
 


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);
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to