[PATCH] D131532: [Sema] Only invoke DiagnoseNullConversions for CPlusPlus (-Wnull-conversion)

Justin Stitt via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 9 17:00:45 PDT 2022


justinstitt created this revision.
Herald added a subscriber: pengfei.
Herald added a project: All.
justinstitt requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

-Wnull-conversion is not supported in C and therefore
DiagnoseNullConversions should only be called for C++.

When testing this change on Linux Kernel builds (x86_64 defconfig) we
see an approximate 2.1% reduction in build times! This is mainly caused
by two methods no longer needing to be invoked as often:

1. ExprConstant::CheckICE and 2) IntExprEvaluator::VisitBinaryOperator.

The former has had its total cpu cycles reduced by ~90% and the latter
by about ~50% for Kernel builds.

The C++ Standard (https://isocpp.org/files/papers/N4860.pdf) states
that "NULL is an implementation-defined null pointer constant" and
"possible definitions include 0, 0L, but not (void*)0". Which may
explain the difference in C and C++ as seen here: https://godbolt.org/z/c5j8fY39


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131532

Files:
  clang/lib/Sema/SemaChecking.cpp


Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -13865,7 +13865,8 @@
     }
   }
 
-  DiagnoseNullConversion(S, E, T, CC);
+  if (S.getLangOpts().CPlusPlus)
+    DiagnoseNullConversion(S, E, T, CC);
 
   S.DiscardMisalignedMemberAddress(Target, E);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131532.451319.patch
Type: text/x-patch
Size: 385 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220810/60a5f04a/attachment.bin>


More information about the cfe-commits mailing list