[clang] 2b6e5fa - [clang][ASTImporter] Add import of attribute 'enable_if'.

Balázs Kéri via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 12 01:04:33 PDT 2022


Author: Balázs Kéri
Date: 2022-04-12T10:02:51+02:00
New Revision: 2b6e5fa62b80f4c0ca540e2fc0ebe3b15e50b78a

URL: https://github.com/llvm/llvm-project/commit/2b6e5fa62b80f4c0ca540e2fc0ebe3b15e50b78a
DIFF: https://github.com/llvm/llvm-project/commit/2b6e5fa62b80f4c0ca540e2fc0ebe3b15e50b78a.diff

LOG: [clang][ASTImporter] Add import of attribute 'enable_if'.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D123397

Added: 
    

Modified: 
    clang/lib/AST/ASTImporter.cpp
    clang/unittests/AST/ASTImporterTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index e3b3deff7c5c9..b368dbf1d5ce9 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -8583,6 +8583,13 @@ Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) {
     break;
   }
 
+  case attr::EnableIf: {
+    const auto *From = cast<EnableIfAttr>(FromAttr);
+    AI.importAttr(From, AI.importArg(From->getCond()).value(),
+                  From->getMessage());
+    break;
+  }
+
   case attr::AssertCapability: {
     const auto *From = cast<AssertCapabilityAttr>(FromAttr);
     AI.importAttr(From,

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index 1e66701cd7128..7988603c4d734 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -6634,6 +6634,15 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportFormatAttr) {
   EXPECT_EQ(FromAttr->getType()->getName(), ToAttr->getType()->getName());
 }
 
+TEST_P(ImportAttributes, ImportEnableIf) {
+  EnableIfAttr *FromAttr, *ToAttr;
+  importAttr<FunctionDecl>(
+      "void test(int A) __attribute__((enable_if(A == 1, \"message\")));",
+      FromAttr, ToAttr);
+  checkImported(FromAttr->getCond(), ToAttr->getCond());
+  EXPECT_EQ(FromAttr->getMessage(), ToAttr->getMessage());
+}
+
 TEST_P(ImportAttributes, ImportGuardedVar) {
   GuardedVarAttr *FromAttr, *ToAttr;
   importAttr<VarDecl>("int test __attribute__((guarded_var));", FromAttr,


        


More information about the cfe-commits mailing list