Skip to content

Commit 9c332c2

Browse files
tbaederryuxuanchen1997
authored andcommitted
[clang][Interp] Allow ltor casts for null pointers
Summary: We can't read from them but we special-case them later. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251516
1 parent 88c5df3 commit 9c332c2

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

clang/lib/AST/Interp/EvalEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) {
152152

153153
// Implicitly convert lvalue to rvalue, if requested.
154154
if (ConvertResultToRValue) {
155-
if (!Ptr.isDereferencable())
155+
if (!Ptr.isZero() && !Ptr.isDereferencable())
156156
return false;
157157
// Never allow reading from a non-const pointer, unless the memory
158158
// has been created in this evaluation.

clang/test/CodeGenCXX/nullptr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -I%S -emit-llvm -o - %s | FileCheck %s
2+
// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -I%S -emit-llvm -o - %s -fexperimental-new-constant-interpreter | FileCheck %s
23

34
#include <typeinfo>
45

0 commit comments

Comments
 (0)