[Bug 2015686] [NEW] %z[asmSymbolicName] in AssemblerTemplate fails to compile
Leyun Gao
2015686 at bugs.launchpad.net
Sun Apr 9 16:01:47 UTC 2023
Public bug reported:
Ubuntu 22.04.2 LTS
g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
When use modifier `z` on `[asmSymbolicName]`, the code won't compile.
Below shows the source file to trigger the bug.
Unexpectedly, the error report says the wrong modifier is 'Z', but what
I use is actually 'z'. I believe that something must go wrong when GCC
addresses the modifier 'z' followed by [asmSymbolicName].
/*- test.cpp -*/
/*
* This file reports a bug about asm compilation.
*
* When use modifier `z` on `[asmSymbolicName]`,
* the code won't compile.
*
* Ref: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
*/
#include <cstdio>
#include <cinttypes>
#define TRIGGER_ERROR
#ifdef TRIGGER_ERROR
// This one doesn't compiles.
// the one's complement addition on x86_64
template<class T>
inline T onec_add(T a, T b)
{
asm( "add%z[b]\t%[b], %[a]"
"\n\tadc%z[b]\t$0, %[a]"
: [a]"+g"(a) // inputs
: [b]"g"(b) // outputs
: "cc" // clobbers
);
return a;
}
/*
$g++ --version
g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
$ g++ -Wall -g -Og test.cpp -o test
test.cpp: In function ‘int main()’:
test.cpp:42:3: error: invalid 'asm': invalid operand type used with operand code 'Z'
42 | asm( "add%z[b]\t%[b], %[a]"
| ^~~
test.cpp:42:3: error: invalid 'asm': invalid operand type used with operand code 'Z'
test.cpp:42:3: error: invalid 'asm': invalid operand type used with operand code 'Z'
42 | asm( "add%z[b]\t%[b], %[a]"
| ^~~
test.cpp:42:3: error: invalid 'asm': invalid operand type used with operand code 'Z'
test.cpp:42:3: error: invalid 'asm': invalid operand type used with operand code 'Z'
42 | asm( "add%z[b]\t%[b], %[a]"
| ^~~
test.cpp:42:3: error: invalid 'asm': invalid operand type used with operand code 'Z'
test.cpp:42:3: error: invalid 'asm': invalid operand type used with operand code 'Z'
42 | asm( "add%z[b]\t%[b], %[a]"
| ^~~
test.cpp:42:3: error: invalid 'asm': invalid operand type used with operand code 'Z'
*/
#else /* TRIGGER_ERROR */
// This one compiles normally.
// the one's complement addition on x86_64
template<class T>
inline T onec_add(T a, T b)
{
asm( "add%z0\t%[b], %[a]" // NOTE: %z[b] -> %z0
"\n\tadc%z0\t$0, %[a]"
: [a]"+g"(a) // inputs
: [b]"g"(b) // outputs
: "cc" // clobbers
);
return a;
}
#endif /* TRIGGER_ERROR */
int main()
{
{
uint64_t a = ((uint64_t)1 << 63);
uint64_t b = 1;
uint64_t c = onec_add(a, b);
printf("%#" PRIx64 "\n", c); // expect: 0x8000000000000001
}
{
uint32_t a = ((uint32_t)1 << 31);
uint32_t b = 1;
uint32_t c = onec_add(a, b);
printf("%#" PRIx32 "\n", c); // expect: 0x80000001
}
{
uint16_t a = ((uint16_t)1 << 15);
uint16_t b = 1;
uint16_t c = onec_add(a, b);
printf("%#" PRIx16 "\n", c); // expect: 0x8001
}
{
uint8_t a = ((uint8_t)1 << 7);
uint8_t b = 1;
uint8_t c = onec_add(a, b);
printf("%#" PRIx8 "\n", c); // expect: 0x81
}
}
** Affects: gcc-11 (Ubuntu)
Importance: Undecided
Status: New
** Tags: asm
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to gcc-11 in Ubuntu.
https://bugs.launchpad.net/bugs/2015686
Title:
%z[asmSymbolicName] in AssemblerTemplate fails to compile
Status in gcc-11 package in Ubuntu:
New
Bug description:
Ubuntu 22.04.2 LTS
g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
When use modifier `z` on `[asmSymbolicName]`, the code won't compile.
Below shows the source file to trigger the bug.
Unexpectedly, the error report says the wrong modifier is 'Z', but
what I use is actually 'z'. I believe that something must go wrong
when GCC addresses the modifier 'z' followed by [asmSymbolicName].
/*- test.cpp -*/
/*
* This file reports a bug about asm compilation.
*
* When use modifier `z` on `[asmSymbolicName]`,
* the code won't compile.
*
* Ref: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
*/
#include <cstdio>
#include <cinttypes>
#define TRIGGER_ERROR
#ifdef TRIGGER_ERROR
// This one doesn't compiles.
// the one's complement addition on x86_64
template<class T>
inline T onec_add(T a, T b)
{
asm( "add%z[b]\t%[b], %[a]"
"\n\tadc%z[b]\t$0, %[a]"
: [a]"+g"(a) // inputs
: [b]"g"(b) // outputs
: "cc" // clobbers
);
return a;
}
/*
$g++ --version
g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
$ g++ -Wall -g -Og test.cpp -o test
test.cpp: In function ‘int main()’:
test.cpp:42:3: error: invalid 'asm': invalid operand type used with operand code 'Z'
42 | asm( "add%z[b]\t%[b], %[a]"
| ^~~
test.cpp:42:3: error: invalid 'asm': invalid operand type used with operand code 'Z'
test.cpp:42:3: error: invalid 'asm': invalid operand type used with operand code 'Z'
42 | asm( "add%z[b]\t%[b], %[a]"
| ^~~
test.cpp:42:3: error: invalid 'asm': invalid operand type used with operand code 'Z'
test.cpp:42:3: error: invalid 'asm': invalid operand type used with operand code 'Z'
42 | asm( "add%z[b]\t%[b], %[a]"
| ^~~
test.cpp:42:3: error: invalid 'asm': invalid operand type used with operand code 'Z'
test.cpp:42:3: error: invalid 'asm': invalid operand type used with operand code 'Z'
42 | asm( "add%z[b]\t%[b], %[a]"
| ^~~
test.cpp:42:3: error: invalid 'asm': invalid operand type used with operand code 'Z'
*/
#else /* TRIGGER_ERROR */
// This one compiles normally.
// the one's complement addition on x86_64
template<class T>
inline T onec_add(T a, T b)
{
asm( "add%z0\t%[b], %[a]" // NOTE: %z[b] -> %z0
"\n\tadc%z0\t$0, %[a]"
: [a]"+g"(a) // inputs
: [b]"g"(b) // outputs
: "cc" // clobbers
);
return a;
}
#endif /* TRIGGER_ERROR */
int main()
{
{
uint64_t a = ((uint64_t)1 << 63);
uint64_t b = 1;
uint64_t c = onec_add(a, b);
printf("%#" PRIx64 "\n", c); // expect: 0x8000000000000001
}
{
uint32_t a = ((uint32_t)1 << 31);
uint32_t b = 1;
uint32_t c = onec_add(a, b);
printf("%#" PRIx32 "\n", c); // expect: 0x80000001
}
{
uint16_t a = ((uint16_t)1 << 15);
uint16_t b = 1;
uint16_t c = onec_add(a, b);
printf("%#" PRIx16 "\n", c); // expect: 0x8001
}
{
uint8_t a = ((uint8_t)1 << 7);
uint8_t b = 1;
uint8_t c = onec_add(a, b);
printf("%#" PRIx8 "\n", c); // expect: 0x81
}
}
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-11/+bug/2015686/+subscriptions
More information about the foundations-bugs
mailing list