Skip to content

Commit 246f933

Browse files
committed
[llvm-debuginfo-analyzer] Use LLVM_BUILD_DEBUG in class definitions
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. See #139098 for details. Instead, rely on `LLVM_BUILD_DEBUG` for class definitions.
1 parent bf142c5 commit 246f933

15 files changed

+22
-21
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class LVCompare final {
7676
void printItem(LVElement *Element, LVComparePass Pass);
7777
void print(raw_ostream &OS) const;
7878

79-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
79+
#if defined(LLVM_BUILD_DEBUG) || defined(LLVM_ENABLE_DUMP)
8080
void dump() const { print(dbgs()); }
8181
#endif
8282
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class LVLine : public LVElement {
105105
void print(raw_ostream &OS, bool Full = true) const override;
106106
void printExtra(raw_ostream &OS, bool Full = true) const override {}
107107

108-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
108+
#if defined(LLVM_BUILD_DEBUG) || defined(LLVM_ENABLE_DUMP)
109109
void dump() const override { print(dbgs()); }
110110
#endif
111111
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class LVOperation final {
4949

5050
void print(raw_ostream &OS, bool Full = true) const;
5151

52-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
52+
#if defined(LLVM_BUILD_DEBUG) || defined(LLVM_ENABLE_DUMP)
5353
void dump() { print(dbgs()); }
5454
#endif
5555
};
@@ -159,7 +159,7 @@ class LVLocation : public LVObject {
159159
void print(raw_ostream &OS, bool Full = true) const override;
160160
void printExtra(raw_ostream &OS, bool Full = true) const override;
161161

162-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
162+
#if defined(LLVM_BUILD_DEBUG) || defined(LLVM_ENABLE_DUMP)
163163
void dump() const override { print(dbgs()); }
164164
#endif
165165
};

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVOBJECT_H
1616

1717
#include "llvm/BinaryFormat/Dwarf.h"
18+
#include "llvm/Config/llvm-config.h"
1819
#include "llvm/DebugInfo/CodeView/CodeView.h"
1920
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
2021
#include "llvm/DebugInfo/LogicalView/Core/LVSupport.h"
@@ -154,7 +155,7 @@ class LVObject {
154155
// copy constructor to create that object; it is used to print a reference
155156
// to another object and in the case of templates, to print its encoded args.
156157
LVObject(const LVObject &Object) {
157-
#ifndef NDEBUG
158+
#ifdef LLVM_BUILD_DEBUG
158159
incID();
159160
#endif
160161
Properties = Object.Properties;
@@ -165,7 +166,7 @@ class LVObject {
165166
Parent = Object.Parent;
166167
}
167168

168-
#ifndef NDEBUG
169+
#ifdef LLVM_BUILD_DEBUG
169170
// This is an internal ID used for debugging logical elements. It is used
170171
// for cases where an unique offset within the binary input file is not
171172
// available.
@@ -193,7 +194,7 @@ class LVObject {
193194

194195
public:
195196
LVObject() {
196-
#ifndef NDEBUG
197+
#ifdef LLVM_BUILD_DEBUG
197198
incID();
198199
#endif
199200
};
@@ -311,13 +312,13 @@ class LVObject {
311312
// (class attributes, debug ranges, files, directories, etc).
312313
virtual void printExtra(raw_ostream &OS, bool Full = true) const {}
313314

314-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
315+
#if defined(LLVM_BUILD_DEBUG) || defined(LLVM_ENABLE_DUMP)
315316
virtual void dump() const { print(dbgs()); }
316317
#endif
317318

318319
uint64_t getID() const {
319320
return
320-
#ifndef NDEBUG
321+
#ifdef LLVM_BUILD_DEBUG
321322
ID;
322323
#else
323324
0;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ class LVOptions {
435435

436436
void print(raw_ostream &OS) const;
437437

438-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
438+
#if defined(LLVM_BUILD_DEBUG) || defined(LLVM_ENABLE_DUMP)
439439
void dump() const { print(dbgs()); }
440440
#endif
441441
};
@@ -632,7 +632,7 @@ class LVPatterns final {
632632

633633
void print(raw_ostream &OS) const;
634634

635-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
635+
#if defined(LLVM_BUILD_DEBUG) || defined(LLVM_ENABLE_DUMP)
636636
void dump() const { print(dbgs()); }
637637
#endif
638638
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class LVRange final : public LVObject {
8787
void print(raw_ostream &OS, bool Full = true) const override;
8888
void printExtra(raw_ostream &OS, bool Full = true) const override {}
8989

90-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
90+
#if defined(LLVM_BUILD_DEBUG) || defined(LLVM_ENABLE_DUMP)
9191
void dump() const override { print(dbgs()); }
9292
#endif
9393
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class LVReader {
325325
void print(raw_ostream &OS) const;
326326
virtual void printRecords(raw_ostream &OS) const {}
327327

328-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
328+
#if defined(LLVM_BUILD_DEBUG) || defined(LLVM_ENABLE_DUMP)
329329
void dump() const { print(dbgs()); }
330330
#endif
331331
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ class LVScope : public LVElement {
317317
virtual void printWarnings(raw_ostream &OS, bool Full = true) const {}
318318
virtual void printMatchedElements(raw_ostream &OS, bool UseMatchedElements) {}
319319

320-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
320+
#if defined(LLVM_BUILD_DEBUG) || defined(LLVM_ENABLE_DUMP)
321321
void dump() const override { print(dbgs()); }
322322
#endif
323323
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class LVStringPool {
8080
}
8181
}
8282

83-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
83+
#if defined(LLVM_BUILD_DEBUG) || defined(LLVM_ENABLE_DUMP)
8484
void dump() const { print(dbgs()); }
8585
#endif
8686
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class LVSymbol final : public LVElement {
183183
void print(raw_ostream &OS, bool Full = true) const override;
184184
void printExtra(raw_ostream &OS, bool Full = true) const override;
185185

186-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
186+
#if defined(LLVM_BUILD_DEBUG) || defined(LLVM_ENABLE_DUMP)
187187
void dump() const override { print(dbgs()); }
188188
#endif
189189
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class LVType : public LVElement {
139139
void print(raw_ostream &OS, bool Full = true) const override;
140140
void printExtra(raw_ostream &OS, bool Full = true) const override;
141141

142-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
142+
#if defined(LLVM_BUILD_DEBUG) || defined(LLVM_ENABLE_DUMP)
143143
void dump() const override { print(dbgs()); }
144144
#endif
145145
};

llvm/include/llvm/DebugInfo/LogicalView/LVReaderHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class LVReaderHandler {
8888

8989
void print(raw_ostream &OS) const;
9090

91-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
91+
#if defined(LLVM_BUILD_DEBUG) || defined(LLVM_ENABLE_DUMP)
9292
void dump() const { print(dbgs()); }
9393
#endif
9494
};

llvm/include/llvm/DebugInfo/LogicalView/Readers/LVBinaryReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class LVBinaryReader : public LVReader {
232232

233233
void print(raw_ostream &OS) const;
234234

235-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
235+
#if defined(LLVM_BUILD_DEBUG) || defined(LLVM_ENABLE_DUMP)
236236
void dump() const { print(dbgs()); }
237237
#endif
238238
};

llvm/include/llvm/DebugInfo/LogicalView/Readers/LVCodeViewReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class LVCodeViewReader final : public LVBinaryReader {
225225
LogicalVisitor.printRecords(OS);
226226
};
227227

228-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
228+
#if defined(LLVM_BUILD_DEBUG) || defined(LLVM_ENABLE_DUMP)
229229
void dump() const { print(dbgs()); }
230230
#endif
231231
};

llvm/include/llvm/DebugInfo/LogicalView/Readers/LVDWARFReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class LVDWARFReader final : public LVBinaryReader {
146146

147147
void print(raw_ostream &OS) const;
148148

149-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
149+
#if defined(LLVM_BUILD_DEBUG) || defined(LLVM_ENABLE_DUMP)
150150
void dump() const { print(dbgs()); }
151151
#endif
152152
};

0 commit comments

Comments
 (0)