Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug:编译时针对warning出现问题 #23

Open
shlies opened this issue Dec 19, 2023 · 4 comments
Open

bug:编译时针对warning出现问题 #23

shlies opened this issue Dec 19, 2023 · 4 comments

Comments

@shlies
Copy link

shlies commented Dec 19, 2023

文件内容:

#include<stdio.h>
#include<stdlib.h>
int main(int argc, char *argv[ ])
{
      double *p;

      printf("%lld\n", sizeof(int));

      p = (double *)malloc(sizeof(*p));      
      return 0;
}

正常情况:

/usr/bin/gcc -fdiagnostics-color=always -g /home/shlies/pta/pta.c -o /home/shlies/pta/pta
/home/shlies/pta/pta.c: In function ‘main’:
/home/shlies/pta/pta.c:7:18: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
    7 |       printf("%lld\n", sizeof(int));
      |               ~~~^     ~~~~~~~~~~~
      |                  |     |
      |                  |     long unsigned int
      |                  long long int
      |               %ld

更换后:

/usr/bin/gcc -fdiagnostics-color=always -g /home/shlies/pta/pta.c -o /home/shlies/pta/pta

就...就在那个叫‘main’的函数里!:
段错误
    7 |       printf("%lld\n", sizeof(int));
      |       ^~~~~~
0xc29ac3 crash_signal
        ../../src/gcc/toplev.cc:314
0x7f43a5b3a08f ???
        /build/glibc-wuryBv/glibc-2.31/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
0x7f43a5c7f915 ???
        ../sysdeps/x86_64/multiarch/strlen-avx2.S:65
0x1a9115f pp_string(pretty_printer*, char const*)
        ../../src/gcc/pretty-print.cc:1828
0x1a9115f pp_format(pretty_printer*, text_info*)
        ../../src/gcc/pretty-print.cc:1457
0x1a80dd1 diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info*)
        ../../src/gcc/diagnostic.cc:1592
0xc23d66 format_string_diagnostic_t::emit_warning_n_va(int, unsigned long, char const*, char const*, __va_list_tag (*) [1]) const
        ../../src/gcc/substring-locations.cc:216
0xc23ffd format_string_diagnostic_t::emit_warning_va(int, char const*, __va_list_tag (*) [1]) const
        ../../src/gcc/substring-locations.cc:241
0xc23ffd format_string_diagnostic_t::emit_warning(int, char const*, ...) const
        ../../src/gcc/substring-locations.cc:252
0x760c04 format_type_warning
        ../../src/gcc/c-family/c-format.cc:4754
0x7644e1 check_format_types
        ../../src/gcc/c-family/c-format.cc:4272
0x7644e1 argument_parser::check_argument_type(format_char_info const*, length_modifier const&, tree_node*&, char const*&, bool, unsigned long&, tree_node*&, int, char const*, char const*, unsigned int, char)
        ../../src/gcc/c-family/c-format.cc:2859
0x765901 check_format_info_main
        ../../src/gcc/c-family/c-format.cc:3999
0x765901 check_format_arg
        ../../src/gcc/c-family/c-format.cc:1822
0x7622e0 check_format_info
        ../../src/gcc/c-family/c-format.cc:1543
0x7622e0 check_function_format(tree_node const*, tree_node*, int, tree_node**, vec<unsigned int, va_heap, vl_ptr>*)
        ../../src/gcc/c-family/c-format.cc:1198
0x75430c check_function_arguments(unsigned int, tree_node const*, tree_node const*, int, tree_node**, vec<unsigned int, va_heap, vl_ptr>*)
        ../../src/gcc/c-family/c-common.cc:6093
0x6d4440 build_function_call_vec(unsigned int, vec<unsigned int, va_heap, vl_ptr>, tree_node*, vec<tree_node*, va_gc, vl_embed>*, vec<tree_node*, va_gc, vl_embed>*, tree_node*)
        ../../src/gcc/c/c-typeck.cc:3308
0x6f6d91 c_parser_postfix_expression_after_primary
        ../../src/gcc/c/c-parser.cc:11242
0x6e6da2 c_parser_postfix_expression
        ../../src/gcc/c/c-parser.cc:10849
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
参阅 <file:///usr/share/doc/gcc-13/README.Bugs> 以获取指示。

环境

WSL2 Ubuntu20.04.6 LTS
gcc-13

@Bill-Haku
Copy link
Owner

我不知道为什么会报段错误。理论上这应该是gcc主程序的问题。

@dabao1955
Copy link
Contributor

user@localhost ~/mini> /usr/bin/gcc -fdiagnostics-color=always -g main.c
user@localhost ~/mini> cat main.c
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char *argv[ ])
{
      double *p;

      printf("%lld\n", sizeof(int));

      p = (double *)malloc(sizeof(*p));
      return 0;
}
user@localhost ~/mini>

debian12 gcc12.3未出现编译错误

@Elvisass
Copy link

似乎针对printf的warning都会出问题,我这边gcc 7.5.0 ubuntu 18.04直接整个大活:
cc1plus: out of memory allocating 18446744072437955510 bytes after a total of 1957888 bytes

开verbose看到:

就...就在那个叫‘int main(int, char**)’的函数里!:
段错误
             printf("Test loop %lu/%lu in %d ms\n", i, loops, (timeMs() - timec) / 100);
                                                                                      ^
Please submit a full bug report,
with preprocessed source if appropriate.
参阅 <file:///usr/share/doc/gcc-7/README.Bugs> 以获取指示。

删除翻译文件后,gcc正常提示是:

main.cpp: In function ‘int main(int, char**)’:
main.cpp:192:86: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
             printf("Test loop %lu/%lu in %d ms\n", i, loops, (timeMs() - timec) / 100);
                                                              ~~~~~~~~~~~~~~~~~~~~~~~~^
main.cpp: In function ‘Type1* func1(const char*)’:
main.cpp:50:12: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
     ::fread(ret->data, fsize, 1, fp);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~

16 ZB,精彩(

@dabao1955
Copy link
Contributor

root@localhost:~# cc main.c
‘
就...就在那个叫‘main’的函数里!:
段错误
       printf("%lld\n", sizeof(int));
       ^~~~~~
Please submit a full bug report,
with preprocessed source if appropriate.
参阅 <file:///usr/share/doc/gcc-7/README.Bugs> 以获取指示。
root@localhost:~# rm /usr/share/locale/zh_CN/LC_MESSAGES/gcc-7.mo                                                     root@localhost:~# cc main.c
main.c: そ、その ‘main’ という関数の内:
main.c:7:18: ざぁーこ!書式 ‘%lld’ は引数の型が ‘long long int’ であると予期されますが、第 2 引数の型は ‘long unsigned int’ です [-Wformat=]
       printf("%lld\n", sizeof(int));
               ~~~^
               %ld
root@localhost:~# gcc -v
組み込み spec を使用しています。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/7/lto-wrapper
ターゲット: aarch64-linux-gnu
configure 設定: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=aarch64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release --build=aarch64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-linux-gnu
スレッドモデル: posix
gcc バージョン 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
root@localhost:~#

实测同楼上一样,只有日文使用没问题。
如有必要建议优先使用日文版。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants