public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/110683] New: wrong code with '-O2' and specific optimizations
@ 2023-07-16 15:07 19373742 at buaa dot edu.cn
  2023-07-16 15:07 ` [Bug c/110683] " 19373742 at buaa dot edu.cn
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: 19373742 at buaa dot edu.cn @ 2023-07-16 15:07 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110683
           Summary: wrong code with '-O2' and specific optimizations
           Product: gcc
           Version: 12.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 19373742 at buaa dot edu.cn
  Target Milestone: ---

Created attachment 55551
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55551&action=edit
The preprocessed file

*******************************************************************************
OS and Platform:
CentOS Linux release 7.9.2009 (Core), x86_64 GNU/Linux
*******************************************************************************
gcc version:
/home/gcc-releases/gcc-12-0707/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/home/gcc-releases/gcc-12-0707/bin/gcc
COLLECT_LTO_WRAPPER=/home/gcc-releases/gcc-12-0707/libexec/gcc/x86_64-pc-linux-gnu/12.3.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/home/gcc-releases/gcc-12-0707/
--disable-multilib --enable-language=c,c++
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.3.1 20230707 (GCC)
*******************************************************************************
Command Lines:
# /home/gcc-releases/gcc-12-0707/bin/gcc -I
/home/csmith_record/include/csmith-2.3.0/  -O2
-fno-aggressive-loop-optimizations -fno-align-functions -fno-align-jumps
-fno-align-labels -fno-align-loops -fno-allocation-dce
-fno-asynchronous-unwind-tables -fno-auto-inc-dec -fno-bit-tests
-fno-branch-count-reg -fno-caller-saves -fno-code-hoisting
-fno-combine-stack-adjustments -fno-compare-elim -fno-cprop-registers
-fno-crossjumping -fno-cse-follow-jumps -fno-dce -fno-defer-pop
-fno-devirtualize -fno-devirtualize-speculatively -fno-dse -fno-early-inlining
-fno-expensive-optimizations -fno-forward-propagate -fno-fp-int-builtin-inexact
-fno-function-cse -fno-gcse -fno-gcse-after-reload -fno-gcse-lm
-fno-guess-branch-probability -fno-hoist-adjacent-loads -fno-if-conversion
-fno-if-conversion2 -fno-indirect-inlining -fno-inline -fno-inline-atomics
-fno-inline-functions -fno-inline-functions-called-once
-fno-inline-small-functions -fno-ipa-bit-cp -fno-ipa-cp -fno-ipa-cp-clone
-fno-ipa-icf -fno-ipa-icf-functions -fno-ipa-icf-variables -fno-ipa-modref
-fno-ipa-profile -fno-ipa-pure-const -fno-ipa-ra -fno-ipa-reference
-fno-ipa-reference-addressable -fno-ipa-sra -fno-ipa-stack-alignment
-fno-ipa-strict-aliasing -fno-ipa-vrp -fno-ira-hoist-pressure
-fno-ira-share-save-slots -fno-ira-share-spill-slots
-fno-isolate-erroneous-paths-dereference -fno-ivopts -fno-jump-tables
-fno-lifetime-dse -fno-loop-interchange -fno-loop-unroll-and-jam -fno-lra-remat
-fno-math-errno -fno-move-loop-invariants -fno-move-loop-stores
-fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-optimize-strlen
-fno-partial-inlining -fno-peel-loops -fno-peephole -fno-peephole2 -fno-plt
-fno-predictive-commoning -fno-printf-return-value -fno-ree
-fno-reg-struct-return -fno-reorder-blocks -fno-reorder-blocks-and-partition
-fno-reorder-functions -fno-rerun-cse-after-loop
-fno-sched-critical-path-heuristic -fno-sched-dep-count-heuristic
-fno-sched-group-heuristic -fno-sched-interblock -fno-sched-last-insn-heuristic
-fno-sched-rank-heuristic -fno-sched-spec -fno-sched-spec-insn-heuristic
-fno-sched-stalled-insns-dep -fno-schedule-fusion -fno-schedule-insns2
-fno-semantic-interposition -fno-short-enums -fno-shrink-wrap
-fno-shrink-wrap-separate -fno-signed-zeros -fno-split-ivs-in-unroller
-fno-split-loops -fno-split-paths -fno-split-wide-types -fno-ssa-backprop
-fno-ssa-phiopt -fno-stdarg-opt -fno-store-merging -fno-strict-aliasing
-fno-thread-jumps -fno-toplevel-reorder -fno-trapping-math -fno-tree-bit-ccp
-fno-tree-builtin-call-dce -fno-tree-ccp -fno-tree-ch -fno-tree-coalesce-vars
-fno-tree-copy-prop -fno-tree-dce -fno-tree-dominator-opts -fno-tree-dse
-fno-tree-forwprop -fno-tree-fre -fno-tree-loop-distribute-patterns
-fno-tree-loop-distribution -fno-tree-loop-im -fno-tree-loop-ivcanon
-fno-tree-loop-optimize -fno-tree-loop-vectorize -fno-tree-partial-pre
-fno-tree-phiprop -fno-tree-pre -fno-tree-pta -fno-tree-reassoc
-fno-tree-scev-cprop -fno-tree-sink -fno-tree-slp-vectorize -fno-tree-slsr
-fno-tree-sra -fno-tree-switch-conversion -fno-tree-tail-merge -fno-tree-ter
-fno-tree-vrp -fno-unroll-completely-grow-size -fno-unswitch-loops
-fno-unwind-tables -fno-version-loops-for-strides -fno-allow-store-data-races
-fno-associative-math -fno-branch-probabilities -fno-conserve-stack
-fno-cx-fortran-rules -fno-cx-limited-range -fno-delayed-branch
-fno-delete-dead-exceptions -fno-exceptions -fno-finite-loops
-fno-finite-math-only -fno-float-store -fno-gcse-las -fno-gcse-sm -fno-graphite
-fno-graphite-identity -fno-harden-compares -fno-harden-conditional-branches
-fno-ipa-pta -fno-ira-loop-pressure -fno-isolate-erroneous-paths-attribute
-fno-keep-gc-roots-live -fno-limit-function-alignment -fno-live-range-shrinkage
-fno-loop-nest-optimize -fno-loop-parallelize-all -fno-modulo-sched
-fno-modulo-sched-allow-regmoves -fno-non-call-exceptions -fno-opt-info
-fno-pack-struct -fno-profile-partial-training -fno-profile-reorder-functions
-fno-reciprocal-math -fno-rename-registers
-fno-reschedule-modulo-scheduled-loops -fno-rounding-math
-fno-save-optimization-record -fno-sched-pressure -fno-sched-spec-load
-fno-sched-spec-load-dangerous -fno-sched-stalled-insns
-fno-sched2-use-superblocks -fno-schedule-insns -fno-section-anchors
-fno-sel-sched-pipelining -fno-sel-sched-pipelining-outer-loops
-fno-sel-sched-reschedule-pipelined -fno-short-wchar -fno-signaling-nans
-fno-single-precision-constant -fno-split-wide-types-early
-fno-stack-clash-protection -fno-tracer -fno-trapv -fno-tree-cselim
-fno-tree-lrs -fno-tree-vectorize -fno-unconstrained-commons
-fno-unroll-all-loops -fno-unroll-loops -fno-unsafe-math-optimizations
-fno-var-tracking -fno-var-tracking-assignments
-fno-var-tracking-assignments-toggle -fno-var-tracking-uninit
-fno-variable-expansion-in-unroller -fno-vpt -fno-web -fno-wrapv
-fno-wrapv-pointer -gno-statement-frontiers -fno-aggressive-loop-optimizations
-falign-functions -falign-jumps -fno-align-labels -fno-align-loops
-fno-allocation-dce -fasynchronous-unwind-tables -fauto-inc-dec -fno-bit-tests
-fbranch-count-reg -fcaller-saves -fno-code-hoisting
-fno-combine-stack-adjustments -fno-compare-elim -fno-cprop-registers
-fno-crossjumping -fno-cse-follow-jumps -fdce -fdefer-pop -fno-devirtualize
-fno-devirtualize-speculatively -fno-dse -fearly-inlining
-fno-expensive-optimizations -fforward-propagate -ffp-int-builtin-inexact
-ffunction-cse -fno-gcse -fgcse-after-reload -fgcse-lm
-fguess-branch-probability -fno-hoist-adjacent-loads -fif-conversion
-fif-conversion2 -findirect-inlining -finline -finline-atomics
-finline-functions -finline-functions-called-once -fno-inline-small-functions
-fipa-bit-cp -fno-ipa-cp -fipa-cp-clone -fno-ipa-icf -fipa-icf-functions
-fipa-icf-variables -fipa-modref -fno-ipa-profile -fipa-pure-const -fno-ipa-ra
-fipa-reference -fno-ipa-reference-addressable -fno-ipa-sra
-fipa-stack-alignment -fipa-strict-aliasing -fno-ipa-vrp -fira-hoist-pressure
-fno-ira-share-save-slots -fira-share-spill-slots
-fisolate-erroneous-paths-dereference -fno-ivopts -fno-jump-tables
-flifetime-dse -floop-interchange -fno-loop-unroll-and-jam -fno-lra-remat
-fmath-errno -fno-move-loop-invariants -fmove-loop-stores -fomit-frame-pointer
-fno-optimize-sibling-calls -fno-optimize-strlen -fno-partial-inlining
-fno-peel-loops -fpeephole -fpeephole2 -fplt -fno-predictive-commoning
-fno-printf-return-value -fno-ree -freg-struct-return -fno-reorder-blocks
-freorder-blocks-and-partition -freorder-functions -fno-rerun-cse-after-loop
-fsched-critical-path-heuristic -fsched-dep-count-heuristic
-fsched-group-heuristic -fno-sched-interblock -fno-sched-last-insn-heuristic
-fno-sched-rank-heuristic -fsched-spec -fsched-spec-insn-heuristic
-fno-sched-stalled-insns-dep -fschedule-fusion -fschedule-insns2
-fsemantic-interposition -fshort-enums -fno-shrink-wrap
-fno-shrink-wrap-separate -fno-signed-zeros -fno-split-ivs-in-unroller
-fsplit-loops -fno-split-paths -fno-split-wide-types -fno-ssa-backprop
-fno-ssa-phiopt -fno-stdarg-opt -fstore-merging -fno-strict-aliasing
-fthread-jumps -fno-toplevel-reorder -fno-trapping-math -fno-tree-bit-ccp
-ftree-builtin-call-dce -ftree-ccp -fno-tree-ch -ftree-coalesce-vars
-ftree-copy-prop -ftree-dce -ftree-dominator-opts -fno-tree-dse
-fno-tree-forwprop -ftree-fre -ftree-loop-distribute-patterns
-ftree-loop-distribution -ftree-loop-im -ftree-loop-ivcanon
-fno-tree-loop-optimize -ftree-loop-vectorize -ftree-partial-pre -ftree-phiprop
-fno-tree-pre -ftree-pta -ftree-reassoc -fno-tree-scev-cprop -ftree-sink
-fno-tree-slp-vectorize -ftree-slsr -ftree-sra -fno-tree-switch-conversion
-ftree-tail-merge -fno-tree-ter -ftree-vrp -funroll-completely-grow-size
-fno-unswitch-loops -fno-unwind-tables -fversion-loops-for-strides
-fno-allow-store-data-races -fassociative-math -fbranch-probabilities
-fno-conserve-stack -fno-cx-fortran-rules -fno-cx-limited-range
-fdelayed-branch -fdelete-dead-exceptions -fno-exceptions -fno-finite-loops
-ffinite-math-only -fno-float-store -fno-gcse-las -fgcse-sm -fno-graphite
-fgraphite-identity -fharden-compares -fharden-conditional-branches
-fno-ipa-pta -fno-ira-loop-pressure -fno-isolate-erroneous-paths-attribute
-fkeep-gc-roots-live -fno-limit-function-alignment -fno-live-range-shrinkage
-fno-loop-nest-optimize -fno-loop-parallelize-all -fno-modulo-sched
-fno-modulo-sched-allow-regmoves -fnon-call-exceptions -fno-opt-info
-fpack-struct -fno-profile-partial-training -fno-profile-reorder-functions
-freciprocal-math -fno-rename-registers -freschedule-modulo-scheduled-loops
-frounding-math -fno-save-optimization-record -fsched-pressure
-fsched-spec-load -fsched-spec-load-dangerous -fno-sched-stalled-insns
-fsched2-use-superblocks -fno-schedule-insns -fno-section-anchors
-fno-sel-sched-pipelining -fno-sel-sched-pipelining-outer-loops
-fsel-sched-reschedule-pipelined -fno-short-wchar -fno-signaling-nans
-fsingle-precision-constant -fno-split-wide-types-early
-fno-stack-clash-protection -fno-tracer -ftrapv -fno-tree-cselim -fno-tree-lrs
-fno-tree-vectorize -fno-unconstrained-commons -funroll-all-loops
-funroll-loops -fno-unsafe-math-optimizations -fvar-tracking
-fvar-tracking-assignments -fno-var-tracking-assignments-toggle
-fno-var-tracking-uninit -fvariable-expansion-in-unroller -fno-vpt -fweb
-fno-wrapv -fwrapv-pointer -gstatement-frontiers -save-temps ms.c -o m3.o
2>m3.txt

# /home/gcc-releases/gcc-12-0707/bin/gcc -I /home/csmith/include/csmith-2.3.0/
ms.c -o m4.o

# ./m4.o
checksum = 16499F41
# ./m3.o
checksum = 187B9F46

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/110683] wrong code with '-O2' and specific optimizations
  2023-07-16 15:07 [Bug c/110683] New: wrong code with '-O2' and specific optimizations 19373742 at buaa dot edu.cn
@ 2023-07-16 15:07 ` 19373742 at buaa dot edu.cn
  2023-07-16 15:11 ` 19373742 at buaa dot edu.cn
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: 19373742 at buaa dot edu.cn @ 2023-07-16 15:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from CTC <19373742 at buaa dot edu.cn> ---
Created attachment 55552
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55552&action=edit
The compiler output

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/110683] wrong code with '-O2' and specific optimizations
  2023-07-16 15:07 [Bug c/110683] New: wrong code with '-O2' and specific optimizations 19373742 at buaa dot edu.cn
  2023-07-16 15:07 ` [Bug c/110683] " 19373742 at buaa dot edu.cn
@ 2023-07-16 15:11 ` 19373742 at buaa dot edu.cn
  2023-07-16 15:44 ` [Bug c/110683] wrong code with '-O2 -fpack-struct' 19373742 at buaa dot edu.cn
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: 19373742 at buaa dot edu.cn @ 2023-07-16 15:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CTC <19373742 at buaa dot edu.cn> ---
The reduced optimizations is -O2 -fpack-struct

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/110683] wrong code with '-O2 -fpack-struct'
  2023-07-16 15:07 [Bug c/110683] New: wrong code with '-O2' and specific optimizations 19373742 at buaa dot edu.cn
  2023-07-16 15:07 ` [Bug c/110683] " 19373742 at buaa dot edu.cn
  2023-07-16 15:11 ` 19373742 at buaa dot edu.cn
@ 2023-07-16 15:44 ` 19373742 at buaa dot edu.cn
  2023-07-16 16:20 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: 19373742 at buaa dot edu.cn @ 2023-07-16 15:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CTC <19373742 at buaa dot edu.cn> ---
The reduced program is

# cat mss.i
struct a {
  char b;
  int c;
};
union {
  struct a b;
  short c;
} d = {8, 1};
void main() { printf("%d\n", d.c); }

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/110683] wrong code with '-O2 -fpack-struct'
  2023-07-16 15:07 [Bug c/110683] New: wrong code with '-O2' and specific optimizations 19373742 at buaa dot edu.cn
                   ` (2 preceding siblings ...)
  2023-07-16 15:44 ` [Bug c/110683] wrong code with '-O2 -fpack-struct' 19373742 at buaa dot edu.cn
@ 2023-07-16 16:20 ` pinskia at gcc dot gnu.org
  2023-07-16 17:02 ` pinskia at gcc dot gnu.org
  2023-07-17  7:27 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-16 16:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to CTC from comment #3)
> The reduced program is
> 
> # cat mss.i
> struct a {
>   char b;
>   int c;
> };
> union {
>   struct a b;
>   short c;
> } d = {8, 1};
> void main() { printf("%d\n", d.c); }

This reduced case shows that -fpacked-struct will change the layout of struct a
and nothing more. Without the option there is some padding bytes which are
zero. Also also this reduced testcase depends on the endian of the target.

Maybe the original testcase has similar issues with the unions.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/110683] wrong code with '-O2 -fpack-struct'
  2023-07-16 15:07 [Bug c/110683] New: wrong code with '-O2' and specific optimizations 19373742 at buaa dot edu.cn
                   ` (3 preceding siblings ...)
  2023-07-16 16:20 ` pinskia at gcc dot gnu.org
@ 2023-07-16 17:02 ` pinskia at gcc dot gnu.org
  2023-07-17  7:27 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-16 17:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
ms.c:299:24: warning: taking address of packed member of 'union U1' may result
in an unaligned pointer value [-Waddress-of-packed-member]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/110683] wrong code with '-O2 -fpack-struct'
  2023-07-16 15:07 [Bug c/110683] New: wrong code with '-O2' and specific optimizations 19373742 at buaa dot edu.cn
                   ` (4 preceding siblings ...)
  2023-07-16 17:02 ` pinskia at gcc dot gnu.org
@ 2023-07-17  7:27 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-17  7:27 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
There's a set of options like -fpack-struct that result in a non 1:1 transform
of the program which you probably should avoid using.  In the manual they are
documented to change the ABI.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-07-17  7:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-16 15:07 [Bug c/110683] New: wrong code with '-O2' and specific optimizations 19373742 at buaa dot edu.cn
2023-07-16 15:07 ` [Bug c/110683] " 19373742 at buaa dot edu.cn
2023-07-16 15:11 ` 19373742 at buaa dot edu.cn
2023-07-16 15:44 ` [Bug c/110683] wrong code with '-O2 -fpack-struct' 19373742 at buaa dot edu.cn
2023-07-16 16:20 ` pinskia at gcc dot gnu.org
2023-07-16 17:02 ` pinskia at gcc dot gnu.org
2023-07-17  7:27 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).