Remove tautological undefined comparisons
A "tautological" comparison is a comparison that's only meaningfully necessary when we consider "undefined" C++ behaviors. For context, in well-formed C++ code: 1. references can never be bound to NULL; and 1. the `this` pointer in a member function can never be NULL Historically ORCA has relied on implementation-specific (undefined, actually) behavior where 1. we might call a member function on a potentially NULL object with the `->` operator, or 1. some callers may bind a (possibly-NULL) pointer to a reference with the '*' operator and try to print it into an IOStream While doing so gives the benefit of centralizing the check, a dependence on undefined behavior means we risk producing the wrong code. Indeed, more modern compilers aggressively optimize against undefined behaviors: e.g. by eliminating the `NULL` checks, or assuming the variable used for indexing an array is never out of bound. Commit ee5ef334 is a "tick" towards reducing such undefined comparisons. This commit is the "tock" that eliminates them. For more context GCC 6+ chokes without this: Running on a macOS iMac: ``` env CC='gcc-6' CXX='g++-6' cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -H. -Bbuild.gcc6.debug ninja -C build.gcc6.debug ``` GCC produces this error: ``` ninja: Entering directory `build.gcc6.debug' [548/1027] Building CXX object libgpopt/CMakeFiles/gpopt.dir/src/base/CCTEMap.cpp.o FAILED: libgpopt/CMakeFiles/gpopt.dir/src/base/CCTEMap.cpp.o ccache /usr/local/bin/g++-6 -Dgpopt_EXPORTS -I/usr/local/include -I../libgpos/include -I../libgpopt/include -I../libgpopt/../libgpcost/include -I../libgpopt/../libnaucrates/include -Ilibgpos/include -Wall -Werror -Wextra -pedantic-errors -Wno-variadic-macros -Wno-tautological-undefined-compare -fno-omit-frame-pointer -g -g3 -fPIC -MD -MT libgpopt/CMakeFiles/gpopt.dir/src/base/CCTEMap.cpp.o -MF libgpopt/CMakeFiles/gpopt.dir/src/base/CCTEMap.cpp.o.d -o libgpopt/CMakeFiles/gpopt.dir/src/base/CCTEMap.cpp.o -c ../libgpopt/src/base/CCTEMap.cpp ../libgpopt/src/base/CCTEMap.cpp: In function 'gpos::IOstream& gpopt::operator<<(gpos::IOstream&, gpopt::CCTEMap&)': ../libgpopt/src/base/CCTEMap.cpp:432:18: error: the compiler can assume that the address of 'cm' will never be NULL [-Werror=address] return (NULL == &cm) ? os : cm.OsPrint(os); ^ At global scope: cc1plus: all warnings being treated as errors [549/1027] Building CXX object libgpopt/CMakeFiles/gpopt.dir/src/base/CCTEReq.cpp.o FAILED: libgpopt/CMakeFiles/gpopt.dir/src/base/CCTEReq.cpp.o ccache /usr/local/bin/g++-6 -Dgpopt_EXPORTS -I/usr/local/include -I../libgpos/include -I../libgpopt/include -I../libgpopt/../libgpcost/include -I../libgpopt/../libnaucrates/include -Ilibgpos/include -Wall -Werror -Wextra -pedantic-errors -Wno-variadic-macros -Wno-tautological-undefined-compare -fno-omit-frame-pointer -g -g3 -fPIC -MD -MT libgpopt/CMakeFiles/gpopt.dir/src/base/CCTEReq.cpp.o -MF libgpopt/CMakeFiles/gpopt.dir/src/base/CCTEReq.cpp.o.d -o libgpopt/CMakeFiles/gpopt.dir/src/base/CCTEReq.cpp.o -c ../libgpopt/src/base/CCTEReq.cpp ../libgpopt/src/base/CCTEReq.cpp: In function 'gpos::IOstream& gpopt::operator<<(gpos::IOstream&, gpopt::CCTEReq&)': ../libgpopt/src/base/CCTEReq.cpp:569:18: error: the compiler can assume that the address of 'cter' will never be NULL [-Werror=address] return (NULL == &cter) ? os : cter.OsPrint(os); ^ At global scope: cc1plus: all warnings being treated as errors [557/1027] Linking CXX shared library libnaucrates/libnaucrates.2.47.0.dylib ninja: build stopped: subcommand failed. ```
Showing
想要评论请 注册 或 登录