[PATCH] D81952: Fix ubsan error in tblgen with signed left shift
Stanislav Mekhanoshin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 16 11:00:15 PDT 2020
rampitec created this revision.
rampitec added a reviewer: arsenm.
Herald added subscribers: kerbowa, hiraditya, nhaehnle, wdng, jvesely.
Herald added a project: LLVM.
UBSAN complains when tblgen performs SHL of a negative
value.
https://reviews.llvm.org/D81952
Files:
llvm/lib/TableGen/Record.cpp
llvm/lib/Target/AMDGPU/SMInstructions.td
Index: llvm/lib/Target/AMDGPU/SMInstructions.td
===================================================================
--- llvm/lib/Target/AMDGPU/SMInstructions.td
+++ llvm/lib/Target/AMDGPU/SMInstructions.td
@@ -860,7 +860,7 @@
def : GCNPat <
(i64 (readcyclecounter)),
(REG_SEQUENCE SReg_64,
- (S_GETREG_B32 -26595), sub0,
+ (S_GETREG_B32 getHwRegImm<HWREG.SHADER_CYCLES, 0, -12>.ret), sub0,
(S_MOV_B32 (i32 0)), sub1)
>;
} // let OtherPredicates = [HasNoSMemTimeInst]
Index: llvm/lib/TableGen/Record.cpp
===================================================================
--- llvm/lib/TableGen/Record.cpp
+++ llvm/lib/TableGen/Record.cpp
@@ -1030,7 +1030,7 @@
case MUL: Result = LHSv * RHSv; break;
case AND: Result = LHSv & RHSv; break;
case OR: Result = LHSv | RHSv; break;
- case SHL: Result = LHSv << RHSv; break;
+ case SHL: Result = (uint64_t)LHSv << (uint64_t)RHSv; break;
case SRA: Result = LHSv >> RHSv; break;
case SRL: Result = (uint64_t)LHSv >> (uint64_t)RHSv; break;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81952.271139.patch
Type: text/x-patch
Size: 1055 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200616/e5ffb858/attachment-0001.bin>
More information about the llvm-commits
mailing list