From 7e145808ae3a1b17c0ce4baf06199153ff4e9e9b Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Thu, 9 Jun 2016 14:02:30 -0700 Subject: [PATCH] Fix misc-macro-parentheses warnings in goldfish/opengl. Add parentheses around macro arguments used beside operators. Use NOLINT to suppress warning or clang-tidy can put parentheses at wrong places. Bug: 28705665 Change-Id: I40653d3e617f84c07b308bb9c2869219f6563706 Test: build with clang-tidy --- camera/Converters.h | 40 +++++++++++----------- camera/EmulatedFakeCamera2.cpp | 2 +- .../system/OpenglSystemCommon/HostConnection.cpp | 2 +- opengl/system/egl/ClientAPIExts.cpp | 12 ++++--- opengl/system/egl/egl.cpp | 8 ++--- opengl/system/egl/eglDisplay.h | 2 +- 6 files changed, 34 insertions(+), 32 deletions(-) diff --git a/camera/Converters.h b/camera/Converters.h index 13e2a85..d92751a 100755 --- a/camera/Converters.h +++ b/camera/Converters.h @@ -79,34 +79,34 @@ static const uint32_t kWhite32 = kRed8 | kGreen8 | kBlue8; #if __BYTE_ORDER == __LITTLE_ENDIAN /* Extract red, green, and blue bytes from RGB565 word. */ -#define R16(rgb) static_cast(rgb & kRed5) -#define G16(rgb) static_cast((rgb & kGreen6) >> 5) -#define B16(rgb) static_cast((rgb & kBlue5) >> 11) +#define R16(rgb) static_cast((rgb) & kRed5) +#define G16(rgb) static_cast(((rgb) & kGreen6) >> 5) +#define B16(rgb) static_cast(((rgb) & kBlue5) >> 11) /* Make 8 bits red, green, and blue, extracted from RGB565 word. */ -#define R16_32(rgb) static_cast(((rgb & kRed5) << 3) | ((rgb & kRed5) >> 2)) -#define G16_32(rgb) static_cast(((rgb & kGreen6) >> 3) | ((rgb & kGreen6) >> 9)) -#define B16_32(rgb) static_cast(((rgb & kBlue5) >> 8) | ((rgb & kBlue5) >> 14)) +#define R16_32(rgb) static_cast((((rgb) & kRed5) << 3) | (((rgb) & kRed5) >> 2)) +#define G16_32(rgb) static_cast((((rgb) & kGreen6) >> 3) | (((rgb) & kGreen6) >> 9)) +#define B16_32(rgb) static_cast((((rgb) & kBlue5) >> 8) | (((rgb) & kBlue5) >> 14)) /* Extract red, green, and blue bytes from RGB32 dword. */ -#define R32(rgb) static_cast(rgb & kRed8) -#define G32(rgb) static_cast(((rgb & kGreen8) >> 8) & 0xff) -#define B32(rgb) static_cast(((rgb & kBlue8) >> 16) & 0xff) +#define R32(rgb) static_cast((rgb) & kRed8) +#define G32(rgb) static_cast((((rgb) & kGreen8) >> 8) & 0xff) +#define B32(rgb) static_cast((((rgb) & kBlue8) >> 16) & 0xff) /* Build RGB565 word from red, green, and blue bytes. */ -#define RGB565(r, g, b) static_cast((((static_cast(b) << 6) | g) << 5) | r) +#define RGB565(r, g, b) static_cast((((static_cast(b) << 6) | (g)) << 5) | (r)) /* Build RGB32 dword from red, green, and blue bytes. */ -#define RGB32(r, g, b) static_cast((((static_cast(b) << 8) | g) << 8) | r) +#define RGB32(r, g, b) static_cast((((static_cast(b) << 8) | (g)) << 8) | (r)) #else // __BYTE_ORDER /* Extract red, green, and blue bytes from RGB565 word. */ -#define R16(rgb) static_cast((rgb & kRed5) >> 11) -#define G16(rgb) static_cast((rgb & kGreen6) >> 5) -#define B16(rgb) static_cast(rgb & kBlue5) +#define R16(rgb) static_cast(((rgb) & kRed5) >> 11) +#define G16(rgb) static_cast(((rgb) & kGreen6) >> 5) +#define B16(rgb) static_cast((rgb) & kBlue5) /* Make 8 bits red, green, and blue, extracted from RGB565 word. */ -#define R16_32(rgb) static_cast(((rgb & kRed5) >> 8) | ((rgb & kRed5) >> 14)) -#define G16_32(rgb) static_cast(((rgb & kGreen6) >> 3) | ((rgb & kGreen6) >> 9)) -#define B16_32(rgb) static_cast(((rgb & kBlue5) << 3) | ((rgb & kBlue5) >> 2)) +#define R16_32(rgb) static_cast((((rgb) & kRed5) >> 8) | (((rgb) & kRed5) >> 14)) +#define G16_32(rgb) static_cast((((rgb) & kGreen6) >> 3) | (((rgb) & kGreen6) >> 9)) +#define B16_32(rgb) static_cast((((rgb) & kBlue5) << 3) | (((rgb) & kBlue5) >> 2)) /* Extract red, green, and blue bytes from RGB32 dword. */ -#define R32(rgb) static_cast((rgb & kRed8) >> 16) -#define G32(rgb) static_cast((rgb & kGreen8) >> 8) -#define B32(rgb) static_cast(rgb & kBlue8) +#define R32(rgb) static_cast(((rgb) & kRed8) >> 16) +#define G32(rgb) static_cast(((rgb) & kGreen8) >> 8) +#define B32(rgb) static_cast((rgb) & kBlue8) /* Build RGB565 word from red, green, and blue bytes. */ #define RGB565(r, g, b) static_cast((((static_cast(r) << 6) | g) << 5) | b) /* Build RGB32 dword from red, green, and blue bytes. */ diff --git a/camera/EmulatedFakeCamera2.cpp b/camera/EmulatedFakeCamera2.cpp index d1beb92..186ae8c 100644 --- a/camera/EmulatedFakeCamera2.cpp +++ b/camera/EmulatedFakeCamera2.cpp @@ -31,7 +31,7 @@ #include #include "gralloc_cb.h" -#define ERROR_CAMERA_NOT_PRESENT -EPIPE +#define ERROR_CAMERA_NOT_PRESENT (-EPIPE) #define CAMERA2_EXT_TRIGGER_TESTING_DISCONNECT 0xFFFFFFFF diff --git a/opengl/system/OpenglSystemCommon/HostConnection.cpp b/opengl/system/OpenglSystemCommon/HostConnection.cpp index 940f5ae..7bd4da2 100644 --- a/opengl/system/OpenglSystemCommon/HostConnection.cpp +++ b/opengl/system/OpenglSystemCommon/HostConnection.cpp @@ -21,7 +21,7 @@ #include "GLEncoder.h" #include "GL2Encoder.h" -#define STREAM_BUFFER_SIZE 4*1024*1024 +#define STREAM_BUFFER_SIZE (4*1024*1024) #define STREAM_PORT_NUM 22468 /* Set to 1 to use a QEMU pipe, or 0 for a TCP connection */ diff --git a/opengl/system/egl/ClientAPIExts.cpp b/opengl/system/egl/ClientAPIExts.cpp index 5e81afe..a18754d 100644 --- a/opengl/system/egl/ClientAPIExts.cpp +++ b/opengl/system/egl/ClientAPIExts.cpp @@ -27,11 +27,12 @@ namespace ClientAPIExts // typename has the form __egl_{funcname}_t // #define FUNC_TYPE(fname) __egl_ ## fname ## _t +// NOLINT: clang-tidy adds parentheses around 'params'. #define API_ENTRY(fname,params,args) \ - typedef void (GL_APIENTRY *FUNC_TYPE(fname)) params; + typedef void (GL_APIENTRY *FUNC_TYPE(fname)) params; // NOLINT #define API_ENTRY_RET(rtype,fname,params,args) \ - typedef rtype (GL_APIENTRY *FUNC_TYPE(fname)) params; + typedef rtype (GL_APIENTRY *FUNC_TYPE(fname)) params; // NOLINT #include "ClientAPIExts.in" #undef API_ENTRY @@ -44,7 +45,7 @@ namespace ClientAPIExts // loaded. ///// #define API_ENTRY(fname,params,args) \ - FUNC_TYPE(fname) fname; + FUNC_TYPE(fname) (fname); #define API_ENTRY_RET(rtype,fname,params,args) \ API_ENTRY(fname,params,args) @@ -88,6 +89,7 @@ void initClientFuncs(const EGLClient_glesInterface *iface, int idx) // the current context version and calls to the correct client API // function. // +// NOLINT: clang-tidy adds parentheses around 'args'. #define API_ENTRY(fname,params,args) \ static void _egl_ ## fname params \ { \ @@ -99,7 +101,7 @@ void initClientFuncs(const EGLClient_glesInterface *iface, int idx) if (!s_client_extensions[idx].fname) { \ return; \ } \ - (*s_client_extensions[idx].fname) args; \ + (*s_client_extensions[idx].fname) args; /* NOLINT */ \ } #define API_ENTRY_RET(rtype,fname,params,args) \ @@ -113,7 +115,7 @@ void initClientFuncs(const EGLClient_glesInterface *iface, int idx) if (!s_client_extensions[idx].fname) { \ return (rtype)0; \ } \ - return (*s_client_extensions[idx].fname) args; \ + return (*s_client_extensions[idx].fname) args; /* NOLINT */ \ } #include "ClientAPIExts.in" diff --git a/opengl/system/egl/egl.cpp b/opengl/system/egl/egl.cpp index a9f6cf7..66e97e3 100644 --- a/opengl/system/egl/egl.cpp +++ b/opengl/system/egl/egl.cpp @@ -86,7 +86,7 @@ const char * eglStrError(EGLint err) #endif //LOG_EGL_ERRORS #define VALIDATE_CONFIG(cfg,ret) \ - if(((intptr_t)cfg<0)||((intptr_t)cfg>s_display.getNumConfigs())) { \ + if(((intptr_t)(cfg)<0)||((intptr_t)(cfg)>s_display.getNumConfigs())) { \ RETURN_ERROR(ret,EGL_BAD_CONFIG); \ } @@ -117,13 +117,13 @@ const char * eglStrError(EGLint err) return ret; \ } -#define VALIDATE_CONTEXT_RETURN(context,ret) \ - if (!context) { \ +#define VALIDATE_CONTEXT_RETURN(context,ret) \ + if (!(context)) { \ RETURN_ERROR(ret,EGL_BAD_CONTEXT); \ } #define VALIDATE_SURFACE_RETURN(surface, ret) \ - if (surface != EGL_NO_SURFACE) { \ + if ((surface) != EGL_NO_SURFACE) { \ egl_surface_t* s( static_cast(surface) ); \ if (s->dpy != (EGLDisplay)&s_display) \ setErrorReturn(EGL_BAD_DISPLAY, EGL_FALSE); \ diff --git a/opengl/system/egl/eglDisplay.h b/opengl/system/egl/eglDisplay.h index 9d979d9..b75b8c2 100644 --- a/opengl/system/egl/eglDisplay.h +++ b/opengl/system/egl/eglDisplay.h @@ -25,7 +25,7 @@ #include -#define ATTRIBUTE_NONE -1 +#define ATTRIBUTE_NONE (-1) //FIXME: are we in this namespace? using namespace android; -- 2.11.0