Skip to content

Commit b116102

Browse files
committed
[Clang][CodeGen] Handle parens
1 parent 586bc15 commit b116102

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4795,9 +4795,9 @@ LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
47954795
// Check whether the underlying base pointer is a constant null.
47964796
// If so, we do not set inbounds flag for GEP to avoid breaking some old-style
47974797
// offsetof idioms.
4798-
Expr *UnderlyingBaseExpr = BaseExpr;
4798+
Expr *UnderlyingBaseExpr = BaseExpr->IgnoreParens();
47994799
while (auto *BaseMemberExpr = dyn_cast<MemberExpr>(UnderlyingBaseExpr))
4800-
UnderlyingBaseExpr = BaseMemberExpr->getBase();
4800+
UnderlyingBaseExpr = BaseMemberExpr->getBase()->IgnoreParens();
48014801
bool IsBaseConstantNull = getContext().isSentinelNullExpr(UnderlyingBaseExpr);
48024802
// If this is s.x, emit s as an lvalue. If it is s->x, emit s as a scalar.
48034803
LValue BaseLV;

clang/test/CodeGenCXX/catch-nullptr-and-nonzero-offset-in-offsetof-idiom.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ uintptr_t get_offset_of_y_naively_nested() {
3434
return ((uintptr_t)(&(((T *)nullptr)->s.y)));
3535
}
3636

37+
// CHECK-LABEL: @_Z42get_offset_of_y_naively_nested_with_parensv(
38+
// CHECK-NEXT: entry:
39+
// CHECK-NEXT: ret i64 ptrtoint (ptr getelementptr nuw ([[STRUCT_S:%.*]], ptr getelementptr nuw ([[STRUCT_T:%.*]], ptr null, i32 0, i32 1), i32 0, i32 1) to i64)
40+
//
41+
uintptr_t get_offset_of_y_naively_nested_with_parens() {
42+
return ((uintptr_t)(&((((T *)nullptr)->s).y)));
43+
}
44+
3745
// CHECK-LABEL: @_Z26get_offset_of_zero_storagev(
3846
// CHECK-NEXT: entry:
3947
// CHECK-NEXT: ret i64 ptrtoint (ptr getelementptr (i8, ptr null, i64 16) to i64)

0 commit comments

Comments
 (0)