[PATCH] D158488: [NFC] Initialize member pointers to nullptr.

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 22 05:10:30 PDT 2023


aaron.ballman added inline comments.


================
Comment at: clang/include/clang/AST/Stmt.h:2606-2607
   enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
-  Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
+  Stmt *SubExprs[END_EXPR] = {
+      nullptr}; // SubExprs[INIT] is an expression or declstmt.
   SourceLocation LParenLoc, RParenLoc;
----------------
I don't think this initialization is necessary. The constructor for `ForStmt` initializes all of the valid elements: https://github.com/llvm/llvm-project/blob/87c5a3e203ae3643bc13c9a13917b92a657f4358/clang/lib/AST/Stmt.cpp#L1024

The `EmptyShell` constructor does not initialize anything but that's because it is piecemeal initialized by the AST importer, but all of its fields are also initialized: https://github.com/llvm/llvm-project/blob/87c5a3e203ae3643bc13c9a13917b92a657f4358/clang/lib/Serialization/ASTReaderStmt.cpp#L296


================
Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:934
   // Return value of the runtime offloading call.
-  Value *Return;
+  Value *Return = nullptr;
 
----------------
This is necessary to initialize because `emitTargetKernel()` has an early return which does not initialize the passed reference to this object.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158488/new/

https://reviews.llvm.org/D158488



More information about the cfe-commits mailing list