Skip to content

Commit dab30b9

Browse files
Disable "downcast of address" UBSAN runtime error (#6448)
This is a temporary workaround until we fix: #6446 This should allow us to enable asan/ubsan checks: #6428 --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 7581ff4 commit dab30b9

File tree

12 files changed

+168
-16
lines changed

12 files changed

+168
-16
lines changed

include/llvm/ADT/SparseBitVector.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,19 @@ struct ilist_traits<SparseBitVectorElement<ElementSize> >
248248
: public ilist_default_traits<SparseBitVectorElement<ElementSize> > {
249249
typedef SparseBitVectorElement<ElementSize> Element;
250250

251-
Element *createSentinel() const { return static_cast<Element *>(&Sentinel); }
251+
// HLSL Change Starts
252+
// Temporarily disable "downcast of address" UBSAN runtime error
253+
// https://github.com/microsoft/DirectXShaderCompiler/issues/6446
254+
#ifdef __has_feature
255+
#if __has_feature(undefined_behavior_sanitizer)
256+
__attribute__((no_sanitize("undefined")))
257+
#endif // __has_feature(address_sanitizer)
258+
#endif // defined(__has_feature)
259+
// HLSL Change Ends
260+
Element *
261+
createSentinel() const {
262+
return static_cast<Element *>(&Sentinel);
263+
}
252264
static void destroySentinel(Element *) {}
253265

254266
Element *provideInitialHead() const { return createSentinel(); }

include/llvm/Analysis/IVUsers.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,17 @@ template<> struct ilist_traits<IVStrideUse>
9696
// the list...
9797
// The sentinel is relative to this instance, so we use a non-static
9898
// method.
99-
IVStrideUse *createSentinel() const {
99+
// HLSL Change Starts
100+
// Temporarily disable "downcast of address" UBSAN runtime error
101+
// https://github.com/microsoft/DirectXShaderCompiler/issues/6446
102+
#ifdef __has_feature
103+
#if __has_feature(undefined_behavior_sanitizer)
104+
__attribute__((no_sanitize("undefined")))
105+
#endif // __has_feature(address_sanitizer)
106+
#endif // defined(__has_feature)
107+
// HLSL Change Ends
108+
IVStrideUse *
109+
createSentinel() const {
100110
// since i(p)lists always publicly derive from the corresponding
101111
// traits, placing a data member in this class will augment i(p)list.
102112
// But since the NodeTy is expected to publicly derive from

include/llvm/CodeGen/MachineBasicBlock.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,17 @@ struct ilist_traits<MachineInstr> : public ilist_default_traits<MachineInstr> {
4040
MachineBasicBlock* Parent;
4141

4242
public:
43-
MachineInstr *createSentinel() const {
43+
// HLSL Change Starts
44+
// Temporarily disable "downcast of address" UBSAN runtime error
45+
// https://github.com/microsoft/DirectXShaderCompiler/issues/6446
46+
#ifdef __has_feature
47+
#if __has_feature(undefined_behavior_sanitizer)
48+
__attribute__((no_sanitize("undefined")))
49+
#endif // __has_feature(address_sanitizer)
50+
#endif // defined(__has_feature)
51+
// HLSL Change Ends
52+
MachineInstr *
53+
createSentinel() const {
4454
return static_cast<MachineInstr*>(&Sentinel);
4555
}
4656
void destroySentinel(MachineInstr *) const {}

include/llvm/CodeGen/MachineFunction.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,17 @@ struct ilist_traits<MachineBasicBlock>
4848
: public ilist_default_traits<MachineBasicBlock> {
4949
mutable ilist_half_node<MachineBasicBlock> Sentinel;
5050
public:
51-
MachineBasicBlock *createSentinel() const {
51+
// HLSL Change Starts
52+
// Temporarily disable "downcast of address" UBSAN runtime error
53+
// https://github.com/microsoft/DirectXShaderCompiler/issues/6446
54+
#ifdef __has_feature
55+
#if __has_feature(undefined_behavior_sanitizer)
56+
__attribute__((no_sanitize("undefined")))
57+
#endif // __has_feature(address_sanitizer)
58+
#endif // defined(__has_feature)
59+
// HLSL Change Ends
60+
MachineBasicBlock *
61+
createSentinel() const {
5262
return static_cast<MachineBasicBlock*>(&Sentinel);
5363
}
5464
void destroySentinel(MachineBasicBlock *) const {}

include/llvm/CodeGen/SelectionDAG.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,17 @@ template<> struct ilist_traits<SDNode> : public ilist_default_traits<SDNode> {
8484
private:
8585
mutable ilist_half_node<SDNode> Sentinel;
8686
public:
87-
SDNode *createSentinel() const {
87+
// HLSL Change Starts
88+
// Temporarily disable "downcast of address" UBSAN runtime error
89+
// https://github.com/microsoft/DirectXShaderCompiler/issues/6446
90+
#ifdef __has_feature
91+
#if __has_feature(undefined_behavior_sanitizer)
92+
__attribute__((no_sanitize("undefined")))
93+
#endif // __has_feature(address_sanitizer)
94+
#endif // defined(__has_feature)
95+
// HLSL Change Ends
96+
SDNode *
97+
createSentinel() const {
8898
return static_cast<SDNode*>(&Sentinel);
8999
}
90100
static void destroySentinel(SDNode *) {}

include/llvm/CodeGen/SlotIndexes.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,17 @@ namespace llvm {
7474
private:
7575
mutable ilist_half_node<IndexListEntry> Sentinel;
7676
public:
77-
IndexListEntry *createSentinel() const {
77+
// HLSL Change Starts
78+
// Temporarily disable "downcast of address" UBSAN runtime error
79+
// https://github.com/microsoft/DirectXShaderCompiler/issues/6446
80+
#ifdef __has_feature
81+
#if __has_feature(undefined_behavior_sanitizer)
82+
__attribute__((no_sanitize("undefined")))
83+
#endif // __has_feature(address_sanitizer)
84+
#endif // defined(__has_feature)
85+
// HLSL Change Ends
86+
IndexListEntry *
87+
createSentinel() const {
7888
return static_cast<IndexListEntry*>(&Sentinel);
7989
}
8090
void destroySentinel(IndexListEntry *) const {}

include/llvm/IR/BasicBlock.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,18 @@ class BasicBlock : public Value, // Basic blocks are data objects also
341341

342342
// createSentinel is used to get hold of the node that marks the end of the
343343
// list... (same trick used here as in ilist_traits<Instruction>)
344-
inline BasicBlock *ilist_traits<BasicBlock>::createSentinel() const {
345-
return static_cast<BasicBlock*>(&Sentinel);
344+
// HLSL Change Starts
345+
// Temporarily disable "downcast of address" UBSAN runtime error
346+
// https://github.com/microsoft/DirectXShaderCompiler/issues/6446
347+
#ifdef __has_feature
348+
#if __has_feature(undefined_behavior_sanitizer)
349+
__attribute__((no_sanitize("undefined")))
350+
#endif // __has_feature(address_sanitizer)
351+
#endif // defined(__has_feature)
352+
// HLSL Change Ends
353+
inline BasicBlock *
354+
ilist_traits<BasicBlock>::createSentinel() const {
355+
return static_cast<BasicBlock *>(&Sentinel);
346356
}
347357

348358
// Create wrappers for C Binding types (see CBindingWrapping.h).

include/llvm/IR/Function.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,17 @@ class LLVMContext;
3636
template<> struct ilist_traits<Argument>
3737
: public SymbolTableListTraits<Argument, Function> {
3838

39-
Argument *createSentinel() const {
39+
// HLSL Change Starts
40+
// Temporarily disable "downcast of address" UBSAN runtime error
41+
// https://github.com/microsoft/DirectXShaderCompiler/issues/6446
42+
#ifdef __has_feature
43+
#if __has_feature(undefined_behavior_sanitizer)
44+
__attribute__((no_sanitize("undefined")))
45+
#endif // __has_feature(address_sanitizer)
46+
#endif // defined(__has_feature)
47+
// HLSL Change Ends
48+
Argument *
49+
createSentinel() const {
4050
return static_cast<Argument*>(&Sentinel);
4151
}
4252
static void destroySentinel(Argument*) {}

include/llvm/IR/Instruction.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,17 @@ class Instruction : public User, public ilist_node<Instruction> {
515515
Instruction *cloneImpl() const;
516516
};
517517

518-
inline Instruction *ilist_traits<Instruction>::createSentinel() const {
518+
// HLSL Change Starts
519+
// Temporarily disable "downcast of address" UBSAN runtime error
520+
// https://github.com/microsoft/DirectXShaderCompiler/issues/6446
521+
#ifdef __has_feature
522+
#if __has_feature(undefined_behavior_sanitizer)
523+
__attribute__((no_sanitize("undefined")))
524+
#endif // __has_feature(address_sanitizer)
525+
#endif // defined(__has_feature)
526+
// HLSL Change Ends
527+
inline Instruction *
528+
ilist_traits<Instruction>::createSentinel() const {
519529
// Since i(p)lists always publicly derive from their corresponding traits,
520530
// placing a data member in this class will augment the i(p)list. But since
521531
// the NodeTy is expected to be publicly derive from ilist_node<NodeTy>,

include/llvm/IR/Module.h

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ template<> struct ilist_traits<Function>
4646

4747
// createSentinel is used to get hold of the node that marks the end of the
4848
// list... (same trick used here as in ilist_traits<Instruction>)
49-
Function *createSentinel() const {
49+
// HLSL Change Starts
50+
// Temporarily disable "downcast of address" UBSAN runtime error
51+
// https://github.com/microsoft/DirectXShaderCompiler/issues/6446
52+
#ifdef __has_feature
53+
#if __has_feature(undefined_behavior_sanitizer)
54+
__attribute__((no_sanitize("undefined")))
55+
#endif // __has_feature(address_sanitizer)
56+
#endif // defined(__has_feature)
57+
// HLSL Change Ends
58+
Function *
59+
createSentinel() const {
5060
return static_cast<Function*>(&Sentinel);
5161
}
5262
static void destroySentinel(Function*) {}
@@ -62,7 +72,17 @@ template<> struct ilist_traits<Function>
6272
template<> struct ilist_traits<GlobalVariable>
6373
: public SymbolTableListTraits<GlobalVariable, Module> {
6474
// createSentinel is used to create a node that marks the end of the list.
65-
GlobalVariable *createSentinel() const {
75+
// HLSL Change Starts
76+
// Temporarily disable "downcast of address" UBSAN runtime error
77+
// https://github.com/microsoft/DirectXShaderCompiler/issues/6446
78+
#ifdef __has_feature
79+
#if __has_feature(undefined_behavior_sanitizer)
80+
__attribute__((no_sanitize("undefined")))
81+
#endif // __has_feature(address_sanitizer)
82+
#endif // defined(__has_feature)
83+
// HLSL Change Ends
84+
GlobalVariable *
85+
createSentinel() const {
6686
return static_cast<GlobalVariable*>(&Sentinel);
6787
}
6888
static void destroySentinel(GlobalVariable*) {}
@@ -77,7 +97,17 @@ template<> struct ilist_traits<GlobalVariable>
7797
template<> struct ilist_traits<GlobalAlias>
7898
: public SymbolTableListTraits<GlobalAlias, Module> {
7999
// createSentinel is used to create a node that marks the end of the list.
80-
GlobalAlias *createSentinel() const {
100+
// HLSL Change Starts
101+
// Temporarily disable "downcast of address" UBSAN runtime error
102+
// https://github.com/microsoft/DirectXShaderCompiler/issues/6446
103+
#ifdef __has_feature
104+
#if __has_feature(undefined_behavior_sanitizer)
105+
__attribute__((no_sanitize("undefined")))
106+
#endif // __has_feature(address_sanitizer)
107+
#endif // defined(__has_feature)
108+
// HLSL Change Ends
109+
GlobalAlias *
110+
createSentinel() const {
81111
return static_cast<GlobalAlias*>(&Sentinel);
82112
}
83113
static void destroySentinel(GlobalAlias*) {}
@@ -93,7 +123,17 @@ template<> struct ilist_traits<NamedMDNode>
93123
: public ilist_default_traits<NamedMDNode> {
94124
// createSentinel is used to get hold of a node that marks the end of
95125
// the list...
96-
NamedMDNode *createSentinel() const {
126+
// HLSL Change Starts
127+
// Temporarily disable "downcast of address" UBSAN runtime error
128+
// https://github.com/microsoft/DirectXShaderCompiler/issues/6446
129+
#ifdef __has_feature
130+
#if __has_feature(undefined_behavior_sanitizer)
131+
__attribute__((no_sanitize("undefined")))
132+
#endif // __has_feature(address_sanitizer)
133+
#endif // defined(__has_feature)
134+
// HLSL Change Ends
135+
NamedMDNode *
136+
createSentinel() const {
97137
return static_cast<NamedMDNode*>(&Sentinel);
98138
}
99139
static void destroySentinel(NamedMDNode*) {}

0 commit comments

Comments
 (0)