Skip to content

Commit 9189eaa

Browse files
committed
[Clang][CodeGen] Handle parens
1 parent bf0d1f2 commit 9189eaa

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
@@ -4781,9 +4781,9 @@ LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
47814781
// Check whether the underlying base pointer is a constant null.
47824782
// If so, we do not set inbounds flag for GEP to avoid breaking some old-style
47834783
// offsetof idioms.
4784-
Expr *UnderlyingBaseExpr = BaseExpr;
4784+
Expr *UnderlyingBaseExpr = BaseExpr->IgnoreParens();
47854785
while (auto *BaseMemberExpr = dyn_cast<MemberExpr>(UnderlyingBaseExpr))
4786-
UnderlyingBaseExpr = BaseMemberExpr->getBase();
4786+
UnderlyingBaseExpr = BaseMemberExpr->getBase()->IgnoreParens();
47874787
bool IsBaseConstantNull = getContext().isSentinelNullExpr(UnderlyingBaseExpr);
47884788
// If this is s.x, emit s as an lvalue. If it is s->x, emit s as a scalar.
47894789
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)