[Bug c++/103012] [11/12 Regression] ICE with #pragma GCC optimize followed by long line (4047 long)

2021-12-30 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103012

--- Comment #8 from CVS Commits  ---
The master branch has been updated by Jakub Jelinek :

https://gcc.gnu.org/g:1dbe26b949c6142b278ab7af2bac4545e8d524f2

commit r12-6151-g1dbe26b949c6142b278ab7af2bac4545e8d524f2
Author: Jakub Jelinek 
Date:   Thu Dec 30 14:25:19 2021 +0100

c-family: Use BULTINS_LOCATION for predefined macros changed upon optimize
or target pragmas [PR103012]

The following testcases ICE when an optimize or target pragma
is followed by a long line (4096+ chars).
This is because on such long lines we can't use columns anymore,
but the cpp_define calls performed by c_cpp_builtins_optimize_pragma
or from the backend hooks for target pragma are done on temporary
buffers and expect to get columns from whatever line they appear on
(which happens to be the long line after optimize/target pragma),
and we run into:
 #0  fancy_abort (file=0x3abec67 "../../libcpp/line-map.c", line=502,
function=0x3abecfc "linemap_add") at ../../gcc/diagnostic.c:1986
 #1  0x02e7c335 in linemap_add (set=0x77fca000,
reason=LC_RENAME, sysp=0, to_file=0x41287a0 "pr103012.i", to_line=3) at
../../libcpp/line-map.c:502
 #2  0x02e7cc24 in linemap_line_start (set=0x77fca000,
to_line=3, max_column_hint=128) at ../../libcpp/line-map.c:827
 #3  0x02e7ce2b in linemap_position_for_column (set=0x77fca000,
to_column=1) at ../../libcpp/line-map.c:898
 #4  0x02e771f9 in _cpp_lex_direct (pfile=0x40c3b60) at
../../libcpp/lex.c:3592
 #5  0x02e76c3e in _cpp_lex_token (pfile=0x40c3b60) at
../../libcpp/lex.c:3394
 #6  0x02e610ef in lex_macro_node (pfile=0x40c3b60,
is_def_or_undef=true) at ../../libcpp/directives.c:601
 #7  0x02e61226 in do_define (pfile=0x40c3b60) at
../../libcpp/directives.c:639
 #8  0x02e610b2 in run_directive (pfile=0x40c3b60, dir_no=0,
buf=0x7fffd430 "__OPTIMIZE__ 1\n", count=14) at
../../libcpp/directives.c:589
 #9  0x02e650c1 in cpp_define (pfile=0x40c3b60, str=0x2f784d1
"__OPTIMIZE__") at ../../libcpp/directives.c:2513
 #10 0x02e65100 in cpp_define_unused (pfile=0x40c3b60,
str=0x2f784d1 "__OPTIMIZE__") at ../../libcpp/directives.c:2522
 #11 0x00f50685 in c_cpp_builtins_optimize_pragma (pfile=0x40c3b60,
prev_tree=, cur_tree=)
 at ../../gcc/c-family/c-cppbuiltin.c:600
assertion that LC_RENAME doesn't happen first.

I think the right fix is emit those predefined macros upon
optimize/target pragmas with BUILTINS_LOCATION, like we already do
for those macros at the start of the TU, they don't appear in columns
of the next line after it.  Another possibility would be to force them
at the location of the pragma.

2021-12-30  Jakub Jelinek  

PR c++/103012
gcc/
* config/i386/i386-c.c (ix86_pragma_target_parse): Perform
cpp_define/cpp_undef calls with forced token locations
BUILTINS_LOCATION.
* config/arm/arm-c.c (arm_pragma_target_parse): Likewise.
* config/aarch64/aarch64-c.c (aarch64_pragma_target_parse):
Likewise.
* config/s390/s390-c.c (s390_pragma_target_parse): Likewise.
gcc/c-family/
* c-cppbuiltin.c (c_cpp_builtins_optimize_pragma): Perform
cpp_define_unused/cpp_undef calls with forced token locations
BUILTINS_LOCATION.
gcc/testsuite/
PR c++/103012
* g++.dg/cpp/pr103012.C: New test.
* g++.target/i386/pr103012.C: New test.

[Bug c++/103012] [11/12 Regression] ICE with #pragma GCC optimize followed by long line (4047 long)

2021-12-28 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103012

Jakub Jelinek  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |jakub at gcc dot gnu.org

--- Comment #7 from Jakub Jelinek  ---
Created attachment 52077
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52077=edit
gcc12-pr103012.patch

Untested fix.

[Bug c++/103012] [11/12 Regression] ICE with #pragma GCC optimize followed by long line (4047 long)

2021-11-08 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103012

Martin Liška  changed:

   What|Removed |Added

 CC||nathan at gcc dot gnu.org
   Keywords|needs-bisection |

--- Comment #6 from Martin Liška  ---
Started with r11-338-g2a0225e47868fbfc.

[Bug c++/103012] [11/12 Regression] ICE with #pragma GCC optimize followed by long line (4047 long)

2021-11-06 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103012

Andrew Pinski  changed:

   What|Removed |Added

   Target Milestone|--- |11.3
  Known to fail||11.1.0
   Keywords||needs-bisection
Summary|ICE with #pragma GCC|[11/12 Regression] ICE with
   |optimize followed by long   |#pragma GCC optimize
   |line|followed by long line (4047
   ||long)
  Known to work||10.1.0, 7.5.0

--- Comment #5 from Andrew Pinski  ---
So decent testcase with macros, though you need -save-temps or preprocess it
beforehand if you are invoking cc1plus directly.
#pragma GCC optimize "Og"
#define a1(a) a
#define a2(a) a1(a)a1(a)
#define a4(a) a2(a)a2(a)
#define a8(a) a4(a)a4(a)
#define a16(a) a8(a)a8(a)
#define a32(a) a16(a)a16(a)
#define a64(a) a32(a)a32(a)
#define a128(a) a64(a)a64(a)
#define a256(a) a128(a)a128(a)
#define a512(a) a256(a)a256(a)
#define a1024(a) a512(a)a512(a)
#define a2048(a) a1024(a)a1024(a)
a2048(a)
-- CUT --
What I found also is the line needs to be 4047 characters long. The above line
will a little longer around 4096ish.

Also this worked at r10-6101 but failed at r11-6338.