util/cacheinfo: Fix warning generated by clang
PATCH 1/1 util/cacheinfo: Fix warning generated by clang
Clang generates the following warning on aarch64 host:
CC util/cacheinfo.o/home/pranith/qemu/util/cacheinfo.c:121:48: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]
asm volatile("mrs\t%0, ctr_el0" : "=r"(ctr));
^
/home/pranith/qemu/util/cacheinfo.c:121:28: note: use constraint modifier "w"
asm volatile("mrs\t%0, ctr_el0" : "=r"(ctr));
^~
%w0Constraint modifier 'w' is not (yet?) accepted by gcc. Fix this by increasing the ctr size.
--- util/cacheinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/cacheinfo.c +1 -1
@@ -112,7 +112,7 @@ static void sys_cache_info(int *isize, int *dsize)static void arch_cache_info (int *isize,int *dsize) {if (*isize ==0 || *dsize ==0 ) { -unsigned ctr; +unsigned long ctr;/* The real cache geometry is in CCSIDR_EL1/CLIDR_EL1/CSSELR_EL1, but (at least under Linux) these are marked protected by the
Signature · 1 line
2.13.0
Quoted 11 lines · Pranith Kumar
Clang generates the following warning on aarch64 host:
CC
util/cacheinfo.o/home/pranith/qemu/util/cacheinfo.c:121:48: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]asm volatile("mrs\t%0, ctr_el0" : "=r"(ctr)); ^ /home/pranith/qemu/util/cacheinfo.c:121:28: note: use constraint modifier "w" asm volatile("mrs\t%0, ctr_el0" : "=r"(ctr)); ^~ %w0
Quoted 3 lines
Constraint modifier 'w' is not (yet?) accepted by gcc. Fix this by increasing the ctr size.
Signed-off-by Pranith Kumar <[email protected]>
I can reproduce with clang 3.9.1.
Thanks,
Emilio
Quoted 10 lines · Pranith Kumar
Clang generates the following warning on aarch64 host:
CC
util/cacheinfo.o/home/pranith/qemu/util/cacheinfo.c:121:48: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]asm volatile("mrs\t%0, ctr_el0" : "=r"(ctr)); ^ /home/pranith/qemu/util/cacheinfo.c:121:28: note: use constraint modifier "w" asm volatile("mrs\t%0, ctr_el0" : "=r"(ctr)); ^~ %w0
That is an absolutely stupid warning. There's long precedent for the compiler choosing the prefix for you based on the type of the argument.
Quoted 2 lines
Constraint modifier 'w' is not (yet?) accepted by gcc. Fix this by increasing the ctr size.
Certainly it is -- since the beginning of time.
r~
Quoted 17 lines · Richard Henderson
Quoted 7 lines · Pranith Kumar
Clang generates the following warning on aarch64 host:
CC
util/cacheinfo.o/home/pranith/qemu/util/cacheinfo.c:121:48: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]Quoted 7 lines
asm volatile("mrs\t%0, ctr_el0" : "=r"(ctr)); ^ /home/pranith/qemu/util/cacheinfo.c:121:28: note: use constraint modifier "w" asm volatile("mrs\t%0, ctr_el0" : "=r"(ctr)); ^~ %w0
Quoted 2 lines
That is an absolutely stupid warning. There's long precedent for the compiler choosing the prefix for you based on the type of the argument.
Isn't that the problem? The type of the argument says "32 bits" but the instruction here really wants 64 bits (MRS takes Xn, not Wn).
thanks
-- PMM
Quoted 18 lines · Peter Maydell
Quoted 17 lines · Richard Henderson
Quoted 14 lines · Pranith Kumar
Clang generates the following warning on aarch64 host:
CC
util/cacheinfo.o/home/pranith/qemu/util/cacheinfo.c:121:48: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]asm volatile("mrs\t%0, ctr_el0" : "=r"(ctr)); ^ /home/pranith/qemu/util/cacheinfo.c:121:28: note: use constraint modifier "w" asm volatile("mrs\t%0, ctr_el0" : "=r"(ctr)); ^~ %w0
Quoted 5 lines
Quoted 2 lines
That is an absolutely stupid warning. There's long precedent for the compiler choosing the prefix for you based on the type of the argument.
Isn't that the problem? The type of the argument says "32 bits" but the instruction here really wants 64 bits (MRS takes Xn, not Wn).
The warning is telling me to use %w to force Wn. So if the assembler really doesn't like Wn, the warning is a bit more than confusing.
Perhaps it ought to be telling me to use %x to force Xn in spite of the type?
r~
Quoted 7 lines · Richard Henderson
Quoted 6 lines · Peter Maydell
Quoted 2 lines · Richard Henderson
That is an absolutely stupid warning. There's long precedent for the compiler choosing the prefix for you based on the type of the argument.
Quoted 6 lines
Quoted 2 lines
Isn't that the problem? The type of the argument says "32 bits" but the instruction here really wants 64 bits (MRS takes Xn, not Wn).
The warning is telling me to use %w to force Wn. So if the assembler really doesn't like Wn, the warning is a bit more than confusing.
Wouldn't be the first time a compiler has produced a confusing warning :-)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63359 includes some previous gcc-vs-clang-dev discussion on the topic of the warning. It looks like the clang dev rationale is that having %0 always generate a 64-bit register access even when passed a 32-bit value is confusing (eg people expect "str %0, [addr]" : ... : "r" (var_32bits)" to do a 32 bit store, not a 64 bit store), so better to warn and nudge the code author into being explicit about the size they wanted.
Quoted 2 lines
Perhaps it ought to be telling me to use %x to force Xn in spite of the type?
You always get Xn anyway, regardless of the type.
For us, I think the right thing to do is make 'ctr' be a uint64_t, because we're reading a 64 bit sysreg and silently truncating it as a side effect of the asm constraints is a bit obscure.
thanks
-- PMM
Quoted 9 lines · Peter Maydell
Quoted 2 lines · Richard Henderson
Perhaps it ought to be telling me to use %x to force Xn in spite of the type?
You always get Xn anyway, regardless of the type.
For us, I think the right thing to do is make 'ctr' be a
uint64_t, because we're reading a 64 bit sysreg and silently truncating it as a side effect of the asm constraints is a bit obscure.
Fair enough. Applied as-is to tcg-next.
r~