From 080c925bd8ab9209830949fc1ba955de85526088c039fa85782bcec57845aee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ismail=20D=C3=B6nmez?= Date: Sun, 22 Apr 2012 19:23:50 +0000 Subject: [PATCH 01/11] - Update to svn revision 155320 from 3.1 branch * AVX fixes OBS-URL: https://build.opensuse.org/package/show/devel:tools:compiler/llvm?expand=0&rev=135 --- llvm-3.0.99+svn154914.tar.bz2 | 3 --- llvm-3.0.99+svn155320.tar.bz2 | 3 +++ llvm.changes | 6 ++++++ llvm.spec | 21 +++++++-------------- 4 files changed, 16 insertions(+), 17 deletions(-) delete mode 100644 llvm-3.0.99+svn154914.tar.bz2 create mode 100644 llvm-3.0.99+svn155320.tar.bz2 diff --git a/llvm-3.0.99+svn154914.tar.bz2 b/llvm-3.0.99+svn154914.tar.bz2 deleted file mode 100644 index d8702c3..0000000 --- a/llvm-3.0.99+svn154914.tar.bz2 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:af9ae518982b9385f4bceae48eafcf1ffb309bbd2422a5a95aa1df00f0d216aa -size 16144645 diff --git a/llvm-3.0.99+svn155320.tar.bz2 b/llvm-3.0.99+svn155320.tar.bz2 new file mode 100644 index 0000000..aea83b2 --- /dev/null +++ b/llvm-3.0.99+svn155320.tar.bz2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3dbe664b25fa4c95ffa156c04adab99af0d5155f596c393b6ffddbebb0d478f8 +size 16132490 diff --git a/llvm.changes b/llvm.changes index 9d10c13..0c43a94 100644 --- a/llvm.changes +++ b/llvm.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Sun Apr 22 19:24:24 UTC 2012 - idonmez@suse.com + +- Update to svn revision 155320 from 3.1 branch + * AVX fixes + ------------------------------------------------------------------- Tue Apr 17 07:48:50 UTC 2012 - idonmez@suse.com diff --git a/llvm.spec b/llvm.spec index 554f4b1..909f366 100644 --- a/llvm.spec +++ b/llvm.spec @@ -21,7 +21,7 @@ %define _supported_archs "arm,x86" Name: llvm -Version: 3.0.99+svn154914 +Version: 3.0.99+svn155320 Release: 0 Summary: Low Level Virtual Machine License: NCSA @@ -143,9 +143,6 @@ rm tools/clang/test/Driver/x86_features.c sed -i s,SVN_REVISION,\"%{_revision}\",g tools/clang/lib/Basic/Version.cpp sed -i s,LLVM_REVISION,\"%{_revision}\",g tools/clang/lib/Basic/Version.cpp -# FIXME -rm -rf projects/compiler_rt - # Nasty hardcoded path sed -i s,/lib/,/%{_lib}/,g tools/clang/lib/Driver/Tools.cpp @@ -281,17 +278,13 @@ install -m 755 -d %{buildroot}%{_datadir}/vim/site/syntax/ install -m 644 utils/vim/*.vim %{buildroot}%{_datadir}/vim/site/syntax/ mv utils/vim/README utils/vim/README.vim -# Remove gtest library -rm -f %{buildroot}%{_libdir}/*gtest* - -# Wrong lib name + static -rm -f %{buildroot}%{_libdir}/liblibclang.a - # Stuff we don't want to include -rm -f %{buildroot}%{_libdir}/BugpointPasses.* -rm -f %{buildroot}%{_libdir}/LLVMHello.* -rm -f %{buildroot}%{_libdir}/libCompilerDriver.* -rm -f %{buildroot}%{_libdir}/libEnhancedDisassembly.* +rm %{buildroot}%{_libdir}/*clang*.a +rm %{buildroot}%{_libdir}/BugpointPasses.* +rm %{buildroot}%{_libdir}/LLVMHello.* +rm %{buildroot}%{_libdir}/libCompilerDriver.* +rm %{buildroot}%{_libdir}/libEnhancedDisassembly.* +rm %{buildroot}%{_libdir}/*gtest* %fdupes -s %{buildroot}%{_docdir}/%{name} %fdupes -s %{buildroot}%{_docdir}/%{name}-doc From 3ff2ab3a2b325c7d6e8f77b6b29f8cbd851ce7db6f1b6cb27659a16713cb569f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ismail=20D=C3=B6nmez?= Date: Sun, 22 Apr 2012 19:36:57 +0000 Subject: [PATCH 02/11] Add back FIXME OBS-URL: https://build.opensuse.org/package/show/devel:tools:compiler/llvm?expand=0&rev=136 --- llvm.spec | 3 +++ 1 file changed, 3 insertions(+) diff --git a/llvm.spec b/llvm.spec index 909f366..5fd9b60 100644 --- a/llvm.spec +++ b/llvm.spec @@ -146,6 +146,9 @@ sed -i s,LLVM_REVISION,\"%{_revision}\",g tools/clang/lib/Basic/Version.cpp # Nasty hardcoded path sed -i s,/lib/,/%{_lib}/,g tools/clang/lib/Driver/Tools.cpp +# FIXME +rm -rf projects/compiler_rt + %build TOPLEVEL=$PWD mkdir stage1 stage2 stage3 From 8cf58183ff0c5787379abc449483ae888d7a759af3e211eb442f3b0b85b33249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ismail=20D=C3=B6nmez?= Date: Mon, 23 Apr 2012 12:57:07 +0000 Subject: [PATCH 03/11] Fix build OBS-URL: https://build.opensuse.org/package/show/devel:tools:compiler/llvm?expand=0&rev=137 --- llvm.spec | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/llvm.spec b/llvm.spec index 5fd9b60..04cae59 100644 --- a/llvm.spec +++ b/llvm.spec @@ -100,6 +100,8 @@ Documentation for the LLVM compiler infrastructure. Summary: CLANG frontend for LLVM Group: Development/Languages/Other Requires: %{name} = %{version} +Requires: binutils +Requires: libstdc++-devel Provides: clang %{py_requires} @@ -285,9 +287,6 @@ mv utils/vim/README utils/vim/README.vim rm %{buildroot}%{_libdir}/*clang*.a rm %{buildroot}%{_libdir}/BugpointPasses.* rm %{buildroot}%{_libdir}/LLVMHello.* -rm %{buildroot}%{_libdir}/libCompilerDriver.* -rm %{buildroot}%{_libdir}/libEnhancedDisassembly.* -rm %{buildroot}%{_libdir}/*gtest* %fdupes -s %{buildroot}%{_docdir}/%{name} %fdupes -s %{buildroot}%{_docdir}/%{name}-doc From 9356b84b4109e875f6ab85519d377dea76d29ad4a00fe6da3a10aaa594db9e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ismail=20D=C3=B6nmez?= Date: Tue, 24 Apr 2012 10:10:57 +0000 Subject: [PATCH 04/11] - Fix llvm-config --libs output OBS-URL: https://build.opensuse.org/package/show/devel:tools:compiler/llvm?expand=0&rev=138 --- llvm.changes | 5 +++++ llvm.spec | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/llvm.changes b/llvm.changes index 0c43a94..905d962 100644 --- a/llvm.changes +++ b/llvm.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Tue Apr 24 10:12:32 UTC 2012 - idonmez@suse.com + +- Fix llvm-config --libs output + ------------------------------------------------------------------- Sun Apr 22 19:24:24 UTC 2012 - idonmez@suse.com diff --git a/llvm.spec b/llvm.spec index 04cae59..fa9af5a 100644 --- a/llvm.spec +++ b/llvm.spec @@ -19,6 +19,7 @@ %define _revision 154914 %define _release_version 3.1 %define _supported_archs "arm,x86" +%define _disabled_archs CellSPU CppBackend MBlaze Mips MSP430 PowerPC PTX Sparc XCore Name: llvm Version: 3.0.99+svn155320 @@ -151,6 +152,9 @@ sed -i s,/lib/,/%{_lib}/,g tools/clang/lib/Driver/Tools.cpp # FIXME rm -rf projects/compiler_rt +# Only enable target archs otherwise llvm-config is messed up +sed -i s,"subdirectories = .*","subdirectories = ARM X86", lib/Target/LLVMBuild.txt + %build TOPLEVEL=$PWD mkdir stage1 stage2 stage3 @@ -188,12 +192,12 @@ export CC=$TOPLEVEL/stage2/Release/bin/clang export CXX=$TOPLEVEL/stage2/Release/bin/clang++ ../configure \ - --prefix=%{_prefix} \ + --prefix=%{_prefix} \ --enable-optimized \ --disable-assertions \ --enable-pic \ --disable-timestamps \ - --enable-targets=%{_supported_archs} \ + --enable-targets=%{_supported_archs} \ %if 0%{?suse_version} >= 1220 --with-binutils-include=/usr/include \ %endif @@ -284,7 +288,7 @@ install -m 644 utils/vim/*.vim %{buildroot}%{_datadir}/vim/site/syntax/ mv utils/vim/README utils/vim/README.vim # Stuff we don't want to include -rm %{buildroot}%{_libdir}/*clang*.a +rm %{buildroot}%{_libdir}/libclang.a rm %{buildroot}%{_libdir}/BugpointPasses.* rm %{buildroot}%{_libdir}/LLVMHello.* From 41ef524fc69906ea2c8fde73ad38f0ee170c7bc8f3717a0389c572433145e7fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ismail=20D=C3=B6nmez?= Date: Tue, 24 Apr 2012 10:17:57 +0000 Subject: [PATCH 05/11] - OBS-URL: https://build.opensuse.org/package/show/devel:tools:compiler/llvm?expand=0&rev=139 --- llvm.spec | 1 - 1 file changed, 1 deletion(-) diff --git a/llvm.spec b/llvm.spec index fa9af5a..132cf14 100644 --- a/llvm.spec +++ b/llvm.spec @@ -19,7 +19,6 @@ %define _revision 154914 %define _release_version 3.1 %define _supported_archs "arm,x86" -%define _disabled_archs CellSPU CppBackend MBlaze Mips MSP430 PowerPC PTX Sparc XCore Name: llvm Version: 3.0.99+svn155320 From 5394e24b07a3382330c5d946407d1bbb69ac3d1c987e40e04e094a504e874b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ismail=20D=C3=B6nmez?= Date: Wed, 25 Apr 2012 09:38:22 +0000 Subject: [PATCH 06/11] - More fixes to llvm-config OBS-URL: https://build.opensuse.org/package/show/devel:tools:compiler/llvm?expand=0&rev=140 --- llvm.changes | 5 +++++ llvm.spec | 2 ++ 2 files changed, 7 insertions(+) diff --git a/llvm.changes b/llvm.changes index 905d962..c4b59ae 100644 --- a/llvm.changes +++ b/llvm.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Wed Apr 25 09:40:32 UTC 2012 - idonmez@suse.com + +- More fixes to llvm-config + ------------------------------------------------------------------- Tue Apr 24 10:12:32 UTC 2012 - idonmez@suse.com diff --git a/llvm.spec b/llvm.spec index 132cf14..b0053f4 100644 --- a/llvm.spec +++ b/llvm.spec @@ -153,6 +153,8 @@ rm -rf projects/compiler_rt # Only enable target archs otherwise llvm-config is messed up sed -i s,"subdirectories = .*","subdirectories = ARM X86", lib/Target/LLVMBuild.txt +sed -i s,"IntelJITEvents OProfileJIT","", lib/ExecutionEngine/LLVMBuild.txt +echo > utils/unittest/LLVMBuild.txt %build TOPLEVEL=$PWD From 39d72f1bae83a877ea2f58d3e2f6058be791d76c6bb7bf7c63f4408759e9cd13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ismail=20D=C3=B6nmez?= Date: Thu, 26 Apr 2012 10:53:01 +0000 Subject: [PATCH 07/11] - Switch to 2-stage bootstrap because we don't do build-compare anyway. OBS-URL: https://build.opensuse.org/package/show/devel:tools:compiler/llvm?expand=0&rev=141 --- llvm.changes | 6 ++++++ llvm.spec | 23 +++++------------------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/llvm.changes b/llvm.changes index c4b59ae..eaa73b2 100644 --- a/llvm.changes +++ b/llvm.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Thu Apr 26 10:55:02 UTC 2012 - idonmez@suse.com + +- Switch to 2-stage bootstrap because we don't do build-compare + anyway. + ------------------------------------------------------------------- Wed Apr 25 09:40:32 UTC 2012 - idonmez@suse.com diff --git a/llvm.spec b/llvm.spec index b0053f4..0c7c40e 100644 --- a/llvm.spec +++ b/llvm.spec @@ -158,7 +158,7 @@ echo > utils/unittest/LLVMBuild.txt %build TOPLEVEL=$PWD -mkdir stage1 stage2 stage3 +mkdir stage1 stage2 pushd stage1 ../configure \ @@ -172,25 +172,12 @@ make %{?_smp_mflags} popd pushd stage2 -export CC=$TOPLEVEL/stage1/Release/bin/clang -export CXX=$TOPLEVEL/stage1/Release/bin/clang++ - -../configure \ - --enable-optimized \ - --disable-assertions \ - --enable-targets=host - -make %{?_smp_mflags} - -popd -pushd stage3 - # autotools ignore --libdir mkdir Release ln -s lib Release/lib64 -export CC=$TOPLEVEL/stage2/Release/bin/clang -export CXX=$TOPLEVEL/stage2/Release/bin/clang++ +export CC=$TOPLEVEL/stage1/Release/bin/clang +export CXX=$TOPLEVEL/stage1/Release/bin/clang++ ../configure \ --prefix=%{_prefix} \ @@ -207,13 +194,13 @@ export CXX=$TOPLEVEL/stage2/Release/bin/clang++ make %{?_smp_mflags} REQUIRES_RTTI=1 %check -cd stage3 +cd stage2 make check cd tools/clang make test %install -cd stage3 +cd stage2 %makeinstall cd .. From 6e8d9a2f6575be895e4427b2ffef594fb79f42f59158813d4f85ec0f79bd0faf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ismail=20D=C3=B6nmez?= Date: Thu, 26 Apr 2012 13:19:08 +0000 Subject: [PATCH 08/11] - Update to svn revision 155574 from 3.1 branch * Crash fixes * Correctly enable compiler-rt * Remove unneeded runtime python dependencies OBS-URL: https://build.opensuse.org/package/show/devel:tools:compiler/llvm?expand=0&rev=142 --- llvm-3.0.99+svn155320.tar.bz2 | 3 --- llvm-3.0.99+svn155574.tar.bz2 | 3 +++ llvm.changes | 8 ++++++++ llvm.spec | 17 ++++------------- 4 files changed, 15 insertions(+), 16 deletions(-) delete mode 100644 llvm-3.0.99+svn155320.tar.bz2 create mode 100644 llvm-3.0.99+svn155574.tar.bz2 diff --git a/llvm-3.0.99+svn155320.tar.bz2 b/llvm-3.0.99+svn155320.tar.bz2 deleted file mode 100644 index aea83b2..0000000 --- a/llvm-3.0.99+svn155320.tar.bz2 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:3dbe664b25fa4c95ffa156c04adab99af0d5155f596c393b6ffddbebb0d478f8 -size 16132490 diff --git a/llvm-3.0.99+svn155574.tar.bz2 b/llvm-3.0.99+svn155574.tar.bz2 new file mode 100644 index 0000000..e500102 --- /dev/null +++ b/llvm-3.0.99+svn155574.tar.bz2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5206cb0d1088a96c92b956e31f5f0976fa4f42a5aeb77e258eb366f65c50fee1 +size 16437679 diff --git a/llvm.changes b/llvm.changes index eaa73b2..b33235e 100644 --- a/llvm.changes +++ b/llvm.changes @@ -1,3 +1,11 @@ +------------------------------------------------------------------- +Thu Apr 26 12:35:35 UTC 2012 - idonmez@suse.com + +- Update to svn revision 155574 from 3.1 branch + * Crash fixes + * Correctly enable compiler-rt + * Remove unneeded runtime python dependencies + ------------------------------------------------------------------- Thu Apr 26 10:55:02 UTC 2012 - idonmez@suse.com diff --git a/llvm.spec b/llvm.spec index 0c7c40e..af62f60 100644 --- a/llvm.spec +++ b/llvm.spec @@ -16,12 +16,12 @@ # -%define _revision 154914 +%define _revision 155574 %define _release_version 3.1 %define _supported_archs "arm,x86" Name: llvm -Version: 3.0.99+svn155320 +Version: 3.0.99+svn155574 Release: 0 Summary: Low Level Virtual Machine License: NCSA @@ -103,7 +103,6 @@ Requires: %{name} = %{version} Requires: binutils Requires: libstdc++-devel Provides: clang -%{py_requires} %description clang This package contains the clang (C language) frontend for LLVM. @@ -114,7 +113,6 @@ Summary: CLANG frontend for LLVM (devel package) Group: Development/Languages/Other Requires: clang = %{version} Requires: llvm-devel = %{version} -%{py_requires} %description clang-devel This package contains the clang (C language) frontend for LLVM. @@ -148,9 +146,6 @@ sed -i s,LLVM_REVISION,\"%{_revision}\",g tools/clang/lib/Basic/Version.cpp # Nasty hardcoded path sed -i s,/lib/,/%{_lib}/,g tools/clang/lib/Driver/Tools.cpp -# FIXME -rm -rf projects/compiler_rt - # Only enable target archs otherwise llvm-config is messed up sed -i s,"subdirectories = .*","subdirectories = ARM X86", lib/Target/LLVMBuild.txt sed -i s,"IntelJITEvents OProfileJIT","", lib/ExecutionEngine/LLVMBuild.txt @@ -283,7 +278,7 @@ rm %{buildroot}%{_libdir}/LLVMHello.* %fdupes -s %{buildroot}%{_docdir}/%{name} %fdupes -s %{buildroot}%{_docdir}/%{name}-doc -%post clang -p /sbin/ldconfig +%post clang -p /sbin/ldconfig %postun clang -p /sbin/ldconfig @@ -332,11 +327,7 @@ rm %{buildroot}%{_libdir}/LLVMHello.* %if 0%{?suse_version} >= 1220 %{_libdir}/LLVMgold.so %endif -%dir %{_libdir}/clang -%dir %{_libdir}/clang/* -%dir %{_libdir}/clang/*/include -%{_libdir}/clang/*/include/*.h -%{_libdir}/clang/*/include/module.map +%{_libdir}/clang %files clang-devel %defattr(-,root,root) From 791cae45f59fbb947554915b2699f71239095d59975668c6d3fddf6a06ec56a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ismail=20D=C3=B6nmez?= Date: Fri, 27 Apr 2012 10:00:32 +0000 Subject: [PATCH 09/11] - Update to svn revision 155700 from 3.1 branch * Crash fixes * C++11 fixes OBS-URL: https://build.opensuse.org/package/show/devel:tools:compiler/llvm?expand=0&rev=143 --- llvm-3.0.99+svn155574.tar.bz2 | 3 --- llvm-3.0.99+svn155700.tar.bz2 | 3 +++ llvm.changes | 7 +++++++ llvm.spec | 10 +++------- 4 files changed, 13 insertions(+), 10 deletions(-) delete mode 100644 llvm-3.0.99+svn155574.tar.bz2 create mode 100644 llvm-3.0.99+svn155700.tar.bz2 diff --git a/llvm-3.0.99+svn155574.tar.bz2 b/llvm-3.0.99+svn155574.tar.bz2 deleted file mode 100644 index e500102..0000000 --- a/llvm-3.0.99+svn155574.tar.bz2 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:5206cb0d1088a96c92b956e31f5f0976fa4f42a5aeb77e258eb366f65c50fee1 -size 16437679 diff --git a/llvm-3.0.99+svn155700.tar.bz2 b/llvm-3.0.99+svn155700.tar.bz2 new file mode 100644 index 0000000..ae5a996 --- /dev/null +++ b/llvm-3.0.99+svn155700.tar.bz2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:210924d3da4952b20320749cdfd9ed47c97693512ee008049caba1dc6d7768c5 +size 16428570 diff --git a/llvm.changes b/llvm.changes index b33235e..acf23cf 100644 --- a/llvm.changes +++ b/llvm.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Fri Apr 27 10:02:17 UTC 2012 - idonmez@suse.com + +- Update to svn revision 155700 from 3.1 branch + * Crash fixes + * C++11 fixes + ------------------------------------------------------------------- Thu Apr 26 12:35:35 UTC 2012 - idonmez@suse.com diff --git a/llvm.spec b/llvm.spec index af62f60..7a96959 100644 --- a/llvm.spec +++ b/llvm.spec @@ -16,12 +16,12 @@ # -%define _revision 155574 +%define _revision 155700 %define _release_version 3.1 %define _supported_archs "arm,x86" Name: llvm -Version: 3.0.99+svn155574 +Version: 3.0.99+svn155700 Release: 0 Summary: Low Level Virtual Machine License: NCSA @@ -54,14 +54,10 @@ BuildRequires: gcc-c++ # For tests BuildRequires: glibc-devel-32bit %endif +BuildRequires: libffi-devel BuildRequires: libtool BuildRequires: python -# Code10 does not have libffi -%if 0%{?suse_version} > 1100 -BuildRequires: libffi-devel -%endif - # LLVM is not supported on PPC64 # http://llvm.org/bugs/show_bug.cgi?id=3729 ExcludeArch: ppc64 From 07099d8a6a6dc95d6815f434e5cb42e4aae2797baff44652c6f63259eccf7cec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ismail=20D=C3=B6nmez?= Date: Mon, 30 Apr 2012 12:38:38 +0000 Subject: [PATCH 10/11] - Update to svn revision 155819 from 3.1 branch * C++11 fixes OBS-URL: https://build.opensuse.org/package/show/devel:tools:compiler/llvm?expand=0&rev=144 --- llvm-3.0.99+svn155700.tar.bz2 | 3 --- llvm-3.0.99+svn155819.tar.bz2 | 3 +++ llvm.changes | 6 ++++++ llvm.spec | 4 ++-- 4 files changed, 11 insertions(+), 5 deletions(-) delete mode 100644 llvm-3.0.99+svn155700.tar.bz2 create mode 100644 llvm-3.0.99+svn155819.tar.bz2 diff --git a/llvm-3.0.99+svn155700.tar.bz2 b/llvm-3.0.99+svn155700.tar.bz2 deleted file mode 100644 index ae5a996..0000000 --- a/llvm-3.0.99+svn155700.tar.bz2 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:210924d3da4952b20320749cdfd9ed47c97693512ee008049caba1dc6d7768c5 -size 16428570 diff --git a/llvm-3.0.99+svn155819.tar.bz2 b/llvm-3.0.99+svn155819.tar.bz2 new file mode 100644 index 0000000..76f0f56 --- /dev/null +++ b/llvm-3.0.99+svn155819.tar.bz2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f46df932ad690171d2f5e2de4f2ca542139675b48f921cc7913eda2f027f85d3 +size 16437850 diff --git a/llvm.changes b/llvm.changes index acf23cf..c6c0250 100644 --- a/llvm.changes +++ b/llvm.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Mon Apr 30 12:39:14 UTC 2012 - idonmez@suse.com + +- Update to svn revision 155819 from 3.1 branch + * C++11 fixes + ------------------------------------------------------------------- Fri Apr 27 10:02:17 UTC 2012 - idonmez@suse.com diff --git a/llvm.spec b/llvm.spec index 7a96959..498c4fc 100644 --- a/llvm.spec +++ b/llvm.spec @@ -16,12 +16,12 @@ # -%define _revision 155700 +%define _revision 155819 %define _release_version 3.1 %define _supported_archs "arm,x86" Name: llvm -Version: 3.0.99+svn155700 +Version: 3.0.99+svn155819 Release: 0 Summary: Low Level Virtual Machine License: NCSA From 7fbccf957e612e8431fcdd17d8c5cb6519e4b5e0e154b10396ef042ba80a0cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ismail=20D=C3=B6nmez?= Date: Thu, 3 May 2012 09:14:30 +0000 Subject: [PATCH 11/11] Accepting request 116316 from home:llunak:branches:devel:tools:compiler As discussed previously, the patch that improves usage with icecream. OBS-URL: https://build.opensuse.org/request/show/116316 OBS-URL: https://build.opensuse.org/package/show/devel:tools:compiler/llvm?expand=0&rev=145 --- llvm.changes | 5 + llvm.spec | 2 + rewrite-includes.patch | 695 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 702 insertions(+) create mode 100644 rewrite-includes.patch diff --git a/llvm.changes b/llvm.changes index c6c0250..835f9b9 100644 --- a/llvm.changes +++ b/llvm.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Thu May 3 07:32:06 UTC 2012 - llunak@suse.com + +- patch for -rewrite-includes feature + ------------------------------------------------------------------- Mon Apr 30 12:39:14 UTC 2012 - idonmez@suse.com diff --git a/llvm.spec b/llvm.spec index 498c4fc..1c06e0c 100644 --- a/llvm.spec +++ b/llvm.spec @@ -38,6 +38,7 @@ Patch3: clang-disable-ada-extension.patch # PATCH-FIX-OPENSUSE default-to-i586.patch -- Use i586 as default target for 32bit Patch4: default-to-i586.patch Patch5: clang-fix-mips-test.patch +Patch6: rewrite-includes.patch BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: autoconf BuildRequires: automake @@ -132,6 +133,7 @@ This package contains vim plugins for LLVM like syntax highlighting. %ifarch x86_64 %patch5 -p1 %endif +%patch6 -p0 # We hardcode i586 rm tools/clang/test/Driver/x86_features.c diff --git a/rewrite-includes.patch b/rewrite-includes.patch new file mode 100644 index 0000000..0df143c --- /dev/null +++ b/rewrite-includes.patch @@ -0,0 +1,695 @@ +diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td +index 83c988a..b278082 100644 +--- tools/clang/include/clang/Driver/CC1Options.td ++++ tools/clang/include/clang/Driver/CC1Options.td +@@ -452,6 +452,8 @@ def rewrite_objc : Flag<"-rewrite-objc">, + HelpText<"Rewrite ObjC into C (code rewriter example)">; + def rewrite_macros : Flag<"-rewrite-macros">, + HelpText<"Expand macros without full preprocessing">; ++def rewrite_includes : Flag<"-rewrite-includes">, ++ HelpText<"Expand includes without full preprocessing">; + def migrate : Flag<"-migrate">, + HelpText<"Migrate source code">; + } +diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h +index 888388c..78d3adf 100644 +--- tools/clang/include/clang/Frontend/FrontendOptions.h ++++ tools/clang/include/clang/Frontend/FrontendOptions.h +@@ -43,6 +43,7 @@ namespace frontend { + PrintPreamble, ///< Print the "preamble" of the input file + PrintPreprocessedInput, ///< -E mode. + RewriteMacros, ///< Expand macros but not #includes. ++ RewriteIncludes, ///< Expand #includes but not macros. + RewriteObjC, ///< ObjC->C Rewriter. + RewriteTest, ///< Rewriter playground + RunAnalysis, ///< Run one or more source code analyses. +diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h +index 055008f..638b4aa 100644 +--- tools/clang/include/clang/Lex/Preprocessor.h ++++ tools/clang/include/clang/Lex/Preprocessor.h +@@ -121,6 +121,13 @@ class Preprocessor : public RefCountedBase { + /// DisableMacroExpansion - True if macro expansion is disabled. + bool DisableMacroExpansion : 1; + ++ /// MacroExpansionInDirectivesOverride - Temporarily disables ++ /// DisableMacroExpansion (i.e. enables expansion) when parsing preprocessor ++ /// directives. ++ bool MacroExpansionInDirectivesOverride : 1; ++ ++ class ResetMacroExpansionHelper; ++ + /// \brief Whether we have already loaded macros from the external source. + mutable bool ReadMacrosFromExternalSource : 1; + +@@ -634,6 +641,12 @@ public: + while (Result.getKind() == tok::comment); + } + ++ /// Disables macro expansion everywhere except for preprocessor directives. ++ void SetMacroExpansionOnlyInDirectives() { ++ DisableMacroExpansion = true; ++ MacroExpansionInDirectivesOverride = true; ++ } ++ + /// LookAhead - This peeks ahead N tokens and returns that token without + /// consuming any tokens. LookAhead(0) returns the next token that would be + /// returned by Lex(), LookAhead(1) returns the token after it, etc. This +diff --git a/include/clang/Rewrite/FrontendActions.h b/include/clang/Rewrite/FrontendActions.h +index 6e9ecac..ea876d9 100644 +--- tools/clang/include/clang/Rewrite/FrontendActions.h ++++ tools/clang/include/clang/Rewrite/FrontendActions.h +@@ -73,6 +73,11 @@ protected: + void ExecuteAction(); + }; + ++class RewriteIncludesAction : public PreprocessorFrontendAction { ++protected: ++ void ExecuteAction(); ++}; ++ + } // end namespace clang + + #endif +diff --git a/include/clang/Rewrite/Rewriters.h b/include/clang/Rewrite/Rewriters.h +index 203b9bc..9704fe3 100644 +--- tools/clang/include/clang/Rewrite/Rewriters.h ++++ tools/clang/include/clang/Rewrite/Rewriters.h +@@ -18,6 +18,7 @@ + + namespace clang { + class Preprocessor; ++class PreprocessorOutputOptions; + + /// RewriteMacrosInInput - Implement -rewrite-macros mode. + void RewriteMacrosInInput(Preprocessor &PP, raw_ostream *OS); +@@ -25,6 +26,9 @@ void RewriteMacrosInInput(Preprocessor &PP, raw_ostream *OS); + /// DoRewriteTest - A simple test for the TokenRewriter class. + void DoRewriteTest(Preprocessor &PP, raw_ostream *OS); + ++/// RewriteIncludesInInput - Implement -rewrite-includes mode. ++void RewriteIncludesInInput(Preprocessor &PP, raw_ostream *OS, const PreprocessorOutputOptions &Opts); ++ + } // end namespace clang + + #endif +diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp +index 4c5b063..4e46973 100644 +--- tools/clang/lib/Frontend/CompilerInvocation.cpp ++++ tools/clang/lib/Frontend/CompilerInvocation.cpp +@@ -430,6 +430,7 @@ static const char *getActionName(frontend::ActionKind Kind) { + case frontend::PrintPreamble: return "-print-preamble"; + case frontend::PrintPreprocessedInput: return "-E"; + case frontend::RewriteMacros: return "-rewrite-macros"; ++ case frontend::RewriteIncludes: return "-rewrite-includes"; + case frontend::RewriteObjC: return "-rewrite-objc"; + case frontend::RewriteTest: return "-rewrite-test"; + case frontend::RunAnalysis: return "-analyze"; +@@ -1370,6 +1371,8 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, + Opts.ProgramAction = frontend::PrintPreprocessedInput; break; + case OPT_rewrite_macros: + Opts.ProgramAction = frontend::RewriteMacros; break; ++ case OPT_rewrite_includes: ++ Opts.ProgramAction = frontend::RewriteIncludes; break; + case OPT_rewrite_objc: + Opts.ProgramAction = frontend::RewriteObjC; break; + case OPT_rewrite_test: +diff --git a/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/lib/FrontendTool/ExecuteCompilerInvocation.cpp +index 07d2b8d..49d0bb8 100644 +--- tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp ++++ tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +@@ -73,6 +73,7 @@ static FrontendAction *CreateFrontendBaseAction(CompilerInstance &CI) { + case PrintPreamble: return new PrintPreambleAction(); + case PrintPreprocessedInput: return new PrintPreprocessedAction(); + case RewriteMacros: return new RewriteMacrosAction(); ++ case RewriteIncludes: return new RewriteIncludesAction(); + case RewriteObjC: return new RewriteObjCAction(); + case RewriteTest: return new RewriteTestAction(); + case RunAnalysis: return new ento::AnalysisAction(); +diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp +index 535a852..aa424b4 100644 +--- tools/clang/lib/Lex/Lexer.cpp ++++ tools/clang/lib/Lex/Lexer.cpp +@@ -2022,7 +2022,7 @@ bool Lexer::SaveBCPLComment(Token &Result, const char *CurPtr) { + // directly. + FormTokenWithChars(Result, CurPtr, tok::comment); + +- if (!ParsingPreprocessorDirective) ++ if (!ParsingPreprocessorDirective || LexingRawMode) + return true; + + // If this BCPL-style comment is in a macro definition, transmogrify it into +@@ -2625,7 +2625,8 @@ LexNextToken: + ParsingPreprocessorDirective = false; + + // Restore comment saving mode, in case it was disabled for directive. +- SetCommentRetentionState(PP->getCommentRetentionState()); ++ if (!LexingRawMode) ++ SetCommentRetentionState(PP->getCommentRetentionState()); + + // Since we consumed a newline, we are back at the start of a line. + IsAtStartOfLine = true; +diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp +index 625a204..29a8614 100644 +--- tools/clang/lib/Lex/PPDirectives.cpp ++++ tools/clang/lib/Lex/PPDirectives.cpp +@@ -553,6 +553,22 @@ const FileEntry *Preprocessor::LookupFile( + // Preprocessor Directive Handling. + //===----------------------------------------------------------------------===// + ++class Preprocessor::ResetMacroExpansionHelper ++{ ++public: ++ ResetMacroExpansionHelper(Preprocessor*pp) ++ : PP(pp), save(pp->DisableMacroExpansion) { ++ if (pp->MacroExpansionInDirectivesOverride) ++ pp->DisableMacroExpansion = false; ++ } ++ ~ResetMacroExpansionHelper() { ++ PP->DisableMacroExpansion = save; ++ } ++private: ++ Preprocessor* PP; ++ bool save; ++}; ++ + /// HandleDirective - This callback is invoked when the lexer sees a # token + /// at the start of a line. This consumes the directive, modifies the + /// lexer/preprocessor state, and advances the lexer(s) so that the next token +@@ -604,6 +620,10 @@ void Preprocessor::HandleDirective(Token &Result) { + Diag(Result, diag::ext_embedded_directive); + } + ++ // temporarily enable macro expansion if set so ++ // and reset to previous state when returning from this function ++ ResetMacroExpansionHelper helper(this); ++ + TryAgain: + switch (Result.getKind()) { + case tok::eod: +diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp +index 06e5685..f5d7a51 100644 +--- tools/clang/lib/Lex/Preprocessor.cpp ++++ tools/clang/lib/Lex/Preprocessor.cpp +@@ -134,6 +134,7 @@ void Preprocessor::Initialize(const TargetInfo &Target) { + + // Macro expansion is enabled. + DisableMacroExpansion = false; ++ MacroExpansionInDirectivesOverride = false; + InMacroArgs = false; + InMacroArgPreExpansion = false; + NumCachedTokenLexers = 0; +diff --git a/lib/Rewrite/CMakeLists.txt b/lib/Rewrite/CMakeLists.txt +index 2a05040..8070ba2 100644 +--- tools/clang/lib/Rewrite/CMakeLists.txt ++++ tools/clang/lib/Rewrite/CMakeLists.txt +@@ -6,6 +6,7 @@ add_clang_library(clangRewrite + FrontendActions.cpp + HTMLPrint.cpp + HTMLRewrite.cpp ++ RewriteIncludes.cpp + RewriteMacros.cpp + RewriteModernObjC.cpp + RewriteObjC.cpp +diff --git a/lib/Rewrite/FrontendActions.cpp b/lib/Rewrite/FrontendActions.cpp +index 1753325..e462671 100644 +--- tools/clang/lib/Rewrite/FrontendActions.cpp ++++ tools/clang/lib/Rewrite/FrontendActions.cpp +@@ -181,3 +181,11 @@ void RewriteTestAction::ExecuteAction() { + + DoRewriteTest(CI.getPreprocessor(), OS); + } ++ ++void RewriteIncludesAction::ExecuteAction() { ++ CompilerInstance &CI = getCompilerInstance(); ++ raw_ostream *OS = CI.createDefaultOutputFile(true, getCurrentFile()); ++ if (!OS) return; ++ ++ RewriteIncludesInInput(CI.getPreprocessor(), OS, CI.getPreprocessorOutputOpts()); ++} +diff --git a/lib/Rewrite/RewriteIncludes.cpp b/lib/Rewrite/RewriteIncludes.cpp +new file mode 100644 +index 0000000..679e556 +--- /dev/null ++++ tools/clang/lib/Rewrite/RewriteIncludes.cpp +@@ -0,0 +1,333 @@ ++//===--- RewriteIncludes.cpp - Rewrite includes into their expansions -----===// ++// ++// The LLVM Compiler Infrastructure ++// ++// This file is distributed under the University of Illinois Open Source ++// License. See LICENSE.TXT for details. ++// ++//===----------------------------------------------------------------------===// ++// ++// This code rewrites include invocations into their expansions. This gives you ++// a file with all included files merged into it. ++// ++//===----------------------------------------------------------------------===// ++ ++#include "clang/Rewrite/Rewriters.h" ++#include "clang/Lex/Preprocessor.h" ++#include "clang/Basic/SourceManager.h" ++#include "clang/Frontend/PreprocessorOutputOptions.h" ++#include "llvm/Support/raw_ostream.h" ++ ++using namespace clang; ++using namespace llvm; ++ ++namespace { ++ ++class IncludeRewriter : public PPCallbacks { ++ /// Information about which #includes were actually performed, ++ /// created by preprocessor callbacks. ++ struct FileChange { ++ SourceLocation From; ++ FileID Id; ++ SrcMgr::CharacteristicKind Type; ++ }; ++ Preprocessor &PP; ++ SourceManager &SM; ++ raw_ostream &OS; ++ bool DisableLineMarkers; ++ bool UseLineDirective; ++ typedef std::map FileChangeMap; ++ FileChangeMap FileChanges; ++ unsigned LastInsertedFileChange; ++public: ++ IncludeRewriter(Preprocessor &PP, raw_ostream &OS, bool LineMarkers); ++ bool Process(FileID FileId, SrcMgr::CharacteristicKind Type); ++private: ++ virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason, ++ SrcMgr::CharacteristicKind FileType, ++ FileID PrevFID); ++ virtual void InclusionDirective(SourceLocation HashLoc, ++ const Token &IncludeTok, ++ StringRef FileName, ++ bool IsAngled, ++ const FileEntry *File, ++ SourceLocation EndLoc, ++ StringRef SearchPath, ++ StringRef RelativePath); ++ void WriteLineInfo(const char* Filename, int Line, ++ SrcMgr::CharacteristicKind Type, ++ const char* EOL, StringRef Extra = StringRef()); ++ void OutputContentUpTo(unsigned WriteEnd, unsigned& NextToWrite, ++ int& Lines, const char* EOL, ++ const MemoryBuffer* FromFile, ++ bool EnsureNewline = false); ++ void CommentOutDirective(Lexer& DirectivesLex, const Token& StartToken, ++ unsigned& NextToWrite, int& Lines, ++ const char* EOL, const MemoryBuffer* FromFile); ++ const FileChange* FindFileChangeLocation(SourceLocation Loc) const; ++ StringRef NextIdentifierName(Lexer& RawLex, Token& RawToken); ++}; ++ ++} // end anonymous namespace ++ ++IncludeRewriter::IncludeRewriter(Preprocessor &pp, raw_ostream &os, ++ bool lineMarkers) ++ : PP(pp), SM(PP.getSourceManager()), OS(os), ++ DisableLineMarkers(lineMarkers), LastInsertedFileChange(0) { ++ // If we're in microsoft mode, use normal #line instead of line markers. ++ UseLineDirective = PP.getLangOpts().MicrosoftExt; ++} ++ ++void IncludeRewriter::WriteLineInfo(const char* Filename, int Line, ++ SrcMgr::CharacteristicKind Type, ++ const char* EOL, StringRef Extra) { ++ // Emit #line directives or GNU line markers depending on what mode we're in. ++ if (UseLineDirective) { ++ OS << "#line" << ' ' << Line << ' ' << '"' << Filename << '"'; ++ } else { ++ OS << '#' << ' ' << Line << ' ' << '"' << Filename << '"'; ++ if (!Extra.empty()) ++ OS << Extra; ++ if (Type == SrcMgr::C_System) ++ OS << " 3"; ++ else if (Type == SrcMgr::C_ExternCSystem) ++ OS << " 3 4"; ++ } ++ OS << EOL; ++} ++ ++/// FileChanged - Whenever the preprocessor enters or exits a #include file ++/// it invokes this handler. ++void IncludeRewriter::FileChanged(SourceLocation Loc, ++ FileChangeReason Reason, ++ SrcMgr::CharacteristicKind NewFileType, ++ FileID) { ++ if (Reason == EnterFile) { ++ // InclusionDirective() has already been called, add more info ++ FileID Id = FullSourceLoc(Loc,SM).getFileID(); ++ if (LastInsertedFileChange != 0) { // there may be e.g. "" first ++ FileChange& Ref = FileChanges[LastInsertedFileChange]; ++ Ref.Id = Id; ++ Ref.Type = NewFileType; ++ } ++ } ++} ++ ++/// This should be called whenever the preprocessor encounters include ++/// directives. It does not say whether the file has been included, but it ++/// provides more information about the directive (hash location istead ++/// of location inside the included file. It is assumed that the matching ++/// FileChanged() is called after this (if at all). ++void IncludeRewriter::InclusionDirective(SourceLocation HashLoc, ++ const Token &/*IncludeTok*/, ++ StringRef /*FileName*/, ++ bool /*IsAngled*/, ++ const FileEntry* /*File*/, ++ SourceLocation /*EndLoc*/, ++ StringRef /*SearchPath*/, ++ StringRef /*RelativePath*/) { ++ FileChange Change; ++ Change.From = HashLoc; ++ LastInsertedFileChange = HashLoc.getRawEncoding(); ++ FileChanges[LastInsertedFileChange] = Change; ++} ++ ++const IncludeRewriter::FileChange* ++IncludeRewriter::FindFileChangeLocation(SourceLocation Loc) const { ++ FileChangeMap ::const_iterator Find = FileChanges.find(Loc.getRawEncoding()); ++ if(Find != FileChanges.end()) ++ return &Find->second; ++ return NULL; ++} ++ ++inline unsigned CountNewLines(const char* Pos, int Len) { ++ const char* End = Pos + Len; ++ unsigned Lines = 0; ++ --Pos; ++ while ((Pos = static_cast(memchr(Pos + 1, '\n', End - Pos - 1)))) ++ ++Lines; ++ return Lines; ++} ++ ++static const char* DetectEOL(const MemoryBuffer* FromFile) { ++ // detect what line endings the file uses, so that added content does not mix ++ // the style ++ const char* Pos = strchr(FromFile->getBufferStart(), '\n'); ++ if (Pos == NULL) ++ return "\n"; ++ if (Pos+1 < FromFile->getBufferEnd() && *(Pos+1) == '\r') ++ return "\n\r"; ++ if (Pos-1 >= FromFile->getBufferStart() && *(Pos+1) == '\r') ++ return "\r\n"; ++ return "\n"; ++} ++ ++/// Copies next not yet written file content up (and not including) to writeEnd. ++void IncludeRewriter::OutputContentUpTo(unsigned WriteEnd, ++ unsigned& NextToWrite, ++ int& Lines, const char* EOL, ++ const MemoryBuffer* FromFile, ++ bool EnsureNewline) { ++ if (WriteEnd > NextToWrite) { ++ OS.write(FromFile->getBufferStart() + NextToWrite, WriteEnd - NextToWrite); ++ // count lines manually, it's faster than getPresumedLoc() ++ Lines += CountNewLines(FromFile->getBufferStart() + NextToWrite, ++ WriteEnd - NextToWrite); ++ if (EnsureNewline) { ++ char LastChar = FromFile->getBufferStart()[WriteEnd - 1]; ++ if (LastChar != '\n' && LastChar != '\r') ++ OS << EOL; ++ } ++ NextToWrite = WriteEnd; ++ } ++} ++ ++void IncludeRewriter::CommentOutDirective(Lexer& DirectiveLex, ++ const Token& StartToken, ++ unsigned& NextToWrite, int& Lines, ++ const char* EOL, ++ const MemoryBuffer* FromFile) { ++ OutputContentUpTo(SM.getFileOffset(StartToken.getLocation()), NextToWrite, ++ Lines, EOL, FromFile); ++ Token DirectiveToken; ++ do { ++ DirectiveLex.LexFromRawLexer(DirectiveToken); ++ } while (!DirectiveToken.is(tok::eod) && DirectiveToken.isNot(tok::eof)); ++ OS << "#if 0 /* expanded by -rewrite-includes */" << EOL; ++ OutputContentUpTo(SM.getFileOffset(DirectiveToken.getLocation()) ++ + DirectiveToken.getLength(), NextToWrite, Lines, EOL, FromFile); ++ OS << "#endif /* expanded by -rewrite-includes */" << EOL; ++} ++ ++StringRef IncludeRewriter::NextIdentifierName(Lexer& RawLex, Token& RawToken) { ++ RawLex.LexFromRawLexer(RawToken); ++ if (RawToken.is(tok::raw_identifier)) ++ PP.LookUpIdentifierInfo(RawToken); ++ if (RawToken.is(tok::identifier)) ++ return RawToken.getIdentifierInfo()->getName(); ++ return StringRef(); ++} ++ ++bool IncludeRewriter::Process(FileID FileId, SrcMgr::CharacteristicKind Type) ++{ ++ bool Invalid; ++ const char* FileName = SM.getBufferName(SM.getLocForStartOfFile(FileId), ++ &Invalid); ++ if (Invalid) ++ return false; ++ ++ // Use a raw lexer to analyze the input file, incrementally copying parts of ++ // it and including content of included files recursively. ++ const MemoryBuffer *FromFile = SM.getBuffer(FileId); ++ Lexer RawLex(FileId, FromFile, PP.getSourceManager(), PP.getLangOpts()); ++ RawLex.SetCommentRetentionState(false); ++ ++ const char* EOL = DetectEOL(FromFile); ++ ++ WriteLineInfo(FileName, 1, Type, EOL, " 1"); ++ ++ if (SM.getFileIDSize(FileId) == 0) ++ return true; ++ ++ // file position from which the content has not yet been copied to the output ++ unsigned NextToWrite = 0; ++ int Lines = 1; // current input file line number ++ ++ Token RawToken; ++ RawLex.LexFromRawLexer(RawToken); ++ ++ // TODO: It might be beneficial to have a switch that removes content of lines ++ // that are irrevelant for compile, i.e. comments. Comments are usually ++ // a significant part of the resulting file and cleaning up such lines would ++ // significantly reduce the size of the resulting file without having any ++ // effect on any following usage (with the exception of human inspection). ++ while (RawToken.isNot(tok::eof)) { ++ if (RawToken.is(tok::hash) && RawToken.isAtStartOfLine()) { ++ RawLex.setParsingPreprocessorDirective(true); ++ Token HashToken = RawToken; ++ RawLex.LexFromRawLexer(RawToken); ++ if (RawToken.is(tok::raw_identifier)) ++ PP.LookUpIdentifierInfo(RawToken); ++ if (RawToken.is(tok::identifier)) { ++ switch (RawToken.getIdentifierInfo()->getPPKeywordID()) { ++ case tok::pp_include: ++ case tok::pp_include_next: ++ case tok::pp_import: { ++ // keep the directive in, commented out ++ // (clang sometimes optimizes and does not repeatedly include some ++ // files even though it should, so all includes need to be ++ // commented, otherwise valid directives would be left in) ++ CommentOutDirective(RawLex, HashToken, NextToWrite, Lines, EOL, ++ FromFile); ++ // fix up lineinfo, commenting out has added lines ++ bool NeedFixup = true; ++ if (const FileChange* Change = FindFileChangeLocation( ++ HashToken.getLocation())) { ++ // now include and recursively process the file ++ if(Process(Change->Id, Change->Type)) { ++ // and set lineinfo back to this file, if the nested one was ++ // actually included ++ WriteLineInfo(FileName, Lines, Type, EOL, " 2"); ++ NeedFixup = false; ++ } ++ } ++ if(NeedFixup) ++ WriteLineInfo(FileName, Lines, Type, EOL); ++ break; ++ } ++ case tok::pp_pragma: { ++ StringRef Identifier = NextIdentifierName(RawLex, RawToken); ++ if (Identifier == "clang" || Identifier == "GCC") { ++ if (NextIdentifierName(RawLex, RawToken) == "system_header") { ++ // keep the directive in, commented out ++ CommentOutDirective(RawLex, HashToken, NextToWrite, Lines, ++ EOL, FromFile); ++ // update our own type ++ Type = SM.getFileCharacteristic(RawToken.getLocation()); ++ WriteLineInfo(FileName, Lines, Type, EOL); ++ } ++ } else if (Identifier == "once") { ++ // keep the directive in, commented out ++ CommentOutDirective(RawLex, HashToken, NextToWrite, Lines, ++ EOL, FromFile); ++ WriteLineInfo(FileName, Lines, Type, EOL); ++ } ++ break; ++ } ++ default: ++ break; ++ } ++ } ++ RawLex.setParsingPreprocessorDirective(false); ++ RawLex.SetCommentRetentionState(false); ++ } ++ RawLex.LexFromRawLexer(RawToken); ++ } ++ OutputContentUpTo(SM.getFileOffset(SM.getLocForEndOfFile(FileId)) + 1, ++ NextToWrite, Lines, EOL, FromFile, true); ++ return true; ++} ++ ++/// RewriteIncludesInInput - Implement -rewrite-includes mode. ++void clang::RewriteIncludesInInput(Preprocessor &PP, raw_ostream *OS, ++ const PreprocessorOutputOptions &Opts) { ++ SourceManager &SM = PP.getSourceManager(); ++ IncludeRewriter* Rewrite = new IncludeRewriter(PP, *OS,!Opts.ShowLineMarkers); ++ PP.addPPCallbacks(Rewrite); ++ ++ // First let the preprocessor process the entire file and call callbacks. ++ // Callbacks will record which #include's were actually performed. ++ PP.EnterMainSourceFile(); ++ Token Tok; ++ // Only preprocessor directives matter here, so disable macro expansion ++ // everywhere else as an optimization. ++ // TODO: It would be even faster if the preprocessor could be switched ++ // to a mode where it would parse only preprocessor directives and comments, ++ // nothing else matters for parsing or processing. ++ PP.SetMacroExpansionOnlyInDirectives(); ++ do { ++ PP.Lex(Tok); ++ } while (Tok.isNot(tok::eof)); ++ Rewrite->Process(SM.getMainFileID(), SrcMgr::C_User); ++ OS->flush(); ++} +diff --git a/test/Frontend/Inputs/rewrite-includes1.h b/test/Frontend/Inputs/rewrite-includes1.h +new file mode 100644 +index 0000000..1b6c80d +--- /dev/null ++++ tools/clang/test/Frontend/Inputs/rewrite-includes1.h +@@ -0,0 +1,3 @@ ++#pragma clang system_header ++included_line1 ++#include "rewrite-includes2.h" +diff --git a/test/Frontend/Inputs/rewrite-includes2.h b/test/Frontend/Inputs/rewrite-includes2.h +new file mode 100644 +index 0000000..1114e51 +--- /dev/null ++++ tools/clang/test/Frontend/Inputs/rewrite-includes2.h +@@ -0,0 +1 @@ ++included_line2 +diff --git a/test/Frontend/Inputs/rewrite-includes3.h b/test/Frontend/Inputs/rewrite-includes3.h +new file mode 100644 +index 0000000..3757bc8 +--- /dev/null ++++ tools/clang/test/Frontend/Inputs/rewrite-includes3.h +@@ -0,0 +1 @@ ++included_line3 +diff --git a/test/Frontend/Inputs/rewrite-includes4.h b/test/Frontend/Inputs/rewrite-includes4.h +new file mode 100644 +index 0000000..b4e25d2 +--- /dev/null ++++ tools/clang/test/Frontend/Inputs/rewrite-includes4.h +@@ -0,0 +1 @@ ++included_line4 +diff --git a/test/Frontend/Inputs/rewrite-includes5.h b/test/Frontend/Inputs/rewrite-includes5.h +new file mode 100644 +index 0000000..934bf41 +--- /dev/null ++++ tools/clang/test/Frontend/Inputs/rewrite-includes5.h +@@ -0,0 +1 @@ ++included_line5 +diff --git a/test/Frontend/Inputs/rewrite-includes6.h b/test/Frontend/Inputs/rewrite-includes6.h +new file mode 100644 +index 0000000..c18e501 +--- /dev/null ++++ tools/clang/test/Frontend/Inputs/rewrite-includes6.h +@@ -0,0 +1,2 @@ ++#pragma once ++included_line6 +diff --git a/test/Frontend/rewrite-includes.c b/test/Frontend/rewrite-includes.c +new file mode 100644 +index 0000000..fbe901f +--- /dev/null ++++ tools/clang/test/Frontend/rewrite-includes.c +@@ -0,0 +1,77 @@ ++// RUN: %clang_cc1 -verify -rewrite-includes -DFIRST -I %S/Inputs %s -o %t ++// RUN: cat %t | FileCheck -strict-whitespace %s ++// STARTCOMPARE ++#define A(a,b) a ## b ++A(1,2) ++#include "rewrite-includes1.h" ++#ifdef FIRST ++#define HEADER "rewrite-includes3.h" ++#include HEADER ++#else ++#include "rewrite-includes4.h" ++#endif ++#/**/include /**/ "rewrite-includes5.h" /**/ \ ++ ++#include "rewrite-includes6.h" // comment ++ ++#include "rewrite-includes6.h" /* comment ++ continues */ ++// ENDCOMPARE ++ ++// CHECK: {{^}}// STARTCOMPARE{{$}} ++// CHECK-NEXT: {{^}}#define A(a,b) a ## b{{$}} ++// CHECK-NEXT: {{^}}A(1,2){{$}} ++// CHECK-NEXT: {{^}}#if 0 /* expanded by -rewrite-includes */{{$}} ++// CHECK-NEXT: {{^}}#include "rewrite-includes1.h"{{$}} ++// CHECK-NEXT: {{^}}#endif /* expanded by -rewrite-includes */{{$}} ++// CHECK-NEXT: {{^}}# 1 "{{.*}}/Inputs/rewrite-includes1.h" 1{{$}} ++// CHECK-NEXT: {{^}}#if 0 /* expanded by -rewrite-includes */{{$}} ++// CHECK-NEXT: {{^}}#pragma clang system_header{{$}} ++// CHECK-NEXT: {{^}}#endif /* expanded by -rewrite-includes */{{$}} ++// CHECK-NEXT: {{^}}# 2 "{{.*}}/Inputs/rewrite-includes1.h" 3{{$}} ++// CHECK-NEXT: {{^}}included_line1{{$}} ++// CHECK-NEXT: {{^}}#if 0 /* expanded by -rewrite-includes */{{$}} ++// CHECK-NEXT: {{^}}#include "rewrite-includes2.h"{{$}} ++// CHECK-NEXT: {{^}}#endif /* expanded by -rewrite-includes */{{$}} ++// CHECK-NEXT: {{^}}# 1 "{{.*}}/Inputs/rewrite-includes2.h" 1 3{{$}} ++// CHECK-NEXT: {{^}}included_line2{{$}} ++// CHECK-NEXT: {{^}}# 4 "{{.*}}/Inputs/rewrite-includes1.h" 2 3{{$}} ++// CHECK-NEXT: {{^}}# 7 "{{.*}}rewrite-includes.c" 2{{$}} ++// CHECK-NEXT: {{^}}#ifdef FIRST{{$}} ++// CHECK-NEXT: {{^}}#define HEADER "rewrite-includes3.h"{{$}} ++// CHECK-NEXT: {{^}}#if 0 /* expanded by -rewrite-includes */{{$}} ++// CHECK-NEXT: {{^}}#include HEADER{{$}} ++// CHECK-NEXT: {{^}}#endif /* expanded by -rewrite-includes */{{$}} ++// CHECK-NEXT: {{^}}# 1 "{{.*}}/Inputs/rewrite-includes3.h" 1{{$}} ++// CHECK-NEXT: {{^}}included_line3{{$}} ++// CHECK-NEXT: {{^}}# 10 "{{.*}}rewrite-includes.c" 2{{$}} ++// CHECK-NEXT: {{^}}#else{{$}} ++// CHECK-NEXT: {{^}}#if 0 /* expanded by -rewrite-includes */{{$}} ++// CHECK-NEXT: {{^}}#include "rewrite-includes4.h"{{$}} ++// CHECK-NEXT: {{^}}#endif /* expanded by -rewrite-includes */{{$}} ++// CHECK-NEXT: {{^}}# 12 "{{.*}}rewrite-includes.c"{{$}} ++// CHECK-NEXT: {{^}}#endif{{$}} ++// CHECK-NEXT: {{^}}#if 0 /* expanded by -rewrite-includes */{{$}} ++// CHECK-NEXT: {{^}}#/**/include /**/ "rewrite-includes5.h" /**/ {{\\}}{{$}} ++// CHECK-NEXT: {{^}} {{$}} ++// CHECK-NEXT: {{^}}#endif /* expanded by -rewrite-includes */{{$}} ++// CHECK-NEXT: {{^}}# 1 "{{.*}}/Inputs/rewrite-includes5.h" 1{{$}} ++// CHECK-NEXT: {{^}}included_line5{{$}} ++// CHECK-NEXT: {{^}}# 15 "{{.*}}rewrite-includes.c" 2{{$}} ++// CHECK-NEXT: {{^}}#if 0 /* expanded by -rewrite-includes */{{$}} ++// CHECK-NEXT: {{^}}#include "rewrite-includes6.h" // comment{{$}} ++// CHECK-NEXT: {{^}}#endif /* expanded by -rewrite-includes */{{$}} ++// CHECK-NEXT: {{^}}# 1 "{{.*}}/Inputs/rewrite-includes6.h" 1{{$}} ++// CHECK-NEXT: {{^}}#if 0 /* expanded by -rewrite-includes */{{$}} ++// CHECK-NEXT: {{^}}#pragma once{{$}} ++// CHECK-NEXT: {{^}}#endif /* expanded by -rewrite-includes */{{$}} ++// CHECK-NEXT: {{^}}# 2 "{{.*}}/Inputs/rewrite-includes6.h"{{$}} ++// CHECK-NEXT: {{^}}included_line6{{$}} ++// CHECK-NEXT: {{^}}# 16 "{{.*}}rewrite-includes.c" 2{{$}} ++// CHECK-NEXT: {{^}} {{$}} ++// CHECK-NEXT: {{^}}#if 0 /* expanded by -rewrite-includes */{{$}} ++// CHECK-NEXT: {{^}}#include "rewrite-includes6.h" /* comment{{$}} ++// CHECK-NEXT: {{^}} continues */{{$}} ++// CHECK-NEXT: {{^}}#endif /* expanded by -rewrite-includes */{{$}} ++// CHECK-NEXT: {{^}}# 19 "{{.*}}rewrite-includes.c"{{$}} ++// CHECK-NEXT: {{^}}// ENDCOMPARE{{$}}