diff options
author | Jakub Jelinek <jakub@redhat.com> | 2022-01-17 18:10:34 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2022-01-17 18:10:34 +0100 |
commit | aeca44768d54b089243004d1ef00d34dfa9f6530 (patch) | |
tree | 02a011d8b42f22feaf41b04b75afd9ab09b5a953 /libcpp/directives.c | |
parent | d3a57993359c9759990fe8f2aa4088684ed82190 (diff) | |
download | gcc-aeca44768d54b089243004d1ef00d34dfa9f6530.zip gcc-aeca44768d54b089243004d1ef00d34dfa9f6530.tar.gz gcc-aeca44768d54b089243004d1ef00d34dfa9f6530.tar.bz2 |
c++: Fix cp_genericize_target_expr for TARGET_EXPRs created for global initialization [PR104031]
The following patch is miscompiled, cp_genericize_target_expr expects
that for the constant part split_nonconstant_init will emit an INIT_EXPR
that will initialize it, but that doesn't happen and instead we get
DECL_INITIAL on the TARGET_EXPR_SLOT that isn't initialized anywhere
in the IL.
The problem is that the TARGET_EXPR has been created while
current_function_decl was NULL, it is inside a global var initializer.
That means the build_local_temp created VAR_DECL has NULL DECL_CONTEXT.
Later on when genericizing the ssdf (current_function_decl is already
non-NULL), the new cp_genericize_target_expr is called and during
split_nonconstant_init it checks is_local_temp, but that due to the NULL
DECL_CONTEXT returns false. DECL_CONTEXT is set only later on during
gimplification.
The following patch fixes it by setting DECL_CONTEXT also inside of
cp_genericize_target_expr, which fixes the testcase. But if there are
better spots to do that, please let me know...
2022-01-17 Jakub Jelinek <jakub@redhat.com>
PR c++/104031
* cp-gimplify.c (cp_genericize_target_expr): Set DECL_CONTEXT of
TARGET_EXPR_SLOT to current_function_decl if it was NULL.
* g++.dg/cpp1y/pr104031.C: New test.
Diffstat (limited to 'libcpp/directives.c')
0 files changed, 0 insertions, 0 deletions