[PATCH] D26196: Add support for non-zero null pointers

John McCall via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 8 14:43:00 PST 2016


rjmccall added a comment.

In https://reviews.llvm.org/D26196#589493, @yaxunl wrote:

> Fixed list initialization of large struct which are mostly initialized by 0 through memset.
>  Added tests for casting literal 0 and non-literal integer to pointer.
>
> There are many more places need to be changed. I am wondering if it makes sense to split this feature into multiple pieces, e.g. for C and OpenCL, C++, Objective-C, OpenMP, incrementally.


It's fine to split it up.  Note that at least some of the Objective-C code doesn't need to be updated, because Objective-C object pointers can't be in an alternate address space.



================
Comment at: lib/CodeGen/CGExprConstant.cpp:1645
   if (const RecordType *RT = T->getAs<RecordType>()) {
-    const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
+    const RecordDecl *RD = cast<RecordDecl>(RT->getDecl());
     return ::EmitNullConstant(*this, RD, /*complete object*/ true);
----------------
The cast<> here is now unnecessary.


================
Comment at: lib/CodeGen/CodeGenModule.h:1159
+  /// Does null pointer have zero value.
+  bool isNullPtrZero(llvm::PointerType *T, QualType QT);
+
----------------
This can just take QT; it's not optimized by taking T as well, and in some cases you wouldn't otherwise need to compute that.


================
Comment at: lib/CodeGen/TargetInfo.cpp:7040
+ auto AS = PT->getAddressSpace();
+ return AS != Ctx.getTargetAddressSpace(LangAS::opencl_local) && AS != 0;
+}
----------------
This check is definitely not correct; this function needs to return true when AS == 0, right?

Also, you should really just be checking QT.getAddressSpace().


https://reviews.llvm.org/D26196





More information about the cfe-commits mailing list