Commit ea9d9d74 by Richard Biener Committed by Richard Biener

re PR c++/89698 (Run-time error due to optimization of field access after cast…

re PR c++/89698 (Run-time error due to optimization of field access after cast at -Os/-O2 and higher)

2019-03-14  Richard Biener  <rguenther@suse.de>

	PR middle-end/89698
	* fold-const.c (operand_equal_p): For INDIRECT_REF check
	that the access types are similar.

	* g++.dg/torture/pr89698.C: New testcase.

From-SVN: r269677
parent f54e63df
2019-03-14 Richard Biener <rguenther@suse.de>
PR middle-end/89698
* fold-const.c (operand_equal_p): For INDIRECT_REF check
that the access types are similar.
2019-03-14 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/89703
......
......@@ -3220,10 +3220,16 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
switch (TREE_CODE (arg0))
{
case INDIRECT_REF:
if (!(flags & OEP_ADDRESS_OF)
&& (TYPE_ALIGN (TREE_TYPE (arg0))
!= TYPE_ALIGN (TREE_TYPE (arg1))))
return 0;
if (!(flags & OEP_ADDRESS_OF))
{
if (TYPE_ALIGN (TREE_TYPE (arg0))
!= TYPE_ALIGN (TREE_TYPE (arg1)))
return 0;
/* Verify that the access types are compatible. */
if (TYPE_MAIN_VARIANT (TREE_TYPE (arg0))
!= TYPE_MAIN_VARIANT (TREE_TYPE (arg1)))
return 0;
}
flags &= ~OEP_ADDRESS_OF;
return OP_SAME (0);
......
2019-03-14 Richard Biener <rguenther@suse.de>
PR middle-end/89698
* g++.dg/torture/pr89698.C: New testcase.
2019-03-14 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/89703
......
/* { dg-do run } */
extern "C" void abort (void);
class A {
virtual void f(){};
public:
int x;
A(int in): x(in) {};
};
class B: public A {
public:
int y;
B(int in):A(in-1), y(in) {};
};
int test(void)
{
int res;
B b(2);
A* bp = &b;
void* vp = dynamic_cast<void*>(bp);
if (((A*)vp)->x == 1 && ((B*)vp)->y == 2)
return 1;
return 0;
}
int main() { if (test() != 1) abort (); return 0; }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment