Skip to content

Commit 393311c

Browse files
committed
Add negative test, move isConstantAddressSpace
1 parent 4553484 commit 393311c

File tree

3 files changed

+43
-36
lines changed

3 files changed

+43
-36
lines changed

llvm/include/llvm/Support/AMDGPUAddrSpace.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,33 @@ inline bool isExtendedGlobalAddrSpace(unsigned AS) {
9393
AS == AMDGPUAS::CONSTANT_ADDRESS_32BIT ||
9494
AS > AMDGPUAS::MAX_AMDGPU_ADDRESS;
9595
}
96+
97+
inline bool isConstantAddressSpace(unsigned AS) {
98+
switch(AS) {
99+
using namespace AMDGPUAS;
100+
case CONSTANT_ADDRESS:
101+
case CONSTANT_ADDRESS_32BIT:
102+
case CONSTANT_BUFFER_0:
103+
case CONSTANT_BUFFER_1:
104+
case CONSTANT_BUFFER_2:
105+
case CONSTANT_BUFFER_3:
106+
case CONSTANT_BUFFER_4:
107+
case CONSTANT_BUFFER_5:
108+
case CONSTANT_BUFFER_6:
109+
case CONSTANT_BUFFER_7:
110+
case CONSTANT_BUFFER_8:
111+
case CONSTANT_BUFFER_9:
112+
case CONSTANT_BUFFER_10:
113+
case CONSTANT_BUFFER_11:
114+
case CONSTANT_BUFFER_12:
115+
case CONSTANT_BUFFER_13:
116+
case CONSTANT_BUFFER_14:
117+
case CONSTANT_BUFFER_15:
118+
return true;
119+
default:
120+
return false;
121+
}
122+
}
96123
} // end namespace AMDGPU
97124

98125
} // end namespace llvm

llvm/lib/Analysis/Lint.cpp

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ class Lint : public InstVisitor<Lint> {
122122
Value *findValue(Value *V, bool OffsetOk) const;
123123
Value *findValueImpl(Value *V, bool OffsetOk,
124124
SmallPtrSetImpl<Value *> &Visited) const;
125-
126-
bool isConstantAddressSpace(unsigned AS) const;
127125
public:
128126
Module *Mod;
129127
Triple TT;
@@ -382,36 +380,6 @@ void Lint::visitReturnInst(ReturnInst &I) {
382380
}
383381
}
384382

385-
bool Lint::isConstantAddressSpace(unsigned AS) const {
386-
if (TT.isAMDGPU()) {
387-
switch(AS) {
388-
using namespace AMDGPUAS;
389-
case CONSTANT_ADDRESS:
390-
case CONSTANT_ADDRESS_32BIT:
391-
case CONSTANT_BUFFER_0:
392-
case CONSTANT_BUFFER_1:
393-
case CONSTANT_BUFFER_2:
394-
case CONSTANT_BUFFER_3:
395-
case CONSTANT_BUFFER_4:
396-
case CONSTANT_BUFFER_5:
397-
case CONSTANT_BUFFER_6:
398-
case CONSTANT_BUFFER_7:
399-
case CONSTANT_BUFFER_8:
400-
case CONSTANT_BUFFER_9:
401-
case CONSTANT_BUFFER_10:
402-
case CONSTANT_BUFFER_11:
403-
case CONSTANT_BUFFER_12:
404-
case CONSTANT_BUFFER_13:
405-
case CONSTANT_BUFFER_14:
406-
case CONSTANT_BUFFER_15:
407-
return true;
408-
default:
409-
return false;
410-
}
411-
}
412-
return false;
413-
}
414-
415383
// TODO: Check that the reference is in bounds.
416384
// TODO: Check readnone/readonly function attributes.
417385
void Lint::visitMemoryReference(Instruction &I, const MemoryLocation &Loc,
@@ -435,8 +403,9 @@ void Lint::visitMemoryReference(Instruction &I, const MemoryLocation &Loc,
435403
"Unusual: Address one pointer dereference", &I);
436404

437405
if (Flags & MemRef::Write) {
438-
Check(!isConstantAddressSpace(UnderlyingObject->getType()->getPointerAddressSpace()),
439-
"Undefined behavior: Write to const memory", &I);
406+
if (TT.isAMDGPU())
407+
Check(!AMDGPU::isConstantAddressSpace(UnderlyingObject->getType()->getPointerAddressSpace()),
408+
"Undefined behavior: Write to const memory", &I);
440409

441410
if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(UnderlyingObject))
442411
Check(!GV->isConstant(), "Undefined behavior: Write to read-only memory",
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
; RUN: not opt --mtriple=amdgcn --passes=lint --lint-abort-on-error %s -o - |& FileCheck %s
2-
; RUN: not opt --mtriple=amdgcn --mcpu=gfx1030 --passes=lint --lint-abort-on-error %s -o - |& FileCheck %s
1+
; RUN: not opt --mtriple=amdgcn --passes=lint --lint-abort-on-error %s -o /dev/null |& FileCheck %s
2+
; RUN: opt --mtriple=amdgcn --mcpu=gfx1030 --passes=lint %s -o /dev/null |& FileCheck %s --check-prefixes=CHECK,CHECK0
3+
; RUN: opt --mtriple=x86_64 --passes=lint --lint-abort-on-error %s -o /dev/null |& FileCheck %s --allow-empty --check-prefix=NOERR
4+
; NOERR: {{^$}}
35

46
define amdgpu_kernel void @store_const(ptr addrspace(4) %out, i32 %a, i32 %b) {
57
; CHECK: Undefined behavior: Write to const memory
@@ -8,3 +10,12 @@ define amdgpu_kernel void @store_const(ptr addrspace(4) %out, i32 %a, i32 %b) {
810
store i32 %r, ptr addrspace(4) %out
911
ret void
1012
}
13+
14+
define amdgpu_kernel void @memcpy_to_const(ptr addrspace(6) %dst, ptr %src) {
15+
; CHECK0: Undefined behavior: Write to const memory
16+
; CHECK0-NEXT: call void @llvm.memcpy.p6.p0.i32(ptr addrspace(6) %dst, ptr %src, i32 256, i1 false)
17+
call void @llvm.memcpy.px.py.i32(ptr addrspace(6) %dst, ptr %src, i32 256, i1 false)
18+
ret void
19+
}
20+
21+
declare void @llvm.memcpy.px.py.i32(ptr addrspace(6) noalias nocapture writeonly, ptr noalias nocapture readonly, i32, i1 immarg)

0 commit comments

Comments
 (0)