[llvm-branch-commits] [clang] 0439d1d - [Clang] Fix handling of reference types in tryEvaluateBuiltinObjectSize (#138247)
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue May 13 14:36:22 PDT 2025
Author: cor3ntin
Date: 2025-05-13T14:35:50-07:00
New Revision: 0439d1d36312b4abe705d8048cfae64e7fedff6a
URL: https://github.com/llvm/llvm-project/commit/0439d1d36312b4abe705d8048cfae64e7fedff6a
DIFF: https://github.com/llvm/llvm-project/commit/0439d1d36312b4abe705d8048cfae64e7fedff6a.diff
LOG: [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 at nvidia.com>
Added:
Modified:
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/builtin-object-size-cxx14.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5aae78dd2fee7..23602362eaa79 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -12710,11 +12710,13 @@ static bool determineEndOffset(EvalInfo &Info, SourceLocation ExprLoc,
bool DetermineForCompleteObject = refersToCompleteObject(LVal);
auto CheckedHandleSizeof = [&](QualType Ty, CharUnits &Result) {
- if (Ty.isNull() || Ty->isIncompleteType() || Ty->isFunctionType())
+ if (Ty.isNull())
return false;
- if (Ty->isReferenceType())
- Ty = Ty.getNonReferenceType();
+ Ty = Ty.getNonReferenceType();
+
+ if (Ty->isIncompleteType() || Ty->isFunctionType())
+ return false;
return HandleSizeof(Info, ExprLoc, Ty, Result);
};
diff --git a/clang/test/SemaCXX/builtin-object-size-cxx14.cpp b/clang/test/SemaCXX/builtin-object-size-cxx14.cpp
index b7c6f6be01f54..fdd3cb7af088f 100644
--- a/clang/test/SemaCXX/builtin-object-size-cxx14.cpp
+++ b/clang/test/SemaCXX/builtin-object-size-cxx14.cpp
@@ -1,5 +1,7 @@
// 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++2b %s
+
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}}
return __builtin_object_size(p, 0);
}
+
+
+namespace GH129397 {
+
+struct incomplete;
+void test(incomplete &ref) {
+ __builtin_object_size(&ref, 1);
+}
+
+}
More information about the llvm-branch-commits
mailing list