public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [ubsan] Properly create const char type
@ 2013-08-05 15:15 Marek Polacek
  0 siblings, 0 replies; only message in thread
From: Marek Polacek @ 2013-08-05 15:15 UTC (permalink / raw)
  To: GCC Patches

I was creating the const char type in a wrong way.  I should've used
build_qualified_type, otherwise we'd ICE in the C++ FE later on due to
mismatched TYPE_CANONICALs...

Tested x86_64-pc-linux-gnu, applying to ubsan branch.

2013-08-05  Marek Polacek  <polacek@redhat.com>

	* ubsan.c (ubsan_source_location_type): Properly create
	const char type using build_qualified_type.

	* c-c++-common/ubsan/const-char-1.c: New test.

--- gcc/ubsan.c.mp	2013-08-05 16:15:03.769489097 +0200
+++ gcc/ubsan.c	2013-08-05 16:15:12.352528297 +0200
@@ -226,8 +226,8 @@ ubsan_source_location_type (void)
   static const char *field_names[3]
     = { "__filename", "__line", "__column" };
   tree fields[3], ret;
-  tree const_char_type = char_type_node;
-  TYPE_READONLY (const_char_type) = 1;
+  tree const_char_type = build_qualified_type (char_type_node,
+					       TYPE_QUAL_CONST);
 
   ret = make_node (RECORD_TYPE);
   for (int i = 0; i < 3; i++)
--- gcc/testsuite/c-c++-common/ubsan/const-char-1.c.mp	2013-08-05 16:15:48.733686613 +0200
+++ gcc/testsuite/c-c++-common/ubsan/const-char-1.c	2013-08-05 16:18:06.384287418 +0200
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=shift" } */
+
+void
+foo (void)
+{
+  int y = 1 << 2;
+  __builtin_printf ("%d\n", y);
+}

	Marek

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-08-05 15:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-05 15:15 [ubsan] Properly create const char type Marek Polacek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).