Bug 104182 - [12 Regression] Wrong code since r12-6329-g4f6bc28fc7dd86bd
Summary: [12 Regression] Wrong code since r12-6329-g4f6bc28fc7dd86bd
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.0
: P1 critical
Target Milestone: 12.0
Assignee: Jason Merrill
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2022-01-22 09:25 UTC by Martin Liška
Modified: 2024-10-31 04:32 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2022-01-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liška 2022-01-22 09:25:22 UTC
Originally reported here:
https://gitlab.kitware.com/cmake/cmake/-/issues/23126#note_1111696

for the following we emit a wrong code:

$ cat cmake-repro.C
#include <iostream>
#include <string>
#include <vector>

struct S
{
  int A;
  std::string B;
};

struct V
{
  std::vector<S> v;
};

static const V v{ { { { 1, "2" } } } };

int main()
{
  if (v.v[0].A != 1 || v.v[0].B[0] != '2')
    __builtin_abort();
  return 0;
}

$ g++ cmake-repro.C && ./a.out
Aborted (core dumped)
Comment 1 GCC Commits 2022-01-23 03:19:13 UTC
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:9718bc4b03c1a94f7cf64860bbc828aa53c56234

commit r12-6822-g9718bc4b03c1a94f7cf64860bbc828aa53c56234
Author: Jason Merrill <jason@redhat.com>
Date:   Sat Jan 22 17:11:54 2022 -0500

    c++: array temporary at file scope [PR104182]
    
    This is the same issue as PR104031, but that patch doesn't fix this
    testcase because in this case, current_function_decl isn't set when we get
    to cp_genericize_target_expr.  But there seems to be no need for
    is_local_temp to check for function scope; !TREE_STATIC should be enough.
    
            PR c++/104182
    
    gcc/cp/ChangeLog:
    
            * cp-gimplify.cc (cp_genericize_target_expr): Make sure nothing
            has set DECL_INITIAL on a TARGET_EXPR slot.
            * tree.cc (is_local_temp): Don't check DECL_CONTEXT.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/initlist127.C: New test.
Comment 2 Jason Merrill 2022-01-23 22:34:05 UTC
Fixed.