[Bug c++/109260] New: -fdump-ada-spec does not support C++ namespaces
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109260 Bug ID: 109260 Summary: -fdump-ada-spec does not support C++ namespaces Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mytbk920423 at gmail dot com Target Milestone: --- For example, the following C++ code has three namespaces: namespace test_ns { namespace test_ns_1 { struct A_Record { int x, y; }; } namespace test_ns_2 { struct A_Record { int x, y, z; }; } } Using g++ -fdump-ada-spec generates the following package, which has declaration conflicts: package test_ns_hh is type A_Record is record x : aliased int; -- test_ns.hh:5 y : aliased int; -- test_ns.hh:5 end record with Convention => C_Pass_By_Copy; -- test_ns.hh:5 type A_Record is record x : aliased int; -- test_ns.hh:10 y : aliased int; -- test_ns.hh:10 z : aliased int; -- test_ns.hh:10 end record with Convention => C_Pass_By_Copy; -- test_ns.hh:10 end test_ns_hh;
[Bug c/102909] Missing -Wunused-but-set-variable warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102909 --- Comment #3 from Iru Cai --- Looks like this kind of things are detected in the front-end. The GNAT front-end can warn on the similar things: procedure Main is A : Integer; B : constant Integer := 1; begin A := 0; A := A + B; end Main; $ gcc -O2 -gnatwa -gnatwe -c main.adb main.adb:6:09: warning: possibly useless assignment to "A", value might not be referenced
[Bug c/102909] Missing -Wunused-but-set-variable warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102909 --- Comment #2 from Iru Cai --- So it looks something like https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44677 GCC thinks ``a`` is set but not used in ``a = 1 + b;``, but is used in ``a = 1; a += b;``.
[Bug c/102909] New: Missing -Wunused-but-set-variable warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102909 Bug ID: 102909 Summary: Missing -Wunused-but-set-variable warning Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: mytbk920423 at gmail dot com Target Milestone: --- GCC misses the -Wunused-but-set-variable in the some code (GCC and Clang output can be seen in https://godbolt.org/z/7658M4qra). I first found a bug caused by the following code, in which no compilers warn: void ioapic_set_max_vectors(void *ioapic_base, int mre_count) { u32 reg; u8 count; reg = io_apic_read(ioapic_base, 0x01); count = reg >> 16; if (mre_count > 0) count = mre_count - 1; // reg is defined but not used after this reg &= ~(0xff << 16); reg |= count << 16; // ``count`` should be ``reg`` in the following line io_apic_write(ioapic_base, 0x01, count); } I think that's because the variable ``reg`` is only unused in part of the control flow, so I change the code as following. However, GCC doesn't warn on this either. void ioapic_set_max_vectors(void *ioapic_base, int mre_count) { u32 reg; u32 new_reg; u8 count; reg = io_apic_read(ioapic_base, 0x01); count = reg >> 16; if (mre_count > 0) count = mre_count - 1; // new_reg is defined but not used new_reg = reg & (~(0xff << 16)); new_reg |= count << 16; // ``count`` should be ``new_reg`` in the following io_apic_write(ioapic_base, 0x01, count); }
[Bug other/102495] New: optimize some consecutive byte load pattern to word load
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102495 Bug ID: 102495 Summary: optimize some consecutive byte load pattern to word load Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: mytbk920423 at gmail dot com Target Milestone: --- I use the following code get a 32-bit word from a byte array by loading each byte and shifting them, but GCC doesn't optimize the code to a single word load when I put the byte load in a loop. Clang trunk can optimize all of the follows: https://gcc.godbolt.org/z/KfWE67K5c ``` #define SHL(a,b) ((uint32_t)(a) << (b)) // both GCC and Clang optimize to *(uint32_t*)(vv) uint32_t getword_b(const uint8_t *vv) { return SHL(vv[3], 24) | SHL(vv[2], 16) | SHL(vv[1], 8) | SHL(vv[0], 0); } // GCC cannot optimize this, Clang can uint32_t getword_forloop(const uint8_t *vv) { uint32_t res = 0; for (size_t i = 0; i < 4; i++) { res |= SHL(vv[i], (i * 8)); } return res; } // both GCC and Clang optimize to ((uint32_t*)(vec))[word_idx] uint32_t getword_from_vec(const uint8_t *vec, size_t word_idx) { size_t byte_idx = word_idx * 4; const uint8_t *vv = vec + byte_idx; return SHL(vv[3], 24) | SHL(vv[2], 16) | SHL(vv[1], 8) | SHL(vv[0], 0); } // neither GCC nor Clang 12.0.1 can optimize this, Clang trunk can uint32_t getword_from_vec_forloop(const uint8_t *vec, size_t word_idx) { size_t byte_idx = word_idx * 4; uint32_t res = 0; for (size_t i = 0; i < 4; i++) { res |= SHL(vec[byte_idx + i], (i * 8)); } return res; } ```
[Bug c++/101775] New: G++ drops namespace prefix of argument in the referenced function symbol
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101775 Bug ID: 101775 Summary: G++ drops namespace prefix of argument in the referenced function symbol Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mytbk920423 at gmail dot com Target Milestone: --- When g++ builds following code, the function foo() referenced by this program is compiled to symbol ``foo(VecReg&)``, which should be ``foo(MyISA::VecReg&)`` with the namespace prefix. This results in a linking error. ``` // test.cc #include #include namespace MyISA { typedef struct { uint8_t data[64]; } VecReg; } void foo(MyISA::VecReg ); using MyISA::VecReg; class A { VecReg v; public: void test(); }; typedef MyISA::VecReg VecReg; void A::test() { foo(v); } int main() { A a; a.test(); } ``` ``` // foo.cc #include namespace MyISA { typedef struct { uint8_t data[64]; } VecReg; } void foo(MyISA::VecReg ) { v.data[0] = 42; } ``` $ g++ -c test.cc ; g++ -c foo.cc ; g++ -o main test.o foo.o /usr/bin/ld: test.o: in function `A::test()': test.cc:(.text+0x14): undefined reference to `foo(VecReg&)' $ nm -C test.o foo.o test.o: U _GLOBAL_OFFSET_TABLE_ 001b T main U __stack_chk_fail U foo(VecReg&) T A::test() foo.o: T foo(MyISA::VecReg&)
[Bug ada/101385] -Werror doesn't have effect on Ada frontend
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101385 --- Comment #2 from Iru Cai --- Thanks, -gnatwe works for both gcc and gnatmake. I see in the gnat_ugn manual that there is still the -Werror option that causes GCC back end to treat warnings as errors. Is that means -gnatwe is for front end, and -Werror for back end?
[Bug ada/101385] New: -Werror doesn't have effect on Ada frontend
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101385 Bug ID: 101385 Summary: -Werror doesn't have effect on Ada frontend Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ada Assignee: unassigned at gcc dot gnu.org Reporter: mytbk920423 at gmail dot com Target Milestone: --- I try to make the GCC Ada compiler error when there're warnings, but -Werror doesn't work. $ gcc -c -O2 -Werror test.adb && echo "Command returns $?" test.adb:3:22: warning: value not in range of type "MyChar" defined at line 2 test.adb:3:22: warning: "Constraint_Error" will be raised at run time Command returns 0 $ gnatmake test.adb -cargs -Werror && echo "Command returns $?" gcc -c -Werror test.adb test.adb:3:22: warning: value not in range of type "MyChar" defined at line 2 test.adb:3:22: warning: "Constraint_Error" will be raised at run time gnatbind -x test.ali gnatlink test.ali gnatlink: warning: executable name "test" may conflict with shell command Command returns 0
[Bug target/101175] New: builtin_clz generates wrong bsr instruction
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101175 Bug ID: 101175 Summary: builtin_clz generates wrong bsr instruction Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: mytbk920423 at gmail dot com Target Milestone: --- Built with '-march=x86-64-v3 -O1', the following code generates a bsr instruction, which has undefined behavior when the source operand is zero, thus gives wrong result (code also in https://gcc.godbolt.org/z/zzT7x57MT): static inline int test_clz32(uint32_t value) { if (value != 0) { return __builtin_clz(value); } else { return 32; } } /* returns -1 if x == 0 */ int firstone(uint32_t x) { return 31 - test_clz32(x); } The result assembly: firstone: bsr eax, edi ret Note that the lzcnt instruction has a defined behavior to return the operand size when operand is zero.
[Bug c++/100699] New: g++ doesn't warn uninitialized field when the class is derived from another class
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100699 Bug ID: 100699 Summary: g++ doesn't warn uninitialized field when the class is derived from another class Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mytbk920423 at gmail dot com Target Milestone: --- GCC doesn't warn on the following code when class B is a derived class. --- test.hh --- #include class Base { int v; public: Base(int u): v(u) {} int get() { return v; } }; class A { int a; public: A(int a_): a(a_) {} void print() { printf("%d\n", a); } }; class B: public Base { A a; int b; public: B(int b_); void print() { a.print(); } }; -- end of test.hh --- - test.cpp - #include "test.hh" B::B(int b_): Base(b_), a(b), b(100) {} end of test.cpp --- clang++ warns as follows: $ clang++ -Og -g -Wall -Wextra -c test.cpp test.cpp:5:4: warning: field 'b' is uninitialized when used here [-Wuninitialized] a(b), b(100) ^ 1 warning generated.
[Bug target/100347] [11/12 Regression] GCC 11 does not recognize skylake; translates "march=native" to "x86_64"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100347 Iru Cai changed: What|Removed |Added CC||mytbk920423 at gmail dot com --- Comment #6 from Iru Cai --- I've checked host_detect_local_cpu() in gcc/config/i386/driver-i386.c. GCC detects x86 host CPU micro architecture by cpuid instruction instead of the APIs provided by the OS.
[Bug c/97982] integer casting after abs() causes undefined behavior
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97982 --- Comment #1 from Iru Cai --- Hmm, I saw in the abs(3) that "Trying to take the absolute value of the most negative integer is not defined." But it's still strange to see a uint32->uint64_t cast results in a negative value.
[Bug c/97982] New: integer casting after abs() causes undefined behavior
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97982 Bug ID: 97982 Summary: integer casting after abs() causes undefined behavior Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: mytbk920423 at gmail dot com Target Milestone: --- The following code has different result when compiling with -O0/-O1 and -O2. Also, ubsan will report an error. But I don't know why the signed(INT_MIN)->unsigned data conversion is undefined. It's found in GCC 10.2.0 and 4.8.5. clang does fine with both -O0 and -O2 and reports no ubsan errors. #include #include #include int main() { char str[20]; scanf("%s", str); int32_t x = strtol(str, NULL, 0); uint32_t u = abs(x); // x=0x8000 will trigger an undefined behavior uint64_t val = u; printf("0x%lx\n", val); }