Author: Timm Baeder Date: 2026-08-31T09:25:47+02:00 New Revision: a6baa3f0fe3a959cca13bd4cb84b604d29d88530
URL: https://github.com/llvm/llvm-project/commit/a6baa3f0fe3a959cca13bd4cb84b604d29d88530 DIFF: https://github.com/llvm/llvm-project/commit/a6baa3f0fe3a959cca13bd4cb84b604d29d88530.diff LOG: [clang][bytecode] Keep sourcemaps smaller (#219878) 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. Added: Modified: clang/lib/AST/ByteCode/ByteCodeEmitter.cpp clang/lib/AST/ByteCode/InterpFrame.cpp clang/lib/AST/ByteCode/Source.h clang/test/AST/ByteCode/virtual-bases.cpp Removed: ################################################################################ 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 37548f47f9082..9422bd47c7c60 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 { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
