85 lines · c
1// Check how builtins using varargs behave with the modules.2 3// REQUIRES: x86-registered-target4// RUN: rm -rf %t5// RUN: split-file %s %t6 7// RUN: %clang_cc1 -triple x86_64-apple-darwin \8// RUN: -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules \9// RUN: -emit-module -fmodule-name=DeclareVarargs \10// RUN: -x c %t/include/module.modulemap -o %t/DeclareVarargs.pcm \11// RUN: -fmodule-map-file=%t/resource_dir/module.modulemap -isystem %t/resource_dir12// RUN: %clang_cc1 -triple x86_64-apple-darwin \13// RUN: -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules \14// RUN: -emit-pch -fmodule-name=Prefix \15// RUN: -x c-header %t/prefix.pch -o %t/prefix.pch.gch \16// RUN: -fmodule-map-file=%t/include/module.modulemap -fmodule-file=DeclareVarargs=%t/DeclareVarargs.pcm \17// RUN: -I %t/include18// RUN: %clang_cc1 -triple x86_64-apple-darwin \19// RUN: -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules \20// RUN: -emit-obj -fmodule-name=test \21// RUN: -x c %t/test.c -o %t/test.o \22// RUN: -Werror=incompatible-pointer-types \23// RUN: -fmodule-file=%t/DeclareVarargs.pcm -include-pch %t/prefix.pch.gch \24// RUN: -I %t/include25 26//--- include/declare-varargs.h27#ifndef DECLARE_VARARGS_H28#define DECLARE_VARARGS_H29 30#include <stdarg.h>31 32int vprintf(const char *format, va_list args);33 34// 1. initializeBuiltins 'acos' causes its deserialization and deserialization35// of 'implementation_of_builtin'. Because this is done before Sema initialization,36// 'implementation_of_builtin' DeclID is added to PreloadedDeclIDs.37#undef acos38#define acos(__x) implementation_of_builtin(__x)39 40// 2. Because of 'static' the function isn't added to EagerlyDeserializedDecls41// and not deserialized in `ASTReader::StartTranslationUnit` before `ASTReader::InitializeSema`.42// 3. Because of '__overloadable__' attribute the function requires name mangling during deserialization.43// And the name mangling requires '__builtin_va_list' decl.44// Because the function is added to PreloadedDeclIDs, the deserialization happens in `ASTReader::InitializeSema`.45static int __attribute__((__overloadable__)) implementation_of_builtin(int x) {46 return x;47}48 49#endif // DECLARE_VARARGS_H50 51//--- include/module.modulemap52module DeclareVarargs {53 header "declare-varargs.h"54 export *55}56 57//--- resource_dir/stdarg.h58#ifndef STDARG_H59#define STDARG_H60 61typedef __builtin_va_list va_list;62#define va_start(ap, param) __builtin_va_start(ap, param)63#define va_end(ap) __builtin_va_end(ap)64 65#endif // STDARG_H66 67//--- resource_dir/module.modulemap68module _Builtin_stdarg {69 header "stdarg.h"70 export *71}72 73//--- prefix.pch74#include <declare-varargs.h>75 76//--- test.c77#include <declare-varargs.h>78 79void test(const char *format, ...) {80 va_list argParams;81 va_start(argParams, format);82 vprintf(format, argParams);83 va_end(argParams);84}85