[clang] Fix GCC warning by enclosing operand with parentheses. (PR #230939)

via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 11 03:21:45 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Douglas Yung (dyung)

<details>
<summary>Changes</summary>

PR #<!-- -->174549 made a change to `APValue.h` which causes GCC to emit a warning like this:
```
clang/include/clang/AST/APValue.h: In static member function ‘static clang::DynamicAllocLValue clang::DynamicAllocLValue::getFromOpaqueValue(const void*)’:
clang/include/clang/AST/APValue.h:114:54: warning: suggest parentheses around ‘-’ in operand of ‘&’ [-Wparentheses]
  114 |     V.AllocKind = Combined & (1 << NumAllocKindBits) - 1;
      |                              ~~~~~~~~~~~~~~~~~~~~~~~~^~~
```

>From my build with gcc, this shows up around 1200 times in the logfile for my build. The problem with this is that for distributed builds, this forces the build of the file where the warning is emitted to be done locally which causes a bottleneck. This fixes the source of the warning so that the build of the files which include `APValue.h` can again be distributed.

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


1 Files Affected:

- (modified) clang/include/clang/AST/APValue.h (+1-1) 


``````````diff
diff --git a/clang/include/clang/AST/APValue.h b/clang/include/clang/AST/APValue.h
index 54e51b7e2fd34..7a69a98702a8c 100644
--- a/clang/include/clang/AST/APValue.h
+++ b/clang/include/clang/AST/APValue.h
@@ -112,7 +112,7 @@ class DynamicAllocLValue {
     DynamicAllocLValue V;
     uintptr_t Combined =
         reinterpret_cast<uintptr_t>(Value) >> NumLowBitsAvailable;
-    V.AllocKind = Combined & (1 << NumAllocKindBits) - 1;
+    V.AllocKind = Combined & ((1 << NumAllocKindBits) - 1);
     V.Index = Combined >> NumAllocKindBits;
     return V;
   }

``````````

</details>


https://github.com/llvm/llvm-project/pull/230939


More information about the cfe-commits mailing list