https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88937

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmalcolm at gcc dot gnu.org

--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
So it's really problem, one can easily see it with:

$ cat x.C
#if __has_include("x")
#endif

$ valgrind --trace-children=yes ./xgcc -B. x.C  -c
==22322== Memcheck, a memory error detector
==22322== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==22322== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==22322== Command: ./xgcc -B. x.C -c
==22322== 
==22323== Memcheck, a memory error detector
==22323== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==22323== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==22323== Command: ./cc1plus -quiet -iprefix
/dev/shm/objdir/gcc/../lib64/gcc/x86_64-pc-linux-gnu/9.0.1/ -isystem ./include
-isystem ./include-fixed -D_GNU_SOURCE x.C -quiet -dumpbase x.C -mtune=generic
-march=x86-64 -auxbase x -o /tmp/ccBLUwdo.s
==22323== 
==22323== Conditional jump or move depends on uninitialised value(s)
==22323==    at 0x18F99FA: parse_has_include(cpp_reader*, include_type)
(expr.c:2247)
==22323==    by 0x18F6E81: eval_token(cpp_reader*, cpp_token const*, unsigned
int) (expr.c:1157)
==22323==    by 0x18F717D: _cpp_parse_expr (expr.c:1328)
==22323==    by 0x18F110C: do_if(cpp_reader*) (directives.c:2008)
==22323==    by 0x18F27CA: _cpp_handle_directive (directives.c:543)
==22323==    by 0x1901994: _cpp_lex_token (lex.c:2609)
==22323==    by 0x19091D9: cpp_get_token_1(cpp_reader*, unsigned int*)
(macro.c:2703)
==22323==    by 0x190964C: cpp_get_token_with_location(cpp_reader*, unsigned
int*) (macro.c:2889)
==22323==    by 0xA9496E: c_lex_with_flags(tree_node**, unsigned int*, unsigned
char*, int) (c-lex.c:405)
==22323==    by 0x95549E: cp_lexer_get_preprocessor_token(cp_lexer*, cp_token*)
(parser.c:788)
==22323==    by 0x9925F7: cp_parser_initial_pragma (parser.c:40586)
==22323==    by 0x9925F7: cp_lexer_new_main (parser.c:642)
==22323==    by 0x9925F7: cp_parser_new (parser.c:3933)
==22323==    by 0x9925F7: c_parse_file() (parser.c:41027)
==22323==    by 0xA9E670: c_common_parse_file() (c-opts.c:1155)
==22323== 
==22323== Conditional jump or move depends on uninitialised value(s)
==22323==    at 0x18F7408: _cpp_parse_expr (expr.c:1429)
==22323==    by 0x18F110C: do_if(cpp_reader*) (directives.c:2008)
==22323==    by 0x18F27CA: _cpp_handle_directive (directives.c:543)
==22323==    by 0x1901994: _cpp_lex_token (lex.c:2609)
==22323==    by 0x19091D9: cpp_get_token_1(cpp_reader*, unsigned int*)
(macro.c:2703)
==22323==    by 0x190964C: cpp_get_token_with_location(cpp_reader*, unsigned
int*) (macro.c:2889)
==22323==    by 0xA9496E: c_lex_with_flags(tree_node**, unsigned int*, unsigned
char*, int) (c-lex.c:405)
==22323==    by 0x95549E: cp_lexer_get_preprocessor_token(cp_lexer*, cp_token*)
(parser.c:788)
==22323==    by 0x9925F7: cp_parser_initial_pragma (parser.c:40586)
==22323==    by 0x9925F7: cp_lexer_new_main (parser.c:642)
==22323==    by 0x9925F7: cp_parser_new (parser.c:3933)
==22323==    by 0x9925F7: c_parse_file() (parser.c:41027)
==22323==    by 0xA9E670: c_common_parse_file() (c-opts.c:1155)
==22323==    by 0xF55A8E: compile_file() (toplev.c:456)
==22323==    by 0x856C19: do_compile (toplev.c:2176)
==22323==    by 0x856C19: toplev::main(int, char**) (toplev.c:2311)

When putting following breakpoint:
(gdb) b expr.c:2218


you'll see:

$ (gdb) p token->val
$2 = {
  node = {
    node = 0x3, 
    spelling = 0x254eedc
  }, 
  source = 0x3, 
  str = {
    len = 3, 
    text = 0x254eedc "\"x\""
  }, 
  macro_arg = {
    arg_no = 3, 
    spelling = 0x254eedc
  }, 
  token_no = 3, 
  pragma = 3
}

so val.str is used from the union. Thus one shouldn't use
      node = token->val.node.node;

that will be 0x03. Later than the pointer is saved here:

  /* A possible controlling macro of the form #if !__has_include__ ().
     _cpp_parse_expr checks there was no other junk on the line.  */
  if (node)
    pfile->mi_ind_cmacro = node;

David will you please take a look?

Reply via email to