Skip to content

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

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

Merged
merged 1 commit into from
Jun 3, 2025
Merged
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 @@ -3707,6 +3707,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
22 changes: 22 additions & 0 deletions clang/test/BoundsSafety/AST/merge-vsnprintf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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 <ptrcheck.h>
#include <stdarg.h>
#include <stddef.h>

#define __printf(string_index, first_to_check) \
__attribute__((__format__(__printf__, string_index, first_to_check)))

#ifndef __cplusplus
#define __restrict restrict
#endif

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