Skip to content

[BoundsSafety] Don't drop va_list typedef during function merging #10709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3851,6 +3851,21 @@ QualType ASTContext::mergeBoundsSafetyPointerTypes(
if (OrigDstTy.isNull())
OrigDstTy = DstTy;

// An ugly way to keep va_list typedef in DstTy if the merge type doesn't
// change.
// TODO: We need a general way of not stripping sugars.
QualType DesugaredDstTy;
if (const auto *TDT = dyn_cast<TypedefType>(DstTy))
DesugaredDstTy = TDT->desugar();
else if (const auto *ET = dyn_cast<ElaboratedType>(DstTy))
DesugaredDstTy = ET->desugar();
if (!DesugaredDstTy.isNull()) {
QualType MergeTy = mergeBoundsSafetyPointerTypes(DesugaredDstTy, SrcTy,
MergeFunctor, OrigDstTy);
if (MergeTy == DesugaredDstTy)
return DstTy;
}

// FIXME: a brittle hack to avoid skipping ValueTerminatedType outside
// this PtrAutoAttr AttributedType.
bool RecoverPtrAuto = false;
Expand Down
18 changes: 18 additions & 0 deletions clang/test/BoundsSafety/AST/merge-typedef-va-list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -fbounds-safety -ast-dump %s 2>&1 | FileCheck %s
// RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -fbounds-safety -x c++ -fexperimental-bounds-safety-cxx -ast-dump %s 2>&1 | FileCheck %s
// 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
// RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -fexperimental-bounds-safety-attributes -x c -ast-dump %s 2>&1 | FileCheck %s
// RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -fexperimental-bounds-safety-attributes -x c++ -ast-dump %s 2>&1 | FileCheck %s
// RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -fexperimental-bounds-safety-attributes -x objective-c -ast-dump %s 2>&1 | FileCheck %s
// RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -fexperimental-bounds-safety-attributes -x objective-c++ -ast-dump %s 2>&1 | FileCheck %s

#include <stddef.h>

typedef __builtin_va_list va_list;

#define __printflike(fmtarg, firstvararg) \
__attribute__((__format__(__printf__, fmtarg, firstvararg)))

// CHECK: ParmVarDecl {{.+}} foobar 'va_list':'char *'
int vsnprintf(char *__str, size_t __size, const char *__format, va_list foobar)
__printflike(3, 0);