Bug 119480 - Wrong code generated in simple program that uses LLVM::map_to_vector
Summary: Wrong code generated in simple program that uses LLVM::map_to_vector
Status: RESOLVED DUPLICATE of bug 115033
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: alias, wrong-code
Depends on:
Blocks:
 
Reported: 2025-03-26 19:17 UTC by Mark Bourgeault
Modified: 2025-03-26 20:33 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Bourgeault 2025-03-26 19:17:58 UTC
#include <llvm/ADT/SmallVectorExtras.h>

int main()
{
    int data[] = {1,2,3,4,5};
    bool changed = false;
    auto fn = [&](int val) { changed = true; return val; };
    auto out = llvm::map_to_vector(data, fn);
    return changed;
}

Program should print 1.  However, on GCC 12.* and 13.* for -O1 & -O2, the output is 0.

// Summary of Results
//           -O0    -O1/2  -O3
// 11.*      pass   pass   pass
// 12.*      pass   FAIL   pass 
// 13.*      pass   FAIL   pass
// 14.*      pass   pass   pass
Comment 1 Mark Bourgeault 2025-03-26 19:22:47 UTC
https://www.godbolt.org/z/T5qE5M87T shows the issue on Compiler Explorer
Comment 2 Drea Pinski 2025-03-26 19:29:03 UTC
This has already been fixed and it is a dup of bug 115033

*** This bug has been marked as a duplicate of bug 115033 ***
Comment 3 Drea Pinski 2025-03-26 19:32:59 UTC
>// 14.*      pass   pass   pass

No this is incorrect. 14.1.0 fails at -O2, 14.2.0 passes.
Comment 4 Mark Bourgeault 2025-03-26 20:33:42 UTC
Yes, it fails on 14.1.  I was too quick to conclude it was fixed on 14.*.