[PATCH] D93072: Fix PR35902: incorrect alignment used for ubsan check.
James Y Knight via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 28 15:33:24 PST 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4ddf140c0040: Fix PR35902: incorrect alignment used for ubsan check. (authored by jyknight).
Changed prior to commit:
https://reviews.llvm.org/D93072?vs=311036&id=313908#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93072/new/
https://reviews.llvm.org/D93072
Files:
clang/lib/CodeGen/CGCXXABI.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/test/CodeGenCXX/catch-undef-behavior.cpp
Index: clang/test/CodeGenCXX/catch-undef-behavior.cpp
===================================================================
--- clang/test/CodeGenCXX/catch-undef-behavior.cpp
+++ clang/test/CodeGenCXX/catch-undef-behavior.cpp
@@ -430,8 +430,8 @@
// Note: C is laid out such that offsetof(C, B) + sizeof(B) extends outside
// the C object.
struct alignas(16) A { void *a1, *a2; };
- struct B : virtual A { void *b; };
- struct C : virtual A, virtual B {};
+ struct B : virtual A { void *b; void* g(); };
+ struct C : virtual A, virtual B { };
// CHECK-LABEL: define {{.*}} @_ZN15VBaseObjectSize1fERNS_1BE(
B &f(B &b) {
// Size check: check for nvsize(B) == 16 (do not require size(B) == 32)
@@ -443,6 +443,15 @@
// CHECK: and i64 [[PTRTOINT]], 7,
return b;
}
+
+ // CHECK-LABEL: define {{.*}} @_ZN15VBaseObjectSize1B1gEv(
+ void *B::g() {
+ // Ensure that the check on the "this" pointer also uses the proper
+ // alignment. We should be using nvalign(B) == 8, not 16.
+ // CHECK: [[PTRTOINT:%.+]] = ptrtoint {{.*}} to i64,
+ // CHECK: and i64 [[PTRTOINT]], 7
+ return nullptr;
+ }
}
namespace FunctionSanitizerVirtualCalls {
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1137,11 +1137,9 @@
MD->getParent()->getLambdaCaptureDefault() == LCD_None)
SkippedChecks.set(SanitizerKind::Null, true);
- EmitTypeCheck(isa<CXXConstructorDecl>(MD) ? TCK_ConstructorCall
- : TCK_MemberCall,
- Loc, CXXABIThisValue, ThisTy,
- getContext().getTypeAlignInChars(ThisTy->getPointeeType()),
- SkippedChecks);
+ EmitTypeCheck(
+ isa<CXXConstructorDecl>(MD) ? TCK_ConstructorCall : TCK_MemberCall,
+ Loc, CXXABIThisValue, ThisTy, CXXABIThisAlignment, SkippedChecks);
}
}
Index: clang/lib/CodeGen/CGCXXABI.cpp
===================================================================
--- clang/lib/CodeGen/CGCXXABI.cpp
+++ clang/lib/CodeGen/CGCXXABI.cpp
@@ -135,8 +135,8 @@
// down to whether we know it's a complete object or not.
auto &Layout = CGF.getContext().getASTRecordLayout(MD->getParent());
if (MD->getParent()->getNumVBases() == 0 || // avoid vcall in common case
- MD->getParent()->hasAttr<FinalAttr>() ||
- !isThisCompleteObject(CGF.CurGD)) {
+ MD->getParent()->isEffectivelyFinal() ||
+ isThisCompleteObject(CGF.CurGD)) {
CGF.CXXABIThisAlignment = Layout.getAlignment();
} else {
CGF.CXXABIThisAlignment = Layout.getNonVirtualAlignment();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93072.313908.patch
Type: text/x-patch
Size: 2743 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201228/4e4650b2/attachment.bin>
More information about the cfe-commits
mailing list