# Suspicious use volatile qualified variable in Clang codegen tests

**URL:** <https://discourse.llvm.org/t/suspicious-use-volatile-qualified-variable-in-clang-codegen-tests/90837>\
**Category:** PowerPC\
**Tags:** clang\
**Created:** [May 19, 2026, 2:09pm UTC](https://discourse.llvm.org/t/suspicious-use-volatile-qualified-variable-in-clang-codegen-tests/90837 "2026-05-19T14:09:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seraphimt](https://sea1.discourse-cdn.com/flex021/user_avatar/discourse.llvm.org/seraphimt/32/25416_2.png) [@Seraphimt](https://discourse.llvm.org/u/Seraphimt)\
**Post date:** [May 19, 2026, 2:09pm UTC](https://discourse.llvm.org/t/suspicious-use-volatile-qualified-variable-in-clang-codegen-tests/90837/1 "2026-05-19T14:09:24Z")

</div>

Hi! I expanded unsequence check in Clang and found suspicious use volatile qualified variable in several tests:  
\clang\test\CodeGen\PowerPC\builtins-ppc-fma.c  
\clang\test\CodeGen\PowerPC\builtins-ppc-fpconstrained.c  
For C and C++ standards order of evaluate funcall argument is unsequence(or indeterminate sequence) and unsequence access for same volatile variable is UB, but I don’t know if that extends to this compiler builtin.

Example from builtins-ppc-fma.c:

```auto
volatile vec_float vf;

void test_fma(void) {
vf = __builtin_vsx_xvmaddasp(vf, vf, vf);
…
}

```

Is it correct reworking them like this?

```auto
volatile vec_float vf, vf1, vf2, vf3;

void test_fma(void) {
vf = __builtin_vsx_xvmaddasp(vf1, vf2, vf3);
…
}

```

---

<div class="post-metadata">

**Author:** ![jhuber6](https://sea1.discourse-cdn.com/flex021/user_avatar/discourse.llvm.org/jhuber6/32/2235_2.png) [@jhuber6](https://discourse.llvm.org/u/jhuber6)\
**Post date:** [May 19, 2026, 3:01pm UTC](https://discourse.llvm.org/t/suspicious-use-volatile-qualified-variable-in-clang-codegen-tests/90837/2 "2026-05-19T15:01:26Z")

</div>

Volatile forces explicit loads and stores, so I would just expect this to be three separate loads in arbitrary order followed by one store. The reads are unsequenced, but there’s no side-effects without a write, which only happens at the end, which is sequenced. I’m not a language lawyer though.

---

<div class="post-metadata">

**Author:** ![Seraphimt](https://sea1.discourse-cdn.com/flex021/user_avatar/discourse.llvm.org/seraphimt/32/25416_2.png) [@Seraphimt](https://discourse.llvm.org/u/Seraphimt)\
**Post date:** [May 19, 2026, 6:16pm UTC](https://discourse.llvm.org/t/suspicious-use-volatile-qualified-variable-in-clang-codegen-tests/90837/3 "2026-05-19T18:16:41Z")

</div>

> [@jhuber6](#):
>
> but there’s no side-effects without a write

I far I understand, according C\C++ standards, read volatile qualified variable is already side-effects.

---

<div class="post-metadata">

**Author:** ![reinterpretcast](https://sea1.discourse-cdn.com/flex021/user_avatar/discourse.llvm.org/reinterpretcast/32/2099_2.png) [@reinterpretcast](https://discourse.llvm.org/u/reinterpretcast)\
**Post date:** [May 20, 2026, 2:00am UTC](https://discourse.llvm.org/t/suspicious-use-volatile-qualified-variable-in-clang-codegen-tests/90837/4 "2026-05-20T02:00:09Z")

</div>

> [@Seraphimt](#):
>
> Is it correct reworking them like this?

I think you can ignore the possibility of the built-in having any special semantics that suppresses the undefined behaviour from unsequenced side effects on the same memory location.

---

<div class="post-metadata">

**Author:** ![Seraphimt](https://sea1.discourse-cdn.com/flex021/user_avatar/discourse.llvm.org/seraphimt/32/25416_2.png) [@Seraphimt](https://discourse.llvm.org/u/Seraphimt)\
**Post date:** [June 8, 2026, 5:38pm UTC](https://discourse.llvm.org/t/suspicious-use-volatile-qualified-variable-in-clang-codegen-tests/90837/5 "2026-06-08T17:38:55Z")

</div>

Hi! I created PR that fixes these tests. Could someone familiar with powerPC please review PR.

> <https://github.com/llvm/llvm-project/pull/199338>
>
> When trying to add new Sema check in PR https://github.com/llvm/llvm-project/pul…l/180955 some tests failed.
> The following pattern is observed in these tests:
> \`\`\`
> volatile x;
> x = \_\_builtinXXX(x, x, x);
> 
> \`\`\`
> For C and C++ standards order of evaluate funcall argument is unsequence(or indeterminate sequence) and unsequence access for same volatile variable is UB(because read volatile qualified variable is side-effects).
> 
> As far as I undestand, unsequenced accesses is unwanted and new warning is correct. 
> This PR try to fix it for tests:
> \`\`\`
> \\clang\\test\\CodeGen\\PowerPC\\builtins-ppc-fma.c
> \\clang\\test\\CodeGen\\PowerPC\\builtins-ppc-fpconstrained.c
> \`\`\`
> Topics on discourse: https://discourse.llvm.org/t/suspicious-use-volatile-qualified-variable-in-clang-codegen-tests/90837
> Closed similar issue for SystemZ : https://github.com/llvm/llvm-project/issues/186584
