From 64c0792946b792839b2f39e4e208fdd7398aaea0 Mon Sep 17 00:00:00 2001
From: Leonard Chan <leonardchan@google.com>
Date: Thu, 8 Oct 2020 10:27:47 -0700
Subject: [PATCH] [clang][feature] Add cxx_abi_relative_vtable feature

This will be enabled if relative vtables is enabled.

Differential revision: https://reviews.llvm.org/D85924
---
 clang/include/clang/Basic/Features.def              |  2 ++
 .../Lexer/has_feature_cxx_abi_relative_vtable.cpp   | 13 +++++++++++++
 2 files changed, 15 insertions(+)
 create mode 100644 clang/test/Lexer/has_feature_cxx_abi_relative_vtable.cpp

diff --git a/clang/include/clang/Basic/Features.def b/clang/include/clang/Basic/Features.def
index 999bcb7e2e29..302c56763c39 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -256,5 +256,7 @@ EXTENSION(gnu_asm, LangOpts.GNUAsm)
 EXTENSION(gnu_asm_goto_with_outputs, LangOpts.GNUAsm)
 EXTENSION(matrix_types, LangOpts.MatrixTypes)
 
+FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && LangOpts.RelativeCXXABIVTables)
+
 #undef EXTENSION
 #undef FEATURE
diff --git a/clang/test/Lexer/has_feature_cxx_abi_relative_vtable.cpp b/clang/test/Lexer/has_feature_cxx_abi_relative_vtable.cpp
new file mode 100644
index 000000000000..d0f0c27b09d3
--- /dev/null
+++ b/clang/test/Lexer/has_feature_cxx_abi_relative_vtable.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -E %s -triple x86_64-linux-gnu -x c++ -o - | FileCheck %s --check-prefix=NO-RELATIVE-VTABLE
+// RUN: %clang_cc1 -E %s -triple x86_64-linux-gnu -x c++ -fexperimental-relative-c++-abi-vtables -o - | FileCheck %s --check-prefix=RELATIVE-VTABLE
+// RUN: %clang_cc1 -E %s -triple x86_64-linux-gnu -x c++ -fno-experimental-relative-c++-abi-vtables -o - | FileCheck %s --check-prefix=NO-RELATIVE-VTABLE
+// RUN: %clang_cc1 -E %s -triple x86_64-linux-gnu -x c -fexperimental-relative-c++-abi-vtables -o - | FileCheck %s --check-prefix=NO-RELATIVE-VTABLE
+
+#if __has_feature(cxx_abi_relative_vtable)
+int has_relative_vtable();
+#else
+int has_no_relative_vtable();
+#endif
+
+// RELATIVE-VTABLE: has_relative_vtable
+// NO-RELATIVE-VTABLE: has_no_relative_vtable