Manna created this revision.
Manna added a reviewer: tahonermann.
Herald added subscribers: mattd, gchakrabarti, asavonic, manas, ASDenysPetrov,
dkrupp, donat.nagy, Szelethus, a.sidorin, baloghadamsoftware.
Herald added a project: All.
Manna requested review of this revision.
Herald added a project: clang.
In getNVPTXLaneID(CodeGenFunction &), the value of LaneIDBits is 4294967295
since function call
llvm::Log2_32(CGF->getTarget()->getGridValue().GV_Warp_Size) might return
4294967295.
unsigned LaneIDBits =
llvm::Log2_32(CGF.getTarget().getGridValue().GV_Warp_Size);
unsigned LaneIDMask = ~0u >> (32u - LaneIDBits);
`
The shift amount (32U - LaneIDBits) might be 33, So it has undefined behavior
for right shifting by more than 31 bits.
This patch adds an assert to guard the LaneIDBits overflow issue with
LaneIDMask value.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D151606
Files:
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===================================================================
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -528,6 +528,8 @@
CGBuilderTy &Bld = CGF.Builder;
unsigned LaneIDBits =
llvm::Log2_32(CGF.getTarget().getGridValue().GV_Warp_Size);
+ assert((32U - LaneIDBits) <= 33 &&
+ "Invalid LaneIDBits size in NVPTX device.");
unsigned LaneIDMask = ~0u >> (32u - LaneIDBits);
auto &RT = static_cast<CGOpenMPRuntimeGPU &>(CGF.CGM.getOpenMPRuntime());
return Bld.CreateAnd(RT.getGPUThreadID(CGF), Bld.getInt32(LaneIDMask),
Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===================================================================
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -528,6 +528,8 @@
CGBuilderTy &Bld = CGF.Builder;
unsigned LaneIDBits =
llvm::Log2_32(CGF.getTarget().getGridValue().GV_Warp_Size);
+ assert((32U - LaneIDBits) <= 33 &&
+ "Invalid LaneIDBits size in NVPTX device.");
unsigned LaneIDMask = ~0u >> (32u - LaneIDBits);
auto &RT = static_cast<CGOpenMPRuntimeGPU &>(CGF.CGM.getOpenMPRuntime());
return Bld.CreateAnd(RT.getGPUThreadID(CGF), Bld.getInt32(LaneIDMask),
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits