From da2012af42fb704365cfaff7ae68fc7de59981da Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sun, 12 Dec 2021 21:11:40 +0100 Subject: [PATCH] Revert clang change that breaks CTF on aarch64 Revert commit e655e74a318e from llvm git (by Peter Collingbourne): AST: Create __va_list in the std namespace even in C. This ensures that the mangled type names match between C and C++, which is significant when using -fsanitize=cfi-icall. Ideally we wouldn't have created this namespace at all, but it's now part of the ABI (e.g. in mangled names), so we can't change it. Differential Revision: https://reviews.llvm.org/D104830 As reported by Jessica in https://reviews.llvm.org/D104830#3129527, this upstream change is implemented in such a way that it breaks DTrace's CTF. Since a proper fix has not yet been forthcoming, and we are unaffected by the (CFI-related) problem upstream was trying to address, revert the change for now. Requested by: jrtc27 MFC after: 3 days --- .../llvm-project/clang/lib/AST/ASTContext.cpp | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/contrib/llvm-project/clang/lib/AST/ASTContext.cpp b/contrib/llvm-project/clang/lib/AST/ASTContext.cpp index 0e163f3161a3..9a51cace3c14 100644 --- a/contrib/llvm-project/clang/lib/AST/ASTContext.cpp +++ b/contrib/llvm-project/clang/lib/AST/ASTContext.cpp @@ -8002,21 +8002,19 @@ static TypedefDecl *CreateVoidPtrBuiltinVaListDecl(const ASTContext *Context) { static TypedefDecl * CreateAArch64ABIBuiltinVaListDecl(const ASTContext *Context) { + // struct __va_list RecordDecl *VaListTagDecl = Context->buildImplicitRecord("__va_list"); - // namespace std { struct __va_list { - // Note that we create the namespace even in C. This is intentional so that - // the type is consistent between C and C++, which is important in cases where - // the types need to match between translation units (e.g. with - // -fsanitize=cfi-icall). Ideally we wouldn't have created this namespace at - // all, but it's now part of the ABI (e.g. in mangled names), so we can't - // change it. - auto *NS = NamespaceDecl::Create( - const_cast(*Context), Context->getTranslationUnitDecl(), - /*Inline*/ false, SourceLocation(), SourceLocation(), - &Context->Idents.get("std"), - /*PrevDecl*/ nullptr); - NS->setImplicit(); - VaListTagDecl->setDeclContext(NS); + if (Context->getLangOpts().CPlusPlus) { + // namespace std { struct __va_list { + NamespaceDecl *NS; + NS = NamespaceDecl::Create(const_cast(*Context), + Context->getTranslationUnitDecl(), + /*Inline*/ false, SourceLocation(), + SourceLocation(), &Context->Idents.get("std"), + /*PrevDecl*/ nullptr); + NS->setImplicit(); + VaListTagDecl->setDeclContext(NS); + } VaListTagDecl->startDefinition();