This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Wrap a macro in do {} while (0) (PR sanitizer/80063)


PVS-Studio tool complained about this and it's right, macros shouldn't expand
to multiple statements like this.

Bootstrapped/regtested on x86_64-linux, applying to trunk.

2017-03-20  Marek Polacek  <polacek@redhat.com>

	PR sanitizer/80063
	* asan.c (DEF_SANITIZER_BUILTIN): Use do { } while (0).

diff --git gcc/asan.c gcc/asan.c
index edcc6ea..a13679d 100644
--- gcc/asan.c
+++ gcc/asan.c
@@ -2567,10 +2567,12 @@ initialize_sanitizer_builtins (void)
 #define DEF_BUILTIN_STUB(ENUM, NAME)
 #undef DEF_SANITIZER_BUILTIN
 #define DEF_SANITIZER_BUILTIN(ENUM, NAME, TYPE, ATTRS) \
-  decl = add_builtin_function ("__builtin_" NAME, TYPE, ENUM,		\
-			       BUILT_IN_NORMAL, NAME, NULL_TREE);	\
-  set_call_expr_flags (decl, ATTRS);					\
-  set_builtin_decl (ENUM, decl, true);
+  do {									\
+    decl = add_builtin_function ("__builtin_" NAME, TYPE, ENUM,		\
+				 BUILT_IN_NORMAL, NAME, NULL_TREE);	\
+    set_call_expr_flags (decl, ATTRS);					\
+    set_builtin_decl (ENUM, decl, true);				\
+  } while (0);
 
 #include "sanitizer.def"
 

	Marek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]