Skip to content

Commit 95f5d6c

Browse files
rguenthRichard Biener
authored andcommitted
middle-end/66279 - gimplification clobbers shared asm constraints
When the C++ frontend clones a CTOR we do not copy ASM_EXPR constraints fully as walk_tree does not recurse to TREE_PURPOSE of TREE_LIST nodes. At this point doing that seems too dangerous so the following instead avoids gimplification of ASM_EXPRs to clobber the shared constraints and unshares it there, like it also unshares TREE_VALUE when it re-writes a "+" output constraint to separate "=" output and matching input constraint. PR middle-end/66279 * gimplify.cc (gimplify_asm_expr): Copy TREE_PURPOSE before rewriting it for "+" processing. * g++.dg/pr66279.C: New testcase.
1 parent 616d1bd commit 95f5d6c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

gcc/gimplify.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7810,6 +7810,7 @@ gimplify_asm_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
78107810
/* Turn the in/out constraint into an output constraint. */
78117811
char *p = xstrdup (constraint);
78127812
p[0] = '=';
7813+
TREE_PURPOSE (link) = unshare_expr (TREE_PURPOSE (link));
78137814
TREE_VALUE (TREE_PURPOSE (link)) = build_string (constraint_len, p);
78147815

78157816
/* And add a matching input constraint. */

gcc/testsuite/g++.dg/pr66279.C

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// { dg-do run }
2+
3+
struct A {};
4+
5+
struct B : public virtual A
6+
{
7+
B();
8+
};
9+
10+
B::B()
11+
{
12+
unsigned int x = 42;
13+
14+
__asm__ __volatile__ ("" : "+r"(x));
15+
16+
if (x != 42)
17+
__builtin_abort ();
18+
}
19+
20+
int main()
21+
{
22+
B b;
23+
}

0 commit comments

Comments
 (0)