diff options
| author | Yonghong Song <yhs@fb.com> | 2022-03-12 11:05:40 -0800 |
|---|---|---|
| committer | Yonghong Song <yhs@fb.com> | 2022-03-21 14:59:03 -0700 |
| commit | bdf69f63df2cf4c9e3cd1af5cfcd503bc8e2869b (patch) | |
| tree | cc9547c10a34016e47884107a929c6c179020202 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
| parent | cc5b0868ff6a8203a45b82654ab936406d69594d (diff) | |
[Clang] Fix an unused-but-set-variable warning with volatile variable
For the following code,
void test() {
volatile int j = 0;
for (int i = 0; i < 1000; i++)
j += 1;
return;
}
If compiled with
clang -g -Wall -Werror -S -emit-llvm test.c
we will see the following error:
test.c:2:6: error: variable 'j' set but not used [-Werror,-Wunused-but-set-variable]
volatile int j = 0;
^
This is not quite right since 'j' is indeed used due to '+=' operator.
gcc doesn't emit error either in this case.
Also if we change 'j += 1' to 'j++', the warning will disappear
with latest clang.
Note that clang will issue the warning if the volatile declaration
involves only simple assignment (var = ...).
To fix the issue, in function MaybeDecrementCount(), if the
operator is a compound assignment (i.e., +=, -=, etc.) and the
variable is volatile, the count for RefsMinusAssignments will be
decremented, similar to 'j++' case.
Differential Revision: https://reviews.llvm.org/D121715
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
0 files changed, 0 insertions, 0 deletions
