Skip to content

Commit 0439d1d

Browse files
cor3ntinerichkeane
authored andcommitted
[Clang] Fix handling of reference types in tryEvaluateBuiltinObjectSize (llvm#138247)
The order of operation was slightly incorrect, as we were checking for incomplete types *before* handling reference types. Fixes llvm#129397 --------- Co-authored-by: Erich Keane <[email protected]>
1 parent 74ed1ac commit 0439d1d

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12710,11 +12710,13 @@ static bool determineEndOffset(EvalInfo &Info, SourceLocation ExprLoc,
1271012710
bool DetermineForCompleteObject = refersToCompleteObject(LVal);
1271112711

1271212712
auto CheckedHandleSizeof = [&](QualType Ty, CharUnits &Result) {
12713-
if (Ty.isNull() || Ty->isIncompleteType() || Ty->isFunctionType())
12713+
if (Ty.isNull())
1271412714
return false;
1271512715

12716-
if (Ty->isReferenceType())
12717-
Ty = Ty.getNonReferenceType();
12716+
Ty = Ty.getNonReferenceType();
12717+
12718+
if (Ty->isIncompleteType() || Ty->isFunctionType())
12719+
return false;
1271812720

1271912721
return HandleSizeof(Info, ExprLoc, Ty, Result);
1272012722
};

clang/test/SemaCXX/builtin-object-size-cxx14.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx14 -std=c++14 %s
22
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s
3+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2b %s
4+
35

46
typedef __SIZE_TYPE__ size_t;
57

@@ -119,3 +121,13 @@ constexpr int bos_new() { // cxx14-error {{constant expression}}
119121
void *p = new int; // cxx14-note {{until C++20}}
120122
return __builtin_object_size(p, 0);
121123
}
124+
125+
126+
namespace GH129397 {
127+
128+
struct incomplete;
129+
void test(incomplete &ref) {
130+
__builtin_object_size(&ref, 1);
131+
}
132+
133+
}

0 commit comments

Comments
 (0)