Skip to content

Commit 4e5e1d5

Browse files
[BoundsSafety] Don't drop va_list typedef during function merging (#10771)
rdar://151611200 (cherry picked from commit 9d03aa6)
1 parent 94e4dcb commit 4e5e1d5

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3707,6 +3707,21 @@ QualType ASTContext::mergeBoundsSafetyPointerTypes(
37073707
if (OrigDstTy.isNull())
37083708
OrigDstTy = DstTy;
37093709

3710+
// An ugly way to keep va_list typedef in DstTy if the merge type doesn't
3711+
// change.
3712+
// TODO: We need a general way of not stripping sugars.
3713+
QualType DesugaredDstTy;
3714+
if (const auto *TDT = dyn_cast<TypedefType>(DstTy))
3715+
DesugaredDstTy = TDT->desugar();
3716+
else if (const auto *ET = dyn_cast<ElaboratedType>(DstTy))
3717+
DesugaredDstTy = ET->desugar();
3718+
if (!DesugaredDstTy.isNull()) {
3719+
QualType MergeTy = mergeBoundsSafetyPointerTypes(DesugaredDstTy, SrcTy,
3720+
MergeFunctor, OrigDstTy);
3721+
if (MergeTy == DesugaredDstTy)
3722+
return DstTy;
3723+
}
3724+
37103725
// FIXME: a brittle hack to avoid skipping ValueTerminatedType outside
37113726
// this PtrAutoAttr AttributedType.
37123727
bool RecoverPtrAuto = false;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -fbounds-safety -ast-dump %s 2>&1 | FileCheck %s
2+
// RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -fbounds-safety -x c++ -fexperimental-bounds-safety-cxx -ast-dump %s 2>&1 | FileCheck %s
3+
// RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -fbounds-safety -x objective-c -fexperimental-bounds-safety-objc -ast-dump %s 2>&1 | FileCheck %s
4+
// RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -fexperimental-bounds-safety-attributes -x c -ast-dump %s 2>&1 | FileCheck %s
5+
// RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -fexperimental-bounds-safety-attributes -x c++ -ast-dump %s 2>&1 | FileCheck %s
6+
// RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -fexperimental-bounds-safety-attributes -x objective-c -ast-dump %s 2>&1 | FileCheck %s
7+
// RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -fexperimental-bounds-safety-attributes -x objective-c++ -ast-dump %s 2>&1 | FileCheck %s
8+
9+
#include <ptrcheck.h>
10+
#include <stdarg.h>
11+
#include <stddef.h>
12+
13+
#define __printf(string_index, first_to_check) \
14+
__attribute__((__format__(__printf__, string_index, first_to_check)))
15+
16+
#ifndef __cplusplus
17+
#define __restrict restrict
18+
#endif
19+
20+
// CHECK: ParmVarDecl {{.+}} foo_args 'va_list':'char *'
21+
int vsnprintf(char *__restrict __counted_by(__size) __str, size_t __size,
22+
const char *__restrict __format, va_list foo_args) __printf(3, 0);

0 commit comments

Comments
 (0)