6767#include " llvm/IR/PassManager.h"
6868#include " llvm/IR/Type.h"
6969#include " llvm/IR/Value.h"
70+ #include " llvm/Support/AMDGPUAddrSpace.h"
7071#include " llvm/Support/Casting.h"
7172#include " llvm/Support/KnownBits.h"
7273#include " llvm/Support/raw_ostream.h"
@@ -102,6 +103,8 @@ class Lint : public InstVisitor<Lint> {
102103 void visitReturnInst (ReturnInst &I);
103104 void visitLoadInst (LoadInst &I);
104105 void visitStoreInst (StoreInst &I);
106+ void visitAtomicCmpXchgInst (AtomicCmpXchgInst &I);
107+ void visitAtomicRMWInst (AtomicRMWInst &I);
105108 void visitXor (BinaryOperator &I);
106109 void visitSub (BinaryOperator &I);
107110 void visitLShr (BinaryOperator &I);
@@ -124,6 +127,7 @@ class Lint : public InstVisitor<Lint> {
124127
125128public:
126129 Module *Mod;
130+ Triple TT;
127131 const DataLayout *DL;
128132 AliasAnalysis *AA;
129133 AssumptionCache *AC;
@@ -135,8 +139,8 @@ class Lint : public InstVisitor<Lint> {
135139
136140 Lint (Module *Mod, const DataLayout *DL, AliasAnalysis *AA,
137141 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) {}
140144
141145 void WriteValues (ArrayRef<const Value *> Vs) {
142146 for (const Value *V : Vs) {
@@ -401,6 +405,11 @@ void Lint::visitMemoryReference(Instruction &I, const MemoryLocation &Loc,
401405 " Unusual: Address one pointer dereference" , &I);
402406
403407 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+
404413 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(UnderlyingObject))
405414 Check (!GV->isConstant (), " Undefined behavior: Write to read-only memory" ,
406415 &I);
@@ -480,6 +489,16 @@ void Lint::visitStoreInst(StoreInst &I) {
480489 I.getOperand (0 )->getType (), MemRef::Write);
481490}
482491
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+
483502void Lint::visitXor (BinaryOperator &I) {
484503 Check (!isa<UndefValue>(I.getOperand (0 )) || !isa<UndefValue>(I.getOperand (1 )),
485504 " Undefined result: xor(undef, undef)" , &I);
0 commit comments