[PATCH] D146775: Summary:[amdgpu] Fix broken error detection in LDS lowering

Jon Chesterfield via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 23 17:42:13 PDT 2023


JonChesterfield created this revision.
JonChesterfield added a reviewer: arsenm.
Herald added subscribers: kosarev, foad, kerbowa, hiraditya, tpr, dstuttard, yaxunl, jvesely, kzhuravl.
Herald added a project: All.
JonChesterfield requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

std::optional<uint32_t> can be compared to uint32_t without warning, but does
not compare to the value within the optional. It needs to be prefixed *.
Wconversion does not warn about this.

bool bug(uint32_t Offset, std::optional<uint32_t> Expect)
{

  return (Offset != Expect);

}
bool deref(uint32_t Offset, std::optional<uint32_t> Expect)
{

  return (Offset != *Expect);

}

Both compile without warnings. Wrote the former, intended the latter.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146775

Files:
  llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp


Index: llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp
@@ -135,7 +135,7 @@
     if (GV && !canElideModuleLDS(F)) {
       unsigned Offset = allocateLDSGlobal(M->getDataLayout(), *GV, Align());
       std::optional<uint32_t> Expect = getLDSAbsoluteAddress(*GV);
-      if (!Expect || (Offset != Expect)) {
+      if (!Expect || (Offset != *Expect)) {
         report_fatal_error("Inconsistent metadata on module LDS variable");
       }
     }
@@ -145,7 +145,7 @@
       // before any other non-module LDS variables.
       unsigned Offset = allocateLDSGlobal(M->getDataLayout(), *KV, Align());
       std::optional<uint32_t> Expect = getLDSAbsoluteAddress(*KV);
-      if (!Expect || (Offset != Expect)) {
+      if (!Expect || (Offset != *Expect)) {
         report_fatal_error("Inconsistent metadata on kernel LDS variable");
       }
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146775.507928.patch
Type: text/x-patch
Size: 1019 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230324/9ac77ec9/attachment.bin>


More information about the llvm-commits mailing list