Skip to content

Commit 383b326

Browse files
authored
[llvm-debuginfo-analyzer] Fix ODR violation in llvm::logicalview::LVObject (#140265)
Some data members are only part of a class definition in a Debug build, e.g. `LVObject::ID`. If `debuginfologicalview` is used as a library, `NDEBUG` cannot be used for this purpose, as this PP macro may have a different definition in a downstream project, which in turn triggers an ODR violation. Fix it by - Making `LVObject::ID` an unconditional data member. - Making `LVObject::dump()` non-virtual. Rationale: `virtual` is not needed (and it calls `print()`, which is virtual anyway). Fixes #139098.
1 parent 0952992 commit 383b326

File tree

10 files changed

+15
-61
lines changed

10 files changed

+15
-61
lines changed

llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,7 @@ INTERNAL
676676
Typically these kind of options are available only in *debug* builds.
677677

678678
:program:`llvm-debuginfo-analyzer` supports these advanced options in
679-
both *release* and *debug* builds, with the exception of the unique ID
680-
that is generated only in *debug* builds.
679+
both *release* and *debug* builds.
681680

682681
.. option:: --internal=<value[,value,...]>
683682

llvm/include/llvm/DebugInfo/LogicalView/Core/LVLine.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ class LLVM_ABI LVLine : public LVElement {
105105

106106
void print(raw_ostream &OS, bool Full = true) const override;
107107
void printExtra(raw_ostream &OS, bool Full = true) const override {}
108-
109-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
110-
void dump() const override { print(dbgs()); }
111-
#endif
112108
};
113109

114110
// Class to represent a DWARF line record object.

llvm/include/llvm/DebugInfo/LogicalView/Core/LVLocation.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class LVOperation final {
5151
LLVM_ABI void print(raw_ostream &OS, bool Full = true) const;
5252

5353
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
54-
void dump() { print(dbgs()); }
54+
void dump() const { print(dbgs()); }
5555
#endif
5656
};
5757

@@ -159,10 +159,6 @@ class LLVM_ABI LVLocation : public LVObject {
159159

160160
void print(raw_ostream &OS, bool Full = true) const override;
161161
void printExtra(raw_ostream &OS, bool Full = true) const override;
162-
163-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
164-
void dump() const override { print(dbgs()); }
165-
#endif
166162
};
167163

168164
class LLVM_ABI LVLocationSymbol final : public LVLocation {

llvm/include/llvm/DebugInfo/LogicalView/Core/LVObject.h

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace logicalview {
3636
using LVSectionIndex = uint64_t;
3737
using LVAddress = uint64_t;
3838
using LVHalf = uint16_t;
39-
using LVLevel = uint32_t;
39+
using LVLevel = uint16_t;
4040
using LVOffset = uint64_t;
4141
using LVSigned = int64_t;
4242
using LVUnsigned = uint64_t;
@@ -129,8 +129,6 @@ class LLVM_ABI LVObject {
129129
HasCodeViewLocation, // CodeView object with debug location.
130130
LastEntry
131131
};
132-
// Typed bitvector with properties for this object.
133-
LVProperties<Property> Properties;
134132

135133
LVOffset Offset = 0;
136134
uint32_t LineNumber = 0;
@@ -140,6 +138,14 @@ class LLVM_ABI LVObject {
140138
dwarf::Attribute Attr;
141139
LVSmall Opcode;
142140
} TagAttrOpcode = {dwarf::DW_TAG_null};
141+
// Typed bitvector with properties for this object.
142+
LVProperties<Property> Properties;
143+
144+
// This is an internal ID used for debugging logical elements. It is used
145+
// for cases where an unique offset within the binary input file is not
146+
// available.
147+
static uint32_t GID;
148+
uint32_t ID = 0;
143149

144150
// The parent of this object (nullptr if the root scope). For locations,
145151
// the parent is a symbol object; otherwise it is a scope object.
@@ -155,9 +161,7 @@ class LLVM_ABI LVObject {
155161
// copy constructor to create that object; it is used to print a reference
156162
// to another object and in the case of templates, to print its encoded args.
157163
LVObject(const LVObject &Object) {
158-
#ifndef NDEBUG
159164
incID();
160-
#endif
161165
Properties = Object.Properties;
162166
Offset = Object.Offset;
163167
LineNumber = Object.LineNumber;
@@ -166,18 +170,10 @@ class LLVM_ABI LVObject {
166170
Parent = Object.Parent;
167171
}
168172

169-
#ifndef NDEBUG
170-
// This is an internal ID used for debugging logical elements. It is used
171-
// for cases where an unique offset within the binary input file is not
172-
// available.
173-
static uint64_t GID;
174-
uint64_t ID = 0;
175-
176173
void incID() {
177174
++GID;
178175
ID = GID;
179176
}
180-
#endif
181177

182178
protected:
183179
// Get a string representation for the given number and discriminator.
@@ -193,11 +189,7 @@ class LLVM_ABI LVObject {
193189
virtual void printFileIndex(raw_ostream &OS, bool Full = true) const {}
194190

195191
public:
196-
LVObject() {
197-
#ifndef NDEBUG
198-
incID();
199-
#endif
200-
};
192+
LVObject() { incID(); };
201193
LVObject &operator=(const LVObject &) = delete;
202194
virtual ~LVObject() = default;
203195

@@ -313,17 +305,10 @@ class LLVM_ABI LVObject {
313305
virtual void printExtra(raw_ostream &OS, bool Full = true) const {}
314306

315307
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
316-
virtual void dump() const { print(dbgs()); }
308+
void dump() const { print(dbgs()); }
317309
#endif
318310

319-
uint64_t getID() const {
320-
return
321-
#ifndef NDEBUG
322-
ID;
323-
#else
324-
0;
325-
#endif
326-
}
311+
uint32_t getID() const { return ID; }
327312
};
328313

329314
} // end namespace logicalview

llvm/include/llvm/DebugInfo/LogicalView/Core/LVRange.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ class LLVM_ABI LVRange final : public LVObject {
8787

8888
void print(raw_ostream &OS, bool Full = true) const override;
8989
void printExtra(raw_ostream &OS, bool Full = true) const override {}
90-
91-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
92-
void dump() const override { print(dbgs()); }
93-
#endif
9490
};
9591

9692
} // end namespace logicalview

llvm/include/llvm/DebugInfo/LogicalView/Core/LVScope.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,6 @@ class LLVM_ABI LVScope : public LVElement {
325325
void printExtra(raw_ostream &OS, bool Full = true) const override;
326326
virtual void printWarnings(raw_ostream &OS, bool Full = true) const {}
327327
virtual void printMatchedElements(raw_ostream &OS, bool UseMatchedElements) {}
328-
329-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
330-
void dump() const override { print(dbgs()); }
331-
#endif
332328
};
333329

334330
// Class to represent a DWARF Union/Structure/Class.

llvm/include/llvm/DebugInfo/LogicalView/Core/LVSymbol.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ class LLVM_ABI LVSymbol final : public LVElement {
183183

184184
void print(raw_ostream &OS, bool Full = true) const override;
185185
void printExtra(raw_ostream &OS, bool Full = true) const override;
186-
187-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
188-
void dump() const override { print(dbgs()); }
189-
#endif
190186
};
191187

192188
} // end namespace logicalview

llvm/include/llvm/DebugInfo/LogicalView/Core/LVType.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ class LLVM_ABI LVType : public LVElement {
146146

147147
void print(raw_ostream &OS, bool Full = true) const override;
148148
void printExtra(raw_ostream &OS, bool Full = true) const override;
149-
150-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
151-
void dump() const override { print(dbgs()); }
152-
#endif
153149
};
154150

155151
// Class to represent DW_TAG_typedef_type.

llvm/lib/DebugInfo/LogicalView/Core/LVObject.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ using namespace llvm::logicalview;
2121

2222
#define DEBUG_TYPE "Object"
2323

24-
#ifndef NDEBUG
25-
uint64_t LVObject::GID = 0;
26-
#endif
24+
uint32_t LVObject::GID = 0;
2725

2826
StringRef llvm::logicalview::typeNone() { return StringRef(); }
2927
StringRef llvm::logicalview::typeVoid() { return "void"; }
@@ -137,10 +135,8 @@ void LVObject::printAttributes(raw_ostream &OS, bool Full, StringRef Name,
137135
}
138136

139137
void LVObject::printAttributes(raw_ostream &OS, bool Full) const {
140-
#ifndef NDEBUG
141138
if (options().getInternalID())
142139
OS << hexSquareString(getID());
143-
#endif
144140
if (options().getCompareExecute() &&
145141
(options().getAttributeAdded() || options().getAttributeMissing()))
146142
OS << (getIsAdded() ? '+' : getIsMissing() ? '-' : ' ');

llvm/lib/DebugInfo/LogicalView/Core/LVOptions.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,10 @@ void LVOptions::resolveDependencies() {
259259
}
260260

261261
void LVOptions::calculateIndentationSize() {
262-
#ifndef NDEBUG
263262
if (getInternalID()) {
264263
std::string String = hexSquareString(0);
265264
IndentationSize += String.length();
266265
}
267-
#endif
268266
if (getCompareExecute() && (getAttributeAdded() || getAttributeMissing()))
269267
++IndentationSize;
270268
if (getAttributeOffset()) {

0 commit comments

Comments
 (0)