From: Reid Kleckner Date: Fri, 2 May 2014 00:05:16 +0000 (+0000) Subject: MS ABI: Fix logic bug in member pointer null test code X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fb3f2a93e5796908d768ad50bc3e51de8332f3dd;p=clang MS ABI: Fix logic bug in member pointer null test code This code is trying to test if the pointer is *not* null. Therefore we should use 'or' instead of 'and' to combine the results of 'icmp ne'. This logic is consistent with the general member pointer comparison code in EmitMemberPointerComparison. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207815 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/MicrosoftCXXABI.cpp b/lib/CodeGen/MicrosoftCXXABI.cpp index 528cdf6238..869734ab4e 100644 --- a/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/lib/CodeGen/MicrosoftCXXABI.cpp @@ -1628,7 +1628,7 @@ MicrosoftCXXABI::EmitMemberPointerIsNotNull(CodeGenFunction &CGF, for (int I = 1, E = fields.size(); I < E; ++I) { llvm::Value *Field = Builder.CreateExtractValue(MemPtr, I); llvm::Value *Next = Builder.CreateICmpNE(Field, fields[I], "memptr.cmp"); - Res = Builder.CreateAnd(Res, Next, "memptr.tobool"); + Res = Builder.CreateOr(Res, Next, "memptr.tobool"); } return Res; } diff --git a/test/CodeGenCXX/microsoft-abi-member-pointers.cpp b/test/CodeGenCXX/microsoft-abi-member-pointers.cpp index 8d9a848cbc..c5eeb4ef49 100644 --- a/test/CodeGenCXX/microsoft-abi-member-pointers.cpp +++ b/test/CodeGenCXX/microsoft-abi-member-pointers.cpp @@ -229,10 +229,10 @@ bool nullTestDataUnspecified(int Unspecified::*mp) { // CHECK: %[[cmp0:.*]] = icmp ne i32 %[[mp0]], 0 // CHECK: %[[mp1:.*]] = extractvalue { i32, i32, i32 } %[[mp]], 1 // CHECK: %[[cmp1:.*]] = icmp ne i32 %[[mp1]], 0 -// CHECK: %[[and0:.*]] = and i1 %[[cmp0]], %[[cmp1]] +// CHECK: %[[and0:.*]] = or i1 %[[cmp0]], %[[cmp1]] // CHECK: %[[mp2:.*]] = extractvalue { i32, i32, i32 } %[[mp]], 2 // CHECK: %[[cmp2:.*]] = icmp ne i32 %[[mp2]], -1 -// CHECK: %[[and1:.*]] = and i1 %[[and0]], %[[cmp2]] +// CHECK: %[[and1:.*]] = or i1 %[[and0]], %[[cmp2]] // CHECK: ret i1 %[[and1]] // CHECK: } }