Skip to content

Commit 9d03aa6

Browse files
[BoundsSafety] Don't drop va_list typedef during function merging
rdar://151611200
1 parent 7aed92a commit 9d03aa6

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
@@ -3865,6 +3865,21 @@ QualType ASTContext::mergeBoundsSafetyPointerTypes(
38653865
if (OrigDstTy.isNull())
38663866
OrigDstTy = DstTy;
38673867

3868+
// An ugly way to keep va_list typedef in DstTy if the merge type doesn't
3869+
// change.
3870+
// TODO: We need a general way of not stripping sugars.
3871+
QualType DesugaredDstTy;
3872+
if (const auto *TDT = dyn_cast<TypedefType>(DstTy))
3873+
DesugaredDstTy = TDT->desugar();
3874+
else if (const auto *ET = dyn_cast<ElaboratedType>(DstTy))
3875+
DesugaredDstTy = ET->desugar();
3876+
if (!DesugaredDstTy.isNull()) {
3877+
QualType MergeTy = mergeBoundsSafetyPointerTypes(DesugaredDstTy, SrcTy,
3878+
MergeFunctor, OrigDstTy);
3879+
if (MergeTy == DesugaredDstTy)
3880+
return DstTy;
3881+
}
3882+
38683883
// FIXME: a brittle hack to avoid skipping ValueTerminatedType outside
38693884
// this PtrAutoAttr AttributedType.
38703885
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)