[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>
This commit is contained in:
cor3ntin 2025-05-02 18:45:24 +02:00 committed by GitHub
parent b752822c44
commit cb068dcec1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 4 deletions

View File

@ -635,6 +635,8 @@ Bug Fixes to C++ Support
- Clang now emits a warning when class template argument deduction for alias templates is used in C++17. (#GH133806) - Clang now emits a warning when class template argument deduction for alias templates is used in C++17. (#GH133806)
- Fix a crash when checking the template template parameters of a dependent lambda appearing in an alias declaration. - Fix a crash when checking the template template parameters of a dependent lambda appearing in an alias declaration.
(#GH136432), (#GH137014), (#GH138018) (#GH136432), (#GH137014), (#GH138018)
- Fixed an assertion when trying to constant-fold various builtins when the argument
referred to a reference to an incomplete type. (#GH129397)
Bug Fixes to AST Handling Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -12772,11 +12772,13 @@ static bool determineEndOffset(EvalInfo &Info, SourceLocation ExprLoc,
bool DetermineForCompleteObject = refersToCompleteObject(LVal); bool DetermineForCompleteObject = refersToCompleteObject(LVal);
auto CheckedHandleSizeof = [&](QualType Ty, CharUnits &Result) { auto CheckedHandleSizeof = [&](QualType Ty, CharUnits &Result) {
if (Ty.isNull() || Ty->isIncompleteType() || Ty->isFunctionType()) if (Ty.isNull())
return false; return false;
if (Ty->isReferenceType()) Ty = Ty.getNonReferenceType();
Ty = Ty.getNonReferenceType();
if (Ty->isIncompleteType() || Ty->isFunctionType())
return false;
return HandleSizeof(Info, ExprLoc, Ty, Result); return HandleSizeof(Info, ExprLoc, Ty, Result);
}; };

View File

@ -1,5 +1,7 @@
// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx14 -std=c++14 %s // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx14 -std=c++14 %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2b %s
typedef __SIZE_TYPE__ size_t; typedef __SIZE_TYPE__ size_t;
@ -119,3 +121,13 @@ constexpr int bos_new() { // cxx14-error {{constant expression}}
void *p = new int; // cxx14-note {{until C++20}} void *p = new int; // cxx14-note {{until C++20}}
return __builtin_object_size(p, 0); return __builtin_object_size(p, 0);
} }
namespace GH129397 {
struct incomplete;
void test(incomplete &ref) {
__builtin_object_size(&ref, 1);
}
}