llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

Only add new entries if they are different than the currently last entry. This 
means we won't have an entry for _all_ opcodes in the source map anymore.

---
Full diff: https://github.com/llvm/llvm-project/pull/219878.diff


4 Files Affected:

- (modified) clang/lib/AST/ByteCode/ByteCodeEmitter.cpp (+3-3) 
- (modified) clang/lib/AST/ByteCode/InterpFrame.cpp (+1-2) 
- (modified) clang/lib/AST/ByteCode/Source.h (+14-4) 
- (modified) clang/test/AST/ByteCode/virtual-bases.cpp (+2-3) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp 
b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
index 317c86f554c37..def93866fb0c9 100644
--- a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
@@ -209,9 +209,9 @@ bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &...Args, 
SourceInfo SI) {
   // The opcode is followed by arguments. The source info is
   // attached to the address after the opcode.
   emit(P, Code, Op, Success);
-  if (LocOverride)
-    SrcMap.push(Code.size(), *LocOverride);
-  else if (SI)
+
+  SI = LocOverride.value_or(SI);
+  if (SrcMap.empty() || SrcMap.back() != SI)
     SrcMap.push(Code.size(), SI);
 
   (..., emit(P, Code, Args, Success));
diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp 
b/clang/lib/AST/ByteCode/InterpFrame.cpp
index c41190dd26b2d..4ec08deeb3279 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.cpp
+++ b/clang/lib/AST/ByteCode/InterpFrame.cpp
@@ -230,8 +230,7 @@ SourceRange InterpFrame::getCallRange() const {
     if (!C->RetPC)
       continue;
     SourceRange CallRange =
-        C->Caller->Func->getSource(C->getRetOpPC() - sizeof(uintptr_t))
-            .getRange();
+        C->Caller->Func->getSource(C->getRetOpPC()).getRange();
     if (CallRange.isValid())
       return CallRange;
   }
diff --git a/clang/lib/AST/ByteCode/Source.h b/clang/lib/AST/ByteCode/Source.h
index db935da7c7c49..659054aa2c4ff 100644
--- a/clang/lib/AST/ByteCode/Source.h
+++ b/clang/lib/AST/ByteCode/Source.h
@@ -76,7 +76,7 @@ class CodePtr final {
 /// Describes the statement/declaration an opcode was generated from.
 class SourceInfo final {
 public:
-  SourceInfo() {}
+  SourceInfo() : Source(nullptr) {}
   SourceInfo(const Stmt *E) : Source(E) {}
   SourceInfo(const Decl *D) : Source(D) {}
 
@@ -91,7 +91,9 @@ class SourceInfo final {
   }
   const Expr *asExpr() const { return dyn_cast_if_present<Expr>(asStmt()); }
 
-  operator bool() const { return !Source.isNull(); }
+  explicit operator bool() const { return !Source.isNull(); }
+
+  bool operator!=(SourceInfo O) { return Source != O.Source; }
 
 private:
   llvm::PointerUnion<const Decl *, const Stmt *> Source;
@@ -112,13 +114,22 @@ class SourceMap final {
     Infos.push_back(Info);
   }
 
+  bool empty() const { return Offsets.empty(); }
+  SourceInfo back() const { return Infos.back(); }
+
   SourceInfo findSourceForOffset(uint32_t Offset) const {
     assert(!Offsets.empty());
     assert(Offsets.size() == Infos.size());
 #ifndef NDEBUG
     assert(llvm::is_sorted(Offsets));
 #endif
-    const auto *It = llvm::lower_bound(Offsets, Offset);
+
+    // Find the last offset <= Offset.
+    auto *It = llvm::upper_bound(Offsets, Offset);
+    if (It == Offsets.begin())
+      return Infos[0];
+
+    --It;
     return Infos[It - Offsets.begin()];
   }
 };
@@ -127,7 +138,6 @@ class SourceMap final {
 class SourceMapper {
 public:
   virtual ~SourceMapper() {}
-
   /// Returns source information for a given PC in a function.
   virtual SourceInfo getSource(CodePtr PC) const = 0;
 
diff --git a/clang/test/AST/ByteCode/virtual-bases.cpp 
b/clang/test/AST/ByteCode/virtual-bases.cpp
index a7233f2df9c17..f8dabd43749a5 100644
--- a/clang/test/AST/ByteCode/virtual-bases.cpp
+++ b/clang/test/AST/ByteCode/virtual-bases.cpp
@@ -414,12 +414,11 @@ namespace ConstantDestruction {
     }
   };
 
-  struct X : virtual V { // expected-note {{in call to}}
+  struct X : virtual V {
     constexpr X() : V(true) {}
   };
   constexpr X x; // both-error {{constexpr variable 'x' must have constant 
destruction}} \
-                 // both-note {{in call to}} \
-                 // ref-note {{in call to}}
+                 // both-note 2{{in call to}}
 }
 
 namespace Offsets {

``````````

</details>


https://github.com/llvm/llvm-project/pull/219878
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to