Author: majnemer Date: Mon Jun 29 22:30:26 2015 New Revision: 241038 URL: http://llvm.org/viewvc/llvm-project?rev=241038&view=rev Log: [MS ABI] Workaround corner-case bug in the ABI for operator delete
MSVC only genreates array cookies if the class has a destructor. This is problematic when having to call T::operator delete[](void *, size_t) because the second argument's argument is impossible to synthesize correctly if the class has no destructor (because there will be no array cookie). Instead, MSVC passes the size of the class. Do the same, for compatibility, instead of crashing. This fixes PR23990. Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp cfe/trunk/test/CodeGenCXX/microsoft-abi-array-cookies.cpp Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=241038&r1=241037&r2=241038&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Mon Jun 29 22:30:26 2015 @@ -1548,7 +1548,8 @@ namespace { // The size of an element, multiplied by the number of elements. llvm::Value *Size = llvm::ConstantInt::get(SizeTy, ElementTypeSize.getQuantity()); - Size = CGF.Builder.CreateMul(Size, NumElements); + if (NumElements) + Size = CGF.Builder.CreateMul(Size, NumElements); // Plus the size of the cookie if applicable. if (!CookieSize.isZero()) { Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-array-cookies.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-array-cookies.cpp?rev=241038&r1=241037&r2=241038&view=diff ============================================================================== --- cfe/trunk/test/CodeGenCXX/microsoft-abi-array-cookies.cpp (original) +++ cfe/trunk/test/CodeGenCXX/microsoft-abi-array-cookies.cpp Mon Jun 29 22:30:26 2015 @@ -58,4 +58,14 @@ void check_array_cookies_aligned() { // CHECK: getelementptr inbounds i8, i8* [[ARRAY_AS_CHAR]], i64 -8 } +namespace PR23990 { +struct S { + char x[42]; + void operator delete[](void *p, __SIZE_TYPE__); + // CHECK-LABEL: define void @"\01?delete_s@PR23990@@YAXPAUS@1@@Z"( + // CHECK: call void @"\01??_VS@PR23990@@SAXPAXI@Z"(i8* {{.*}}, i32 42) +}; +void delete_s(S *s) { delete[] s; } +} + // CHECK: attributes [[NUW]] = { nounwind{{.*}} } _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits