Skip to content

Conversation

@kwk
Copy link
Contributor

@kwk kwk commented Dec 4, 2025

Addresses this warning:

/home/fedora/src/llvm-project/main/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp:3358
79: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
 3358 |          (getImm(I.getOperand(4), MRI) && foldImm(I.getOperand(4), MRI) == 0) &&
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
 3359 |              "Cannot translate GEP to OpAccessChain. First index must be 0.");
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@kwk kwk requested a review from s-perron December 4, 2025 12:28
@llvmbot
Copy link
Member

llvmbot commented Dec 4, 2025

@llvm/pr-subscribers-backend-spir-v

Author: Konrad Kleine (kwk)

Changes

Addresses this warning:

/home/fedora/src/llvm-project/main/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp:3358
79: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
 3358 |          (getImm(I.getOperand(4), MRI) && foldImm(I.getOperand(4), MRI) == 0) &&
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
 3359 |              "Cannot translate GEP to OpAccessChain. First index must be 0.");
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Full diff: https://github.com/llvm/llvm-project/pull/170652.diff

1 Files Affected:

  • (modified) llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp (+5-4)
diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
index a2e29366dc4cc..281b36b2225aa 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
@@ -3353,10 +3353,11 @@ bool SPIRVInstructionSelector::selectGEP(Register ResVReg,
                  .addUse(GR.getSPIRVTypeID(ResType))
                  // Object to get a pointer to.
                  .addUse(I.getOperand(3).getReg());
-  assert(Opcode == SPIRV::OpPtrAccessChain ||
-         Opcode == SPIRV::OpInBoundsPtrAccessChain ||
-         (getImm(I.getOperand(4), MRI) && foldImm(I.getOperand(4), MRI) == 0) &&
-             "Cannot translate GEP to OpAccessChain. First index must be 0.");
+  assert(
+      Opcode == SPIRV::OpPtrAccessChain ||
+      Opcode == SPIRV::OpInBoundsPtrAccessChain ||
+      ((getImm(I.getOperand(4), MRI) && foldImm(I.getOperand(4), MRI) == 0) &&
+       "Cannot translate GEP to OpAccessChain. First index must be 0."));
 
   // Adding indices.
   const unsigned StartingIndex =

```
/home/fedora/src/llvm-project/main/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp:3358
79: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
 3358 |          (getImm(I.getOperand(4), MRI) && foldImm(I.getOperand(4), MRI) == 0) &&
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
 3359 |              "Cannot translate GEP to OpAccessChain. First index must be 0.");
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
@kwk kwk force-pushed the add-parenthesis-around-and-within-or branch from b16c0cb to 2401dfa Compare December 4, 2025 12:47
Copy link
Contributor

@Keenuts Keenuts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kwk kwk merged commit 9a23702 into llvm:main Dec 4, 2025
11 checks passed
@kwk kwk deleted the add-parenthesis-around-and-within-or branch December 4, 2025 14:04
kcloudy0717 pushed a commit to kcloudy0717/llvm-project that referenced this pull request Dec 4, 2025
Addresses this warning:

```
/home/fedora/src/llvm-project/main/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp:3358
79: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
 3358 |          (getImm(I.getOperand(4), MRI) && foldImm(I.getOperand(4), MRI) == 0) &&
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
 3359 |              "Cannot translate GEP to OpAccessChain. First index must be 0.");
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants