Bug 1682941

Summary: -O2 level (apparently) elided foo = std::max(foo,1) before foo = std::min(foo, CONST)
Product: [Fedora] Fedora Reporter: Caolan McNamara <caolanm>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED CURRENTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 30CC: aoliva, davejohansen, dmalcolm, fweimer, jakub, jwakely, law, mpolacek, msebor, nickc, pnemade
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-03-02 13:33:45 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1678319    
Attachments:
Description Flags
preprocessed code none

Description Caolan McNamara 2019-02-25 21:37:51 UTC
Created attachment 1538599 [details]
preprocessed code

Description of problem:

code of...

nColCount = 1;
...
nColCount = std::max<sal_Int32>(aIter.toInt32(), 1);
nColCount = std::min<sal_Int32>(nColCount, MAXCOLCOUNT);

results as if std::max line was elided, nColCount ends as 1 regardless of result of aIter.toInt32()

Version-Release number of selected component (if applicable):
gcc-9.0.1-0.4.fc30

How reproducible:
100%

Steps to Reproduce:
1. g++ -std=gnu++2a -fPIC -c -O2 ~/xmlcoli.ii

Actual results:
linking that into LibreOffice gives failure as described in bug #1678319

Additional info:
2. g++ -std=gnu++2a -fPIC -c -O1 ~/xmlcoli.ii

is ok, and rewriting as 

nColCount = aIter.toInt32();
if (nColCount < 1)
    nColCount = 1;
else if (nColCount > MAXCOLCOUNT)
    nColCount = MAXCOLCOUNT;

works fine

Comment 1 Jakub Jelinek 2019-02-28 13:19:12 UTC
Please try gcc-9.0.1-0.8.fc30.

Comment 2 Caolan McNamara 2019-03-02 13:33:45 UTC
works great, thanks