git: da2012af42fb - main - Revert clang change that breaks CTF on aarch64

From: Dimitry Andric <dim_at_FreeBSD.org>
Date: Sun, 12 Dec 2021 20:12:18 UTC
The branch main has been updated by dim:

URL: https://cgit.FreeBSD.org/src/commit/?id=da2012af42fb704365cfaff7ae68fc7de59981da

commit da2012af42fb704365cfaff7ae68fc7de59981da
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2021-12-12 20:11:40 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-12-12 20:11:40 +0000

    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
---
 contrib/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<ASTContext &>(*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<ASTContext &>(*Context),
+                               Context->getTranslationUnitDecl(),
+                               /*Inline*/ false, SourceLocation(),
+                               SourceLocation(), &Context->Idents.get("std"),
+                               /*PrevDecl*/ nullptr);
+    NS->setImplicit();
+    VaListTagDecl->setDeclContext(NS);
+  }
 
   VaListTagDecl->startDefinition();