67
67
#include " llvm/IR/PassManager.h"
68
68
#include " llvm/IR/Type.h"
69
69
#include " llvm/IR/Value.h"
70
+ #include " llvm/Support/AMDGPUAddrSpace.h"
70
71
#include " llvm/Support/Casting.h"
71
72
#include " llvm/Support/KnownBits.h"
72
73
#include " llvm/Support/raw_ostream.h"
@@ -102,6 +103,8 @@ class Lint : public InstVisitor<Lint> {
102
103
void visitReturnInst (ReturnInst &I);
103
104
void visitLoadInst (LoadInst &I);
104
105
void visitStoreInst (StoreInst &I);
106
+ void visitAtomicCmpXchgInst (AtomicCmpXchgInst &I);
107
+ void visitAtomicRMWInst (AtomicRMWInst &I);
105
108
void visitXor (BinaryOperator &I);
106
109
void visitSub (BinaryOperator &I);
107
110
void visitLShr (BinaryOperator &I);
@@ -124,6 +127,7 @@ class Lint : public InstVisitor<Lint> {
124
127
125
128
public:
126
129
Module *Mod;
130
+ Triple TT;
127
131
const DataLayout *DL;
128
132
AliasAnalysis *AA;
129
133
AssumptionCache *AC;
@@ -135,8 +139,8 @@ class Lint : public InstVisitor<Lint> {
135
139
136
140
Lint (Module *Mod, const DataLayout *DL, AliasAnalysis *AA,
137
141
AssumptionCache *AC, DominatorTree *DT, TargetLibraryInfo *TLI)
138
- : Mod(Mod), DL(DL), AA(AA), AC(AC), DT(DT ), TLI(TLI ),
139
- MessagesStr (Messages) {}
142
+ : Mod(Mod), TT(Triple::normalize(Mod-> getTargetTriple ())), DL(DL ), AA(AA ),
143
+ AC(AC), DT(DT), TLI(TLI), MessagesStr(Messages) {}
140
144
141
145
void WriteValues (ArrayRef<const Value *> Vs) {
142
146
for (const Value *V : Vs) {
@@ -401,6 +405,11 @@ void Lint::visitMemoryReference(Instruction &I, const MemoryLocation &Loc,
401
405
" Unusual: Address one pointer dereference" , &I);
402
406
403
407
if (Flags & MemRef::Write) {
408
+ if (TT.isAMDGPU ())
409
+ Check (!AMDGPU::isConstantAddressSpace (
410
+ UnderlyingObject->getType ()->getPointerAddressSpace ()),
411
+ " Undefined behavior: Write to memory in const addrspace" , &I);
412
+
404
413
if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(UnderlyingObject))
405
414
Check (!GV->isConstant (), " Undefined behavior: Write to read-only memory" ,
406
415
&I);
@@ -480,6 +489,16 @@ void Lint::visitStoreInst(StoreInst &I) {
480
489
I.getOperand (0 )->getType (), MemRef::Write);
481
490
}
482
491
492
+ void Lint::visitAtomicCmpXchgInst (AtomicCmpXchgInst &I) {
493
+ visitMemoryReference (I, MemoryLocation::get (&I), I.getAlign (),
494
+ I.getOperand (0 )->getType (), MemRef::Write);
495
+ }
496
+
497
+ void Lint::visitAtomicRMWInst (AtomicRMWInst &I) {
498
+ visitMemoryReference (I, MemoryLocation::get (&I), I.getAlign (),
499
+ I.getOperand (0 )->getType (), MemRef::Write);
500
+ }
501
+
483
502
void Lint::visitXor (BinaryOperator &I) {
484
503
Check (!isa<UndefValue>(I.getOperand (0 )) || !isa<UndefValue>(I.getOperand (1 )),
485
504
" Undefined result: xor(undef, undef)" , &I);
0 commit comments