Update to LLVM 17.0.6
1. Use llvm-cmake-util package 2. Add tools-extra-devel package to include clang-tidy 3. Use LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR to specify the path of clang-tool-extra src 4. Add Patchs for fix build error(Reference fedora) 5. Add clang-tblgen to clang-devel package
This commit is contained in:
parent
1869d557d1
commit
fb545c1c29
@ -1,42 +0,0 @@
|
||||
From c6b921c8d833546946b70a8c2640032fd7c62461 Mon Sep 17 00:00:00 2001
|
||||
From: serge-sans-paille <sguelton@redhat.com>
|
||||
Date: Thu, 25 Feb 2021 14:04:52 +0100
|
||||
Subject: [PATCH 1/6] [PATCH][clang] Reorganize gtest integration
|
||||
|
||||
---
|
||||
clang/CMakeLists.txt | 12 +++++-------
|
||||
1 file changed, 5 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
|
||||
index 9e74014..0185276 100644
|
||||
--- a/clang/CMakeLists.txt
|
||||
+++ b/clang/CMakeLists.txt
|
||||
@@ -153,12 +153,6 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
|
||||
set(LLVM_UTILS_PROVIDED ON)
|
||||
set(CLANG_TEST_DEPS FileCheck count not)
|
||||
endif()
|
||||
- set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
|
||||
- if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
|
||||
- AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
|
||||
- AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
|
||||
- add_subdirectory(${UNITTEST_DIR} utils/unittest)
|
||||
- endif()
|
||||
else()
|
||||
# Seek installed Lit.
|
||||
find_program(LLVM_LIT
|
||||
@@ -537,7 +531,11 @@ endif()
|
||||
|
||||
|
||||
if( CLANG_INCLUDE_TESTS )
|
||||
- if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h)
|
||||
+ set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
|
||||
+ if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
|
||||
+ AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
|
||||
+ AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
|
||||
+ add_subdirectory(${UNITTEST_DIR} utils/unittest)
|
||||
add_subdirectory(unittests)
|
||||
list(APPEND CLANG_TEST_DEPS ClangUnitTests)
|
||||
list(APPEND CLANG_TEST_PARAMS
|
||||
--
|
||||
1.8.3.1
|
||||
|
||||
Binary file not shown.
Binary file not shown.
BIN
clang-tools-extra-17.0.6.src.tar.xz
Normal file
BIN
clang-tools-extra-17.0.6.src.tar.xz
Normal file
Binary file not shown.
107
clang.spec
107
clang.spec
@ -1,17 +1,19 @@
|
||||
%bcond_with sys_llvm
|
||||
%bcond_with check
|
||||
%bcond_without sys_llvm
|
||||
%bcond_without check
|
||||
|
||||
%global maj_ver 12
|
||||
%global maj_ver 17
|
||||
%global min_ver 0
|
||||
%global patch_ver 1
|
||||
%global patch_ver 6
|
||||
%global clang_version %{maj_ver}.%{min_ver}.%{patch_ver}
|
||||
|
||||
%if %{with sys_llvm}
|
||||
%global pkg_name clang
|
||||
%global install_prefix %{_prefix}
|
||||
%global install_datadir %{_datadir}
|
||||
%else
|
||||
%global pkg_name clang%{maj_ver}
|
||||
%global install_prefix %{_libdir}/llvm%{maj_ver}
|
||||
%global install_datadir %{install_prefix}/share
|
||||
%endif
|
||||
|
||||
%global install_bindir %{install_prefix}/bin
|
||||
@ -34,7 +36,7 @@
|
||||
|
||||
Name: %{pkg_name}
|
||||
Version: %{clang_version}
|
||||
Release: 4
|
||||
Release: 1
|
||||
Summary: A C language family front-end for LLVM
|
||||
|
||||
License: NCSA
|
||||
@ -42,10 +44,11 @@ URL: http://llvm.org
|
||||
Source0: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{clang_version}/%{clang_srcdir}.tar.xz
|
||||
Source1: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{clang_version}/%{clang_tools_srcdir}.tar.xz
|
||||
|
||||
Patch1: 0001-fedora-PATCH-clang-Reorganize-gtest-integration.patch
|
||||
Patch2: 0003-fedora-PATCH-clang-Don-t-install-static-libraries.patch
|
||||
Patch201: support-ignored_and_replaced_opts.patch
|
||||
Patch202: support-print-c-function-prototype.patch
|
||||
Patch0: fedora-PATCH-clang-Don-t-install-static-libraries.patch
|
||||
|
||||
# Patches for clang-tools-extra
|
||||
# See https://reviews.llvm.org/D120301
|
||||
Patch201: fedora-clang-tools-extra-Make-test-dependency-on-LLVMHello-.patch
|
||||
|
||||
BuildRequires: gcc
|
||||
BuildRequires: gcc-c++
|
||||
@ -57,11 +60,13 @@ BuildRequires: llvm-devel = %{version}
|
||||
BuildRequires: llvm-static = %{version}
|
||||
BuildRequires: llvm-test = %{version}
|
||||
BuildRequires: llvm-googletest = %{version}
|
||||
BuildRequires: llvm-cmake-utils = %{version}
|
||||
%else
|
||||
BuildRequires: llvm%{maj_ver}-devel = %{version}
|
||||
BuildRequires: llvm%{maj_ver}-static = %{version}
|
||||
BuildRequires: llvm%{maj_ver}-test = %{version}
|
||||
BuildRequires: llvm%{maj_ver}-googletest = %{version}
|
||||
BuildRequires: llvm%{maj_ver}-cmake-utils = %{version}
|
||||
%endif
|
||||
|
||||
BuildRequires: libxml2-devel
|
||||
@ -89,6 +94,8 @@ BuildRequires: perl(Sys::Hostname)
|
||||
Requires: %{name}-libs%{?_isa} = %{version}-%{release}
|
||||
|
||||
Requires: libstdc++-devel
|
||||
# Require gcc libs installed during rumtime
|
||||
Requires: gcc
|
||||
Requires: gcc-c++
|
||||
|
||||
Provides: clang(major) = %{maj_ver}
|
||||
@ -155,6 +162,13 @@ Requires: emacs-filesystem
|
||||
%description tools-extra
|
||||
A set of extra tools built using Clang's tooling API.
|
||||
|
||||
%package tools-extra-devel
|
||||
Summary: Development header files for clang tools
|
||||
Requires: %{name}-tools-extra = %{version}-%{release}
|
||||
|
||||
%description tools-extra-devel
|
||||
Development header files for clang tools.
|
||||
|
||||
%package -n git-clang-format
|
||||
Summary: Integration of clang-format for git
|
||||
Requires: %{name}-tools-extra = %{version}-%{release}
|
||||
@ -166,24 +180,27 @@ clang-format integration for git.
|
||||
|
||||
%prep
|
||||
%setup -T -q -b 1 -n %{clang_tools_srcdir}
|
||||
%autopatch -m200 -p2
|
||||
|
||||
# failing test case
|
||||
#rm test/clang-tidy/checkers/altera/struct-pack-align.cpp
|
||||
|
||||
pathfix.py -i %{__python3} -pn \
|
||||
clang-tidy/tool/*.py
|
||||
clang-tidy/tool/ \
|
||||
clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
|
||||
|
||||
%setup -q -n %{clang_srcdir}
|
||||
%autopatch -M200 -p2
|
||||
%autopatch -m200 -p1
|
||||
|
||||
# failing test case
|
||||
rm test/CodeGen/profile-filter.c
|
||||
|
||||
pathfix.py -i %{__python3} -pn \
|
||||
tools/clang-format/*.py \
|
||||
tools/clang-format/ \
|
||||
tools/clang-format/git-clang-format \
|
||||
utils/hmaptool/hmaptool \
|
||||
tools/scan-view/bin/scan-view
|
||||
|
||||
mv ../%{clang_tools_srcdir} tools/extra
|
||||
tools/scan-view/bin/scan-view \
|
||||
tools/scan-view/share/Reporter.py \
|
||||
tools/scan-view/share/startfile.py \
|
||||
tools/scan-build-py/bin/* \
|
||||
tools/scan-build-py/libexec/*
|
||||
|
||||
%build
|
||||
mkdir -p _build
|
||||
@ -204,6 +221,7 @@ cd _build
|
||||
-DLLVM_MAIN_SRC_DIR=%{install_prefix}/src \
|
||||
-DLLVM_LIT_ARGS="-vv" \
|
||||
-DLLVM_BUILD_UTILS:BOOL=ON \
|
||||
-DLLVM_COMMON_CMAKE_UTILS=%{install_datadir}/llvm/cmake \
|
||||
-DCLANG_ENABLE_ARCMT:BOOL=ON \
|
||||
-DCLANG_ENABLE_STATIC_ANALYZER:BOOL=ON \
|
||||
-DCLANG_INCLUDE_DOCS:BOOL=ON \
|
||||
@ -218,6 +236,12 @@ cd _build
|
||||
-DCLANG_BUILD_EXAMPLES:BOOL=OFF \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
-DCLANG_REPOSITORY_STRING="%{?distro} %{version}-%{release}" \
|
||||
-DLLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR=../../%{clang_tools_srcdir} \
|
||||
%if 0%{?__isa_bits} == 64
|
||||
-DCLANG_RESOURCE_DIR=../lib64/clang/%{maj_ver} \
|
||||
%else
|
||||
-DCLANG_RESOURCE_DIR=../lib/clang/%{maj_ver} \
|
||||
%endif
|
||||
%if 0%{?__isa_bits} == 64
|
||||
-DLLVM_LIBDIR_SUFFIX=64 \
|
||||
%else
|
||||
@ -232,15 +256,18 @@ cd _build
|
||||
%ninja_install -C _build
|
||||
mkdir -p %{buildroot}/%{_bindir}
|
||||
|
||||
rm -vf %{buildroot}%{_datadir}/clang/clang-format-bbedit.applescript
|
||||
rm -vf %{buildroot}%{_datadir}/clang/clang-format-sublime.py*
|
||||
|
||||
rm -vf %{buildroot}%{install_sharedir}/clang/clang-format-bbedit.applescript
|
||||
rm -vf %{buildroot}%{install_sharedir}/clang/clang-format-sublime.py*
|
||||
|
||||
rm -Rvf %{buildroot}%{install_docdir}/clang/html
|
||||
rm -Rvf %{buildroot}%{install_docdir}/Clang/clang/html
|
||||
rm -Rvf %{buildroot}%{install_sharedir}/clang/clang-doc-default-stylesheet.css
|
||||
rm -Rvf %{buildroot}%{install_sharedir}/clang/index.js
|
||||
rm -vf %{buildroot}%{install_sharedir}/clang/bash-autocomplete.sh
|
||||
|
||||
mkdir -p %{buildroot}%{install_libdir}/clang/%{version}/{include,lib,share}/
|
||||
mkdir -p %{buildroot}%{install_libdir}/clang/%{maj_ver}/{bin,include,lib,share}/
|
||||
|
||||
%check
|
||||
%if %{with check}
|
||||
@ -259,33 +286,44 @@ LD_LIBRARY_PATH=%{buildroot}/%{install_libdir} %{__ninja} check-all -C ./_build
|
||||
|
||||
%files libs
|
||||
%{install_libdir}/*.so.*
|
||||
%{install_libdir}/clang/%{version}/include/*
|
||||
%{install_libdir}/clang/%{maj_ver}/include/*
|
||||
|
||||
%files devel
|
||||
%{install_libdir}/*.so
|
||||
%{install_includedir}/clang/
|
||||
%{install_includedir}/clang-c/
|
||||
%{install_includedir}/clang-tidy/
|
||||
%{install_libdir}/cmake/*
|
||||
|
||||
%{_bindir}/clang-tblgen
|
||||
%dir %{_datadir}/clang/
|
||||
|
||||
%files resource-filesystem
|
||||
%dir %{install_libdir}/clang/%{version}/
|
||||
%dir %{install_libdir}/clang/%{version}/include/
|
||||
%dir %{install_libdir}/clang/%{version}/lib/
|
||||
%dir %{install_libdir}/clang/%{version}/share/
|
||||
%dir %{install_libdir}/clang/%{maj_ver}/
|
||||
%dir %{install_libdir}/clang/%{maj_ver}/include/
|
||||
%dir %{install_libdir}/clang/%{maj_ver}/lib/
|
||||
%dir %{install_libdir}/clang/%{maj_ver}/share/
|
||||
%dir %{install_libdir}/clang/
|
||||
|
||||
%files analyzer
|
||||
%{install_libexecdir}/ccc-analyzer
|
||||
%{install_libexecdir}/c++-analyzer
|
||||
%{install_libexecdir}/analyze-c++
|
||||
%{install_libexecdir}/analyze-cc
|
||||
%{install_libexecdir}/intercept-c++
|
||||
%{install_libexecdir}/intercept-cc
|
||||
%{install_bindir}/scan-view
|
||||
%{install_bindir}/scan-build
|
||||
%{install_bindir}/analyze-build
|
||||
%{install_bindir}/intercept-build
|
||||
%{install_bindir}/scan-build-py
|
||||
%{install_prefix}/share/man/man1/*
|
||||
%{install_libdir}/libear
|
||||
%{install_libdir}/libscanbuild
|
||||
%{install_sharedir}/scan-view
|
||||
%{install_sharedir}/scan-build
|
||||
|
||||
|
||||
%files tools-extra
|
||||
%{install_bindir}/amdgpu-arch
|
||||
%{install_bindir}/c-index-test
|
||||
%{install_bindir}/clang-apply-replacements
|
||||
%{install_bindir}/clang-change-namespace
|
||||
@ -293,22 +331,28 @@ LD_LIBRARY_PATH=%{buildroot}/%{install_libdir} %{__ninja} check-all -C ./_build
|
||||
%{install_bindir}/clang-doc
|
||||
%{install_bindir}/clang-extdef-mapping
|
||||
%{install_bindir}/clang-format
|
||||
%{install_bindir}/clang-include-cleaner
|
||||
%{install_bindir}/clang-include-fixer
|
||||
%{install_bindir}/clang-move
|
||||
%{install_bindir}/clang-offload-bundler
|
||||
%{install_bindir}/clang-offload-wrapper
|
||||
%{install_bindir}/clang-offload-packager
|
||||
%{install_bindir}/clang-linker-wrapper
|
||||
%{install_bindir}/clang-pseudo
|
||||
%{install_bindir}/clang-query
|
||||
%{install_bindir}/clang-refactor
|
||||
%{install_bindir}/clang-rename
|
||||
%{install_bindir}/clang-reorder-fields
|
||||
%{install_bindir}/clang-repl
|
||||
%{install_bindir}/clang-scan-deps
|
||||
%{install_bindir}/clang-tidy
|
||||
%{install_bindir}/clangd
|
||||
%{install_bindir}/diagtool
|
||||
%{install_bindir}/hmaptool
|
||||
%{install_bindir}/nvptx-arch
|
||||
%{install_bindir}/pp-trace
|
||||
%{install_bindir}/find-all-symbols
|
||||
%{install_bindir}/modularize
|
||||
%{install_bindir}/run-clang-tidy
|
||||
%{install_sharedir}/clang/clang-format.el
|
||||
%{install_sharedir}/clang/clang-rename.el
|
||||
%{install_sharedir}/clang/clang-include-fixer.el
|
||||
@ -317,13 +361,18 @@ LD_LIBRARY_PATH=%{buildroot}/%{install_libdir} %{__ninja} check-all -C ./_build
|
||||
%{install_sharedir}/clang/clang-include-fixer.py
|
||||
%{install_sharedir}/clang/clang-tidy-diff.py
|
||||
%{install_sharedir}/clang/run-find-all-symbols.py
|
||||
%{install_sharedir}/clang/run-clang-tidy.py
|
||||
%{install_sharedir}/clang/clang-rename.py
|
||||
|
||||
%files tools-extra-devel
|
||||
%{install_includedir}/clang-tidy/
|
||||
|
||||
%files -n git-clang-format
|
||||
%{install_bindir}/git-clang-format
|
||||
|
||||
%changelog
|
||||
* Thu Nov 30 2023 zhoujing <zhoujing106@huawei.com> -17.0.6-1
|
||||
- Update to 17.0.6
|
||||
|
||||
* Thu Jul 6 2023 cf-zhao <zhaochuanfeng@huawei.com> -12.0.1-4
|
||||
- Make this spec file support both system-version and multi-version.
|
||||
|
||||
|
||||
@ -1,25 +1,24 @@
|
||||
From 2c6cd40d016f492d53e16f1c7424a0d9878ae7ec Mon Sep 17 00:00:00 2001
|
||||
From 88704fc2eabb9dd19a9c3eb81a9b3dc37d95651c Mon Sep 17 00:00:00 2001
|
||||
From: Tom Stellard <tstellar@redhat.com>
|
||||
Date: Fri, 31 Jan 2020 11:04:57 -0800
|
||||
Subject: [PATCH 3/6] [PATCH][clang] Don't install static libraries
|
||||
Subject: [PATCH][clang] Don't install static libraries
|
||||
|
||||
---
|
||||
clang/cmake/modules/AddClang.cmake | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/clang/cmake/modules/AddClang.cmake b/clang/cmake/modules/AddClang.cmake
|
||||
index 704278a..1737b24 100644
|
||||
index 5752f4277444..0f52822d91f0 100644
|
||||
--- a/clang/cmake/modules/AddClang.cmake
|
||||
+++ b/clang/cmake/modules/AddClang.cmake
|
||||
@@ -111,7 +111,7 @@ macro(add_clang_library name)
|
||||
@@ -113,7 +113,7 @@ macro(add_clang_library name)
|
||||
if(TARGET ${lib})
|
||||
target_link_libraries(${lib} INTERFACE ${LLVM_COMMON_LIBS})
|
||||
|
||||
- if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ARG_INSTALL_WITH_TOOLCHAIN)
|
||||
+ if (ARG_SHARED AND (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ARG_INSTALL_WITH_TOOLCHAIN))
|
||||
set(export_to_clangtargets)
|
||||
if(${lib} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
|
||||
"clang-libraries" IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
|
||||
get_target_export_arg(${name} Clang export_to_clangtargets UMBRELLA clang-libraries)
|
||||
install(TARGETS ${lib}
|
||||
COMPONENT ${lib}
|
||||
--
|
||||
1.8.3.1
|
||||
|
||||
2.30.2
|
||||
@ -0,0 +1,84 @@
|
||||
From 22d62b32cd3be5fb0ae10723b35a781e0f862b71 Mon Sep 17 00:00:00 2001
|
||||
From: Tom Stellard <tstellar@redhat.com>
|
||||
Date: Tue, 24 Jan 2023 22:46:25 +0000
|
||||
Subject: [PATCH] clang-tools-extra: Make test dependency on LLVMHello optional
|
||||
|
||||
This fixes clang + clang-tools-extra standalone build after
|
||||
36892727e4f19a60778e371d78f8fb09d8122c85.
|
||||
---
|
||||
clang-tools-extra/test/CMakeLists.txt | 10 +++++++++-
|
||||
clang-tools-extra/test/clang-tidy/CTTestTidyModule.cpp | 2 +-
|
||||
clang-tools-extra/test/lit.cfg.py | 3 +++
|
||||
clang-tools-extra/test/lit.site.cfg.py.in | 1 +
|
||||
4 files changed, 14 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/clang-tools-extra/test/CMakeLists.txt b/clang-tools-extra/test/CMakeLists.txt
|
||||
index f4c529ee8af2..1cfb4dd529aa 100644
|
||||
--- a/clang-tools-extra/test/CMakeLists.txt
|
||||
+++ b/clang-tools-extra/test/CMakeLists.txt
|
||||
@@ -7,10 +7,15 @@
|
||||
set(CLANG_TOOLS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||
set(CLANG_TOOLS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/..")
|
||||
|
||||
+if (TARGET LLVMHello)
|
||||
+ set (LLVM_HAS_LLVM_HELLO 1)
|
||||
+endif()
|
||||
+
|
||||
llvm_canonicalize_cmake_booleans(
|
||||
CLANG_TIDY_ENABLE_STATIC_ANALYZER
|
||||
CLANG_PLUGIN_SUPPORT
|
||||
LLVM_INSTALL_TOOLCHAIN_ONLY
|
||||
+ LLVM_HAS_LLVM_HELLO
|
||||
)
|
||||
|
||||
configure_lit_site_cfg(
|
||||
@@ -86,7 +91,10 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
||||
endif()
|
||||
|
||||
if(TARGET CTTestTidyModule)
|
||||
- list(APPEND CLANG_TOOLS_TEST_DEPS CTTestTidyModule LLVMHello)
|
||||
+ list(APPEND CLANG_TOOLS_TEST_DEPS CTTestTidyModule)
|
||||
+ if (TARGET LLVMHello)
|
||||
+ list(APPEND CLANG_TOOLS_TEST_DEPS CTTestTidyModule)
|
||||
+ endif()
|
||||
target_include_directories(CTTestTidyModule PUBLIC BEFORE "${CLANG_TOOLS_SOURCE_DIR}")
|
||||
if(CLANG_PLUGIN_SUPPORT AND (WIN32 OR CYGWIN))
|
||||
set(LLVM_LINK_COMPONENTS
|
||||
diff --git a/clang-tools-extra/test/clang-tidy/CTTestTidyModule.cpp b/clang-tools-extra/test/clang-tidy/CTTestTidyModule.cpp
|
||||
index c66a94f458cf..b4e7a5d691e5 100644
|
||||
--- a/clang-tools-extra/test/clang-tidy/CTTestTidyModule.cpp
|
||||
+++ b/clang-tools-extra/test/clang-tidy/CTTestTidyModule.cpp
|
||||
@@ -1,4 +1,4 @@
|
||||
-// REQUIRES: plugins
|
||||
+// REQUIRES: plugins, llvm-hello
|
||||
// RUN: clang-tidy -checks='-*,mytest*' --list-checks -load %llvmshlibdir/CTTestTidyModule%pluginext -load %llvmshlibdir/LLVMHello%pluginext | FileCheck --check-prefix=CHECK-LIST %s
|
||||
// CHECK-LIST: Enabled checks:
|
||||
// CHECK-LIST-NEXT: mytest1
|
||||
diff --git a/clang-tools-extra/test/lit.cfg.py b/clang-tools-extra/test/lit.cfg.py
|
||||
index 9f64fd3d2ffa..1b258a00ddf9 100644
|
||||
--- a/clang-tools-extra/test/lit.cfg.py
|
||||
+++ b/clang-tools-extra/test/lit.cfg.py
|
||||
@@ -75,6 +75,9 @@ config.substitutions.append(("%clang_tidy_headers", clang_tidy_headers))
|
||||
if config.has_plugins and config.llvm_plugin_ext:
|
||||
config.available_features.add("plugins")
|
||||
|
||||
+if config.has_llvm_hello:
|
||||
+ config.available_features.add("llvm-hello")
|
||||
+
|
||||
# It is not realistically possible to account for all options that could
|
||||
# possibly be present in system and user configuration files, so disable
|
||||
# default configs for the test runs.
|
||||
diff --git a/clang-tools-extra/test/lit.site.cfg.py.in b/clang-tools-extra/test/lit.site.cfg.py.in
|
||||
index 4eb830a1baf1..6e5559348454 100644
|
||||
--- a/clang-tools-extra/test/lit.site.cfg.py.in
|
||||
+++ b/clang-tools-extra/test/lit.site.cfg.py.in
|
||||
@@ -11,6 +11,7 @@ config.target_triple = "@LLVM_TARGET_TRIPLE@"
|
||||
config.host_triple = "@LLVM_HOST_TRIPLE@"
|
||||
config.clang_tidy_staticanalyzer = @CLANG_TIDY_ENABLE_STATIC_ANALYZER@
|
||||
config.has_plugins = @CLANG_PLUGIN_SUPPORT@ & ~@LLVM_INSTALL_TOOLCHAIN_ONLY@
|
||||
+config.has_llvm_hello = @LLVM_HAS_LLVM_HELLO@
|
||||
# Support substitution of the tools and libs dirs with user parameters. This is
|
||||
# used when we can't determine the tool dir at configuration time.
|
||||
config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
|
||||
--
|
||||
2.40.1
|
||||
@ -1,201 +0,0 @@
|
||||
From e6c1017c1bc412148662f64156a4d60315e59eb3 Mon Sep 17 00:00:00 2001
|
||||
From: cokeom <cokelin@hnu.edu.cn>
|
||||
Date: Fri, 14 Oct 2022 18:20:15 +0800
|
||||
Subject: [PATCH] Implement ignored options and replaced options.
|
||||
|
||||
---
|
||||
include/clang/Basic/DiagnosticDriverKinds.td | 6 +++
|
||||
include/clang/Driver/Options.td | 25 ++++++++++++
|
||||
lib/Driver/Driver.cpp | 41 ++++++++++++++++++++
|
||||
lib/Driver/ToolChains/Clang.cpp | 16 ++++++++
|
||||
test/Driver/ignored-and-replaced-options.c | 25 ++++++++++++
|
||||
test/Misc/warning-flags.c | 3 +-
|
||||
6 files changed, 115 insertions(+), 1 deletion(-)
|
||||
create mode 100644 test/Driver/ignored-and-replaced-options.c
|
||||
|
||||
diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td
|
||||
index ad13f923..bd7225b5 100644
|
||||
--- a/include/clang/Basic/DiagnosticDriverKinds.td
|
||||
+++ b/include/clang/Basic/DiagnosticDriverKinds.td
|
||||
@@ -536,4 +536,10 @@ def err_drv_invalid_object_mode : Error<"OBJECT_MODE setting %0 is not recognize
|
||||
|
||||
def err_aix_default_altivec_abi : Error<
|
||||
"The default Altivec ABI on AIX is not yet supported, use '-mabi=vec-extabi' for the extended Altivec ABI">;
|
||||
+
|
||||
+def warn_drv_ignore_options : Warning<"unsupported option '%0', ignore it.">,
|
||||
+ InGroup<OptionIgnored>;
|
||||
+
|
||||
+def warn_drv_replace_options
|
||||
+ : Warning<"unsupported option '%0', use '%1' instead.">;
|
||||
}
|
||||
diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
|
||||
index 81779892..04521197 100644
|
||||
--- a/include/clang/Driver/Options.td
|
||||
+++ b/include/clang/Driver/Options.td
|
||||
@@ -466,6 +466,31 @@ defvar std = !strconcat("LangStandard::getLangStandardForKind(", lang_std.KeyPat
|
||||
// C++ => CXX
|
||||
// . => _
|
||||
|
||||
+// Options to ignore and replace
|
||||
+def clang_ignored_options_Group : OptionGroup<"<clang_ignored_options_Group>">,
|
||||
+ Group<f_Group>,
|
||||
+ Flags<[Ignored]>;
|
||||
+def ip : Flag<["-"], "ip">,
|
||||
+ Group<clang_ignored_options_Group>,
|
||||
+ HelpText<"Enables additional interprocedural optimizations for "
|
||||
+ "single-file compilation">;
|
||||
+def assume : Separate<["-"], "assume">,
|
||||
+ Group<clang_ignored_options_Group>,
|
||||
+ HelpText<"Determines whether units for the OPEN statement RECL "
|
||||
+ "specifier (record length) value in unformatted files "
|
||||
+ "are in bytes or longwords (four-byte units)">;
|
||||
+def fdec : Flag<["-"], "fdec">,
|
||||
+ Group<clang_ignored_options_Group>,
|
||||
+ HelpText<"Enables extensions and other features that mimic the "
|
||||
+ "default behavior of older compilers (such as DEC)">;
|
||||
+
|
||||
+def clang_replaced_options_Group
|
||||
+ : OptionGroup<"<clang_replaced_options_Group>">,
|
||||
+ Group<f_Group>;
|
||||
+def convert : Separate<["-"], "convert">,
|
||||
+ Group<clang_replaced_options_Group>,
|
||||
+ HelpText<"Generate big-endian/little-endian code">;
|
||||
+
|
||||
// Developer Driver Options
|
||||
|
||||
def internal_Group : OptionGroup<"<clang internal options>">, Flags<[HelpHidden]>;
|
||||
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
|
||||
index 418e1d3e..95c0e256 100644
|
||||
--- a/lib/Driver/Driver.cpp
|
||||
+++ b/lib/Driver/Driver.cpp
|
||||
@@ -996,6 +996,47 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
|
||||
CLOptions = std::make_unique<InputArgList>(
|
||||
ParseArgStrings(ArgList.slice(1), IsCLMode(), ContainsError));
|
||||
|
||||
+ // Compiler replacement option function.
|
||||
+ for (auto *Opt :
|
||||
+ CLOptions->filtered(options::OPT_clang_replaced_options_Group)) {
|
||||
+ switch (Opt->getOption().getID()) {
|
||||
+ default:
|
||||
+ Diag(diag::err_drv_unsupported_opt) << Opt->getAsString(*CLOptions);
|
||||
+ break;
|
||||
+ case options::OPT_convert:
|
||||
+ auto *OptLastArg =
|
||||
+ CLOptions->getLastArg(options::OPT_mlittle_endian,
|
||||
+ options::OPT_mbig_endian, options::OPT_convert);
|
||||
+ if (OptLastArg->getOption().matches(options::OPT_convert)) {
|
||||
+ StringRef OptionValue = OptLastArg->getValue();
|
||||
+ if (OptionValue.equals("big_endian")) {
|
||||
+ Diag(diag::warn_drv_replace_options)
|
||||
+ << OptLastArg->getAsString(*CLOptions) << "-mbig-endian";
|
||||
+ StringRef SpellingReplaced = StringRef("-mbig-endian");
|
||||
+ unsigned IndexReplaced = CLOptions->MakeIndex(SpellingReplaced);
|
||||
+ Option OptReplaced = getOpts().getOption(options::OPT_mbig_endian);
|
||||
+ Arg *ArgReplaced =
|
||||
+ new Arg(OptReplaced, SpellingReplaced, IndexReplaced);
|
||||
+ CLOptions->append(ArgReplaced);
|
||||
+ } else if (OptionValue.equals("little_endian")) {
|
||||
+ Diag(diag::warn_drv_replace_options)
|
||||
+ << OptLastArg->getAsString(*CLOptions) << "-mlittle-endian";
|
||||
+ StringRef SpellingReplaced = StringRef("-mlittle-endian");
|
||||
+ unsigned IndexReplaced = CLOptions->MakeIndex(SpellingReplaced);
|
||||
+ Option OptReplaced = getOpts().getOption(options::OPT_mlittle_endian);
|
||||
+ Arg *ArgReplaced =
|
||||
+ new Arg(OptReplaced, SpellingReplaced, IndexReplaced);
|
||||
+ CLOptions->append(ArgReplaced);
|
||||
+ } else {
|
||||
+ Diag(diag::err_drv_unknown_argument)
|
||||
+ << OptLastArg->getAsString(*CLOptions);
|
||||
+ }
|
||||
+ }
|
||||
+ CLOptions->eraseArg(options::OPT_convert);
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
// Try parsing configuration file.
|
||||
if (!ContainsError)
|
||||
ContainsError = loadConfigFile();
|
||||
diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp
|
||||
index 1976b48e..706d0431 100644
|
||||
--- a/lib/Driver/ToolChains/Clang.cpp
|
||||
+++ b/lib/Driver/ToolChains/Clang.cpp
|
||||
@@ -5178,6 +5178,22 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
||||
A->claim();
|
||||
}
|
||||
|
||||
+ // Warn about ignored options to clang
|
||||
+ for (const Arg *A : Args.filtered(options::OPT_clang_ignored_options_Group)) {
|
||||
+ if (A->getOption().matches(options::OPT_assume)) {
|
||||
+ StringRef OptionValue = A->getValue();
|
||||
+ if (OptionValue.equals("byterecl")) {
|
||||
+ D.Diag(diag::warn_drv_ignore_options) << A->getAsString(Args);
|
||||
+ } else {
|
||||
+ D.Diag(diag::err_drv_unknown_argument) << A->getAsString(Args);
|
||||
+ }
|
||||
+ A->claim();
|
||||
+ continue;
|
||||
+ }
|
||||
+ D.Diag(diag::warn_drv_ignore_options) << A->getAsString(Args);
|
||||
+ A->claim();
|
||||
+ }
|
||||
+
|
||||
claimNoWarnArgs(Args);
|
||||
|
||||
Args.AddAllArgs(CmdArgs, options::OPT_R_Group);
|
||||
diff --git a/test/Driver/ignored-and-replaced-options.c b/test/Driver/ignored-and-replaced-options.c
|
||||
new file mode 100644
|
||||
index 00000000..a13944db
|
||||
--- /dev/null
|
||||
+++ b/test/Driver/ignored-and-replaced-options.c
|
||||
@@ -0,0 +1,25 @@
|
||||
+// Test that Some options are ignored and replaced.
|
||||
+//
|
||||
+// REQUIRES: clang-driver
|
||||
+
|
||||
+// RUN: %clang -### -ip -c %s 2>&1 \
|
||||
+// RUN: | FileCheck --check-prefix=WARN %s
|
||||
+// WARN: warning: unsupported option '-ip', ignore it.
|
||||
+
|
||||
+// RUN: %clang -### -fdec -c %s 2>&1 \
|
||||
+// RUN: | FileCheck --check-prefix=WARN1 %s
|
||||
+// WARN1: warning: unsupported option '-fdec', ignore it.
|
||||
+
|
||||
+// RUN: %clang -### -assume byterecl -c %s 2>&1 \
|
||||
+// RUN: | FileCheck --check-prefix=WARN2 %s
|
||||
+// WARN2: warning: unsupported option '-assume byterecl', ignore it.
|
||||
+
|
||||
+// RUN: %clang -convert little_endian -c %s 2>&1 \
|
||||
+// RUN: | FileCheck --check-prefix=WARN3 %s
|
||||
+// WARN3: warning: unsupported option '-convert little_endian', use
|
||||
+// '-mlittle-endian' instead.
|
||||
+
|
||||
+// RUN: %clang -convert big_endian -c %s 2>&1 \
|
||||
+// RUN: | FileCheck --check-prefix=WARN4 %s
|
||||
+// WARN4: warning: unsupported option '-convert big_endian', use '-mbig-endian'
|
||||
+// instead.
|
||||
\ No newline at end of file
|
||||
diff --git a/test/Misc/warning-flags.c b/test/Misc/warning-flags.c
|
||||
index 54e36e1e..1b9b779e 100644
|
||||
--- a/test/Misc/warning-flags.c
|
||||
+++ b/test/Misc/warning-flags.c
|
||||
@@ -18,7 +18,7 @@ This test serves two purposes:
|
||||
|
||||
The list of warnings below should NEVER grow. It should gradually shrink to 0.
|
||||
|
||||
-CHECK: Warnings without flags (68):
|
||||
+CHECK: Warnings without flags (69):
|
||||
|
||||
CHECK-NEXT: ext_expected_semi_decl_list
|
||||
CHECK-NEXT: ext_explicit_specialization_storage_class
|
||||
@@ -47,6 +47,7 @@ CHECK-NEXT: warn_double_const_requires_fp64
|
||||
CHECK-NEXT: warn_drv_assuming_mfloat_abi_is
|
||||
CHECK-NEXT: warn_drv_clang_unsupported
|
||||
CHECK-NEXT: warn_drv_pch_not_first_include
|
||||
+CHECK-NEXT: warn_drv_replace_options
|
||||
CHECK-NEXT: warn_dup_category_def
|
||||
CHECK-NEXT: warn_enum_value_overflow
|
||||
CHECK-NEXT: warn_expected_qualified_after_typename
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,499 +0,0 @@
|
||||
From feb61342aaf3e5ef2bcc36b3d512eba600e03c9c Mon Sep 17 00:00:00 2001
|
||||
From: cokeom <cokelin@hnu.edu.cn>
|
||||
Date: Fri, 14 Oct 2022 18:30:00 +0800
|
||||
Subject: [PATCH] Implement -aux-info option.
|
||||
|
||||
---
|
||||
include/clang/AST/DeclBase.h | 2 +
|
||||
include/clang/AST/PrettyPrinter.h | 6 +-
|
||||
include/clang/Driver/Options.td | 7 ++
|
||||
include/clang/Frontend/ASTConsumers.h | 3 +
|
||||
include/clang/Frontend/FrontendActions.h | 6 ++
|
||||
include/clang/Frontend/FrontendOptions.h | 3 +
|
||||
lib/AST/DeclPrinter.cpp | 96 +++++++++++++++++++
|
||||
lib/AST/TypePrinter.cpp | 23 +++--
|
||||
lib/Driver/Driver.cpp | 6 +-
|
||||
lib/Driver/ToolChains/Clang.cpp | 7 ++
|
||||
lib/Frontend/ASTConsumers.cpp | 34 +++++++
|
||||
lib/Frontend/CompilerInvocation.cpp | 7 ++
|
||||
lib/Frontend/FrontendActions.cpp | 13 +++
|
||||
.../ExecuteCompilerInvocation.cpp | 2 +
|
||||
test/Frontend/print-function-prototype.c | 28 ++++++
|
||||
15 files changed, 230 insertions(+), 13 deletions(-)
|
||||
create mode 100644 test/Frontend/print-function-prototype.c
|
||||
|
||||
diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h
|
||||
index 15eb29f7..a46b13e4 100644
|
||||
--- a/include/clang/AST/DeclBase.h
|
||||
+++ b/include/clang/AST/DeclBase.h
|
||||
@@ -1164,6 +1164,8 @@ public:
|
||||
bool PrintInstantiation = false) const;
|
||||
void print(raw_ostream &Out, const PrintingPolicy &Policy,
|
||||
unsigned Indentation = 0, bool PrintInstantiation = false) const;
|
||||
+ void printDeclPrototype(raw_ostream &Out, unsigned Indentation = 0,
|
||||
+ bool PrintInstantiation = false) const;
|
||||
static void printGroup(Decl** Begin, unsigned NumDecls,
|
||||
raw_ostream &Out, const PrintingPolicy &Policy,
|
||||
unsigned Indentation = 0);
|
||||
diff --git a/include/clang/AST/PrettyPrinter.h b/include/clang/AST/PrettyPrinter.h
|
||||
index 3baf2b2b..f147fd87 100644
|
||||
--- a/include/clang/AST/PrettyPrinter.h
|
||||
+++ b/include/clang/AST/PrettyPrinter.h
|
||||
@@ -74,7 +74,8 @@ struct PrintingPolicy {
|
||||
MSWChar(LO.MicrosoftExt && !LO.WChar), IncludeNewlines(true),
|
||||
MSVCFormatting(false), ConstantsAsWritten(false),
|
||||
SuppressImplicitBase(false), FullyQualifiedName(false),
|
||||
- PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true) {}
|
||||
+ PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true),
|
||||
+ PrintRestrict(true) {}
|
||||
|
||||
/// Adjust this printing policy for cases where it's known that we're
|
||||
/// printing C++ code (for instance, if AST dumping reaches a C++-only
|
||||
@@ -273,6 +274,9 @@ struct PrintingPolicy {
|
||||
/// invalid C++ code.
|
||||
unsigned PrintInjectedClassNameWithArguments : 1;
|
||||
|
||||
+ /// Whether to print the keyword "restrict" in the function prototype.
|
||||
+ unsigned PrintRestrict : 1;
|
||||
+
|
||||
/// Callbacks to use to allow the behavior of printing to be customized.
|
||||
const PrintingCallbacks *Callbacks = nullptr;
|
||||
};
|
||||
diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
|
||||
index 04521197..2126f0df 100644
|
||||
--- a/include/clang/Driver/Options.td
|
||||
+++ b/include/clang/Driver/Options.td
|
||||
@@ -491,6 +491,13 @@ def convert : Separate<["-"], "convert">,
|
||||
Group<clang_replaced_options_Group>,
|
||||
HelpText<"Generate big-endian/little-endian code">;
|
||||
|
||||
+def aux_info : Separate<["-"], "aux-info">,
|
||||
+ Flags<[NoXarchOption, CoreOption, CC1Option]>,
|
||||
+ Group<Action_Group>,
|
||||
+ HelpText<"Output to the given filename prototyped declarations "
|
||||
+ "for all functions declared and/or defined in a "
|
||||
+ "translation unit, including those in header files">;
|
||||
+
|
||||
// Developer Driver Options
|
||||
|
||||
def internal_Group : OptionGroup<"<clang internal options>">, Flags<[HelpHidden]>;
|
||||
diff --git a/include/clang/Frontend/ASTConsumers.h b/include/clang/Frontend/ASTConsumers.h
|
||||
index 98cfc7ca..ecd3c268 100644
|
||||
--- a/include/clang/Frontend/ASTConsumers.h
|
||||
+++ b/include/clang/Frontend/ASTConsumers.h
|
||||
@@ -50,6 +50,9 @@ std::unique_ptr<ASTConsumer> CreateASTDeclNodeLister();
|
||||
// function declarations to stderr.
|
||||
std::unique_ptr<ASTConsumer> CreateASTViewer();
|
||||
|
||||
+std::unique_ptr<ASTConsumer>
|
||||
+CreateASTFunctionPrinter(std::unique_ptr<llvm::raw_fd_ostream> Out);
|
||||
+
|
||||
} // end clang namespace
|
||||
|
||||
#endif
|
||||
diff --git a/include/clang/Frontend/FrontendActions.h b/include/clang/Frontend/FrontendActions.h
|
||||
index 25ca9598..d2b294a5 100644
|
||||
--- a/include/clang/Frontend/FrontendActions.h
|
||||
+++ b/include/clang/Frontend/FrontendActions.h
|
||||
@@ -74,6 +74,12 @@ protected:
|
||||
StringRef InFile) override;
|
||||
};
|
||||
|
||||
+class ASTFunctionPrinterAction : public ASTFrontendAction {
|
||||
+protected:
|
||||
+ std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
|
||||
+ StringRef InFile) override;
|
||||
+};
|
||||
+
|
||||
class GeneratePCHAction : public ASTFrontendAction {
|
||||
protected:
|
||||
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
|
||||
diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h
|
||||
index 223c1e05..3362a2fc 100644
|
||||
--- a/include/clang/Frontend/FrontendOptions.h
|
||||
+++ b/include/clang/Frontend/FrontendOptions.h
|
||||
@@ -44,6 +44,9 @@ enum ActionKind {
|
||||
/// Parse ASTs and view them in Graphviz.
|
||||
ASTView,
|
||||
|
||||
+ /// Print function prototype.
|
||||
+ ASTFunctionPrinter,
|
||||
+
|
||||
/// Dump the compiler configuration.
|
||||
DumpCompilerOptions,
|
||||
|
||||
diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp
|
||||
index ca64f8f6..a857466e 100644
|
||||
--- a/lib/AST/DeclPrinter.cpp
|
||||
+++ b/lib/AST/DeclPrinter.cpp
|
||||
@@ -115,6 +115,7 @@ namespace {
|
||||
void prettyPrintAttributes(Decl *D);
|
||||
void prettyPrintPragmas(Decl *D);
|
||||
void printDeclType(QualType T, StringRef DeclName, bool Pack = false);
|
||||
+ void printFunctionDeclPrototype(FunctionDecl *D);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -135,6 +136,14 @@ void TemplateParameterList::print(raw_ostream &Out, const ASTContext &Context,
|
||||
print(Out, Context, Context.getPrintingPolicy(), OmitTemplateKW);
|
||||
}
|
||||
|
||||
+void Decl::printDeclPrototype(raw_ostream &Out, unsigned Indentation,
|
||||
+ bool PrintInstantiation) const {
|
||||
+ DeclPrinter Printer(Out, getASTContext().getPrintingPolicy(), getASTContext(),
|
||||
+ Indentation, PrintInstantiation);
|
||||
+ auto *FD = const_cast<FunctionDecl *>(dyn_cast<FunctionDecl>(this));
|
||||
+ Printer.printFunctionDeclPrototype(FD);
|
||||
+}
|
||||
+
|
||||
void TemplateParameterList::print(raw_ostream &Out, const ASTContext &Context,
|
||||
const PrintingPolicy &Policy,
|
||||
bool OmitTemplateKW) const {
|
||||
@@ -784,6 +793,93 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
|
||||
}
|
||||
}
|
||||
|
||||
+void DeclPrinter::printFunctionDeclPrototype(FunctionDecl *D) {
|
||||
+ if (!Policy.SuppressSpecifiers) {
|
||||
+ switch (D->getStorageClass()) {
|
||||
+ case SC_None:
|
||||
+ case SC_Extern:
|
||||
+ case SC_PrivateExtern:
|
||||
+ Out << "extern ";
|
||||
+ break;
|
||||
+ case SC_Static:
|
||||
+ Out << "static ";
|
||||
+ break;
|
||||
+ case SC_Auto:
|
||||
+ case SC_Register:
|
||||
+ llvm_unreachable("invalid for functions");
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ PrintingPolicy SubPolicy(Policy);
|
||||
+ SubPolicy.SuppressSpecifiers = false;
|
||||
+ SubPolicy.PrintRestrict = false;
|
||||
+ std::string Proto;
|
||||
+
|
||||
+ /// Print the function name.
|
||||
+ if (Policy.FullyQualifiedName) {
|
||||
+ Proto += D->getQualifiedNameAsString();
|
||||
+ } else {
|
||||
+ llvm::raw_string_ostream OS(Proto);
|
||||
+ if (!Policy.SuppressScope) {
|
||||
+ if (const NestedNameSpecifier *NS = D->getQualifier()) {
|
||||
+ NS->print(OS, Policy);
|
||||
+ }
|
||||
+ }
|
||||
+ D->getNameInfo().printName(OS, Policy);
|
||||
+ }
|
||||
+
|
||||
+ QualType Ty = D->getType();
|
||||
+ while (const ParenType *PT = dyn_cast<ParenType>(Ty)) {
|
||||
+ Proto = '(' + Proto + ')';
|
||||
+ Ty = PT->getInnerType();
|
||||
+ }
|
||||
+ if (const FunctionType *AFT = Ty->getAs<FunctionType>()) {
|
||||
+ const FunctionProtoType *FT = nullptr;
|
||||
+ if (D->hasWrittenPrototype())
|
||||
+ FT = dyn_cast<FunctionProtoType>(AFT);
|
||||
+
|
||||
+ Proto += "(";
|
||||
+
|
||||
+ /// Print function parameters.
|
||||
+ if (FT) {
|
||||
+ llvm::raw_string_ostream POut(Proto);
|
||||
+ for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
|
||||
+ if (i)
|
||||
+ POut << ", ";
|
||||
+ ParmVarDecl *PVD = D->getParamDecl(i);
|
||||
+ QualType T = PVD->getTypeSourceInfo()
|
||||
+ ? PVD->getTypeSourceInfo()->getType()
|
||||
+ : PVD->getASTContext().getUnqualifiedObjCPointerType(
|
||||
+ PVD->getType());
|
||||
+ T.print(POut, SubPolicy, "", Indentation);
|
||||
+ }
|
||||
+
|
||||
+ if (FT->isVariadic()) {
|
||||
+ if (D->getNumParams())
|
||||
+ POut << ", ";
|
||||
+ POut << "...";
|
||||
+ } else if (!D->getNumParams()) {
|
||||
+ POut << "void";
|
||||
+ }
|
||||
+ } else if (D->doesThisDeclarationHaveABody() && !D->hasPrototype()) {
|
||||
+ for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
|
||||
+ if (i)
|
||||
+ Proto += ", ";
|
||||
+ Proto += D->getParamDecl(i)->getNameAsString();
|
||||
+ }
|
||||
+ if (!D->getNumParams()) {
|
||||
+ Proto += "void";
|
||||
+ }
|
||||
+ }
|
||||
+ Proto += ")";
|
||||
+
|
||||
+ /// Print the function return type.
|
||||
+ AFT->getReturnType().print(Out, Policy, Proto);
|
||||
+ } else {
|
||||
+ Ty.print(Out, Policy, Proto);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
void DeclPrinter::VisitFriendDecl(FriendDecl *D) {
|
||||
if (TypeSourceInfo *TSI = D->getFriendType()) {
|
||||
unsigned NumTPLists = D->getFriendTypeNumTemplateParameterLists();
|
||||
diff --git a/lib/AST/TypePrinter.cpp b/lib/AST/TypePrinter.cpp
|
||||
index 25d7874b..37d116ca 100644
|
||||
--- a/lib/AST/TypePrinter.cpp
|
||||
+++ b/lib/AST/TypePrinter.cpp
|
||||
@@ -139,7 +139,7 @@ namespace {
|
||||
} // namespace
|
||||
|
||||
static void AppendTypeQualList(raw_ostream &OS, unsigned TypeQuals,
|
||||
- bool HasRestrictKeyword) {
|
||||
+ bool HasRestrictKeyword, bool PrintRestrict) {
|
||||
bool appendSpace = false;
|
||||
if (TypeQuals & Qualifiers::Const) {
|
||||
OS << "const";
|
||||
@@ -151,11 +151,13 @@ static void AppendTypeQualList(raw_ostream &OS, unsigned TypeQuals,
|
||||
appendSpace = true;
|
||||
}
|
||||
if (TypeQuals & Qualifiers::Restrict) {
|
||||
- if (appendSpace) OS << ' ';
|
||||
- if (HasRestrictKeyword) {
|
||||
- OS << "restrict";
|
||||
- } else {
|
||||
- OS << "__restrict";
|
||||
+ if (PrintRestrict) {
|
||||
+ if (appendSpace) OS << ' ';
|
||||
+ if (HasRestrictKeyword) {
|
||||
+ OS << "restrict";
|
||||
+ } else {
|
||||
+ OS << "__restrict";
|
||||
+ }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -506,8 +508,8 @@ void TypePrinter::printConstantArrayAfter(const ConstantArrayType *T,
|
||||
raw_ostream &OS) {
|
||||
OS << '[';
|
||||
if (T->getIndexTypeQualifiers().hasQualifiers()) {
|
||||
- AppendTypeQualList(OS, T->getIndexTypeCVRQualifiers(),
|
||||
- Policy.Restrict);
|
||||
+ AppendTypeQualList(OS, T->getIndexTypeCVRQualifiers(), Policy.Restrict,
|
||||
+ Policy.PrintRestrict);
|
||||
OS << ' ';
|
||||
}
|
||||
|
||||
@@ -542,7 +544,8 @@ void TypePrinter::printVariableArrayAfter(const VariableArrayType *T,
|
||||
raw_ostream &OS) {
|
||||
OS << '[';
|
||||
if (T->getIndexTypeQualifiers().hasQualifiers()) {
|
||||
- AppendTypeQualList(OS, T->getIndexTypeCVRQualifiers(), Policy.Restrict);
|
||||
+ AppendTypeQualList(OS, T->getIndexTypeCVRQualifiers(), Policy.Restrict,
|
||||
+ Policy.PrintRestrict);
|
||||
OS << ' ';
|
||||
}
|
||||
|
||||
@@ -2149,7 +2152,7 @@ void Qualifiers::print(raw_ostream &OS, const PrintingPolicy& Policy,
|
||||
|
||||
unsigned quals = getCVRQualifiers();
|
||||
if (quals) {
|
||||
- AppendTypeQualList(OS, quals, Policy.Restrict);
|
||||
+ AppendTypeQualList(OS, quals, Policy.Restrict, Policy.PrintRestrict);
|
||||
addSpace = true;
|
||||
}
|
||||
if (hasUnaligned()) {
|
||||
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
|
||||
index 95c0e256..ce677965 100644
|
||||
--- a/lib/Driver/Driver.cpp
|
||||
+++ b/lib/Driver/Driver.cpp
|
||||
@@ -309,7 +309,8 @@ phases::ID Driver::getFinalPhase(const DerivedArgList &DAL,
|
||||
(PhaseArg = DAL.getLastArg(options::OPT_rewrite_legacy_objc)) ||
|
||||
(PhaseArg = DAL.getLastArg(options::OPT__migrate)) ||
|
||||
(PhaseArg = DAL.getLastArg(options::OPT__analyze)) ||
|
||||
- (PhaseArg = DAL.getLastArg(options::OPT_emit_ast))) {
|
||||
+ (PhaseArg = DAL.getLastArg(options::OPT_emit_ast)) ||
|
||||
+ (PhaseArg = DAL.getLastArg(options::OPT_aux_info))) {
|
||||
FinalPhase = phases::Compile;
|
||||
|
||||
// -S only runs up to the backend.
|
||||
@@ -3851,7 +3852,8 @@ Action *Driver::ConstructPhaseAction(
|
||||
return C.MakeAction<PrecompileJobAction>(Input, OutputTy);
|
||||
}
|
||||
case phases::Compile: {
|
||||
- if (Args.hasArg(options::OPT_fsyntax_only))
|
||||
+ if (Args.hasArg(options::OPT_fsyntax_only) ||
|
||||
+ Args.hasArg(options::OPT_aux_info))
|
||||
return C.MakeAction<CompileJobAction>(Input, types::TY_Nothing);
|
||||
if (Args.hasArg(options::OPT_rewrite_objc))
|
||||
return C.MakeAction<CompileJobAction>(Input, types::TY_RewrittenObjC);
|
||||
diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp
|
||||
index 706d0431..e7946529 100644
|
||||
--- a/lib/Driver/ToolChains/Clang.cpp
|
||||
+++ b/lib/Driver/ToolChains/Clang.cpp
|
||||
@@ -6258,6 +6258,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
||||
}
|
||||
}
|
||||
|
||||
+ if (Arg *A = Args.getLastArg(options::OPT_aux_info)) {
|
||||
+ if (Input.getType() == types::TY_C) {
|
||||
+ CmdArgs.push_back("-aux-info");
|
||||
+ CmdArgs.push_back(A->getValue());
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
// With -save-temps, we want to save the unoptimized bitcode output from the
|
||||
// CompileJobAction, use -disable-llvm-passes to get pristine IR generated
|
||||
// by the frontend.
|
||||
diff --git a/lib/Frontend/ASTConsumers.cpp b/lib/Frontend/ASTConsumers.cpp
|
||||
index a73cc887..48f999ab 100644
|
||||
--- a/lib/Frontend/ASTConsumers.cpp
|
||||
+++ b/lib/Frontend/ASTConsumers.cpp
|
||||
@@ -212,3 +212,37 @@ void ASTViewer::HandleTopLevelSingleDecl(Decl *D) {
|
||||
std::unique_ptr<ASTConsumer> clang::CreateASTViewer() {
|
||||
return std::make_unique<ASTViewer>();
|
||||
}
|
||||
+
|
||||
+//===----------------------------------------------------------------------===//
|
||||
+/// ASTFunctionPrototype - AST FunctionPrototype print
|
||||
+namespace {
|
||||
+ class ASTFunctionPrinter : public ASTConsumer {
|
||||
+ private:
|
||||
+ llvm::raw_fd_ostream &Out;
|
||||
+ std::unique_ptr<llvm::raw_fd_ostream> OwnedOut;
|
||||
+ public:
|
||||
+ ASTFunctionPrinter(std::unique_ptr<llvm::raw_fd_ostream> Out)
|
||||
+ : Out(Out ? *Out : llvm::outs()), OwnedOut(std::move(Out)) {}
|
||||
+
|
||||
+ bool HandleTopLevelDecl(DeclGroupRef D) override {
|
||||
+ for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I)
|
||||
+ HandleTopLevelSingleDecl(*I);
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ void HandleTopLevelSingleDecl(Decl *D);
|
||||
+ };
|
||||
+} // namespace
|
||||
+
|
||||
+void ASTFunctionPrinter::HandleTopLevelSingleDecl(Decl *D) {
|
||||
+ if (isa<FunctionDecl>(D)) {
|
||||
+ D->printDeclPrototype(Out);
|
||||
+ Out << ";";
|
||||
+ Out << '\n';
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+std::unique_ptr<ASTConsumer>
|
||||
+clang::CreateASTFunctionPrinter(std::unique_ptr<llvm::raw_fd_ostream> Out) {
|
||||
+ return std::make_unique<ASTFunctionPrinter>(std::move(Out));
|
||||
+}
|
||||
\ No newline at end of file
|
||||
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
|
||||
index 5c5cf461..9665b4ed 100644
|
||||
--- a/lib/Frontend/CompilerInvocation.cpp
|
||||
+++ b/lib/Frontend/CompilerInvocation.cpp
|
||||
@@ -1574,6 +1574,8 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
|
||||
Opts.ProgramAction = frontend::ASTPrint; break;
|
||||
case OPT_ast_view:
|
||||
Opts.ProgramAction = frontend::ASTView; break;
|
||||
+ case OPT_aux_info:
|
||||
+ Opts.ProgramAction = frontend::ASTFunctionPrinter; break;
|
||||
case OPT_compiler_options_dump:
|
||||
Opts.ProgramAction = frontend::DumpCompilerOptions; break;
|
||||
case OPT_dump_raw_tokens:
|
||||
@@ -2711,6 +2713,7 @@ static bool isStrictlyPreprocessorAction(frontend::ActionKind Action) {
|
||||
case frontend::ASTDump:
|
||||
case frontend::ASTPrint:
|
||||
case frontend::ASTView:
|
||||
+ case frontend::ASTFunctionPrinter:
|
||||
case frontend::EmitAssembly:
|
||||
case frontend::EmitBC:
|
||||
case frontend::EmitHTML:
|
||||
@@ -2971,6 +2974,10 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
|
||||
|
||||
FixupInvocation(Res, Diags, Args, DashX);
|
||||
|
||||
+ if (Arg *A = Args.getLastArg(OPT_aux_info)) {
|
||||
+ Res.getFrontendOpts().OutputFile = A->getValue();
|
||||
+ }
|
||||
+
|
||||
return Success;
|
||||
}
|
||||
|
||||
diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp
|
||||
index 060cec23..1d0044c8 100644
|
||||
--- a/lib/Frontend/FrontendActions.cpp
|
||||
+++ b/lib/Frontend/FrontendActions.cpp
|
||||
@@ -93,6 +93,19 @@ ASTViewAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
|
||||
return CreateASTViewer();
|
||||
}
|
||||
|
||||
+std::unique_ptr<ASTConsumer>
|
||||
+ASTFunctionPrinterAction::CreateASTConsumer(CompilerInstance &CI,
|
||||
+ StringRef InFile) {
|
||||
+ StringRef OutputFileName = CI.getFrontendOpts().OutputFile;
|
||||
+ std::unique_ptr<llvm::raw_fd_ostream> OutFile;
|
||||
+ if (!OutputFileName.empty() && OutputFileName != "-") {
|
||||
+ std::error_code EC;
|
||||
+ OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC,
|
||||
+ llvm::sys::fs::CD_CreateAlways));
|
||||
+ }
|
||||
+ return CreateASTFunctionPrinter(std::move(OutFile));
|
||||
+}
|
||||
+
|
||||
std::unique_ptr<ASTConsumer>
|
||||
GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
|
||||
std::string Sysroot;
|
||||
diff --git a/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/lib/FrontendTool/ExecuteCompilerInvocation.cpp
|
||||
index ac64e170..63a6b403 100644
|
||||
--- a/lib/FrontendTool/ExecuteCompilerInvocation.cpp
|
||||
+++ b/lib/FrontendTool/ExecuteCompilerInvocation.cpp
|
||||
@@ -46,6 +46,8 @@ CreateFrontendBaseAction(CompilerInstance &CI) {
|
||||
case ASTDump: return std::make_unique<ASTDumpAction>();
|
||||
case ASTPrint: return std::make_unique<ASTPrintAction>();
|
||||
case ASTView: return std::make_unique<ASTViewAction>();
|
||||
+ case ASTFunctionPrinter:
|
||||
+ return std::make_unique<ASTFunctionPrinterAction>();
|
||||
case DumpCompilerOptions:
|
||||
return std::make_unique<DumpCompilerOptionsAction>();
|
||||
case DumpRawTokens: return std::make_unique<DumpRawTokensAction>();
|
||||
diff --git a/test/Frontend/print-function-prototype.c b/test/Frontend/print-function-prototype.c
|
||||
new file mode 100644
|
||||
index 00000000..5abc7550
|
||||
--- /dev/null
|
||||
+++ b/test/Frontend/print-function-prototype.c
|
||||
@@ -0,0 +1,28 @@
|
||||
+// Test that -aux-info prints correct function prototypes.
|
||||
+// RUN: %clang %s -aux-info %t 2>&1 \
|
||||
+// RUN: | FileCheck -input-file=%t %s
|
||||
+// CHECK: extern void function1(int, const int, float);
|
||||
+// CHECK: extern int function2(int, int);
|
||||
+// CHECK: extern void function3(int, double, float);
|
||||
+// CHECK: static void function4(void);
|
||||
+// CHECK: extern int function5(volatile int *);
|
||||
+// CHECK: extern int function6(int *);
|
||||
+// CHECK: extern const int function7(void);
|
||||
+// CHECK: extern volatile float function8(void);
|
||||
+// CHECK: extern int main(void);
|
||||
+// CHECK: extern void function1(int, const int, float);
|
||||
+
|
||||
+void function1(int, const int, float);
|
||||
+int function2(int a, int b) { return a + b; }
|
||||
+void function3(int a, double b, float c) {}
|
||||
+static void function4() {}
|
||||
+inline int function5(volatile int *j);
|
||||
+int function6(int *a) { return 0; }
|
||||
+const int function7() { return 1; }
|
||||
+volatile float function8() { return 0.; }
|
||||
+int main() {
|
||||
+ function1(1, 1, 0.0);
|
||||
+ function2(1, 1);
|
||||
+ return 0;
|
||||
+}
|
||||
+void function1(int a, const int b, float c) {}
|
||||
\ No newline at end of file
|
||||
--
|
||||
2.25.1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user