Bug 51793 - pragma GCC optimize wrapv leads to invalid code on Solaris
Summary: pragma GCC optimize wrapv leads to invalid code on Solaris
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.5.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-08 13:18 UTC by Bruno Haible
Modified: 2021-04-29 01:22 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64-*-*, i?86-*-*
Build:
Known to work: 10.3.0, 11.1.0, 5.5.0, 6.5.0, 7.5.0, 8.4.0, 9.3.0
Known to fail: 4.5.4, 4.6.4, 4.7.3, 4.8.5, 4.9.4
Last reconfirmed: 2012-01-09 00:00:00


Attachments
Test case (74 bytes, application/octet-stream)
2012-01-08 13:18 UTC, Bruno Haible
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bruno Haible 2012-01-08 13:18:48 UTC
Created attachment 26274 [details]
Test case

The use of
#pragma GCC optimize ("wrapv")
with optimization level -O2 turns the ".p2align 4,,15" to ".p2align 4,,-1".
This can be observed on both i386-pc-solaris2.11 and i386-pc-linux-gnu systems.
On i386-pc-solaris2.11 it causes a compilation failure, because the assembler
does not understand this syntax.

How to reproduce:
================================== foo.c ==================================
#pragma GCC optimize ("wrapv")
int foo () { return 17; }
int bar () { return 42; }
===========================================================================


$ gcc -O2 -c foo.c
Assembler: foo.c
	"/var/tmp//ccwQaWQO.s", line 3 : .align test amount has negative value
	"/var/tmp//ccwQaWQO.s", line 10 : .align test amount has negative value

$ gcc -O2 -S foo.c

$ cat foo.s
	.file	"foo.c"
	.text
	.p2align 4,,-1
.globl foo
	.type	foo, @function
foo:
	movl	$17, %eax
	ret
	.size	foo, .-foo
	.p2align 4,,-1
.globl bar
	.type	bar, @function
bar:
	movl	$42, %eax
	ret
	.size	bar, .-bar
	.ident	"GCC: (GNU) 4.5.2"


$ gcc --version
gcc (GCC) 4.5.2
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/gcc/4.5/lib/gcc/i386-pc-solaris2.11/4.5.2/lto-wrapper
Target: i386-pc-solaris2.11
Configured with: /builds/hudson/workspace/nightly/build/i386/components/gcc45/gcc-4.5.2/configure CC=/ws/onnv-tools/SUNWspro/sunstudio12.1/bin/cc CXX=/ws/onnv-tools/SUNWspro/sunstudio12.1/bin/CC --prefix=/usr/gcc/4.5 --mandir=/usr/gcc/4.5/share/man --bindir=/usr/gcc/4.5/bin --libdir=/usr/gcc/4.5/lib --sbindir=/usr/gcc/4.5/sbin --enable-languages=c,c++,fortran,objc --enable-shared --with-gmp-include=/usr/include/gmp --with-mpfr-include=/usr/include/mpfr --prefix=/usr/gcc/4.5 --mandir=/usr/gcc/4.5/share/man --infodir=/usr/gcc/4.5/share/info --libexecdir=/usr/gcc/4.5/lib CFLAGS='-g -O2 '
Thread model: posix
gcc version 4.5.2 (GCC) 


$ type as
as is hashed (/usr/bin/as)

$ as -V
as: Sun Compiler Common 12 SunOS_i386 snv_174 08/25/2011
Usage: as [-V] [-Q{y,n}] [-s]
	  [-S[aAbBcClL]] [-K {pic,PIC}] [-o objfile] [-L] [-T]
	  [-P [[-Ipath] [-Dname] [-Dname=def] [-Uname]]...]
	  [-m [-Ym,path]] [-n] [-xF] [-F] [-b] [-i] file.s ...
Comment 1 Richard Biener 2012-01-09 11:59:09 UTC
Huh, weird.  Works with GCC 4.3 (which does not implement the pragma).

Confirmed.  At least generic x86 is affected.
Comment 2 Eric Gallager 2021-04-28 23:39:49 UTC
I've seen this bug referenced in some versions of gnulib's mktime.c; is it still relevant?
Comment 3 Bruno Haible 2021-04-29 01:14:08 UTC
It works fine on
- Solaris 11.4 (gcc 7.3.0): foo.s contains '.p2align 4,,15'
- Solaris 11 OpenIndiana (gcc 7.2.0): likewise
- Solaris 11 OmniOS (gcc 9.3.0): foo.s does not contain .p2align directives any more

More details by testing various versions on i386-pc-linux-gnu:

4.5.4 -> .p2align 4,,-1
4.6.4 -> .p2align 4,,-1
4.7.3 -> .p2align 4,,-1
4.8.5 -> .p2align 4,,-1
4.9.4 -> .p2align 4,,-1
5.5.0 -> no .p2align any more
6.5.0 -> .p2align 4,,15
7.5.0 -> .p2align 4,,15
8.4.0 -> .p2align 4,,15
9.3.0 -> .p2align 4
10.3.0 -> .p2align 4
11.1.0 -> .p2align 4

In summary, it appears to be fixed since GCC version 5.x.
Comment 4 Bruno Haible 2021-04-29 01:22:09 UTC
Correction to comment #3:
It works fine on
- Solaris 11.4 (gcc 7.3.0): foo.s contains '.p2align 4,,15'
- Solaris 11 OpenIndiana (gcc 7.2.0): likewise
- Solaris 11 OmniOS (gcc 9.3.0): foo.s contains '.p2align 4'

Consistently with what we see on Linux.