Bug 108829 - [12 Regression] internal compiler error: in is_capture_proxy, at cp/lambda.cc:272
Summary: [12 Regression] internal compiler error: in is_capture_proxy, at cp/lambda.cc...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.2.1
: P2 normal
Target Milestone: 12.3
Assignee: Marek Polacek
URL:
Keywords: c++-lambda, ice-checking, ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2023-02-16 18:42 UTC by Slava Barinov
Modified: 2023-02-20 17:28 UTC (History)
2 users (show)

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


Attachments
Reduced test case (174 bytes, text/plain)
2023-02-16 18:42 UTC, Slava Barinov
Details
Result of -freport-bug (209.78 KB, application/gzip)
2023-02-16 18:43 UTC, Slava Barinov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Slava Barinov 2023-02-16 18:42:13 UTC
Created attachment 54474 [details]
Reduced test case

Found an ICE during build of gdal-3.5.3 library

 gdal-3.6.2/ogr/ogrsf_frmts/openfilegdb/filegdbindex_write.cpp: In instantiation of ‘bool OpenFileGDB::WriteIndex(VSILFILE*, std::vector<ValueOIDPair>&, void (*)(std::vector<unsigned char>&, const typename ValueOIDPair::first_type&, int), int&, int) [with ValueOIDPair = std::pair<long int, int>; VSILFILE = FILE; typename ValueOIDPair::first_type = long int]’:
 gdal-3.6.2/ogr/ogrsf_frmts/openfilegdb/filegdbindex_write.cpp:1300:27:   required from here
 gdal-3.6.2/ogr/ogrsf_frmts/openfilegdb/filegdbindex_write.cpp:500:9: internal compiler error: in is_capture_proxy, at cp/lambda.cc:272
Comment 1 Slava Barinov 2023-02-16 18:43:28 UTC
Created attachment 54475 [details]
Result of -freport-bug

Added full output of -freport-bug call
Comment 2 Marek Polacek 2023-02-16 18:46:27 UTC
I can see the ICE but the reduced test seems overreduced and invalid; do you have the original .ii file?
Comment 3 Andrew Pinski 2023-02-16 18:48:40 UTC
Reduced better (to a valid testcase):
```
template <int>
void f(void) {
  constexpr int IDX_PAGE_SIZE = 4096;
  int abyPage = [=, abyPage] { return IDX_PAGE_SIZE; }();
}
void h() {
  f<1>();
}
```
Comment 4 Andrew Pinski 2023-02-16 18:49:34 UTC
(In reply to Marek Polacek from comment #2)
> I can see the ICE but the reduced test seems overreduced and invalid; do you
> have the original .ii file?

It was attached in comment #1 too.
Comment 5 Marek Polacek 2023-02-16 18:55:34 UTC
Oop, I overlooked that.

Started with r12-6065.  So I guess we just need to add the missing STRIP_ANY_LOCATION_WRAPPER somewhere.
Comment 6 GCC Commits 2023-02-20 14:18:03 UTC
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:02d8ab3e4e2f3d9dc12157a98c976d6698e71e29

commit r13-6141-g02d8ab3e4e2f3d9dc12157a98c976d6698e71e29
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu Feb 16 17:41:24 2023 -0500

    c++: ICE with redundant capture [PR108829]
    
    Here we crash in is_capture_proxy:
    
      /* Location wrappers should be stripped or otherwise handled by the
         caller before using this predicate.  */
      gcc_checking_assert (!location_wrapper_p (decl));
    
    We only crash with the redundant capture:
    
      int abyPage = [=, abyPage] { ... }
    
    because prune_lambda_captures is only called when there was a default
    capture, and with [=] only abyPage won't be in LAMBDA_EXPR_CAPTURE_LIST.
    
    The problem is that LAMBDA_CAPTURE_EXPLICIT_P wasn't propagated
    correctly and so var_to_maybe_prune proceeded where it shouldn't.
    
    Co-Authored by: Patrick Palka <ppalka@redhat.com>
    
            PR c++/108829
    
    gcc/cp/ChangeLog:
    
            * pt.cc (prepend_one_capture): Set LAMBDA_CAPTURE_EXPLICIT_P.
            (tsubst_lambda_expr): Pass LAMBDA_CAPTURE_EXPLICIT_P to
            prepend_one_capture.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/lambda/lambda-108829-2.C: New test.
            * g++.dg/cpp0x/lambda/lambda-108829.C: New test.
Comment 7 Marek Polacek 2023-02-20 15:48:52 UTC
Fixed on trunk so far.
Comment 8 GCC Commits 2023-02-20 17:27:34 UTC
The releases/gcc-12 branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:12cdc0e266f02c3ba4e80c3d971463ff507e049b

commit r12-9191-g12cdc0e266f02c3ba4e80c3d971463ff507e049b
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu Feb 16 17:41:24 2023 -0500

    c++: ICE with redundant capture [PR108829]
    
    Here we crash in is_capture_proxy:
    
      /* Location wrappers should be stripped or otherwise handled by the
         caller before using this predicate.  */
      gcc_checking_assert (!location_wrapper_p (decl));
    
    We only crash with the redundant capture:
    
      int abyPage = [=, abyPage] { ... }
    
    because prune_lambda_captures is only called when there was a default
    capture, and with [=] only abyPage won't be in LAMBDA_EXPR_CAPTURE_LIST.
    
    The problem is that LAMBDA_CAPTURE_EXPLICIT_P wasn't propagated
    correctly and so var_to_maybe_prune proceeded where it shouldn't.
    
    Co-Authored by: Patrick Palka <ppalka@redhat.com>
    
            PR c++/108829
    
    gcc/cp/ChangeLog:
    
            * pt.cc (prepend_one_capture): Set LAMBDA_CAPTURE_EXPLICIT_P.
            (tsubst_lambda_expr): Pass LAMBDA_CAPTURE_EXPLICIT_P to
            prepend_one_capture.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/lambda/lambda-108829-2.C: New test.
            * g++.dg/cpp0x/lambda/lambda-108829.C: New test.
    
    (cherry picked from commit 02d8ab3e4e2f3d9dc12157a98c976d6698e71e29)
Comment 9 Marek Polacek 2023-02-20 17:28:02 UTC
Fixed.