@@ -1,3 +1,8 @@
+2013-08-20 Marek Polacek <polacek@redhat.com>
+
+ * ubsan.c (is_ubsan_builtin_p): New function.
+ * ubsan.h: Declare it.
+
2013-08-05 Marek Polacek <polacek@redhat.com>
* ubsan.c (ubsan_source_location_type): Properly create
@@ -1,3 +1,7 @@
+2013-08-20 Marek Polacek <polacek@redhat.com>
+
+ * error.c (dump_expr): Special-case ubsan builtins.
+
2013-07-30 Marek Polacek <polacek@redhat.com>
* typeck.c (cp_build_binary_op): Sanitize only when
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree-pretty-print.h"
#include "pointer-set.h"
#include "c-family/c-objc.h"
+#include "ubsan.h"
#define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',')
#define pp_separate_with_semicolon(PP) pp_cxx_separate_with (PP, ';')
@@ -1972,6 +1973,12 @@ dump_expr (tree t, int flags)
}
skipfirst = true;
}
+ if (flag_sanitize & SANITIZE_UNDEFINED
+ && is_ubsan_builtin_p (fn))
+ {
+ pp_string (cxx_pp, M_("<ubsan routine call>"));
+ break;
+ }
dump_expr (fn, flags | TFF_EXPR_IN_PARENS);
dump_call_expr_args (t, flags, skipfirst);
}
@@ -1,3 +1,7 @@
+2013-08-20 Marek Polacek <polacek@redhat.com>
+
+ * g++.dg/ubsan/div-by-zero-1.C: New test.
+
2013-08-15 Marek Polacek <polacek@redhat.com>
* c-c++-common/ubsan/save-expr-1.c: New test.
new file mode 100644
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=shift -w" } */
+
+void
+foo (int i)
+{
+ switch (i)
+ case 0 * (1 / 0): /* { dg-error "is not a constant expression" } */
+ ;
+}
@@ -456,3 +456,13 @@ ubsan_instrument_unreachable (location_t loc)
tree t = builtin_decl_explicit (BUILT_IN_UBSAN_HANDLE_BUILTIN_UNREACHABLE);
return build_call_expr_loc (loc, t, 1, build_fold_addr_expr_loc (loc, data));
}
+
+/* Return true if T is a call to a libubsan routine. */
+
+bool
+is_ubsan_builtin_p (tree t)
+{
+ gcc_checking_assert (TREE_CODE (t) == FUNCTION_DECL);
+ return strncmp (IDENTIFIER_POINTER (DECL_NAME (t)),
+ "__builtin___ubsan_", 18) == 0;
+}
@@ -25,6 +25,7 @@ extern tree ubsan_instrument_unreachable (location_t);
extern tree ubsan_create_data (const char *, location_t, ...);
extern tree ubsan_type_descriptor (tree);
extern tree ubsan_encode_value (tree);
+extern bool is_ubsan_builtin_p (tree);
#endif /* GCC_UBSAN_H */