This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Wrap a macro in do {} while (0) (PR sanitizer/80063)
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 20 Mar 2017 14:28:02 +0100
- Subject: [PATCH] Wrap a macro in do {} while (0) (PR sanitizer/80063)
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=polacek at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6FC1561BB9
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6FC1561BB9
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