Commit a5430019 by Marek Polacek Committed by Marek Polacek

re PR sanitizer/58413 (ubsan constant folding)

2013-09-20  Marek Polacek  <polacek@redhat.com>

	PR sanitizer/58413
	* ubsan.c (get_ubsan_type_info_for_type): Use TYPE_SIZE instead of
	TYPE_PRECISION.  Add asserts.

testsuite/
	* c-c++-common/ubsan/shift-4.c: New test.

From-SVN: r202776
parent 9fed7f3a
2013-09-20 Marek Polacek <polacek@redhat.com>
PR sanitizer/58413
* ubsan.c (get_ubsan_type_info_for_type): Use TYPE_SIZE instead of
TYPE_PRECISION. Add asserts.
2013-09-20 Richard Biener <rguenther@suse.de> 2013-09-20 Richard Biener <rguenther@suse.de>
PR tree-optimization/58453 PR tree-optimization/58453
......
2013-09-20 Marek Polacek <polacek@redhat.com>
PR sanitizer/58413
* c-c++-common/ubsan/shift-4.c: New test.
2013-09-20 Richard Biener <rguenther@suse.de> 2013-09-20 Richard Biener <rguenther@suse.de>
PR tree-optimization/58453 PR tree-optimization/58453
......
/* { dg-do run } */
/* { dg-options "-fsanitize=shift -w" } */
struct S { unsigned long long int b:40; } s;
int
main ()
{
s.b = 2;
s.b <<= 120;
return 0;
}
/* { dg-output "shift exponent 120 is too large\[^\n\r]*(\n|\r\n|\r)" } */
...@@ -233,10 +233,9 @@ ubsan_source_location (location_t loc) ...@@ -233,10 +233,9 @@ ubsan_source_location (location_t loc)
static unsigned short static unsigned short
get_ubsan_type_info_for_type (tree type) get_ubsan_type_info_for_type (tree type)
{ {
int prec = exact_log2 (TYPE_PRECISION (type)); gcc_assert (TYPE_SIZE (type) && host_integerp (TYPE_SIZE (type), 1));
if (prec == -1) int prec = exact_log2 (tree_low_cst (TYPE_SIZE (type), 1));
error ("unexpected size of type %qT", type); gcc_assert (prec != -1);
return (prec << 1) | !TYPE_UNSIGNED (type); return (prec << 1) | !TYPE_UNSIGNED (type);
} }
......
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