Skip to content

Commit cb068dc

Browse files
cor3ntinerichkeane
andauthored
[Clang] Fix handling of reference types in tryEvaluateBuiltinObjectSize (#138247)
The order of operation was slightly incorrect, as we were checking for incomplete types *before* handling reference types. Fixes #129397 --------- Co-authored-by: Erich Keane <ekeane@nvidia.com>
1 parent b752822 commit cb068dc

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

clang/docs/ReleaseNotes.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,8 @@ Bug Fixes to C++ Support
635635
- Clang now emits a warning when class template argument deduction for alias templates is used in C++17. (#GH133806)
636636
- Fix a crash when checking the template template parameters of a dependent lambda appearing in an alias declaration.
637637
(#GH136432), (#GH137014), (#GH138018)
638+
- Fixed an assertion when trying to constant-fold various builtins when the argument
639+
referred to a reference to an incomplete type. (#GH129397)
638640

639641
Bug Fixes to AST Handling
640642
^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -781,7 +783,7 @@ clang-format
781783

782784
libclang
783785
--------
784-
- Fixed a bug in ``clang_File_isEqual`` that sometimes led to different
786+
- Fixed a bug in ``clang_File_isEqual`` that sometimes led to different
785787
in-memory files to be considered as equal.
786788
- Added ``clang_visitCXXMethods``, which allows visiting the methods
787789
of a class.

clang/lib/AST/ExprConstant.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -12772,11 +12772,13 @@ static bool determineEndOffset(EvalInfo &Info, SourceLocation ExprLoc,
1277212772
bool DetermineForCompleteObject = refersToCompleteObject(LVal);
1277312773

1277412774
auto CheckedHandleSizeof = [&](QualType Ty, CharUnits &Result) {
12775-
if (Ty.isNull() || Ty->isIncompleteType() || Ty->isFunctionType())
12775+
if (Ty.isNull())
1277612776
return false;
1277712777

12778-
if (Ty->isReferenceType())
12779-
Ty = Ty.getNonReferenceType();
12778+
Ty = Ty.getNonReferenceType();
12779+
12780+
if (Ty->isIncompleteType() || Ty->isFunctionType())
12781+
return false;
1278012782

1278112783
return HandleSizeof(Info, ExprLoc, Ty, Result);
1278212784
};

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

+12
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)