[Bug ada/116644] Warnings in generic code don't report column number
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116644 --- Comment #2 from Iru Cai --- (In reply to Eric Botcazou from comment #1) > Why is that insufficient exactly? 256 is clearly not in range of My_Byte. I mean the warning messages don't have the information pointing out which code in this line has bugs, just saying "value not in range of type "My_Byte" defined at line 5" but not saying what this value is or giving the column number of the buggy code.
[Bug ada/116644] New: Warnings in generic code don't report column number
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116644 Bug ID: 116644 Summary: Warnings in generic code don't report column number Product: gcc Version: 14.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ada Assignee: unassigned at gcc dot gnu.org Reporter: mytbk920423 at gmail dot com CC: dkm at gcc dot gnu.org Target Milestone: --- When compiling the following Ada code, GCC gives a warning with the correct line number, but doesn't have the column number in it, which is insufficient for me to find the bug in the code. code: -- gen_testpkg.ads generic type T is mod <>; package Gen_Testpkg is function Test_Mod(A : T) return T; end Gen_Testpkg; -- gen_testpkg.adb package body Gen_Testpkg is function Test_Mod(A : T) return T is type U8 is mod 256; Map : constant array (U8) of U8 := (1, 3, 5, others => 0); begin return T(Map(U8(A mod 256))); --^^^ -- If T'Modulus <= 256, then 256 is not in range of type T -- We can use U8'Mod(A) instead end Test_Mod; end Gen_Testpkg; -- test_generic.adb with Gen_Testpkg; procedure Test_Generic is type My_Byte is mod 256; package My_Pkg is new Gen_Testpkg(T => My_Byte); begin null; end Test_Generic; warning: test_generic.adb:6:03: warning: in instantiation at gen_testpkg.adb:8 [enabled by default] test_generic.adb:6:03: warning: value not in range of type "My_Byte" defined at line 5 [enabled by default] test_generic.adb:6:03: warning: Constraint_Error will be raised at run time [enabled by default]
[Bug tree-optimization/115824] [12 Regression] Strange -Warray-bounds warning when assigning an initializer list to a vector of pointers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115824 --- Comment #11 from Iru Cai --- (In reply to Sam James from comment #7) > (In reply to Randy MacLeod from comment #5) > > As far as I know, the commit itself is fine, and it's the pesky middle-end > warnings again getting confused. > > Jonathan might be willing to try rework it to avoid the warnings but it's a > lot of busywork and not particularly satisfying. > > If someone can suggest some trivial change which shuts it up, that might > work. We can just use these "pragma GCC diagnostic" things to silence this warnings. Also I found that it also has strange warnings with -Wstringop-overread, so I add this to the ignored. diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 6e648e48ad0..312d5242d70 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -430,9 +430,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __copy_m(_Tp* __first, _Tp* __last, _Up* __result) { const ptrdiff_t _Num = __last - __first; - if (__builtin_expect(_Num > 1, true)) + if (__builtin_expect(_Num > 1, true)) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" +#pragma GCC diagnostic ignored "-Wstringop-overread" __builtin_memmove(__result, __first, sizeof(_Tp) * _Num); - else if (_Num == 1) +#pragma GCC diagnostic pop + } else if (_Num == 1) std::__copy_move<_IsMove, false, random_access_iterator_tag>:: __assign_one(__result, __first); return __result + _Num;
[Bug tree-optimization/115824] [12 Regression] Strange -Warray-bounds warning when assigning an initializer list to a vector of pointers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115824 --- Comment #6 from Iru Cai --- I build a GCC with 12.3.0 source, and replace the libstdc++ with the 12.4.0 one, and reproduce this problem.
[Bug libstdc++/115824] New: Strange -Warray-bounds warning when assigning an initializer list to a vector of pointers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115824 Bug ID: 115824 Summary: Strange -Warray-bounds warning when assigning an initializer list to a vector of pointers Product: gcc Version: 12.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: mytbk920423 at gmail dot com Target Milestone: --- The following code has a strange warning on GCC 12.4.0 when compiled with -O2 -Warray-bounds. (compiler explorer link: https://godbolt.org/z/sr56Yro6n) #include std::vector v; void test(int a) { int *p = new int(a); v = {p}; } stl_algobase.h:434:30: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' forming offset 8 is out of the bounds [0, 8] of object '' with type 'int* const [1]' [-Warray-bounds] 434 | __builtin_memmove(__result, __first, sizeof(_Tp) * _Num); | ~^~~ In GCC release 12.3.0, 13.x, 14.x and trunk, there is no such warning. I think it can be some problem in the libstdc++ change in 12.4.0 release.
[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 &v); 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) { 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); }
[Bug c++/92968] New: C style struct initialization fail to compile in g++ when initializing array fields
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92968 Bug ID: 92968 Summary: C style struct initialization fail to compile in g++ when initializing array fields Product: gcc Version: 9.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 program cannot be compiled with g++ but can be compiled with clang++ or any C compiler including gcc. typedef struct AStruct { int a[2]; } AStruct; int main() { AStruct t0 = { .a[0] = 5 }; }
[Bug c/87367] GCC gives false warning on -Wnull-dereference when using -O2
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87367 Iru Cai changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #1 from Iru Cai --- Looks like it's not a bug, the warning of NULL dereference is right.
[Bug c/87367] New: GCC gives false warning on -Wnull-dereference when using -O2
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87367 Bug ID: 87367 Summary: GCC gives false warning on -Wnull-dereference when using -O2 Product: gcc Version: 8.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: mytbk920423 at gmail dot com Target Milestone: --- When compiling the following program with -Wnull-dereference, GCC doesn't warn when using -O1, but warns when using -O2. #include typedef struct list_element_s { void *data; struct list_element_s *next; } list_element_s, list_element_p[1]; list_element_s *list_new() { list_element_s *n = malloc(sizeof(list_element_s)); if (!n) { return NULL; } n->data = NULL; n->next = NULL; return n; } size_t otrng_list_len(list_element_s *head) { list_element_s *cursor = head; size_t size = 0; while (cursor) { if (cursor->data) { size++; } cursor = cursor->next; } return size; } list_element_s *otrng_list_copy(list_element_s *head) { if (otrng_list_len(head) == 0) { return NULL; } list_element_s *cursor = head; list_element_s *copy = list_new(); if (!copy) { return NULL; } copy->data = cursor->data; copy->next = NULL; list_element_s *ret = copy; cursor = cursor->next; while (cursor) { copy->next = list_new(); copy = copy->next; copy->data = cursor->data; copy->next = NULL; cursor = cursor->next; } return ret; } $ gcc -c -O2 -Wnull-dereference list.c list.c: In function 'otrng_list_copy': list.c:54:16: warning: potential null pointer dereference [-Wnull-dereference] copy->next = NULL; ^ list.c:53:16: warning: potential null pointer dereference [-Wnull-dereference] copy->data = cursor->data; ~~~^~