From 222e2a7620e6520ffaf4fc4e69d79c18da31542e Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Mon, 24 Sep 2012 09:58:17 +1000 Subject: Add the clang library to the repo (with some of my changes, too). --- clang/test/PCH/Inputs/arc.h | 26 +++ clang/test/PCH/Inputs/chain-decls1.h | 11 ++ clang/test/PCH/Inputs/chain-decls2.h | 12 ++ clang/test/PCH/Inputs/chain-ext_vector1.h | 3 + clang/test/PCH/Inputs/chain-ext_vector2.h | 3 + clang/test/PCH/Inputs/chain-external-defs1.h | 13 ++ clang/test/PCH/Inputs/chain-external-defs2.h | 11 ++ clang/test/PCH/Inputs/chain-macro-override1.h | 5 + clang/test/PCH/Inputs/chain-macro-override2.h | 5 + clang/test/PCH/Inputs/chain-macro1.h | 1 + clang/test/PCH/Inputs/chain-macro2.h | 1 + clang/test/PCH/Inputs/chain-remap-types1.h | 10 + clang/test/PCH/Inputs/chain-remap-types2.h | 8 + clang/test/PCH/Inputs/chain-selectors1.h | 16 ++ clang/test/PCH/Inputs/chain-selectors2.h | 15 ++ clang/test/PCH/Inputs/chain-trivial1.h | 0 clang/test/PCH/Inputs/chain-trivial2.h | 0 clang/test/PCH/Inputs/cxx-method.h | 6 + clang/test/PCH/Inputs/namespaces.h | 44 +++++ clang/test/PCH/Inputs/preamble.h | 1 + clang/test/PCH/Inputs/typo.h | 6 + clang/test/PCH/Inputs/typo.hpp | 8 + clang/test/PCH/Inputs/va_arg.h | 2 + clang/test/PCH/Inputs/working-directory-1.h | 5 + clang/test/PCH/arc.m | 17 ++ clang/test/PCH/asm.c | 11 ++ clang/test/PCH/asm.h | 14 ++ clang/test/PCH/attrs-PR8406.c | 23 +++ clang/test/PCH/attrs.c | 17 ++ clang/test/PCH/blocks.c | 12 ++ clang/test/PCH/blocks.h | 14 ++ clang/test/PCH/builtins.c | 10 + clang/test/PCH/builtins.h | 2 + clang/test/PCH/chain-categories.m | 51 +++++ clang/test/PCH/chain-categories2.m | 57 ++++++ clang/test/PCH/chain-class-extension.m | 42 ++++ clang/test/PCH/chain-conversion-lookup.cpp | 26 +++ clang/test/PCH/chain-cxx.cpp | 142 ++++++++++++++ clang/test/PCH/chain-decls.c | 27 +++ clang/test/PCH/chain-empty-initial-namespace.cpp | 24 +++ clang/test/PCH/chain-ext_vector.c | 11 ++ clang/test/PCH/chain-external-defs.c | 54 +++++ clang/test/PCH/chain-friend-instantiation.cpp | 61 ++++++ clang/test/PCH/chain-implicit-definition.cpp | 39 ++++ clang/test/PCH/chain-late-anonymous-namespace.cpp | 61 ++++++ clang/test/PCH/chain-macro-override.c | 14 ++ clang/test/PCH/chain-macro.c | 9 + clang/test/PCH/chain-pending-instantiations.cpp | 33 ++++ clang/test/PCH/chain-predecl.h | 3 + clang/test/PCH/chain-predecl.m | 16 ++ clang/test/PCH/chain-remap-types.m | 12 ++ clang/test/PCH/chain-selectors.m | 40 ++++ clang/test/PCH/chain-trivial.c | 4 + clang/test/PCH/changed-files.c | 28 +++ clang/test/PCH/check-deserializations.cpp | 20 ++ clang/test/PCH/cmdline-include.c | 6 + clang/test/PCH/cmdline-include1.h | 1 + clang/test/PCH/cmdline-include2.h | 1 + clang/test/PCH/cocoa.m | 7 + clang/test/PCH/cuda-kernel-call.cu | 25 +++ clang/test/PCH/cxx-alias-decl.cpp | 20 ++ clang/test/PCH/cxx-alias-decl.h | 11 ++ clang/test/PCH/cxx-chain-function-template.cpp | 32 +++ clang/test/PCH/cxx-constexpr.cpp | 19 ++ clang/test/PCH/cxx-exprs.cpp | 27 +++ clang/test/PCH/cxx-for-range.cpp | 19 ++ clang/test/PCH/cxx-for-range.h | 35 ++++ clang/test/PCH/cxx-friends.cpp | 13 ++ clang/test/PCH/cxx-friends.h | 6 + clang/test/PCH/cxx-functions.cpp | 10 + clang/test/PCH/cxx-functions.h | 1 + clang/test/PCH/cxx-implicit-moves.cpp | 23 +++ clang/test/PCH/cxx-member-init.cpp | 22 +++ clang/test/PCH/cxx-method.cpp | 8 + .../cxx-ms-function-specialization-class-scope.cpp | 13 ++ .../cxx-ms-function-specialization-class-scope.h | 29 +++ clang/test/PCH/cxx-namespaces.cpp | 10 + clang/test/PCH/cxx-namespaces.h | 7 + clang/test/PCH/cxx-offsetof-base.cpp | 2 + clang/test/PCH/cxx-offsetof-base.h | 5 + clang/test/PCH/cxx-reference.cpp | 6 + clang/test/PCH/cxx-reference.h | 13 ++ clang/test/PCH/cxx-required-decls.cpp | 10 + clang/test/PCH/cxx-required-decls.h | 12 ++ clang/test/PCH/cxx-static_assert.cpp | 20 ++ clang/test/PCH/cxx-templates.cpp | 70 +++++++ clang/test/PCH/cxx-templates.h | 217 +++++++++++++++++++++ clang/test/PCH/cxx-trailing-return.cpp | 15 ++ clang/test/PCH/cxx-traits.cpp | 11 ++ clang/test/PCH/cxx-traits.h | 16 ++ clang/test/PCH/cxx-typeid.cpp | 9 + clang/test/PCH/cxx-typeid.h | 3 + clang/test/PCH/cxx-using.cpp | 15 ++ clang/test/PCH/cxx-using.h | 16 ++ clang/test/PCH/cxx-variadic-templates.cpp | 11 ++ clang/test/PCH/cxx-variadic-templates.h | 18 ++ clang/test/PCH/cxx0x-default-delete.cpp | 34 ++++ clang/test/PCH/cxx0x-delegating-ctors.cpp | 20 ++ clang/test/PCH/cxx11-constexpr.cpp | 29 +++ clang/test/PCH/cxx11-enum-template.cpp | 26 +++ clang/test/PCH/cxx11-exception-spec.cpp | 17 ++ clang/test/PCH/cxx11-lambdas.mm | 48 +++++ clang/test/PCH/cxx11-user-defined-literals.cpp | 21 ++ clang/test/PCH/cxx_exprs.cpp | 39 ++++ clang/test/PCH/cxx_exprs.h | 83 ++++++++ clang/test/PCH/designated-init.c | 7 + clang/test/PCH/designated-init.c.h | 42 ++++ clang/test/PCH/enum.c | 15 ++ clang/test/PCH/enum.h | 16 ++ clang/test/PCH/exprs.c | 98 ++++++++++ clang/test/PCH/exprs.h | 107 ++++++++++ clang/test/PCH/ext_vector.c | 10 + clang/test/PCH/ext_vector.h | 4 + clang/test/PCH/external-defs.c | 19 ++ clang/test/PCH/external-defs.h | 13 ++ clang/test/PCH/functions.c | 25 +++ clang/test/PCH/functions.h | 11 ++ clang/test/PCH/fuzzy-pch.c | 19 ++ clang/test/PCH/fuzzy-pch.h | 2 + clang/test/PCH/headermap.h | 3 + clang/test/PCH/headermap.m | 15 ++ clang/test/PCH/headersearch.cpp | 44 +++++ clang/test/PCH/libroot/usr/include/reloc.h | 15 ++ clang/test/PCH/libroot/usr/include/reloc2.h | 15 ++ clang/test/PCH/line-directive.c | 25 +++ clang/test/PCH/line-directive.h | 2 + clang/test/PCH/method-redecls.m | 18 ++ clang/test/PCH/method_pool.h | 36 ++++ clang/test/PCH/method_pool.m | 21 ++ clang/test/PCH/missing-file.cpp | 31 +++ clang/test/PCH/modified-header-crash.c | 10 + clang/test/PCH/modified-header-crash.h | 1 + clang/test/PCH/modified-header-error.c | 12 ++ clang/test/PCH/ms-if-exists.cpp | 29 +++ clang/test/PCH/multiple_decls.c | 17 ++ clang/test/PCH/multiple_decls.h | 7 + clang/test/PCH/namespaces.cpp | 45 +++++ clang/test/PCH/nonvisible-external-defs.c | 10 + clang/test/PCH/nonvisible-external-defs.h | 11 ++ clang/test/PCH/objc_container.h | 26 +++ clang/test/PCH/objc_container.m | 20 ++ clang/test/PCH/objc_exprs.h | 26 +++ clang/test/PCH/objc_exprs.m | 27 +++ clang/test/PCH/objc_import.h | 7 + clang/test/PCH/objc_import.m | 15 ++ clang/test/PCH/objc_literals.m | 66 +++++++ clang/test/PCH/objc_literals.mm | 65 ++++++ clang/test/PCH/objc_methods.h | 11 ++ clang/test/PCH/objc_methods.m | 16 ++ clang/test/PCH/objc_property.h | 12 ++ clang/test/PCH/objc_property.m | 11 ++ clang/test/PCH/objc_stmts.h | 22 +++ clang/test/PCH/objc_stmts.m | 12 ++ clang/test/PCH/objcxx-ivar-class.h | 16 ++ clang/test/PCH/objcxx-ivar-class.mm | 15 ++ clang/test/PCH/opencl-extensions.cl | 17 ++ clang/test/PCH/pchpch.c | 6 + clang/test/PCH/pchpch1.h | 0 clang/test/PCH/pchpch2.h | 0 clang/test/PCH/pending-ids.m | 33 ++++ clang/test/PCH/pr4489.c | 48 +++++ clang/test/PCH/pragma-diag-section.cpp | 29 +++ clang/test/PCH/pragma-diag.c | 20 ++ clang/test/PCH/pragma-weak.c | 10 + clang/test/PCH/pragma-weak.h | 10 + clang/test/PCH/preamble.c | 23 +++ clang/test/PCH/preprocess.c | 8 + clang/test/PCH/preprocess.h | 7 + clang/test/PCH/pth.c | 7 + clang/test/PCH/pth.h | 12 ++ clang/test/PCH/rdar10830559.cpp | 35 ++++ clang/test/PCH/rdar8852495.c | 26 +++ clang/test/PCH/reinclude.cpp | 10 + clang/test/PCH/reinclude1.h | 7 + clang/test/PCH/reinclude2.h | 1 + clang/test/PCH/reloc.c | 14 ++ clang/test/PCH/replaced-decl.m | 22 +++ clang/test/PCH/selector-warning.h | 24 +++ clang/test/PCH/selector-warning.m | 19 ++ clang/test/PCH/single-token-macro.c | 24 +++ clang/test/PCH/source-manager-stack.c | 12 ++ clang/test/PCH/stmts.c | 14 ++ clang/test/PCH/stmts.h | 96 +++++++++ clang/test/PCH/struct.c | 28 +++ clang/test/PCH/struct.h | 29 +++ clang/test/PCH/subscripting-literals.m | 47 +++++ clang/test/PCH/tentative-defs.c | 9 + clang/test/PCH/tentative-defs.h | 9 + clang/test/PCH/types.c | 73 +++++++ clang/test/PCH/types.h | 50 +++++ clang/test/PCH/typo.cpp | 17 ++ clang/test/PCH/typo.m | 6 + clang/test/PCH/typo2.cpp | 13 ++ clang/test/PCH/va_arg.c | 12 ++ clang/test/PCH/va_arg.cpp | 16 ++ clang/test/PCH/va_arg.h | 8 + clang/test/PCH/variables.c | 47 +++++ clang/test/PCH/variables.h | 25 +++ clang/test/PCH/working-directory.cpp | 12 ++ clang/test/PCH/working-directory.h | 1 + 200 files changed, 4295 insertions(+) create mode 100644 clang/test/PCH/Inputs/arc.h create mode 100644 clang/test/PCH/Inputs/chain-decls1.h create mode 100644 clang/test/PCH/Inputs/chain-decls2.h create mode 100644 clang/test/PCH/Inputs/chain-ext_vector1.h create mode 100644 clang/test/PCH/Inputs/chain-ext_vector2.h create mode 100644 clang/test/PCH/Inputs/chain-external-defs1.h create mode 100644 clang/test/PCH/Inputs/chain-external-defs2.h create mode 100644 clang/test/PCH/Inputs/chain-macro-override1.h create mode 100644 clang/test/PCH/Inputs/chain-macro-override2.h create mode 100644 clang/test/PCH/Inputs/chain-macro1.h create mode 100644 clang/test/PCH/Inputs/chain-macro2.h create mode 100644 clang/test/PCH/Inputs/chain-remap-types1.h create mode 100644 clang/test/PCH/Inputs/chain-remap-types2.h create mode 100644 clang/test/PCH/Inputs/chain-selectors1.h create mode 100644 clang/test/PCH/Inputs/chain-selectors2.h create mode 100644 clang/test/PCH/Inputs/chain-trivial1.h create mode 100644 clang/test/PCH/Inputs/chain-trivial2.h create mode 100644 clang/test/PCH/Inputs/cxx-method.h create mode 100644 clang/test/PCH/Inputs/namespaces.h create mode 100644 clang/test/PCH/Inputs/preamble.h create mode 100644 clang/test/PCH/Inputs/typo.h create mode 100644 clang/test/PCH/Inputs/typo.hpp create mode 100644 clang/test/PCH/Inputs/va_arg.h create mode 100644 clang/test/PCH/Inputs/working-directory-1.h create mode 100644 clang/test/PCH/arc.m create mode 100644 clang/test/PCH/asm.c create mode 100644 clang/test/PCH/asm.h create mode 100644 clang/test/PCH/attrs-PR8406.c create mode 100644 clang/test/PCH/attrs.c create mode 100644 clang/test/PCH/blocks.c create mode 100644 clang/test/PCH/blocks.h create mode 100644 clang/test/PCH/builtins.c create mode 100644 clang/test/PCH/builtins.h create mode 100644 clang/test/PCH/chain-categories.m create mode 100644 clang/test/PCH/chain-categories2.m create mode 100644 clang/test/PCH/chain-class-extension.m create mode 100644 clang/test/PCH/chain-conversion-lookup.cpp create mode 100644 clang/test/PCH/chain-cxx.cpp create mode 100644 clang/test/PCH/chain-decls.c create mode 100644 clang/test/PCH/chain-empty-initial-namespace.cpp create mode 100644 clang/test/PCH/chain-ext_vector.c create mode 100644 clang/test/PCH/chain-external-defs.c create mode 100644 clang/test/PCH/chain-friend-instantiation.cpp create mode 100644 clang/test/PCH/chain-implicit-definition.cpp create mode 100644 clang/test/PCH/chain-late-anonymous-namespace.cpp create mode 100644 clang/test/PCH/chain-macro-override.c create mode 100644 clang/test/PCH/chain-macro.c create mode 100644 clang/test/PCH/chain-pending-instantiations.cpp create mode 100644 clang/test/PCH/chain-predecl.h create mode 100644 clang/test/PCH/chain-predecl.m create mode 100644 clang/test/PCH/chain-remap-types.m create mode 100644 clang/test/PCH/chain-selectors.m create mode 100644 clang/test/PCH/chain-trivial.c create mode 100644 clang/test/PCH/changed-files.c create mode 100644 clang/test/PCH/check-deserializations.cpp create mode 100644 clang/test/PCH/cmdline-include.c create mode 100644 clang/test/PCH/cmdline-include1.h create mode 100644 clang/test/PCH/cmdline-include2.h create mode 100644 clang/test/PCH/cocoa.m create mode 100644 clang/test/PCH/cuda-kernel-call.cu create mode 100644 clang/test/PCH/cxx-alias-decl.cpp create mode 100644 clang/test/PCH/cxx-alias-decl.h create mode 100644 clang/test/PCH/cxx-chain-function-template.cpp create mode 100644 clang/test/PCH/cxx-constexpr.cpp create mode 100644 clang/test/PCH/cxx-exprs.cpp create mode 100644 clang/test/PCH/cxx-for-range.cpp create mode 100644 clang/test/PCH/cxx-for-range.h create mode 100644 clang/test/PCH/cxx-friends.cpp create mode 100644 clang/test/PCH/cxx-friends.h create mode 100644 clang/test/PCH/cxx-functions.cpp create mode 100644 clang/test/PCH/cxx-functions.h create mode 100644 clang/test/PCH/cxx-implicit-moves.cpp create mode 100644 clang/test/PCH/cxx-member-init.cpp create mode 100644 clang/test/PCH/cxx-method.cpp create mode 100644 clang/test/PCH/cxx-ms-function-specialization-class-scope.cpp create mode 100644 clang/test/PCH/cxx-ms-function-specialization-class-scope.h create mode 100644 clang/test/PCH/cxx-namespaces.cpp create mode 100644 clang/test/PCH/cxx-namespaces.h create mode 100644 clang/test/PCH/cxx-offsetof-base.cpp create mode 100644 clang/test/PCH/cxx-offsetof-base.h create mode 100644 clang/test/PCH/cxx-reference.cpp create mode 100644 clang/test/PCH/cxx-reference.h create mode 100644 clang/test/PCH/cxx-required-decls.cpp create mode 100644 clang/test/PCH/cxx-required-decls.h create mode 100644 clang/test/PCH/cxx-static_assert.cpp create mode 100644 clang/test/PCH/cxx-templates.cpp create mode 100644 clang/test/PCH/cxx-templates.h create mode 100644 clang/test/PCH/cxx-trailing-return.cpp create mode 100644 clang/test/PCH/cxx-traits.cpp create mode 100644 clang/test/PCH/cxx-traits.h create mode 100644 clang/test/PCH/cxx-typeid.cpp create mode 100644 clang/test/PCH/cxx-typeid.h create mode 100644 clang/test/PCH/cxx-using.cpp create mode 100644 clang/test/PCH/cxx-using.h create mode 100644 clang/test/PCH/cxx-variadic-templates.cpp create mode 100644 clang/test/PCH/cxx-variadic-templates.h create mode 100644 clang/test/PCH/cxx0x-default-delete.cpp create mode 100644 clang/test/PCH/cxx0x-delegating-ctors.cpp create mode 100644 clang/test/PCH/cxx11-constexpr.cpp create mode 100644 clang/test/PCH/cxx11-enum-template.cpp create mode 100644 clang/test/PCH/cxx11-exception-spec.cpp create mode 100644 clang/test/PCH/cxx11-lambdas.mm create mode 100644 clang/test/PCH/cxx11-user-defined-literals.cpp create mode 100644 clang/test/PCH/cxx_exprs.cpp create mode 100644 clang/test/PCH/cxx_exprs.h create mode 100644 clang/test/PCH/designated-init.c create mode 100644 clang/test/PCH/designated-init.c.h create mode 100644 clang/test/PCH/enum.c create mode 100644 clang/test/PCH/enum.h create mode 100644 clang/test/PCH/exprs.c create mode 100644 clang/test/PCH/exprs.h create mode 100644 clang/test/PCH/ext_vector.c create mode 100644 clang/test/PCH/ext_vector.h create mode 100644 clang/test/PCH/external-defs.c create mode 100644 clang/test/PCH/external-defs.h create mode 100644 clang/test/PCH/functions.c create mode 100644 clang/test/PCH/functions.h create mode 100644 clang/test/PCH/fuzzy-pch.c create mode 100644 clang/test/PCH/fuzzy-pch.h create mode 100644 clang/test/PCH/headermap.h create mode 100644 clang/test/PCH/headermap.m create mode 100644 clang/test/PCH/headersearch.cpp create mode 100644 clang/test/PCH/libroot/usr/include/reloc.h create mode 100644 clang/test/PCH/libroot/usr/include/reloc2.h create mode 100644 clang/test/PCH/line-directive.c create mode 100644 clang/test/PCH/line-directive.h create mode 100644 clang/test/PCH/method-redecls.m create mode 100644 clang/test/PCH/method_pool.h create mode 100644 clang/test/PCH/method_pool.m create mode 100644 clang/test/PCH/missing-file.cpp create mode 100644 clang/test/PCH/modified-header-crash.c create mode 100644 clang/test/PCH/modified-header-crash.h create mode 100644 clang/test/PCH/modified-header-error.c create mode 100644 clang/test/PCH/ms-if-exists.cpp create mode 100644 clang/test/PCH/multiple_decls.c create mode 100644 clang/test/PCH/multiple_decls.h create mode 100644 clang/test/PCH/namespaces.cpp create mode 100644 clang/test/PCH/nonvisible-external-defs.c create mode 100644 clang/test/PCH/nonvisible-external-defs.h create mode 100644 clang/test/PCH/objc_container.h create mode 100644 clang/test/PCH/objc_container.m create mode 100644 clang/test/PCH/objc_exprs.h create mode 100644 clang/test/PCH/objc_exprs.m create mode 100644 clang/test/PCH/objc_import.h create mode 100644 clang/test/PCH/objc_import.m create mode 100644 clang/test/PCH/objc_literals.m create mode 100644 clang/test/PCH/objc_literals.mm create mode 100644 clang/test/PCH/objc_methods.h create mode 100644 clang/test/PCH/objc_methods.m create mode 100644 clang/test/PCH/objc_property.h create mode 100644 clang/test/PCH/objc_property.m create mode 100644 clang/test/PCH/objc_stmts.h create mode 100644 clang/test/PCH/objc_stmts.m create mode 100644 clang/test/PCH/objcxx-ivar-class.h create mode 100644 clang/test/PCH/objcxx-ivar-class.mm create mode 100644 clang/test/PCH/opencl-extensions.cl create mode 100644 clang/test/PCH/pchpch.c create mode 100644 clang/test/PCH/pchpch1.h create mode 100644 clang/test/PCH/pchpch2.h create mode 100644 clang/test/PCH/pending-ids.m create mode 100644 clang/test/PCH/pr4489.c create mode 100644 clang/test/PCH/pragma-diag-section.cpp create mode 100644 clang/test/PCH/pragma-diag.c create mode 100644 clang/test/PCH/pragma-weak.c create mode 100644 clang/test/PCH/pragma-weak.h create mode 100644 clang/test/PCH/preamble.c create mode 100644 clang/test/PCH/preprocess.c create mode 100644 clang/test/PCH/preprocess.h create mode 100644 clang/test/PCH/pth.c create mode 100644 clang/test/PCH/pth.h create mode 100644 clang/test/PCH/rdar10830559.cpp create mode 100644 clang/test/PCH/rdar8852495.c create mode 100644 clang/test/PCH/reinclude.cpp create mode 100644 clang/test/PCH/reinclude1.h create mode 100644 clang/test/PCH/reinclude2.h create mode 100644 clang/test/PCH/reloc.c create mode 100644 clang/test/PCH/replaced-decl.m create mode 100644 clang/test/PCH/selector-warning.h create mode 100644 clang/test/PCH/selector-warning.m create mode 100644 clang/test/PCH/single-token-macro.c create mode 100644 clang/test/PCH/source-manager-stack.c create mode 100644 clang/test/PCH/stmts.c create mode 100644 clang/test/PCH/stmts.h create mode 100644 clang/test/PCH/struct.c create mode 100644 clang/test/PCH/struct.h create mode 100644 clang/test/PCH/subscripting-literals.m create mode 100644 clang/test/PCH/tentative-defs.c create mode 100644 clang/test/PCH/tentative-defs.h create mode 100644 clang/test/PCH/types.c create mode 100644 clang/test/PCH/types.h create mode 100644 clang/test/PCH/typo.cpp create mode 100644 clang/test/PCH/typo.m create mode 100644 clang/test/PCH/typo2.cpp create mode 100644 clang/test/PCH/va_arg.c create mode 100644 clang/test/PCH/va_arg.cpp create mode 100644 clang/test/PCH/va_arg.h create mode 100644 clang/test/PCH/variables.c create mode 100644 clang/test/PCH/variables.h create mode 100644 clang/test/PCH/working-directory.cpp create mode 100644 clang/test/PCH/working-directory.h (limited to 'clang/test/PCH') diff --git a/clang/test/PCH/Inputs/arc.h b/clang/test/PCH/Inputs/arc.h new file mode 100644 index 0000000..304e612 --- /dev/null +++ b/clang/test/PCH/Inputs/arc.h @@ -0,0 +1,26 @@ +// Header for Objective-C ARC-related PCH tests + +typedef const void *CFTypeRef; +typedef const struct __CFString *CFStringRef; + +CFTypeRef CFCreateSomething(); +CFStringRef CFCreateString(); +CFTypeRef CFGetSomething(); +CFStringRef CFGetString(); + +@interface NSString +@end + +id CreateSomething(); +NSString *CreateNSString(); + +#if __has_feature(objc_arc) +#define BRIDGE __bridge +#else +#define BRIDGE +#endif + +typedef int array0[sizeof((BRIDGE id)CFCreateSomething())]; +typedef int array1[sizeof((BRIDGE CFTypeRef)CreateSomething())]; + + diff --git a/clang/test/PCH/Inputs/chain-decls1.h b/clang/test/PCH/Inputs/chain-decls1.h new file mode 100644 index 0000000..9de4461 --- /dev/null +++ b/clang/test/PCH/Inputs/chain-decls1.h @@ -0,0 +1,11 @@ +void f(); + +struct one {}; +void two(); + +void many(int i); +struct many; +void many(int j); +struct many; + +void noret(); diff --git a/clang/test/PCH/Inputs/chain-decls2.h b/clang/test/PCH/Inputs/chain-decls2.h new file mode 100644 index 0000000..b8b7d04 --- /dev/null +++ b/clang/test/PCH/Inputs/chain-decls2.h @@ -0,0 +1,12 @@ +void g(); + +struct two {}; +void one(); +struct three {}; // for verification + +void many(int k); +struct many; +void many(int l); +struct many {}; + +void noret() __attribute__((noreturn)); diff --git a/clang/test/PCH/Inputs/chain-ext_vector1.h b/clang/test/PCH/Inputs/chain-ext_vector1.h new file mode 100644 index 0000000..5109336 --- /dev/null +++ b/clang/test/PCH/Inputs/chain-ext_vector1.h @@ -0,0 +1,3 @@ +// First header file for chain-ext_vector.c PCH test + +typedef __attribute__((ext_vector_type(2))) float float2; diff --git a/clang/test/PCH/Inputs/chain-ext_vector2.h b/clang/test/PCH/Inputs/chain-ext_vector2.h new file mode 100644 index 0000000..bdaeccc --- /dev/null +++ b/clang/test/PCH/Inputs/chain-ext_vector2.h @@ -0,0 +1,3 @@ +// Second header file for chain-ext_vector.c PCH test + +typedef __attribute__((ext_vector_type(4))) float float4; diff --git a/clang/test/PCH/Inputs/chain-external-defs1.h b/clang/test/PCH/Inputs/chain-external-defs1.h new file mode 100644 index 0000000..36a2653 --- /dev/null +++ b/clang/test/PCH/Inputs/chain-external-defs1.h @@ -0,0 +1,13 @@ +// Helper 1 for chain-external-defs.c test + +// Tentative definitions +int x; +int x2; + +// Should not show up +static int z; + +int incomplete_array[]; +int incomplete_array2[]; + +struct S s; diff --git a/clang/test/PCH/Inputs/chain-external-defs2.h b/clang/test/PCH/Inputs/chain-external-defs2.h new file mode 100644 index 0000000..72af92f --- /dev/null +++ b/clang/test/PCH/Inputs/chain-external-defs2.h @@ -0,0 +1,11 @@ +// Helper 2 for chain-external-defs.c test + +// Tentative definitions +int y; +int y2; + +// Should still not show up +static int z; + +int incomplete_array[]; +int incomplete_array3[]; diff --git a/clang/test/PCH/Inputs/chain-macro-override1.h b/clang/test/PCH/Inputs/chain-macro-override1.h new file mode 100644 index 0000000..d956396 --- /dev/null +++ b/clang/test/PCH/Inputs/chain-macro-override1.h @@ -0,0 +1,5 @@ +void f() __attribute__((unavailable)); +void g(); +#define g() f() +#define h() f() +#define x x diff --git a/clang/test/PCH/Inputs/chain-macro-override2.h b/clang/test/PCH/Inputs/chain-macro-override2.h new file mode 100644 index 0000000..e4bff77 --- /dev/null +++ b/clang/test/PCH/Inputs/chain-macro-override2.h @@ -0,0 +1,5 @@ +#define f() g() +#undef g +#undef h +#define h() g() +int x; diff --git a/clang/test/PCH/Inputs/chain-macro1.h b/clang/test/PCH/Inputs/chain-macro1.h new file mode 100644 index 0000000..2e80e47 --- /dev/null +++ b/clang/test/PCH/Inputs/chain-macro1.h @@ -0,0 +1 @@ +#define FOOBAR void f(); diff --git a/clang/test/PCH/Inputs/chain-macro2.h b/clang/test/PCH/Inputs/chain-macro2.h new file mode 100644 index 0000000..e888228 --- /dev/null +++ b/clang/test/PCH/Inputs/chain-macro2.h @@ -0,0 +1 @@ +#define BARFOO void g(); diff --git a/clang/test/PCH/Inputs/chain-remap-types1.h b/clang/test/PCH/Inputs/chain-remap-types1.h new file mode 100644 index 0000000..d105489 --- /dev/null +++ b/clang/test/PCH/Inputs/chain-remap-types1.h @@ -0,0 +1,10 @@ +@class X; + +struct Y { + X *my_X; +}; + +@interface X { +} +@property X *prop; +@end diff --git a/clang/test/PCH/Inputs/chain-remap-types2.h b/clang/test/PCH/Inputs/chain-remap-types2.h new file mode 100644 index 0000000..55ca8a9 --- /dev/null +++ b/clang/test/PCH/Inputs/chain-remap-types2.h @@ -0,0 +1,8 @@ +void h(X*); + +@interface X (Blah) { +} +@end + +void g(X*); + diff --git a/clang/test/PCH/Inputs/chain-selectors1.h b/clang/test/PCH/Inputs/chain-selectors1.h new file mode 100644 index 0000000..b0b68f8 --- /dev/null +++ b/clang/test/PCH/Inputs/chain-selectors1.h @@ -0,0 +1,16 @@ +@interface X + -(void)f; + -(void)f2; + -(void)g:(int)p; + -(void)h:(int)p1 foo:(int)p2; +@end + +void foo1() { + // FIXME: Can't verify warnings in headers + //(void)@selector(x); + (void)@selector(f); +} + +@interface X (Blah) +- (void)blah_method; +@end diff --git a/clang/test/PCH/Inputs/chain-selectors2.h b/clang/test/PCH/Inputs/chain-selectors2.h new file mode 100644 index 0000000..973fc10 --- /dev/null +++ b/clang/test/PCH/Inputs/chain-selectors2.h @@ -0,0 +1,15 @@ +@interface Y + -(void)f; + -(double)f2; + -(void)e; +@end + +void foo2() { + // FIXME: Can't verify warnings in headers + //(void)@selector(y); + //(void)@selector(e); +} + +@interface X (Blarg) +- (void)blarg_method; +@end diff --git a/clang/test/PCH/Inputs/chain-trivial1.h b/clang/test/PCH/Inputs/chain-trivial1.h new file mode 100644 index 0000000..e69de29 diff --git a/clang/test/PCH/Inputs/chain-trivial2.h b/clang/test/PCH/Inputs/chain-trivial2.h new file mode 100644 index 0000000..e69de29 diff --git a/clang/test/PCH/Inputs/cxx-method.h b/clang/test/PCH/Inputs/cxx-method.h new file mode 100644 index 0000000..6adb859 --- /dev/null +++ b/clang/test/PCH/Inputs/cxx-method.h @@ -0,0 +1,6 @@ +struct S { + void m(int x); + + operator const char*(); + operator char*(); +}; diff --git a/clang/test/PCH/Inputs/namespaces.h b/clang/test/PCH/Inputs/namespaces.h new file mode 100644 index 0000000..bd2c3ee --- /dev/null +++ b/clang/test/PCH/Inputs/namespaces.h @@ -0,0 +1,44 @@ +// Header for PCH test namespaces.cpp + +namespace N1 { + typedef int t1; +} + +namespace N1 { + typedef int t2; + + void used_func(); + + struct used_cls { }; +} + +namespace N2 { + typedef float t1; + + namespace Inner { + typedef int t3; + }; +} + +namespace { + void anon() { } + class C; +} + +namespace N3 { + namespace { + class C; + } +} + +namespace Alias1 = N2::Inner; + +using namespace N2::Inner; + +extern "C" { + void ext(); +} + +inline namespace N4 { + struct MemberOfN4; +} diff --git a/clang/test/PCH/Inputs/preamble.h b/clang/test/PCH/Inputs/preamble.h new file mode 100644 index 0000000..aee330a --- /dev/null +++ b/clang/test/PCH/Inputs/preamble.h @@ -0,0 +1 @@ +int f(int); diff --git a/clang/test/PCH/Inputs/typo.h b/clang/test/PCH/Inputs/typo.h new file mode 100644 index 0000000..63b553b --- /dev/null +++ b/clang/test/PCH/Inputs/typo.h @@ -0,0 +1,6 @@ + + +@interface NSString ++ (id)alloc; +@end + diff --git a/clang/test/PCH/Inputs/typo.hpp b/clang/test/PCH/Inputs/typo.hpp new file mode 100644 index 0000000..c811595 --- /dev/null +++ b/clang/test/PCH/Inputs/typo.hpp @@ -0,0 +1,8 @@ +namespace boost { + template class function {}; + + namespace graph { + template class adjacency_list { }; + }; +} + diff --git a/clang/test/PCH/Inputs/va_arg.h b/clang/test/PCH/Inputs/va_arg.h new file mode 100644 index 0000000..1244e9f --- /dev/null +++ b/clang/test/PCH/Inputs/va_arg.h @@ -0,0 +1,2 @@ +#include + diff --git a/clang/test/PCH/Inputs/working-directory-1.h b/clang/test/PCH/Inputs/working-directory-1.h new file mode 100644 index 0000000..e42eda4 --- /dev/null +++ b/clang/test/PCH/Inputs/working-directory-1.h @@ -0,0 +1,5 @@ +template struct A { + A() { + int a; + } +}; diff --git a/clang/test/PCH/arc.m b/clang/test/PCH/arc.m new file mode 100644 index 0000000..64b390c --- /dev/null +++ b/clang/test/PCH/arc.m @@ -0,0 +1,17 @@ +// Test this without pch. +// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin11 -fobjc-arc -include %S/Inputs/arc.h -fsyntax-only -emit-llvm-only %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -fblocks -triple x86_64-apple-darwin11 -fobjc-arc -x objective-c-header -o %t %S/Inputs/arc.h +// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin11 -fobjc-arc -include-pch %t -fsyntax-only -emit-llvm-only %s + +// Test error when pch's -fobjc-arc state is different. +// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin11 -include-pch %t -fsyntax-only -emit-llvm-only %s 2>&1 | FileCheck -check-prefix=ERR1 %s +// RUN: %clang_cc1 -emit-pch -fblocks -triple x86_64-apple-darwin11 -x objective-c-header -o %t %S/Inputs/arc.h +// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin11 -fobjc-arc -include-pch %t -fsyntax-only -emit-llvm-only %s 2>&1 | FileCheck -check-prefix=ERR2 %s + +array0 a0; +array1 a1; + +// CHECK-ERR1: Objective-C automated reference counting was enabled in PCH file but is currently disabled +// CHECK-ERR2: Objective-C automated reference counting was disabled in PCH file but is currently enabled diff --git a/clang/test/PCH/asm.c b/clang/test/PCH/asm.c new file mode 100644 index 0000000..99bc14d --- /dev/null +++ b/clang/test/PCH/asm.c @@ -0,0 +1,11 @@ +// Test this without pch. +// RUN: %clang_cc1 -triple i386-unknown-unknown -include %S/asm.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-pch -o %t %S/asm.h +// RUN: %clang_cc1 -triple i386-unknown-unknown -include-pch %t -fsyntax-only -verify %s + + +void call_f(void) { f(); } + +void call_clobbers(void) { clobbers(); } diff --git a/clang/test/PCH/asm.h b/clang/test/PCH/asm.h new file mode 100644 index 0000000..a568058 --- /dev/null +++ b/clang/test/PCH/asm.h @@ -0,0 +1,14 @@ +// Header for the PCH test asm.c + +void f() { + int i; + + asm ("foo\n" : : "a" (i + 2)); + asm ("foo\n" : [symbolic_name] "=a" (i) : "[symbolic_name]" (i)); +} + +void clobbers() { + asm ("nop" : : : "ax", "#ax", "%ax"); + asm ("nop" : : : "eax", "rax", "ah", "al"); + asm ("nop" : : : "0", "%0", "#0"); +} diff --git a/clang/test/PCH/attrs-PR8406.c b/clang/test/PCH/attrs-PR8406.c new file mode 100644 index 0000000..85225f5 --- /dev/null +++ b/clang/test/PCH/attrs-PR8406.c @@ -0,0 +1,23 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %s -emit-llvm -o - %s | FileCheck %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t %s +// RUN: %clang_cc1 -include-pch %t -emit-llvm -o - %s | FileCheck %s + +#ifndef HEADER +#define HEADER + +struct Bar +{ + // CHECK: align 512 + int buffer[123] __attribute__((__aligned__(512))); +}; + +#else + +void foo() { + struct Bar bar; +} + +#endif diff --git a/clang/test/PCH/attrs.c b/clang/test/PCH/attrs.c new file mode 100644 index 0000000..2f868ac --- /dev/null +++ b/clang/test/PCH/attrs.c @@ -0,0 +1,17 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %s -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t %s +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +#ifndef HEADER +#define HEADER + +int f(int) __attribute__((visibility("default"), overloadable)); // expected-note{{previous overload}} + +#else + +double f(double); // expected-error{{overloadable}} + +#endif diff --git a/clang/test/PCH/blocks.c b/clang/test/PCH/blocks.c new file mode 100644 index 0000000..e749886 --- /dev/null +++ b/clang/test/PCH/blocks.c @@ -0,0 +1,12 @@ +// Test this without pch. +// RUN: %clang_cc1 -fblocks -include %S/blocks.h -fsyntax-only -emit-llvm -o - %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -fblocks -o %t %S/blocks.h +// RUN: %clang_cc1 -fblocks -include-pch %t -fsyntax-only -emit-llvm -o - %s + +int do_add(int x, int y) { return add(x, y); } + +int do_scaled_add(int a, int b, int s) { + return scaled_add(a, b, s); +} diff --git a/clang/test/PCH/blocks.h b/clang/test/PCH/blocks.h new file mode 100644 index 0000000..af7bb6f --- /dev/null +++ b/clang/test/PCH/blocks.h @@ -0,0 +1,14 @@ +// Header for PCH test blocks.c + +int call_block(int (^bl)(int x, int y), int a, int b) { + return bl(a, b); +} + +int add(int a, int b) { + return call_block(^(int x, int y) { return x + y; }, a, b); +} + +int scaled_add(int a, int b, int s) { + __block int scale = s; + return call_block(^(int x, int y) { return x*scale + y; }, a, b); +} diff --git a/clang/test/PCH/builtins.c b/clang/test/PCH/builtins.c new file mode 100644 index 0000000..eed2224 --- /dev/null +++ b/clang/test/PCH/builtins.c @@ -0,0 +1,10 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/builtins.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t %S/builtins.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +void hello() { + printf("Hello, World!"); +} diff --git a/clang/test/PCH/builtins.h b/clang/test/PCH/builtins.h new file mode 100644 index 0000000..56e4a53 --- /dev/null +++ b/clang/test/PCH/builtins.h @@ -0,0 +1,2 @@ +// Header for PCH test builtins.c +int printf(char const *, ...); diff --git a/clang/test/PCH/chain-categories.m b/clang/test/PCH/chain-categories.m new file mode 100644 index 0000000..1b91c73 --- /dev/null +++ b/clang/test/PCH/chain-categories.m @@ -0,0 +1,51 @@ +// Without PCH +// RUN: %clang_cc1 -fsyntax-only -verify -include %s -include %s %s + +// With PCH +// RUN: %clang_cc1 -fsyntax-only -verify %s -chain-include %s -chain-include %s + +#ifndef HEADER1 +#define HEADER1 +//===----------------------------------------------------------------------===// +// Primary header + +@interface NSObject +- (id)init; +- (void)finalize; +@end + +//===----------------------------------------------------------------------===// +#elif !defined(HEADER2) +#define HEADER2 +#if !defined(HEADER1) +#error Header inclusion order messed up +#endif + +//===----------------------------------------------------------------------===// +// Dependent header + +@interface MyClass : NSObject ++(void)meth; +@end + +@interface NSObject(ObjExt) +-(void)extMeth; +@end + +//===----------------------------------------------------------------------===// +#else +//===----------------------------------------------------------------------===// + +@implementation MyClass ++(void)meth {} +-(void)finalize { + [super finalize]; +} +@end + +void test(NSObject *o) { + [o extMeth]; +} + +//===----------------------------------------------------------------------===// +#endif diff --git a/clang/test/PCH/chain-categories2.m b/clang/test/PCH/chain-categories2.m new file mode 100644 index 0000000..f230bf9 --- /dev/null +++ b/clang/test/PCH/chain-categories2.m @@ -0,0 +1,57 @@ +// Test that infinite loop in rdar://10418538 was fixed. + +// Without PCH +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class -include %s -include %s %s + +// With PCH +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s -chain-include %s -chain-include %s + +#ifndef HEADER1 +#define HEADER1 +//===----------------------------------------------------------------------===// +// Primary header + +@class I; + +@interface I2 +@property (readonly) id prop1; +@end + +//===----------------------------------------------------------------------===// +#elif !defined(HEADER2) +#define HEADER2 +#if !defined(HEADER1) +#error Header inclusion order messed up +#endif + +//===----------------------------------------------------------------------===// +// Dependent header + +@interface I +@end + +@interface I(Cat1) +@end + +@interface I(Cat2) +@end + +@interface I2() +@property (readwrite,assign) id prop1; +@property (copy) id prop2; +@end + +//===----------------------------------------------------------------------===// +#else +//===----------------------------------------------------------------------===// + +void f(I* i) { + [i meth]; // expected-warning {{not found}} +} + +@implementation I2 +@synthesize prop1, prop2; +@end + +//===----------------------------------------------------------------------===// +#endif diff --git a/clang/test/PCH/chain-class-extension.m b/clang/test/PCH/chain-class-extension.m new file mode 100644 index 0000000..c99d6d4 --- /dev/null +++ b/clang/test/PCH/chain-class-extension.m @@ -0,0 +1,42 @@ +// Without PCH +// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin10 -fobjc-arc %s -include %s -include %s + +// With PCH +// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin10 -fobjc-arc %s -chain-include %s -chain-include %s + +#ifndef HEADER1 +#define HEADER1 +//===----------------------------------------------------------------------===// +// Primary header + +@interface I ++(void)meth; +@end + +//===----------------------------------------------------------------------===// +#elif !defined(HEADER2) +#define HEADER2 +#if !defined(HEADER1) +#error Header inclusion order messed up +#endif + +//===----------------------------------------------------------------------===// +// Dependent header + +@interface I() +@property (assign) id prop; ++(void)meth2; +@end + +//===----------------------------------------------------------------------===// +#else +//===----------------------------------------------------------------------===// + +void foo(I *i) { + [I meth]; + [I meth2]; + i.prop = 0; +} + +//===----------------------------------------------------------------------===// +#endif diff --git a/clang/test/PCH/chain-conversion-lookup.cpp b/clang/test/PCH/chain-conversion-lookup.cpp new file mode 100644 index 0000000..db9d8fc --- /dev/null +++ b/clang/test/PCH/chain-conversion-lookup.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - -chain-include %s -chain-include %s + +#if !defined(PASS1) +#define PASS1 +struct X { + operator int*(); +}; + +struct Z { + operator int*(); +}; +#elif !defined(PASS2) +#define PASS2 +struct Y { + operator int *(); +}; +#else +int main() { + X x; + int *ip = x.operator int*(); + Y y; + int *ip2 = y.operator int*(); + Z z; + int *ip3 = z.operator int*(); +} +#endif diff --git a/clang/test/PCH/chain-cxx.cpp b/clang/test/PCH/chain-cxx.cpp new file mode 100644 index 0000000..0d50e61 --- /dev/null +++ b/clang/test/PCH/chain-cxx.cpp @@ -0,0 +1,142 @@ +// Test C++ chained PCH functionality + +// Without PCH +// RUN: %clang_cc1 -fsyntax-only -verify -include %s -include %s %s + +// With PCH +// RUN: %clang_cc1 -fsyntax-only -verify %s -chain-include %s -chain-include %s + +#ifndef HEADER1 +#define HEADER1 +//===----------------------------------------------------------------------===// +// Primary header for C++ chained PCH test + +void f(); + +// Name not appearing in dependent +void pf(); + +namespace ns { + void g(); + + void pg(); +} + +template +struct S { typedef int G; }; + +// Partially specialize +template +struct S { typedef int H; }; + +template struct TS2; +typedef TS2 TS2int; + +template struct TestBaseSpecifiers { }; +template struct TestBaseSpecifiers2 : TestBaseSpecifiers { }; + +template +struct TS3 { + static const int value = 0; + static const int value2; +}; +template +const int TS3::value; +template +const int TS3::value2 = 1; +// Instantiate struct, but not value. +struct instantiate : TS3 {}; + +// Typedef +typedef int Integer; + +//===----------------------------------------------------------------------===// +#elif not defined(HEADER2) +#define HEADER2 +#if !defined(HEADER1) +#error Header inclusion order messed up +#endif + +//===----------------------------------------------------------------------===// +// Dependent header for C++ chained PCH test + +// Overload function from primary +void f(int); + +// Add function with different name +void f2(); + +// Reopen namespace +namespace ns { + // Overload function from primary + void g(int); + + // Add different name + void g2(); +} + +// Specialize template from primary +template <> +struct S { typedef int I; }; + +// Partially specialize +template +struct S { typedef int J; }; + +// Specialize previous partial specialization +template <> +struct S { typedef int K; }; + +// Specialize the partial specialization from this file +template <> +struct S { typedef int L; }; + +template struct TS2 { }; + +struct TestBaseSpecifiers3 { }; +struct TestBaseSpecifiers4 : TestBaseSpecifiers3 { }; + +struct A { }; +struct B : A { }; + +// Instantiate TS3's members. +static const int ts3m1 = TS3::value; +extern int arr[TS3::value2]; + +// Redefinition of typedef +typedef int Integer; + +//===----------------------------------------------------------------------===// +#else +//===----------------------------------------------------------------------===// + +void test() { + f(); + f(1); + pf(); + f2(); + + ns::g(); + ns::g(1); + ns::pg(); + ns::g2(); + + typedef S::G T1; + typedef S::H T2; + typedef S::I T3; + typedef S::J T4; + typedef S::K T5; + typedef S::L T6; + + TS2int ts2; + + B b; + Integer i = 17; +} + +// Should have remembered that there is a definition. +static const int ts3m2 = TS3::value; +int arr[TS3::value2]; + +//===----------------------------------------------------------------------===// +#endif diff --git a/clang/test/PCH/chain-decls.c b/clang/test/PCH/chain-decls.c new file mode 100644 index 0000000..f5724c4 --- /dev/null +++ b/clang/test/PCH/chain-decls.c @@ -0,0 +1,27 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/Inputs/chain-decls1.h -include %S/Inputs/chain-decls2.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t1 %S/Inputs/chain-decls1.h +// RUN: %clang_cc1 -emit-pch -o %t2 %S/Inputs/chain-decls2.h -include-pch %t1 +// RUN: %clang_cc1 -include-pch %t2 -fsyntax-only -verify %s +// RUN: %clang_cc1 -ast-print -include-pch %t2 %s | FileCheck %s + +// CHECK: void f(); +// CHECK: void g(); + +int h() { + f(); + g(); + + struct one x; + one(); + struct two y; + two(); + struct three z; + + many(0); + struct many m; + + noret(); +} diff --git a/clang/test/PCH/chain-empty-initial-namespace.cpp b/clang/test/PCH/chain-empty-initial-namespace.cpp new file mode 100644 index 0000000..bf15caa --- /dev/null +++ b/clang/test/PCH/chain-empty-initial-namespace.cpp @@ -0,0 +1,24 @@ +// no PCH +// RUN: %clang_cc1 -include %s -include %s -fsyntax-only %s +// full PCH +// RUN: %clang_cc1 -chain-include %s -chain-include %s -fsyntax-only %s +#if !defined(PASS1) +#define PASS1 + +namespace foo {} // no external storage + +#elif !defined(PASS2) +#define PASS2 + +namespace foo { + void bar(); +} + +#else +// PASS3 + +void test() { + foo::bar(); // no-error +} + +#endif diff --git a/clang/test/PCH/chain-ext_vector.c b/clang/test/PCH/chain-ext_vector.c new file mode 100644 index 0000000..d99a732 --- /dev/null +++ b/clang/test/PCH/chain-ext_vector.c @@ -0,0 +1,11 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/Inputs/chain-ext_vector1.h -include %S/Inputs/chain-ext_vector2.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t1 %S/Inputs/chain-ext_vector1.h +// RUN: %clang_cc1 -emit-pch -o %t2 %S/Inputs/chain-ext_vector2.h -include-pch %t1 +// RUN: %clang_cc1 -include-pch %t2 -fsyntax-only -verify %s + +int test(float4 f4) { + return f4.xy; // expected-error{{float2}} +} diff --git a/clang/test/PCH/chain-external-defs.c b/clang/test/PCH/chain-external-defs.c new file mode 100644 index 0000000..7422294 --- /dev/null +++ b/clang/test/PCH/chain-external-defs.c @@ -0,0 +1,54 @@ +// Test with pch. +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -emit-pch -o %t1.pch %S/Inputs/chain-external-defs1.h +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -emit-pch -o %t2.pch %S/Inputs/chain-external-defs2.h -include-pch %t1.pch +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -include-pch %t2.pch -emit-llvm -o %t %s +// RUN: echo FINI >> %t +// RUN: FileCheck -input-file=%t -check-prefix=Z %s +// RUN: FileCheck -input-file=%t -check-prefix=XA %s +// RUN: FileCheck -input-file=%t -check-prefix=YA %s +// RUN: FileCheck -input-file=%t -check-prefix=XB %s +// RUN: FileCheck -input-file=%t -check-prefix=YB %s +// RUN: FileCheck -input-file=%t -check-prefix=AA %s +// RUN: FileCheck -input-file=%t -check-prefix=AB %s +// RUN: FileCheck -input-file=%t -check-prefix=AC %s +// RUN: FileCheck -input-file=%t -check-prefix=S %s + +// Z-NOT: @z + +// XA: @x = common global i32 0 +// XA-NOT: @x = common global i32 0 + +// YA: @y = common global i32 0 +// YA-NOT: @y = common global i32 0 + +// XB: @x2 = global i32 19 +// XB-NOT: @x2 = global i32 19 +int x2 = 19; +// YB: @y2 = global i32 18 +// YB-NOT: @y2 = global i32 18 +int y2 = 18; + +// AA: @incomplete_array = common global [1 x i32] +// AA-NOT: @incomplete_array = common global [1 x i32] +// AB: @incomplete_array2 = common global [17 x i32] +// AB-NOT: @incomplete_array2 = common global [17 x i32] +int incomplete_array2[17]; +// AC: @incomplete_array3 = common global [1 x i32] +// AC-NOT: @incomplete_array3 = common global [1 x i32] +int incomplete_array3[]; + +// S: @s = common global %struct.S +// S-NOT: @s = common global %struct.S +struct S { + int x, y; +}; + +// Z: FINI +// XA: FINI +// YA: FINI +// XB: FINI +// YB: FINI +// AA: FINI +// AB: FINI +// AC: FINI +// S: FINI diff --git a/clang/test/PCH/chain-friend-instantiation.cpp b/clang/test/PCH/chain-friend-instantiation.cpp new file mode 100644 index 0000000..294d979 --- /dev/null +++ b/clang/test/PCH/chain-friend-instantiation.cpp @@ -0,0 +1,61 @@ +// RUN: %clang_cc1 %s -ast-print -o - -chain-include %s -chain-include %s + +#if !defined(PASS1) +#define PASS1 + +template class TClass; + +namespace NS { + template TClass problematic(X * ptr, const TClass &src); + + template + class TBaseClass + { + protected: + template friend TClass problematic(X * ptr, const TClass &src); + }; +} + +template +class TClass: public NS::TBaseClass +{ +public: + inline TClass() { } +}; + + +namespace NS { + template + TClass problematic(X *ptr, const TClass &src); +} + +template +TClass unconst(const TClass &src); + +#elif !defined(PASS2) +#define PASS2 + +namespace std { +class s {}; +} + + +typedef TClass TStr; + +struct crash { + TStr str; + + crash(const TClass p) + { + unconst(p); + } +}; + +#else + +void f() { + const TStr p; + crash c(p); +} + +#endif diff --git a/clang/test/PCH/chain-implicit-definition.cpp b/clang/test/PCH/chain-implicit-definition.cpp new file mode 100644 index 0000000..245e8f9 --- /dev/null +++ b/clang/test/PCH/chain-implicit-definition.cpp @@ -0,0 +1,39 @@ +// no PCH +// RUN: %clang_cc1 -emit-llvm-only -include %s -include %s %s +// with PCH +// RUN: %clang_cc1 -emit-llvm-only -chain-include %s -chain-include %s %s +#if !defined(PASS1) +#define PASS1 + +// A base with a virtual dtor. +struct A { + virtual ~A(); +}; + +// A derived class with an implicit virtual dtor. +struct B : A { + // Key function to suppress vtable definition. + virtual void virt(); +}; + +#elif !defined(PASS2) +#define PASS2 + +// Further derived class that requires ~B(). +// Causes definition of ~B(), but it was lost when saving PCH. +struct C : B { + C(); + ~C() {} +}; + +#else + +void foo() { + // Variable that requires ~C(). + C c; +} + +// VTable placement would again cause definition of ~B(), hiding the bug, +// if not for B::virt(), which suppresses the placement. + +#endif diff --git a/clang/test/PCH/chain-late-anonymous-namespace.cpp b/clang/test/PCH/chain-late-anonymous-namespace.cpp new file mode 100644 index 0000000..87205c6 --- /dev/null +++ b/clang/test/PCH/chain-late-anonymous-namespace.cpp @@ -0,0 +1,61 @@ +// no PCH +// RUN: %clang_cc1 -include %s -include %s -fsyntax-only %s +// with PCH +// RUN: %clang_cc1 -chain-include %s -chain-include %s -fsyntax-only %s +#if !defined(PASS1) +#define PASS1 + +namespace ns {} +namespace os {} + +#elif !defined(PASS2) +#define PASS2 + +namespace ns { + namespace { + extern int x; + } +} + +namespace { + extern int y; +} +namespace { +} + +namespace os { + extern "C" { + namespace { + extern int z; + } + } +} + +#else + +namespace ns { + namespace { + int x; + } + void test() { + (void)x; + } +} + +namespace { + int y; +} +void test() { + (void)y; +} + +namespace os { + namespace { + int z; + } + void test() { + (void)z; + } +} + +#endif diff --git a/clang/test/PCH/chain-macro-override.c b/clang/test/PCH/chain-macro-override.c new file mode 100644 index 0000000..2713e70 --- /dev/null +++ b/clang/test/PCH/chain-macro-override.c @@ -0,0 +1,14 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/Inputs/chain-macro-override1.h -include %S/Inputs/chain-macro-override2.h -fsyntax-only -verify -detailed-preprocessing-record %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t1 %S/Inputs/chain-macro-override1.h -detailed-preprocessing-record +// RUN: %clang_cc1 -emit-pch -o %t2 %S/Inputs/chain-macro-override2.h -include-pch %t1 -detailed-preprocessing-record +// RUN: %clang_cc1 -include-pch %t2 -fsyntax-only -verify %s + +int foo() { + f(); + g(); + h(); + return x; +} diff --git a/clang/test/PCH/chain-macro.c b/clang/test/PCH/chain-macro.c new file mode 100644 index 0000000..18356f7 --- /dev/null +++ b/clang/test/PCH/chain-macro.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -emit-pch -o %t1 -detailed-preprocessing-record %S/Inputs/chain-macro1.h +// RUN: %clang_cc1 -emit-pch -o %t2 -detailed-preprocessing-record %S/Inputs/chain-macro2.h -include-pch %t1 +// RUN: %clang_cc1 -fsyntax-only -verify -include-pch %t2 %s +// RUN: %clang_cc1 -ast-print -include-pch %t2 %s | FileCheck %s + +// CHECK: void f(); +FOOBAR +// CHECK: void g(); +BARFOO diff --git a/clang/test/PCH/chain-pending-instantiations.cpp b/clang/test/PCH/chain-pending-instantiations.cpp new file mode 100644 index 0000000..e49abcd --- /dev/null +++ b/clang/test/PCH/chain-pending-instantiations.cpp @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - -chain-include %s -chain-include %s | FileCheck %s +// CHECK: define linkonce_odr %{{[^ ]+}} @_ZN1AI1BE3getEv +#if !defined(PASS1) +#define PASS1 + +template +struct A { + Derived* get() { return 0; } +}; + +struct B : A { +}; + +#elif !defined(PASS2) +#define PASS2 + +struct C : B { +}; + +struct D : C { + void run() { + (void)get(); + } +}; + +#else + +int main() { + D d; + d.run(); +} + +#endif diff --git a/clang/test/PCH/chain-predecl.h b/clang/test/PCH/chain-predecl.h new file mode 100644 index 0000000..bd332ff --- /dev/null +++ b/clang/test/PCH/chain-predecl.h @@ -0,0 +1,3 @@ +// First header for chain-predecl.m +@class Foo; +@protocol Pro; diff --git a/clang/test/PCH/chain-predecl.m b/clang/test/PCH/chain-predecl.m new file mode 100644 index 0000000..6723b6f --- /dev/null +++ b/clang/test/PCH/chain-predecl.m @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -emit-pch -o %t1 %S/chain-predecl.h -x objective-c +// RUN: %clang_cc1 -emit-pch -o %t2 %s -x objective-c -include-pch %t1 + +// Test predeclarations across chained PCH. +@interface Foo +-(void)bar; +@end +@interface Boom +-(void)bar; +@end +@protocol Pro +-(void)baz; +@end +@protocol Kaboom +-(void)baz; +@end diff --git a/clang/test/PCH/chain-remap-types.m b/clang/test/PCH/chain-remap-types.m new file mode 100644 index 0000000..585da44 --- /dev/null +++ b/clang/test/PCH/chain-remap-types.m @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-pch -x objective-c-header -o %t1 %S/Inputs/chain-remap-types1.h +// RUN: %clang_cc1 -emit-pch -x objective-c-header -o %t2 %S/Inputs/chain-remap-types2.h -include-pch %t1 +// RUN: %clang_cc1 -include-pch %t2 -fsyntax-only -verify %s +// RUN: %clang_cc1 -ast-print -include-pch %t2 %s | FileCheck %s + +// CHECK: @class X; +// CHECK: struct Y +// CHECK: @property ( assign,readwrite,atomic ) X * prop +// CHECK: void h(X *); +// CHECK: @interface X(Blah) +// CHECK: void g(X *); + diff --git a/clang/test/PCH/chain-selectors.m b/clang/test/PCH/chain-selectors.m new file mode 100644 index 0000000..7eae094 --- /dev/null +++ b/clang/test/PCH/chain-selectors.m @@ -0,0 +1,40 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s -Wselector -include %S/Inputs/chain-selectors1.h -include %S/Inputs/chain-selectors2.h + +// RUN: %clang_cc1 -x objective-c -Wno-objc-root-class -emit-pch -o %t1 %S/Inputs/chain-selectors1.h +// RUN: %clang_cc1 -x objective-c -Wno-objc-root-class -emit-pch -o %t2 %S/Inputs/chain-selectors2.h -include-pch %t1 +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s -Wselector -include-pch %t2 + +@implementation X +-(void)f {} +-(void)f2 {} +-(void)g: (int)p {} +-(void)h: (int)p1 foo: (int)p2 {} +@end + +void bar() { + id a = 0; + [a nothing]; // expected-warning {{method '-nothing' not found}} + [a f]; + // FIXME: Can't verify notes in headers + //[a f2]; + + (void)@selector(x); // expected-warning {{unimplemented selector}} + (void)@selector(y); // expected-warning {{unimplemented selector}} + (void)@selector(e); // expected-warning {{unimplemented selector}} +} + +@implementation X (Blah) +- (void)test_Blah { + [self blah_method]; +} + +- (void)blah_method { } +@end + +@implementation X (Blarg) +- (void)test_Blarg { + [self blarg_method]; +} + +- (void)blarg_method { } +@end diff --git a/clang/test/PCH/chain-trivial.c b/clang/test/PCH/chain-trivial.c new file mode 100644 index 0000000..85b1eab --- /dev/null +++ b/clang/test/PCH/chain-trivial.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-pch -o %t1 %S/Inputs/chain-trivial1.h +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-pch -o %t2 -include-pch %t1 %S/Inputs/chain-trivial2.h +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-print -include-pch %t2 %s | FileCheck %s +// CHECK: struct __va_list_tag { diff --git a/clang/test/PCH/changed-files.c b/clang/test/PCH/changed-files.c new file mode 100644 index 0000000..d1b603b --- /dev/null +++ b/clang/test/PCH/changed-files.c @@ -0,0 +1,28 @@ +const char *s0 = m0; +int s1 = m1; +const char *s2 = m0; + +// FIXME: This test fails inexplicably on Windows in a manner that makes it +// look like standard error isn't getting flushed properly. + +// RUN: false +// XFAIL: * + +// RUN: echo '#define m0 ""' > %t.h +// RUN: %clang_cc1 -emit-pch -o %t.h.pch %t.h +// RUN: echo '' > %t.h +// RUN: not %clang_cc1 -include-pch %t.h.pch %s 2> %t.stderr +// RUN: grep "modified" %t.stderr + +// RUN: echo '#define m0 000' > %t.h +// RUN: %clang_cc1 -emit-pch -o %t.h.pch %t.h +// RUN: echo '' > %t.h +// RUN: not %clang_cc1 -include-pch %t.h.pch %s 2> %t.stderr +// RUN: grep "modified" %t.stderr + +// RUN: echo '#define m0 000' > %t.h +// RUN: echo "#define m1 'abcd'" >> %t.h +// RUN: %clang_cc1 -emit-pch -o %t.h.pch %t.h +// RUN: echo '' > %t.h +// RUN: not %clang_cc1 -include-pch %t.h.pch %s 2> %t.stderr +// RUN: grep "modified" %t.stderr diff --git a/clang/test/PCH/check-deserializations.cpp b/clang/test/PCH/check-deserializations.cpp new file mode 100644 index 0000000..9f73c95 --- /dev/null +++ b/clang/test/PCH/check-deserializations.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -emit-pch -o %t %s +// RUN: %clang_cc1 -error-on-deserialized-decl S1_method -include-pch %t -emit-llvm-only %s + +#ifndef HEADER +#define HEADER +// Header. + +struct S1 { + void S1_method(); // This should not be deserialized. + virtual void S1_keyfunc(); +}; + + +#else +// Using the header. + +void test(S1*) { +} + +#endif diff --git a/clang/test/PCH/cmdline-include.c b/clang/test/PCH/cmdline-include.c new file mode 100644 index 0000000..ad45192 --- /dev/null +++ b/clang/test/PCH/cmdline-include.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -include %S/cmdline-include1.h -x c-header %S/cmdline-include2.h -emit-pch -o %t +// RUN: %clang_cc1 %s -include-pch %t -fsyntax-only -verify +// RUN: %clang_cc1 -x c-header %S/cmdline-include1.h -emit-pch -o %t +// RUN: %clang_cc1 %s -include-pch %t -include %S/cmdline-include2.h -fsyntax-only -verify + +int g = x1 + x2; diff --git a/clang/test/PCH/cmdline-include1.h b/clang/test/PCH/cmdline-include1.h new file mode 100644 index 0000000..4f7c661 --- /dev/null +++ b/clang/test/PCH/cmdline-include1.h @@ -0,0 +1 @@ +enum { x1 }; diff --git a/clang/test/PCH/cmdline-include2.h b/clang/test/PCH/cmdline-include2.h new file mode 100644 index 0000000..cf8e37b --- /dev/null +++ b/clang/test/PCH/cmdline-include2.h @@ -0,0 +1 @@ +enum { x2 }; diff --git a/clang/test/PCH/cocoa.m b/clang/test/PCH/cocoa.m new file mode 100644 index 0000000..0159b32 --- /dev/null +++ b/clang/test/PCH/cocoa.m @@ -0,0 +1,7 @@ +// RUN: %clang -arch x86_64 -x objective-c-header %s -o %t.h.pch +// RUN: touch %t.empty.m +// RUN: %clang -arch x86_64 -fsyntax-only %t.empty.m -include %t.h -Xclang -ast-dump 2>&1 > /dev/null +#ifdef __APPLE__ +#include +#endif + diff --git a/clang/test/PCH/cuda-kernel-call.cu b/clang/test/PCH/cuda-kernel-call.cu new file mode 100644 index 0000000..ef12c59 --- /dev/null +++ b/clang/test/PCH/cuda-kernel-call.cu @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -emit-pch -o %t %s +// RUN: %clang_cc1 -include-pch %t -fsyntax-only %s + +#ifndef HEADER +#define HEADER +// Header. + +#include "../SemaCUDA/cuda.h" + +void kcall(void (*kp)()) { + kp<<<1, 1>>>(); +} + +__global__ void kern() { +} + +#else +// Using the header. + +void test() { + kcall(kern); + kern<<<1, 1>>>(); +} + +#endif diff --git a/clang/test/PCH/cxx-alias-decl.cpp b/clang/test/PCH/cxx-alias-decl.cpp new file mode 100644 index 0000000..872658f --- /dev/null +++ b/clang/test/PCH/cxx-alias-decl.cpp @@ -0,0 +1,20 @@ +// Test this without pch. +// RUN: %clang_cc1 -x c++ -std=c++11 -include %S/cxx-alias-decl.h -fsyntax-only -emit-llvm -o - %s + +// Test with pch. +// RUN: %clang_cc1 -x c++ -std=c++11 -emit-pch -o %t %S/cxx-alias-decl.h +// RUN: %clang_cc1 -x c++ -std=c++11 -include-pch %t -fsyntax-only -emit-llvm -o - %s + +template struct T; +C::A a; + +using T1 = decltype(a); +using T1 = D; + +using T2 = B; +using T2 = S; + +using A = int; +template using B = S; +template using C = T; +template using D = typename T::template A; diff --git a/clang/test/PCH/cxx-alias-decl.h b/clang/test/PCH/cxx-alias-decl.h new file mode 100644 index 0000000..26bc716 --- /dev/null +++ b/clang/test/PCH/cxx-alias-decl.h @@ -0,0 +1,11 @@ +// Header for PCH test cxx-alias-decl.cpp + +struct S {}; +template struct T { + template using A = T; +}; + +using A = int; +template using B = S; +template using C = T; +template using D = typename T::template A; diff --git a/clang/test/PCH/cxx-chain-function-template.cpp b/clang/test/PCH/cxx-chain-function-template.cpp new file mode 100644 index 0000000..494e190 --- /dev/null +++ b/clang/test/PCH/cxx-chain-function-template.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -chain-include %s -chain-include %s -fsyntax-only %s +// Just don't crash. +#if !defined(RUN1) +#define RUN1 + +struct CXXRecordDecl { CXXRecordDecl(int); }; + +template +T cast(U u) { + return reinterpret_cast(u); +} + +void test1() { + cast(1); +} + +#elif !defined(RUN2) +#define RUN2 + +template +void test2(T) { + cast(1.0f); +} + +#else + +void test3() { + cast(1.0f); + test2(1); +} + +#endif diff --git a/clang/test/PCH/cxx-constexpr.cpp b/clang/test/PCH/cxx-constexpr.cpp new file mode 100644 index 0000000..8fe48f7 --- /dev/null +++ b/clang/test/PCH/cxx-constexpr.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -pedantic-errors -std=c++98 -emit-pch %s -o %t +// RUN: %clang_cc1 -pedantic-errors -std=c++98 -include-pch %t -verify %s + +// RUN: %clang_cc1 -pedantic-errors -std=c++11 -emit-pch %s -o %t-cxx11 +// RUN: %clang_cc1 -pedantic-errors -std=c++11 -include-pch %t-cxx11 -verify %s + +#ifndef HEADER_INCLUDED + +#define HEADER_INCLUDED +extern const int a; +const int b = a; + +#else + +const int a = 5; +typedef int T[b]; // expected-error {{variable length array}} expected-error {{must be an integer constant expression}} +typedef int T[5]; + +#endif diff --git a/clang/test/PCH/cxx-exprs.cpp b/clang/test/PCH/cxx-exprs.cpp new file mode 100644 index 0000000..9cd3194 --- /dev/null +++ b/clang/test/PCH/cxx-exprs.cpp @@ -0,0 +1,27 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %s -verify -std=c++11 %s + +// Test with pch. +// RUN: %clang_cc1 -std=c++11 -emit-pch -o %t %s +// RUN: %clang_cc1 -include-pch %t -verify -std=c++11 %s + +#ifndef HEADER +#define HEADER + +template +class New { + New(const New&); + +public: + New *clone() { + return new New(*this); + } +}; + +#else + +New *clone_new(New *n) { + return n->clone(); +} + +#endif diff --git a/clang/test/PCH/cxx-for-range.cpp b/clang/test/PCH/cxx-for-range.cpp new file mode 100644 index 0000000..48310db --- /dev/null +++ b/clang/test/PCH/cxx-for-range.cpp @@ -0,0 +1,19 @@ +// Test this without pch. +// RUN: %clang_cc1 -x c++ -std=c++11 -include %S/cxx-for-range.h -fsyntax-only -emit-llvm -o - %s + +// Test with pch. +// RUN: %clang_cc1 -x c++ -std=c++11 -emit-pch -o %t %S/cxx-for-range.h +// RUN: %clang_cc1 -x c++ -std=c++11 -include-pch %t -fsyntax-only -emit-llvm -o - %s + +void h() { + f(); + + g(); + + char a[3] = { 0, 1, 2 }; + for (auto w : a) + for (auto x : S()) + for (auto y : T()) + for (auto z : U()) + ; +} diff --git a/clang/test/PCH/cxx-for-range.h b/clang/test/PCH/cxx-for-range.h new file mode 100644 index 0000000..f15c7e7 --- /dev/null +++ b/clang/test/PCH/cxx-for-range.h @@ -0,0 +1,35 @@ +// Header for PCH test cxx-for-range.cpp + +struct S { + int *begin(); + int *end(); +}; + +struct T { }; +char *begin(T); +char *end(T); + +struct U { }; +namespace std { + char *begin(U); + char *end(U); +} + +void f() { + char a[3] = { 0, 1, 2 }; + for (auto w : a) + for (auto x : S()) + for (auto y : T()) + for (auto z : U()) + ; +} + +template +void g() { + A a[3] = { 0, 1, 2 }; + for (auto &v : a) + for (auto x : S()) + for (auto y : T()) + for (auto z : U()) + ; +} diff --git a/clang/test/PCH/cxx-friends.cpp b/clang/test/PCH/cxx-friends.cpp new file mode 100644 index 0000000..a8d7558 --- /dev/null +++ b/clang/test/PCH/cxx-friends.cpp @@ -0,0 +1,13 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/cxx-friends.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-friends.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +class F { + void m() { + A* a; + a->x = 0; + } +}; diff --git a/clang/test/PCH/cxx-friends.h b/clang/test/PCH/cxx-friends.h new file mode 100644 index 0000000..2a33f15 --- /dev/null +++ b/clang/test/PCH/cxx-friends.h @@ -0,0 +1,6 @@ +// Header for PCH test cxx-friends.cpp + +class A { + int x; + friend class F; +}; diff --git a/clang/test/PCH/cxx-functions.cpp b/clang/test/PCH/cxx-functions.cpp new file mode 100644 index 0000000..74df01a --- /dev/null +++ b/clang/test/PCH/cxx-functions.cpp @@ -0,0 +1,10 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/cxx-functions.h -fsyntax-only -verify %s + +// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-functions.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + + +void test_foo() { + foo(); +} diff --git a/clang/test/PCH/cxx-functions.h b/clang/test/PCH/cxx-functions.h new file mode 100644 index 0000000..8aa4986 --- /dev/null +++ b/clang/test/PCH/cxx-functions.h @@ -0,0 +1 @@ +void foo() throw( int, short, char, float, double ); diff --git a/clang/test/PCH/cxx-implicit-moves.cpp b/clang/test/PCH/cxx-implicit-moves.cpp new file mode 100644 index 0000000..ccdc874 --- /dev/null +++ b/clang/test/PCH/cxx-implicit-moves.cpp @@ -0,0 +1,23 @@ +// Test with PCH +// RUN: %clang_cc1 -std=c++11 -x c++-header -emit-pch -o %t %s +// RUN: %clang_cc1 -std=c++11 -include-pch %t -verify %s + +// PR10847 +#ifndef HEADER +#define HEADER +struct NSSize { + double width; + double height; +}; +typedef struct NSSize NSSize; + +static inline NSSize NSMakeSize(double w, double h) { + NSSize s = { w, h }; + return s; +} +#else +float test(float v1, float v2) { + NSSize s = NSMakeSize(v1, v2); + return s.width; +} +#endif diff --git a/clang/test/PCH/cxx-member-init.cpp b/clang/test/PCH/cxx-member-init.cpp new file mode 100644 index 0000000..2820665 --- /dev/null +++ b/clang/test/PCH/cxx-member-init.cpp @@ -0,0 +1,22 @@ +// Test this without pch. +// RUN: %clang_cc1 -x c++ -std=c++11 -DHEADER -DSOURCE -fsyntax-only -emit-llvm -o - %s + +// Test with pch. +// RUN: %clang_cc1 -x c++ -std=c++11 -DHEADER -emit-pch -o %t %s +// RUN: %clang_cc1 -x c++ -std=c++11 -DHEADER -include-pch %t -fsyntax-only -emit-llvm -o - %s + +#ifdef HEADER +int n; +struct S { + int *p = &m; + int &m = n; + S *that = this; +}; +#endif + +#ifdef SOURCE +S s; +#elif HEADER +#undef HEADER +#define SOURCE +#endif diff --git a/clang/test/PCH/cxx-method.cpp b/clang/test/PCH/cxx-method.cpp new file mode 100644 index 0000000..6ec65b2 --- /dev/null +++ b/clang/test/PCH/cxx-method.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -x c++ -emit-pch %S/Inputs/cxx-method.h -o %t +// RUN: %clang_cc1 -include-pch %t -verify %s + +void S::m(int x) { } + +S::operator char *() { return 0; } + +S::operator const char *() { return 0; } diff --git a/clang/test/PCH/cxx-ms-function-specialization-class-scope.cpp b/clang/test/PCH/cxx-ms-function-specialization-class-scope.cpp new file mode 100644 index 0000000..1803a11 --- /dev/null +++ b/clang/test/PCH/cxx-ms-function-specialization-class-scope.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fms-extensions -triple i386-unknown-unknown -x c++-header -emit-pch -o %t %S/cxx-ms-function-specialization-class-scope.h +// RUN: %clang_cc1 -fms-extensions -triple i386-unknown-unknown -include-pch %t -fsyntax-only -verify %s + + +void test2() +{ + B b(3); + char* ptr; + b.f(ptr); + b.f(99); + b.f(100); +} + diff --git a/clang/test/PCH/cxx-ms-function-specialization-class-scope.h b/clang/test/PCH/cxx-ms-function-specialization-class-scope.h new file mode 100644 index 0000000..7668e73 --- /dev/null +++ b/clang/test/PCH/cxx-ms-function-specialization-class-scope.h @@ -0,0 +1,29 @@ + + + +template +class B { +public: + template + B(U p) { + } + template <> + B(int p) { // expected-warning{{explicit specialization of 'B' within class scope is a Microsoft extension}} + } + + template + void f(U p) { + T y = 9; + } + + + template <> + void f(int p) { // expected-warning{{explicit specialization of 'f' within class scope is a Microsoft extension}} + T a = 3; + } + + void f(int p) { + T a = 3; + } +}; + diff --git a/clang/test/PCH/cxx-namespaces.cpp b/clang/test/PCH/cxx-namespaces.cpp new file mode 100644 index 0000000..0fd3de7 --- /dev/null +++ b/clang/test/PCH/cxx-namespaces.cpp @@ -0,0 +1,10 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/cxx-namespaces.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-namespaces.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +void m() { + N::x = 0; +} diff --git a/clang/test/PCH/cxx-namespaces.h b/clang/test/PCH/cxx-namespaces.h new file mode 100644 index 0000000..f338953 --- /dev/null +++ b/clang/test/PCH/cxx-namespaces.h @@ -0,0 +1,7 @@ +// Header for PCH test cxx-namespaces.cpp + +namespace N { + namespace { + int x; + } +} diff --git a/clang/test/PCH/cxx-offsetof-base.cpp b/clang/test/PCH/cxx-offsetof-base.cpp new file mode 100644 index 0000000..18265de --- /dev/null +++ b/clang/test/PCH/cxx-offsetof-base.cpp @@ -0,0 +1,2 @@ +// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-offsetof-base.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only %s diff --git a/clang/test/PCH/cxx-offsetof-base.h b/clang/test/PCH/cxx-offsetof-base.h new file mode 100644 index 0000000..7c78101 --- /dev/null +++ b/clang/test/PCH/cxx-offsetof-base.h @@ -0,0 +1,5 @@ +// Header for PCH test cxx-offsetof-base.cpp + +struct Base { int x; }; +struct Derived : Base { int y; }; +int o = __builtin_offsetof(Derived, x); diff --git a/clang/test/PCH/cxx-reference.cpp b/clang/test/PCH/cxx-reference.cpp new file mode 100644 index 0000000..a1a44e6 --- /dev/null +++ b/clang/test/PCH/cxx-reference.cpp @@ -0,0 +1,6 @@ +// Test this without pch. +// RUN: %clang_cc1 -x c++ -std=c++11 -include %S/cxx-reference.h -fsyntax-only -emit-llvm -o - %s + +// Test with pch. +// RUN: %clang_cc1 -x c++ -std=c++11 -emit-pch -o %t %S/cxx-reference.h +// RUN: %clang_cc1 -x c++ -std=c++11 -include-pch %t -fsyntax-only -emit-llvm -o - %s diff --git a/clang/test/PCH/cxx-reference.h b/clang/test/PCH/cxx-reference.h new file mode 100644 index 0000000..b46a367 --- /dev/null +++ b/clang/test/PCH/cxx-reference.h @@ -0,0 +1,13 @@ +// Header for PCH test cxx-reference.cpp + +typedef char (&LR); +typedef char (&&RR); + +char c; + +char &lr = c; +char &&rr = 'c'; +LR &lrlr = c; +LR &&rrlr = c; +RR &lrrr = c; +RR &&rrrr = 'c'; diff --git a/clang/test/PCH/cxx-required-decls.cpp b/clang/test/PCH/cxx-required-decls.cpp new file mode 100644 index 0000000..8c4b11c --- /dev/null +++ b/clang/test/PCH/cxx-required-decls.cpp @@ -0,0 +1,10 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/cxx-required-decls.h %s -emit-llvm -o - | FileCheck %s + +// Test with pch. +// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-required-decls.h +// RUN: %clang_cc1 -include-pch %t %s -emit-llvm -o - | FileCheck %s + +// CHECK: @_ZL5globS = internal global %struct.S zeroinitializer +// CHECK: @_ZL3bar = internal global i32 0, align 4 +// CHECK: @glob_var = global i32 0 diff --git a/clang/test/PCH/cxx-required-decls.h b/clang/test/PCH/cxx-required-decls.h new file mode 100644 index 0000000..099d2da --- /dev/null +++ b/clang/test/PCH/cxx-required-decls.h @@ -0,0 +1,12 @@ +// Header for PCH test cxx-required-decls.cpp + +struct S { + S(); +}; + +static S globS; + +extern int ext_foo; +static int bar = ++ext_foo; + +int glob_var; diff --git a/clang/test/PCH/cxx-static_assert.cpp b/clang/test/PCH/cxx-static_assert.cpp new file mode 100644 index 0000000..ace12e0 --- /dev/null +++ b/clang/test/PCH/cxx-static_assert.cpp @@ -0,0 +1,20 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %s -verify -std=c++11 %s + +// Test with pch. +// RUN: %clang_cc1 -std=c++11 -emit-pch -o %t %s +// RUN: %clang_cc1 -include-pch %t -verify -std=c++11 %s + +#ifndef HEADER +#define HEADER + +template struct T { + static_assert(N == 2, "N is not 2!"); // expected-error {{static_assert failed "N is not 2!"}} +}; + +#else + +T<1> t1; // expected-note {{in instantiation of template class 'T<1>' requested here}} +T<2> t2; + +#endif diff --git a/clang/test/PCH/cxx-templates.cpp b/clang/test/PCH/cxx-templates.cpp new file mode 100644 index 0000000..7ce2477 --- /dev/null +++ b/clang/test/PCH/cxx-templates.cpp @@ -0,0 +1,70 @@ +// Test this without pch. +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -include %S/cxx-templates.h -verify %s -ast-dump -o - +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -include %S/cxx-templates.h %s -emit-llvm -o - | FileCheck %s + +// Test with pch. +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -x c++-header -emit-pch -o %t %S/cxx-templates.h +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -include-pch %t -verify %s -ast-dump -o - +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -include-pch %t %s -emit-llvm -o - | FileCheck %s + +// CHECK: define weak_odr void @_ZN2S4IiE1mEv +// CHECK: define linkonce_odr void @_ZN2S3IiE1mEv + +struct A { + typedef int type; + static void my_f(); + template + static T my_templf(T x) { return x; } +}; + +void test(const int (&a6)[17]) { + int x = templ_f(3); + + S::templ(); + S::partial(); + S::explicit_special(); + + Dep::Ty ty; + Dep a; + a.f(); + + S3 s3; + s3.m(); + + TS5 ts(0); + + S6::t2 b6 = a6; +} + +template struct S4; + +S7 s7_5; + +namespace ZeroLengthExplicitTemplateArgs { + template void f(X*); +} + +// This used to overwrite memory and crash. +namespace Test1 { + struct StringHasher { + template static inline unsigned createHash(const T*, unsigned) { + return 0; + } + }; + + struct CaseFoldingHash { + static inline char foldCase(char) { + return 0; + } + + static unsigned hash(const char* data, unsigned length) { + return StringHasher::createHash(data, length); + } + }; +} + +template< typename D > +Foo< D >& Foo< D >::operator=( const Foo& other ) +{ + return *this; +} diff --git a/clang/test/PCH/cxx-templates.h b/clang/test/PCH/cxx-templates.h new file mode 100644 index 0000000..152e8ce --- /dev/null +++ b/clang/test/PCH/cxx-templates.h @@ -0,0 +1,217 @@ +// Header for PCH test cxx-templates.cpp + +template +struct S; + +template +struct S { + S() { } + static void templ(); +}; + +template +struct S { + static void partial(); +}; + +template <> +struct S { + static void explicit_special(); +}; + +template +int tmpl_f2() { return x; } + +template +T templ_f(T x) { + int z = templ_f(3); + z = tmpl_f2(); + T data[y]; + return x+y; +} + +void govl(int); +void govl(char); + +template +struct Unresolv { + void f() { + govl(T()); + } +}; + +template +struct Dep { + typedef typename T::type Ty; + void f() { + Ty x = Ty(); + T::my_f(); + int y = T::template my_templf(0); + ovl(y); + } + + void ovl(int); + void ovl(float); +}; + +template +inline T make_a(const A1& a1) { + T::depend_declref(); + return T(a1); +} + +template class UseBase { + void foo(); + typedef int bar; +}; + +template class UseA : public UseBase { + using UseBase::foo; + using typename UseBase::bar; +}; + +template class Sub : public UseBase { }; + +template + class mem_fun_t + { + public: + explicit + mem_fun_t(_Ret (_Tp::*__pf)()) + {} + + private: + _Ret (_Tp::*_M_f)(); + }; + +template +bool isInt(int x); + +template<> bool isInt<8>(int x) { + try { ++x; } catch(...) { --x; } + return true; +} + +template +int __copy_streambufs_eof(_CharT); + +class basic_streambuf +{ + void m() { } + friend int __copy_streambufs_eof<>(int); +}; + +// PR 7660 +template struct S_PR7660 { void g(void (*)(T)); }; + template<> void S_PR7660::g(void(*)(int)) {} + +// PR 7670 +template class C_PR7670; +template<> class C_PR7670; +template<> class C_PR7670; + +template +struct S2 { + static bool V; +}; + +extern template class S2; + +template +struct S3 { + void m(); +}; + +template +inline void S3::m() { } + +template +struct S4 { + void m() { } +}; +extern template struct S4; + +void S4ImplicitInst() { + S4 s; + s.m(); +} + +struct S5 { + S5(int x); +}; + +struct TS5 { + S5 s; + template + TS5(T y) : s(y) {} +}; + +// PR 8134 +template void f_PR8134(T); +template void f_PR8134(T); +void g_PR8134() { f_PR8134(0); f_PR8134('x'); } + +// rdar8580149 +template +struct S6; + +template +struct S6 +{ +private: + typedef const T t1[N]; +public: + typedef t1& t2; +}; + +template + struct S7; + +template +struct S7 : S6 { }; + +// Zero-length template argument lists +namespace ZeroLengthExplicitTemplateArgs { + template void h(); + + struct Y { + template void f(); + }; + + template + void f(T *ptr) { + T::template g<>(17); + ptr->template g2<>(17); + h(); + h(); + Y y; + y.f(); + } + + struct X { + template static void g(T); + template void g2(T); + }; +} + +namespace NonTypeTemplateParmContext { + template class Vector { }; + + struct String { + template + static String adopt(Vector&); + }; + + template + inline bool equalIgnoringNullity(const Vector& a, const String& b) { return false; } +} + +// +template< typename > class Foo; + +template< typename T > +class Foo : protected T +{ + public: + Foo& operator=( const Foo& other ); +}; diff --git a/clang/test/PCH/cxx-trailing-return.cpp b/clang/test/PCH/cxx-trailing-return.cpp new file mode 100644 index 0000000..ff85f6d --- /dev/null +++ b/clang/test/PCH/cxx-trailing-return.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -pedantic-errors -std=c++11 -emit-pch %s -o %t-cxx11 +// RUN: %clang_cc1 -pedantic-errors -std=c++11 -include-pch %t-cxx11 -verify %s + +#ifndef HEADER_INCLUDED + +#define HEADER_INCLUDED +typedef auto f() -> int; // expected-note {{here}} +typedef int g(); // expected-note {{here}} + +#else + +typedef void f; // expected-error {{typedef redefinition with different types ('void' vs 'auto () -> int')}} +typedef void g; // expected-error {{typedef redefinition with different types ('void' vs 'int ()')}} + +#endif diff --git a/clang/test/PCH/cxx-traits.cpp b/clang/test/PCH/cxx-traits.cpp new file mode 100644 index 0000000..3df3479 --- /dev/null +++ b/clang/test/PCH/cxx-traits.cpp @@ -0,0 +1,11 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/cxx-traits.h -std=c++11 -fsyntax-only -verify %s + +// RUN: %clang_cc1 -x c++-header -std=c++11 -emit-pch -o %t %S/cxx-traits.h +// RUN: %clang_cc1 -std=c++11 -include-pch %t -fsyntax-only -verify %s + +bool _Is_pod_comparator = __is_pod::__value; +bool _Is_empty_check = __is_empty::__value; + +bool default_construct_int = is_trivially_constructible::value; +bool copy_construct_int = is_trivially_constructible::value; diff --git a/clang/test/PCH/cxx-traits.h b/clang/test/PCH/cxx-traits.h new file mode 100644 index 0000000..8b62002 --- /dev/null +++ b/clang/test/PCH/cxx-traits.h @@ -0,0 +1,16 @@ +// Header for PCH test cxx-traits.cpp + +template +struct __is_pod { + enum { __value }; +}; + +template +struct __is_empty { + enum { __value }; +}; + +template +struct is_trivially_constructible { + static const bool value = __is_trivially_constructible(T, Args...); +}; diff --git a/clang/test/PCH/cxx-typeid.cpp b/clang/test/PCH/cxx-typeid.cpp new file mode 100644 index 0000000..41dd544 --- /dev/null +++ b/clang/test/PCH/cxx-typeid.cpp @@ -0,0 +1,9 @@ +// Test this without pch. +// RUN: %clang -include %S/cxx-typeid.h -fsyntax-only -Xclang -verify %s + +// RUN: %clang -ccc-pch-is-pch -x c++-header -o %t.gch %S/cxx-typeid.h +// RUN: %clang -ccc-pch-is-pch -include %t -fsyntax-only -Xclang -verify %s + +void f() { + (void)typeid(int); +} diff --git a/clang/test/PCH/cxx-typeid.h b/clang/test/PCH/cxx-typeid.h new file mode 100644 index 0000000..aa3b16a --- /dev/null +++ b/clang/test/PCH/cxx-typeid.h @@ -0,0 +1,3 @@ +// Header for PCH test cxx-typeid.cpp + +#include diff --git a/clang/test/PCH/cxx-using.cpp b/clang/test/PCH/cxx-using.cpp new file mode 100644 index 0000000..2ca7dad --- /dev/null +++ b/clang/test/PCH/cxx-using.cpp @@ -0,0 +1,15 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/cxx-using.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-using.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +void m() { + D s; // expected-note {{candidate function}} + s.f(); // expected-error {{no matching member}} +} + + + +// expected-note {{candidate function}} diff --git a/clang/test/PCH/cxx-using.h b/clang/test/PCH/cxx-using.h new file mode 100644 index 0000000..572cea2 --- /dev/null +++ b/clang/test/PCH/cxx-using.h @@ -0,0 +1,16 @@ +// Header for PCH test cxx-using.cpp + + + + + + +struct B { + void f(char c); +}; + +struct D : B +{ + using B::f; + void f(int); +}; diff --git a/clang/test/PCH/cxx-variadic-templates.cpp b/clang/test/PCH/cxx-variadic-templates.cpp new file mode 100644 index 0000000..5b58693 --- /dev/null +++ b/clang/test/PCH/cxx-variadic-templates.cpp @@ -0,0 +1,11 @@ +// Test this without pch. +// RUN: %clang_cc1 -std=c++11 -include %S/cxx-variadic-templates.h -verify %s -ast-dump -o - +// RUN: %clang_cc1 -std=c++11 -include %S/cxx-variadic-templates.h %s -emit-llvm -o - | FileCheck %s + +// Test with pch. +// RUN: %clang_cc1 -std=c++11 -x c++-header -emit-pch -o %t %S/cxx-variadic-templates.h +// RUN: %clang_cc1 -std=c++11 -include-pch %t -verify %s -ast-dump -o - +// RUN: %clang_cc1 -std=c++11 -include-pch %t %s -emit-llvm -o - | FileCheck %s + +// CHECK: allocate_shared +shared_ptr spi = shared_ptr::allocate_shared(1, 2); diff --git a/clang/test/PCH/cxx-variadic-templates.h b/clang/test/PCH/cxx-variadic-templates.h new file mode 100644 index 0000000..f6ee787 --- /dev/null +++ b/clang/test/PCH/cxx-variadic-templates.h @@ -0,0 +1,18 @@ +// PR9073 +template +class shared_ptr{ +public: + template + static + shared_ptr<_Tp> + allocate_shared(const _Alloc& __a, _Args&& ...__args); +}; + +template +template +shared_ptr<_Tp> +shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args) +{ + shared_ptr<_Tp> __r; + return __r; +} diff --git a/clang/test/PCH/cxx0x-default-delete.cpp b/clang/test/PCH/cxx0x-default-delete.cpp new file mode 100644 index 0000000..6eb65d6 --- /dev/null +++ b/clang/test/PCH/cxx0x-default-delete.cpp @@ -0,0 +1,34 @@ +// Without PCH +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -include %s %s +// With PCH +// RUN: %clang_cc1 -x c++-header -std=c++11 -emit-pch -o %t %s +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -include-pch %t %s + +#ifndef PASS1 +#define PASS1 + +struct foo { + foo() = default; + void bar() = delete; // expected-note{{deleted here}} +}; + +struct baz { + ~baz() = delete; // expected-note{{deleted here}} +}; + +class quux { + ~quux() = default; // expected-note{{private here}} +}; + +#else + +foo::foo() { } // expected-error{{definition of explicitly defaulted default constructor}} +foo f; +void fn() { + f.bar(); // expected-error{{deleted function}} +} + +baz bz; // expected-error{{deleted function}} +quux qx; // expected-error{{private destructor}} + +#endif diff --git a/clang/test/PCH/cxx0x-delegating-ctors.cpp b/clang/test/PCH/cxx0x-delegating-ctors.cpp new file mode 100644 index 0000000..f2b7e90 --- /dev/null +++ b/clang/test/PCH/cxx0x-delegating-ctors.cpp @@ -0,0 +1,20 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %s -std=c++11 -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -x c++-header -std=c++11 -emit-pch -o %t %s +// RUN: %clang_cc1 -std=c++11 -include-pch %t -fsyntax-only -verify %s + +#ifndef PASS1 +#define PASS1 +struct foo { + foo(int) : foo() { } // expected-note{{it delegates to}} + foo(); + foo(bool) : foo('c') { } // expected-note{{it delegates to}} + foo(char) : foo(true) { } // expected-error{{creates a delegation cycle}} \ + // expected-note{{which delegates to}} +}; +#else +foo::foo() : foo(1) { } // expected-error{{creates a delegation cycle}} \ + // expected-note{{which delegates to}} +#endif diff --git a/clang/test/PCH/cxx11-constexpr.cpp b/clang/test/PCH/cxx11-constexpr.cpp new file mode 100644 index 0000000..338543e --- /dev/null +++ b/clang/test/PCH/cxx11-constexpr.cpp @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -pedantic-errors -std=c++11 -emit-pch %s -o %t +// RUN: %clang_cc1 -pedantic-errors -std=c++11 -include-pch %t -verify %s + +#ifndef HEADER_INCLUDED + +#define HEADER_INCLUDED + +struct B { + B(); // expected-note {{here}} + constexpr B(char) {} +}; + +struct C { // expected-note {{not an aggregate and has no constexpr constructors}} + B b; + double d = 0.0; +}; + +struct D : B { + constexpr D(int n) : B('x'), k(2*n+1) {} + int k; +}; + +#else + +static_assert(D(4).k == 9, ""); +constexpr int f(C c) { return 0; } // expected-error {{not a literal type}} +constexpr B b; // expected-error {{constant expression}} expected-note {{non-constexpr}} + +#endif diff --git a/clang/test/PCH/cxx11-enum-template.cpp b/clang/test/PCH/cxx11-enum-template.cpp new file mode 100644 index 0000000..70b0ff9 --- /dev/null +++ b/clang/test/PCH/cxx11-enum-template.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -pedantic-errors -std=c++11 -emit-pch %s -o %t +// RUN: %clang_cc1 -pedantic-errors -std=c++11 -include-pch %t -verify %s + +#ifndef HEADER_INCLUDED + +#define HEADER_INCLUDED + +template struct S { + enum class E { + e = T() // expected-error {{conversion from 'double' to 'int'}} + }; +}; + +S a; +S::E b; +S::E c; +template struct S; + +#else + +int k1 = (int)S::E::e; +int k2 = (int)decltype(b)::e; +int k3 = (int)decltype(c)::e; // expected-note {{here}} +int k4 = (int)S::E::e; + +#endif diff --git a/clang/test/PCH/cxx11-exception-spec.cpp b/clang/test/PCH/cxx11-exception-spec.cpp new file mode 100644 index 0000000..3fca4e4 --- /dev/null +++ b/clang/test/PCH/cxx11-exception-spec.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -pedantic-errors -std=c++11 -emit-pch %s -o %t +// RUN: %clang_cc1 -pedantic-errors -std=c++11 -include-pch %t -verify %s + +#ifndef HEADER_INCLUDED + +#define HEADER_INCLUDED + +template int f() noexcept(b) {} +decltype(f()) a; +decltype(f()) b; + +#else + +static_assert(!noexcept(f()), ""); +static_assert(noexcept(f()), ""); + +#endif diff --git a/clang/test/PCH/cxx11-lambdas.mm b/clang/test/PCH/cxx11-lambdas.mm new file mode 100644 index 0000000..c00ec63 --- /dev/null +++ b/clang/test/PCH/cxx11-lambdas.mm @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 -pedantic-errors -fblocks -std=c++11 -emit-pch %s -o %t-cxx11 +// RUN: %clang_cc1 -ast-print -pedantic-errors -fblocks -std=c++11 -include-pch %t-cxx11 %s | FileCheck -check-prefix=CHECK-PRINT %s + +#ifndef HEADER_INCLUDED + +#define HEADER_INCLUDED +template +T add_slowly(const T& x, const T &y) { + return [=, &y] { return x + y; }(); +}; + +inline int add_int_slowly_twice(int x, int y) { + int i = add_slowly(x, y); + auto lambda = [&](int z) { return x + z; }; + return i + lambda(y); +} + +inline int sum_array(int n) { + int array[5] = { 1, 2, 3, 4, 5}; + auto lambda = [=](int N) -> int { + int sum = 0; + for (unsigned I = 0; I < N; ++I) + sum += array[N]; + return sum; + }; + + return lambda(n); +} + +inline int to_block_pointer(int n) { + auto lambda = [=](int m) { return n + m; }; + int (^block)(int) = lambda; + return block(17); +} + +#else + +// CHECK-PRINT: T add_slowly +// CHECK-PRINT: return [=, &y] +template float add_slowly(const float&, const float&); + +int add(int x, int y) { + return add_int_slowly_twice(x, y) + sum_array(4) + to_block_pointer(5); +} + +// CHECK-PRINT: inline int add_int_slowly_twice +// CHECK-PRINT: lambda = [&] (int z) +#endif diff --git a/clang/test/PCH/cxx11-user-defined-literals.cpp b/clang/test/PCH/cxx11-user-defined-literals.cpp new file mode 100644 index 0000000..4a7c24b --- /dev/null +++ b/clang/test/PCH/cxx11-user-defined-literals.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -pedantic-errors -std=c++11 -emit-pch %s -o %t +// RUN: %clang_cc1 -pedantic-errors -std=c++11 -include-pch %t -verify %s + +#ifndef HEADER_INCLUDED + +#define HEADER_INCLUDED + +using size_t = decltype(sizeof(int)); +int operator"" _foo(const char *p, size_t); + +template auto f(T t) -> decltype(t + ""_foo) { return 0; } // expected-note {{substitution failure}} + +#else + +int j = ""_foo; +int k = f(0); +int *l = f(&k); +struct S {}; +int m = f(S()); // expected-error {{no matching}} + +#endif diff --git a/clang/test/PCH/cxx_exprs.cpp b/clang/test/PCH/cxx_exprs.cpp new file mode 100644 index 0000000..4cd9bae --- /dev/null +++ b/clang/test/PCH/cxx_exprs.cpp @@ -0,0 +1,39 @@ +// Test this without pch. +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -include %S/cxx_exprs.h -std=c++11 -fsyntax-only -verify %s -ast-dump + +// Test with pch. Use '-ast-dump' to force deserialization of function bodies. +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -x c++-header -std=c++11 -emit-pch -o %t %S/cxx_exprs.h +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-dump + +int integer; +double floating; +char character; +bool boolean; + +// CXXStaticCastExpr +static_cast_result void_ptr = &integer; + +// CXXDynamicCastExpr +Derived *d; +dynamic_cast_result derived_ptr = d; + +// CXXReinterpretCastExpr +reinterpret_cast_result void_ptr2 = &integer; + +// CXXConstCastExpr +const_cast_result char_ptr = &character; + +// CXXFunctionalCastExpr +functional_cast_result *double_ptr = &floating; + +// CXXBoolLiteralExpr +bool_literal_result *bool_ptr = &boolean; +static_assert(true_value, "true_value is true"); +static_assert(!false_value, "false_value is false"); + +// CXXNullPtrLiteralExpr +cxx_null_ptr_result null_ptr = nullptr; + +// CXXTypeidExpr +typeid_result1 typeid_1 = 0; +typeid_result2 typeid_2 = 0; diff --git a/clang/test/PCH/cxx_exprs.h b/clang/test/PCH/cxx_exprs.h new file mode 100644 index 0000000..67ab4a6 --- /dev/null +++ b/clang/test/PCH/cxx_exprs.h @@ -0,0 +1,83 @@ +// Header for PCH test cxx_exprs.cpp + + +// CXXStaticCastExpr +typedef __typeof__(static_cast(0)) static_cast_result; + +// CXXDynamicCastExpr +struct Base { Base(int); virtual void f(int x = 492); ~Base(); }; +struct Derived : Base { Derived(); void g(); }; +Base *base_ptr; +typedef __typeof__(dynamic_cast(base_ptr)) dynamic_cast_result; + +// CXXReinterpretCastExpr +typedef __typeof__(reinterpret_cast(0)) reinterpret_cast_result; + +// CXXConstCastExpr +const char *const_char_ptr_value; +typedef __typeof__(const_cast(const_char_ptr_value)) const_cast_result; + +// CXXFunctionalCastExpr +int int_value; +typedef __typeof__(double(int_value)) functional_cast_result; + +// CXXBoolLiteralExpr +typedef __typeof__(true) bool_literal_result; +const bool true_value = true; +const bool false_value = false; + +// CXXNullPtrLiteralExpr +typedef __typeof__(nullptr) cxx_null_ptr_result; + +void foo(Derived *P) { + // CXXMemberCallExpr + P->f(12); +} + + +// FIXME: This is a hack until works completely. +namespace std { + class type_info {}; +} + +// CXXTypeidExpr - Both expr and type forms. +typedef __typeof__(typeid(int))* typeid_result1; +typedef __typeof__(typeid(2))* typeid_result2; + +Derived foo(); + +Derived::Derived() : Base(4) { +} + +void Derived::g() { + // CXXThisExpr + f(2); // Implicit + this->f(1); // Explicit + + // CXXThrowExpr + throw; + throw 42; + + // CXXDefaultArgExpr + f(); + + const Derived &X = foo(); + + // FIXME: How do I make a CXXBindReferenceExpr, CXXConstructExpr? + + int A = int(0.5); // CXXFunctionalCastExpr + A = int(); // CXXZeroInitValueExpr + + Base *b = new Base(4); // CXXNewExpr + delete b; // CXXDeleteExpr +} + + +// FIXME: The comment on CXXTemporaryObjectExpr is broken, this doesn't make +// one. +struct CtorStruct { CtorStruct(int, float); }; + +CtorStruct create_CtorStruct() { + return CtorStruct(1, 3.14f); // CXXTemporaryObjectExpr +}; + diff --git a/clang/test/PCH/designated-init.c b/clang/test/PCH/designated-init.c new file mode 100644 index 0000000..beb4dff --- /dev/null +++ b/clang/test/PCH/designated-init.c @@ -0,0 +1,7 @@ +// Test this without pch. +// RUN: %clang_cc1 %s -include %s.h -emit-llvm -o %t.withoutpch.ll + +// Test with pch. +// RUN: %clang_cc1 %s.h -emit-pch -o %t.pch +// RUN: %clang_cc1 %s -include-pch %t.pch -emit-llvm -o %t.withpch.ll +// RUN: diff %t.withoutpch.ll %t.withpch.ll diff --git a/clang/test/PCH/designated-init.c.h b/clang/test/PCH/designated-init.c.h new file mode 100644 index 0000000..63b1f79 --- /dev/null +++ b/clang/test/PCH/designated-init.c.h @@ -0,0 +1,42 @@ +static void *FooToken = &FooToken; +static void *FooTable[256] = { + [0x3] = (void *[256]) { // 1 + [0x5b] = (void *[256]) { // 2 + [0x81] = (void *[256]) { // 3 + [0x42] = (void *[256]) { // 4 + [0xa2] = (void *[256]) { // 5 + [0xe] = (void *[256]) { // 6 + [0x20] = (void *[256]) { // 7 + [0xd7] = (void *[256]) { // 8 + [0x39] = (void *[256]) { // 9 + [0xf1] = (void *[256]) { // 10 + [0xa4] = (void *[256]) { // 11 + [0xa8] = (void *[256]) { // 12 + [0x21] = (void *[256]) { // 13 + [0x86] = (void *[256]) { // 14 + [0x1d] = (void *[256]) { // 15 + [0xdc] = (void *[256]) { // 16 + [0xa5] = (void *[256]) { // 17 + [0xef] = (void *[256]) { // 18 + [0x9] = (void *[256]) { // 19 + [0x34] = &FooToken, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + } +}; diff --git a/clang/test/PCH/enum.c b/clang/test/PCH/enum.c new file mode 100644 index 0000000..10ceb7c --- /dev/null +++ b/clang/test/PCH/enum.c @@ -0,0 +1,15 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/enum.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t %S/enum.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +int i = Red; + +int return_enum_constant() { + int result = aRoundShape; + return result; +} + +enum Shape s = Triangle; diff --git a/clang/test/PCH/enum.h b/clang/test/PCH/enum.h new file mode 100644 index 0000000..7dc4e63 --- /dev/null +++ b/clang/test/PCH/enum.h @@ -0,0 +1,16 @@ +/* Used in enum.c test */ + +enum Color { + Red, + Green, + Blue +}; + +enum Shape { + Square, + Triangle = 17, + Rhombus, + Circle +}; + +enum Shape aRoundShape = Circle; diff --git a/clang/test/PCH/exprs.c b/clang/test/PCH/exprs.c new file mode 100644 index 0000000..5928abd --- /dev/null +++ b/clang/test/PCH/exprs.c @@ -0,0 +1,98 @@ +// Test this without pch. +// RUN: %clang_cc1 -fblocks -include %S/exprs.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -fblocks -o %t %S/exprs.h +// RUN: %clang_cc1 -fblocks -include-pch %t -fsyntax-only -verify %s + +__SIZE_TYPE__ size_type_value; +int integer; +long long_integer; +double floating; +_Complex double floating_complex; + +// DeclRefExpr +int_decl_ref *int_ptr1 = &integer; +enum_decl_ref *enum_ptr1 = &integer; + +// IntegerLiteral +integer_literal *int_ptr2 = &integer; +long_literal *long_ptr1 = &long_integer; + +// FloatingLiteral + ParenExpr +floating_literal *double_ptr = &floating; + +// ImaginaryLiteral +imaginary_literal *cdouble_ptr = &floating_complex; + +// StringLiteral +const char* printHello() { + return hello; +} + +// CharacterLiteral +char_literal *int_ptr3 = &integer; + +// UnaryOperator +negate_enum *int_ptr4 = &integer; + +// OffsetOfExpr +offsetof_type *offsetof_ptr = &size_type_value; + +// UnaryExprOrTypeTraitExpr +typeof(sizeof(float)) size_t_value; +typeof_sizeof *size_t_ptr = &size_t_value; +typeof_sizeof2 *size_t_ptr2 = &size_t_value; + +// ArraySubscriptExpr +array_subscript *double_ptr1_5 = &floating; + +// CallExpr +call_returning_double *double_ptr2 = &floating; + +// MemberExpr +member_ref_double *double_ptr3 = &floating; + +// BinaryOperator +add_result *int_ptr5 = &integer; + +// CompoundAssignOperator +addeq_result *int_ptr6 = &integer; + +add_result_with_typeinfo *int_typeinfo_ptr6; + +// ConditionalOperator +conditional_operator *double_ptr4 = &floating; + +// CStyleCastExpr +void_ptr vp1 = &integer; + +// CompoundLiteral +struct S s; +compound_literal *sptr = &s; + +// ExtVectorElementExpr +ext_vector_element *double_ptr5 = &floating; + +// InitListExpr +double get_from_double_array(unsigned Idx) { return double_array[Idx]; } + +/// DesignatedInitExpr +float get_from_designated(unsigned Idx) { + return designated_inits[2].y; +} + +// TypesCompatibleExpr +types_compatible *int_ptr7 = &integer; + +// ChooseExpr +choose_expr *int_ptr8 = &integer; + +// GNUNullExpr FIXME: needs C++ +//null_type null = __null; + +// ShuffleVectorExpr +shuffle_expr *vec_ptr = &vec2; + +// GenericSelectionExpr +generic_selection_expr *double_ptr6 = &floating; diff --git a/clang/test/PCH/exprs.h b/clang/test/PCH/exprs.h new file mode 100644 index 0000000..09a5013 --- /dev/null +++ b/clang/test/PCH/exprs.h @@ -0,0 +1,107 @@ +// Header for PCH test exprs.c + +// DeclRefExpr +int i = 17; +enum Enum { Enumerator = 18 }; +typedef typeof(i) int_decl_ref; +typedef typeof(Enumerator) enum_decl_ref; + +// IntegerLiteral +typedef typeof(17) integer_literal; +typedef typeof(17l) long_literal; + +// FloatingLiteral and ParenExpr +typedef typeof((42.5)) floating_literal; + +// ImaginaryLiteral +typedef typeof(17.0i) imaginary_literal; + +// StringLiteral +const char *hello = "Hello" "PCH" "World"; + +// CharacterLiteral +typedef typeof('a') char_literal; + +// UnaryOperator +typedef typeof(-Enumerator) negate_enum; + +// OffsetOfExpr +struct X { + int member; +}; +struct Y { + struct X array[5]; +}; +struct Z { + struct Y y; +}; +typedef typeof(__builtin_offsetof(struct Z, y.array[1 + 2].member)) + offsetof_type; + +// UnaryExprOrTypeTraitExpr +typedef typeof(sizeof(int)) typeof_sizeof; +typedef typeof(sizeof(Enumerator)) typeof_sizeof2; + +// ArraySubscriptExpr +extern double values[]; +typedef typeof(values[2]) array_subscript; + +// CallExpr +double dplus(double x, double y); +double d0, d1; +typedef typeof((&dplus)(d0, d1)) call_returning_double; + +// MemberExpr +struct S { + double x; +}; +typedef typeof(((struct S*)0)->x) member_ref_double; + +// BinaryOperator +typedef typeof(i + Enumerator) add_result; + +// CompoundAssignOperator +typedef typeof(i += Enumerator) addeq_result; + +// ConditionalOperator +typedef typeof(i? : d0) conditional_operator; + +// CStyleCastExpr +typedef typeof((void *)0) void_ptr; + +// CompoundLiteral +typedef typeof((struct S){.x = 3.5}) compound_literal; + +typedef typeof(i + sizeof(int[i + Enumerator])) add_result_with_typeinfo; + +// ExtVectorElementExpr +typedef __attribute__(( ext_vector_type(2) )) double double2; +extern double2 vec2, vec2b; +typedef typeof(vec2.x) ext_vector_element; + +// InitListExpr +double double_array[3] = { 1.0, 2.0 }; + +// DesignatedInitExpr +struct { + int x; + float y; +} designated_inits[3] = { [0].y = 17, + [2].x = 12.3, // expected-warning {{implicit conversion turns literal floating-point number into integer}} + 3.5 }; + +// TypesCompatibleExpr +typedef typeof(__builtin_types_compatible_p(float, double)) types_compatible; + +// ChooseExpr +typedef typeof(__builtin_choose_expr(17 > 19, d0, 1)) choose_expr; + +// GNUNullExpr FIXME: needs C++ +// typedef typeof(__null) null_type; + +// ShuffleVectorExpr +typedef typeof(__builtin_shufflevector(vec2, vec2b, 2, 1)) shuffle_expr; + +// GenericSelectionExpr +typedef typeof(_Generic(i, char*: 0, int: 0., default: hello)) + generic_selection_expr; diff --git a/clang/test/PCH/ext_vector.c b/clang/test/PCH/ext_vector.c new file mode 100644 index 0000000..bd129ea --- /dev/null +++ b/clang/test/PCH/ext_vector.c @@ -0,0 +1,10 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/ext_vector.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t %S/ext_vector.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +int test(float4 f4) { + return f4.xy; // expected-error{{float2}} +} diff --git a/clang/test/PCH/ext_vector.h b/clang/test/PCH/ext_vector.h new file mode 100644 index 0000000..39ab923 --- /dev/null +++ b/clang/test/PCH/ext_vector.h @@ -0,0 +1,4 @@ +// Header file for ext_vector.c PCH test + +typedef __attribute__((ext_vector_type(2))) float float2; +typedef __attribute__((ext_vector_type(4))) float float4; diff --git a/clang/test/PCH/external-defs.c b/clang/test/PCH/external-defs.c new file mode 100644 index 0000000..5097859 --- /dev/null +++ b/clang/test/PCH/external-defs.c @@ -0,0 +1,19 @@ +// Test with pch. +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -emit-pch -o %t.pch %S/external-defs.h +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -include-pch %t.pch -emit-llvm -o %t %s + +// RUN: grep "@x = common global i32 0" %t | count 1 +// RUN: grep "@z" %t | count 0 + +// RUN: grep "@x2 = global i32 19" %t | count 1 +int x2 = 19; + +// RUN: grep "@incomplete_array = common global .*1 x i32" %t | count 1 +// RUN: grep "@incomplete_array2 = common global .*17 x i32" %t | count 1 +int incomplete_array2[17]; +// RUN: grep "@incomplete_array3 = common global .*1 x i32" %t | count 1 +int incomplete_array3[]; + +struct S { + int x, y; +}; diff --git a/clang/test/PCH/external-defs.h b/clang/test/PCH/external-defs.h new file mode 100644 index 0000000..657b47b --- /dev/null +++ b/clang/test/PCH/external-defs.h @@ -0,0 +1,13 @@ +// Helper for external-defs.c test + +// Tentative definitions +int x; +int x2; + +// Should not show up +static int z; + +int incomplete_array[]; +int incomplete_array2[]; + +struct S s; diff --git a/clang/test/PCH/functions.c b/clang/test/PCH/functions.c new file mode 100644 index 0000000..35e3921 --- /dev/null +++ b/clang/test/PCH/functions.c @@ -0,0 +1,25 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/functions.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t %S/functions.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s +// expected-note{{'f1' declared here}} +int f0(int x0, int y0, ...) { return x0 + y0; } +// expected-note{{passing argument to parameter here}} +float *test_f1(int val, double x, double y) { + if (val > 5) + return f1(x, y); + else + return f1(x); // expected-error{{too few arguments to function call}} +} + +void test_g0(int *x, float * y) { + g0(y); // expected-warning{{incompatible pointer types passing 'float *' to parameter of type 'int *'}} + g0(x); +} + +void __attribute__((noreturn)) test_abort(int code) { + do_abort(code); +} + diff --git a/clang/test/PCH/functions.h b/clang/test/PCH/functions.h new file mode 100644 index 0000000..f57400f --- /dev/null +++ b/clang/test/PCH/functions.h @@ -0,0 +1,11 @@ +/* For use with the functions.c test */ + + + + +int f0(int x, int y, ...); +float *f1(float x, float y); + +void g0(int *); + +void do_abort(int) __attribute__((noreturn)); diff --git a/clang/test/PCH/fuzzy-pch.c b/clang/test/PCH/fuzzy-pch.c new file mode 100644 index 0000000..5675753 --- /dev/null +++ b/clang/test/PCH/fuzzy-pch.c @@ -0,0 +1,19 @@ +// Test with pch. +// RUN: %clang_cc1 -emit-pch -DFOO -o %t %S/variables.h +// RUN: %clang_cc1 -DBAR=int -include-pch %t -fsyntax-only -pedantic %s +// RUN: %clang_cc1 -DFOO -DBAR=int -include-pch %t -Werror %s +// RUN: not %clang_cc1 -DFOO -DBAR=int -DX=5 -include-pch %t -Werror %s + +BAR bar = 17; + +#ifndef FOO +# error FOO was not defined +#endif + +#if FOO != 1 +# error FOO has the wrong definition +#endif + +#ifndef BAR +# error BAR was not defined +#endif diff --git a/clang/test/PCH/fuzzy-pch.h b/clang/test/PCH/fuzzy-pch.h new file mode 100644 index 0000000..9eb1005 --- /dev/null +++ b/clang/test/PCH/fuzzy-pch.h @@ -0,0 +1,2 @@ +// Header for PCH test fuzzy-pch.c +void f(int X); diff --git a/clang/test/PCH/headermap.h b/clang/test/PCH/headermap.h new file mode 100644 index 0000000..efab2d8 --- /dev/null +++ b/clang/test/PCH/headermap.h @@ -0,0 +1,3 @@ +/* Helper for the headermap.m test */ +int x = 17; + diff --git a/clang/test/PCH/headermap.m b/clang/test/PCH/headermap.m new file mode 100644 index 0000000..6ba83d7 --- /dev/null +++ b/clang/test/PCH/headermap.m @@ -0,0 +1,15 @@ +// RUN: touch %t.hmap + +// RUN: %clang_cc1 -x objective-c -emit-pch -o %t.h.pch %S/headermap.h +// RUN: %clang_cc1 -include-pch %t.h.pch %s + +// RUN: %clang_cc1 -x objective-c -emit-pch -o %t.h.pch %S/headermap.h +// RUN: %clang_cc1 -include-pch %t.h.pch -I%t.hmap %s + +// RUN: %clang_cc1 -x objective-c -I%t.hmap -emit-pch -o %t.h.pch %S/headermap.h +// RUN: %clang_cc1 -include-pch %t.h.pch %s + +// RUN: %clang_cc1 -x objective-c -I%t.hmap -emit-pch -o %t.h.pch %S/headermap.h +// RUN: %clang_cc1 -include-pch %t.h.pch -I%t.hmap %s +#import "headermap.h" + diff --git a/clang/test/PCH/headersearch.cpp b/clang/test/PCH/headersearch.cpp new file mode 100644 index 0000000..8ca0c36 --- /dev/null +++ b/clang/test/PCH/headersearch.cpp @@ -0,0 +1,44 @@ +// Test reading of PCH with changed location of original input files, +// i.e. invoking header search. +// REQUIRES: shell + +// Generate the original files: +// RUN: rm -rf %t_orig %t_moved +// RUN: mkdir -p %t_orig/sub %t_orig/sub2 +// RUN: echo 'struct orig_sub{char c; int i; };' > %t_orig/sub/orig_sub.h +// RUN: echo 'void orig_sub2_1();' > %t_orig/sub2/orig_sub2_1.h +// RUN: echo '#include "orig_sub2_1.h"' > %t_orig/sub2/orig_sub2.h +// RUN: echo 'template void tf() { orig_sub2_1(); T::foo(); }' >> %t_orig/sub2/orig_sub2.h +// RUN: echo 'void foo() {}' > %t_orig/tmp2.h +// RUN: echo '#include "tmp2.h"' > %t_orig/all.h +// RUN: echo '#include "sub/orig_sub.h"' >> %t_orig/all.h +// RUN: echo '#include "orig_sub2.h"' >> %t_orig/all.h +// RUN: echo 'int all();' >> %t_orig/all.h + +// Generate the PCH: +// RUN: cd %t_orig && %clang_cc1 -x c++ -emit-pch -o all.h.pch -Isub2 all.h +// RUN: cp -pR %t_orig %t_moved + +// Check diagnostic with location in original source: +// RUN: %clang_cc1 -include-pch all.h.pch -I%t_moved -I%t_moved/sub2 -Wpadded -emit-obj -o %t.o %s 2> %t.stderr +// RUN: grep 'struct orig_sub' %t.stderr + +// Check diagnostic with 2nd location in original source: +// RUN: not %clang_cc1 -DREDECL -include-pch all.h.pch -I%t_moved -I%t_moved/sub2 -emit-obj -o %t.o %s 2> %t.stderr +// RUN: grep 'void foo' %t.stderr + +// Check diagnostic with instantiation location in original source: +// RUN: not %clang_cc1 -DINSTANTIATION -include-pch all.h.pch -I%t_moved -I%t_moved/sub2 -emit-obj -o %t.o %s 2> %t.stderr +// RUN: grep 'orig_sub2_1' %t.stderr + +void qq(orig_sub*) {all();} + +#ifdef REDECL +float foo() {return 0;} +#endif + +#ifdef INSTANTIATION +void f() { + tf(); +} +#endif diff --git a/clang/test/PCH/libroot/usr/include/reloc.h b/clang/test/PCH/libroot/usr/include/reloc.h new file mode 100644 index 0000000..04eeacb --- /dev/null +++ b/clang/test/PCH/libroot/usr/include/reloc.h @@ -0,0 +1,15 @@ +#ifndef RELOC_H +#define RELOC_H + +#include + + + + + + + +// Line number 13 below is important +int x = 2; + +#endif // RELOC_H diff --git a/clang/test/PCH/libroot/usr/include/reloc2.h b/clang/test/PCH/libroot/usr/include/reloc2.h new file mode 100644 index 0000000..995415c --- /dev/null +++ b/clang/test/PCH/libroot/usr/include/reloc2.h @@ -0,0 +1,15 @@ +#ifndef RELOC2_H +#define RELOC2_H +#include + + + + + + + + + +// Line number below is important! +int y = 2; +#endif // RELOC2_H diff --git a/clang/test/PCH/line-directive.c b/clang/test/PCH/line-directive.c new file mode 100644 index 0000000..4710c40 --- /dev/null +++ b/clang/test/PCH/line-directive.c @@ -0,0 +1,25 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/line-directive.h -fsyntax-only %s 2>&1|grep "25:5" + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t %S/line-directive.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only %s 2>&1|grep "25:5" + +double x; // expected-error{{redefinition of 'x' with a different type}} + + + + + + + + + + + + + + + + +// expected-note{{previous definition is here}} diff --git a/clang/test/PCH/line-directive.h b/clang/test/PCH/line-directive.h new file mode 100644 index 0000000..c5594b4 --- /dev/null +++ b/clang/test/PCH/line-directive.h @@ -0,0 +1,2 @@ +#line 25 "line-directive.c" +int x; diff --git a/clang/test/PCH/method-redecls.m b/clang/test/PCH/method-redecls.m new file mode 100644 index 0000000..9d02b6a --- /dev/null +++ b/clang/test/PCH/method-redecls.m @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -x objective-c %s -emit-pch -o %t +// RUN: %clang_cc1 -x objective-c %s -emit-pch -o %t -D IMPL + +// Avoid infinite loop because of method redeclarations. + +@interface Foo +-(void)meth; +-(void)meth; +-(void)meth; +@end + +#ifdef IMPL + +@implementation Foo +-(void)meth { } +@end + +#endif diff --git a/clang/test/PCH/method_pool.h b/clang/test/PCH/method_pool.h new file mode 100644 index 0000000..8085836 --- /dev/null +++ b/clang/test/PCH/method_pool.h @@ -0,0 +1,36 @@ +/* For use with the method_pool.m test */ + +/* Whitespace below is significant */ + + + + + + + + + + + +@interface TestMethodPool1 ++ alloc; +- (double)instMethod:(int)foo; +@end + +@interface TestMethodPool2 +- (char)instMethod:(int)foo; +@end + +@implementation TestMethodPool1 ++ alloc { return 0; } + +- (double)instMethod:(int)foo { + return foo; +} +@end + +@implementation TestMethodPool2 +- (char)instMethod:(int)foo { + return foo; +} +@end diff --git a/clang/test/PCH/method_pool.m b/clang/test/PCH/method_pool.m new file mode 100644 index 0000000..20010fb --- /dev/null +++ b/clang/test/PCH/method_pool.m @@ -0,0 +1,21 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/method_pool.h -fsyntax-only -verify -Wno-objc-root-class %s + +// Test with pch. +// RUN: %clang_cc1 -x objective-c -Wno-objc-root-class -emit-pch -o %t %S/method_pool.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify -Wno-objc-root-class %s + +int message_id(id x) { + return [x instMethod:17]; // expected-warning{{multiple methods}} +} + + + + + +/* Whitespace below is significant */ +/* expected-note{{using}} */ + + + +/* expected-note{{also}} */ diff --git a/clang/test/PCH/missing-file.cpp b/clang/test/PCH/missing-file.cpp new file mode 100644 index 0000000..7d5cd11 --- /dev/null +++ b/clang/test/PCH/missing-file.cpp @@ -0,0 +1,31 @@ +// Test reading of PCH without original input files. + +// Generate the PCH, removing the original file: +// RUN: echo 'struct S{char c; int i; }; void foo() {}' > %t.h +// RUN: echo 'template void tf() { T::foo(); }' >> %t.h +// RUN: %clang_cc1 -x c++ -emit-pch -o %t.h.pch %t.h +// RUN: rm %t.h + +// Check diagnostic with location in original source: +// RUN: %clang_cc1 -include-pch %t.h.pch -Wpadded -emit-obj -o %t.o %s 2> %t.stderr +// RUN: grep 'bytes to align' %t.stderr + +// Check diagnostic with 2nd location in original source: +// RUN: not %clang_cc1 -DREDECL -include-pch %t.h.pch -emit-obj -o %t.o %s 2> %t.stderr +// RUN: grep 'previous definition is here' %t.stderr + +// Check diagnostic with instantiation location in original source: +// RUN: not %clang_cc1 -DINSTANTIATION -include-pch %t.h.pch -emit-obj -o %t.o %s 2> %t.stderr +// RUN: grep 'cannot be used prior to' %t.stderr + +void qq(S*) {} + +#ifdef REDECL +float foo() {return 0f;} +#endif + +#ifdef INSTANTIATION +void f() { + tf(); +} +#endif diff --git a/clang/test/PCH/modified-header-crash.c b/clang/test/PCH/modified-header-crash.c new file mode 100644 index 0000000..c74ce22 --- /dev/null +++ b/clang/test/PCH/modified-header-crash.c @@ -0,0 +1,10 @@ +// Don't crash. + +// RUN: cp %S/modified-header-crash.h %t.h +// RUN: %clang_cc1 -DCAKE -x c-header %t.h -emit-pch -o %t +// RUN: echo >> %t.h +// RUN: not %clang_cc1 %s -include-pch %t -fsyntax-only + +void f(void) { + foo = 3; +} diff --git a/clang/test/PCH/modified-header-crash.h b/clang/test/PCH/modified-header-crash.h new file mode 100644 index 0000000..971746e --- /dev/null +++ b/clang/test/PCH/modified-header-crash.h @@ -0,0 +1 @@ +int foo; diff --git a/clang/test/PCH/modified-header-error.c b/clang/test/PCH/modified-header-error.c new file mode 100644 index 0000000..ef92494 --- /dev/null +++ b/clang/test/PCH/modified-header-error.c @@ -0,0 +1,12 @@ +// RUN: mkdir -p %t.dir +// RUN: echo '#include "header2.h"' > %t.dir/header1.h +// RUN: echo > %t.dir/header2.h +// RUN: cp %s %t.dir/t.c +// RUN: %clang_cc1 -x c-header %t.dir/header1.h -emit-pch -o %t.pch +// RUN: echo >> %t.dir/header2.h +// RUN: %clang_cc1 %t.dir/t.c -include-pch %t.pch -fsyntax-only 2>&1 | FileCheck %s + +#include "header2.h" + +// CHECK: fatal error: file {{.*}} has been modified since the precompiled header was built +// REQUIRES: shell diff --git a/clang/test/PCH/ms-if-exists.cpp b/clang/test/PCH/ms-if-exists.cpp new file mode 100644 index 0000000..4bea198 --- /dev/null +++ b/clang/test/PCH/ms-if-exists.cpp @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -x c++ -fms-extensions -fsyntax-only -emit-pch -o %t %s +// RUN: %clang_cc1 -x c++ -fms-extensions -fsyntax-only -include-pch %t %s -verify + +#ifndef HEADER +#define HEADER +template +void f(T t) { + __if_exists(T::foo) { + { } + t.foo(); + } + + __if_not_exists(T::bar) { + int *i = t; // expected-error{{no viable conversion from 'HasFoo' to 'int *'}} + { } + } +} +#else +struct HasFoo { + void foo(); +}; +struct HasBar { + void bar(int); + void bar(float); +}; + +template void f(HasFoo); // expected-note{{in instantiation of function template specialization 'f' requested here}} +template void f(HasBar); +#endif diff --git a/clang/test/PCH/multiple_decls.c b/clang/test/PCH/multiple_decls.c new file mode 100644 index 0000000..e2cc552 --- /dev/null +++ b/clang/test/PCH/multiple_decls.c @@ -0,0 +1,17 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/multiple_decls.h -fsyntax-only -ast-print -o - %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t %S/multiple_decls.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -ast-print -o - %s + +void f0(char c) { + wide(c); +} + +struct wide w; +struct narrow n; + +void f1(int i) { + narrow(i); +} diff --git a/clang/test/PCH/multiple_decls.h b/clang/test/PCH/multiple_decls.h new file mode 100644 index 0000000..23696b0 --- /dev/null +++ b/clang/test/PCH/multiple_decls.h @@ -0,0 +1,7 @@ +// Header for PCH test multiple_decls.c + +struct wide { int value; }; +int wide(char); + +struct narrow { char narrow; }; +char narrow(int); diff --git a/clang/test/PCH/namespaces.cpp b/clang/test/PCH/namespaces.cpp new file mode 100644 index 0000000..6dd4473 --- /dev/null +++ b/clang/test/PCH/namespaces.cpp @@ -0,0 +1,45 @@ +// Test this without pch. +// RUN: %clang_cc1 -x c++ -include %S/Inputs/namespaces.h -fsyntax-only %s + +// Test with pch. +// RUN: %clang_cc1 -x c++ -emit-pch -o %t %S/Inputs/namespaces.h +// RUN: %clang_cc1 -x c++ -include-pch %t -fsyntax-only %s + +int int_val; +N1::t1 *ip1 = &int_val; +N1::t2 *ip2 = &int_val; +N2::Inner::t3 *ip3 = &int_val; + +float float_val; +namespace N2 { } +N2::t1 *fp1 = &float_val; + +Alias1::t3 *ip4 = &int_val; +t3 *ip5 = &int_val; + +void(*funp1)() = anon; + +namespace { + class C; +} +C* cp1; + +namespace N3 { + namespace { + class C; + } +} + +N3::C *cp2; + +void(*funp2)() = ext; + +using N1::used_func; +void (*pused)() = used_func; + +using N1::used_cls; +used_cls s1; +used_cls* ps1 = &s1; + +inline namespace N4 { } +struct MemberOfN4 *mn4; diff --git a/clang/test/PCH/nonvisible-external-defs.c b/clang/test/PCH/nonvisible-external-defs.c new file mode 100644 index 0000000..49392ca --- /dev/null +++ b/clang/test/PCH/nonvisible-external-defs.c @@ -0,0 +1,10 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/nonvisible-external-defs.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t %S/nonvisible-external-defs.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +int g(int, float); // expected-error{{conflicting types}} + +// expected-note{{previous declaration}} diff --git a/clang/test/PCH/nonvisible-external-defs.h b/clang/test/PCH/nonvisible-external-defs.h new file mode 100644 index 0000000..a36fc2e --- /dev/null +++ b/clang/test/PCH/nonvisible-external-defs.h @@ -0,0 +1,11 @@ +// Helper for PCH test nonvisible-external-defs.h + + + + + + + +void f() { + extern int g(int, int); +} diff --git a/clang/test/PCH/objc_container.h b/clang/test/PCH/objc_container.h new file mode 100644 index 0000000..c83f902 --- /dev/null +++ b/clang/test/PCH/objc_container.h @@ -0,0 +1,26 @@ +@protocol P @end + +@interface NSMutableArray +- (id)objectAtIndexedSubscript:(unsigned int)index; +- (void)setObject:(id)object atIndexedSubscript:(unsigned int)index; +@end + +@interface NSMutableDictionary +- (id)objectForKeyedSubscript:(id)key; +- (void)setObject:(id)object forKeyedSubscript:(id)key; +@end + +void all() { + NSMutableArray *array; + id oldObject = array[10]; + + array[10] = oldObject; + + NSMutableDictionary *dictionary; + id key; + id newObject; + oldObject = dictionary[key]; + + dictionary[key] = newObject; +} + diff --git a/clang/test/PCH/objc_container.m b/clang/test/PCH/objc_container.m new file mode 100644 index 0000000..1e59054 --- /dev/null +++ b/clang/test/PCH/objc_container.m @@ -0,0 +1,20 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/objc_container.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -x objective-c -emit-pch -o %t %S/objc_container.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s +// RUN: %clang -cc1 -include-pch %t -ast-print %s | FileCheck -check-prefix=PRINT %s +// RUN: %clang -cc1 -include-pch %t -emit-llvm -o - %s | FileCheck -check-prefix=IR %s + +// CHECK-PRINT: id oldObject = array[10]; +// CHECK-PRINT: array[10] = oldObject; +// CHECK-PRINT: oldObject = dictionary[key]; +// CHECK-PRINT: dictionary[key] = newObject; + +// CHECK-IR: define void @all() nounwind +// CHECK-IR: {{call.*objc_msgSend}} +// CHECK-IR: {{call.*objc_msgSend}} +// CHECK-IR: {{call.*objc_msgSend}} +// CHECK-IR: {{call.*objc_msgSend}} +// CHECK-IR: ret void diff --git a/clang/test/PCH/objc_exprs.h b/clang/test/PCH/objc_exprs.h new file mode 100644 index 0000000..807304c --- /dev/null +++ b/clang/test/PCH/objc_exprs.h @@ -0,0 +1,26 @@ + +@protocol foo; +@class itf; + +// Expressions +typedef typeof(@"foo" "bar") objc_string; +typedef typeof(@encode(int)) objc_encode; +typedef typeof(@protocol(foo)) objc_protocol; +typedef typeof(@selector(noArgs)) objc_selector_noArgs; +typedef typeof(@selector(oneArg:)) objc_selector_oneArg; +typedef typeof(@selector(foo:bar:)) objc_selector_twoArg; + + +// Types. +typedef typeof(id) objc_id_protocol_ty; + +typedef typeof(itf*) objc_interface_ty; +typedef typeof(itf*) objc_qual_interface_ty; + +@interface PP +@property (assign) id prop; +@end + +static inline id getPseudoObject(PP *p) { + return p.prop; +} diff --git a/clang/test/PCH/objc_exprs.m b/clang/test/PCH/objc_exprs.m new file mode 100644 index 0000000..1f971e7 --- /dev/null +++ b/clang/test/PCH/objc_exprs.m @@ -0,0 +1,27 @@ +// Test this without pch. +// RUN: %clang_cc1 -fblocks -include %S/objc_exprs.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -x objective-c-header -emit-pch -fblocks -o %t %S/objc_exprs.h +// RUN: %clang_cc1 -fblocks -include-pch %t -fsyntax-only -verify %s + +// Expressions +int *A1 = (objc_string)0; // expected-warning {{aka 'NSString *'}} + +char A2 = (objc_encode){}; // expected-error {{not a compile-time constant}} \ + expected-warning {{char [2]}} + +int *A3 = (objc_protocol)0; // expected-warning {{aka 'Protocol *'}} + + +// Types. +int *T0 = (objc_id_protocol_ty)0; // expected-warning {{aka 'id'}} + +int *T1 = (objc_interface_ty)0; // expected-warning {{aka 'itf *'}} +int *T2 = (objc_qual_interface_ty)0; // expected-warning {{aka 'itf *'}} + +objc_selector_noArgs s1; +objc_selector_oneArg s2; +objc_selector_twoArg s3; + + diff --git a/clang/test/PCH/objc_import.h b/clang/test/PCH/objc_import.h new file mode 100644 index 0000000..8af87ab --- /dev/null +++ b/clang/test/PCH/objc_import.h @@ -0,0 +1,7 @@ +/* For use with the objc_import.m test */ + +@interface TestPCH ++ alloc; +- (void)instMethod; +@end + diff --git a/clang/test/PCH/objc_import.m b/clang/test/PCH/objc_import.m new file mode 100644 index 0000000..277c6dd --- /dev/null +++ b/clang/test/PCH/objc_import.m @@ -0,0 +1,15 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/objc_import.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -x objective-c -emit-pch -o %t %S/objc_import.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +#import "objc_import.h" + +void func() { + TestPCH *xx; + + xx = [TestPCH alloc]; + [xx instMethod]; +} diff --git a/clang/test/PCH/objc_literals.m b/clang/test/PCH/objc_literals.m new file mode 100644 index 0000000..cce3173 --- /dev/null +++ b/clang/test/PCH/objc_literals.m @@ -0,0 +1,66 @@ +// RUN: %clang -cc1 -emit-pch -o %t %s +// RUN: %clang -cc1 -include-pch %t -verify %s +// RUN: %clang -cc1 -include-pch %t -ast-print %s | FileCheck -check-prefix=PRINT %s +// RUN: %clang -cc1 -include-pch %t -emit-llvm -o - %s | FileCheck -check-prefix=IR %s + +#ifndef HEADER +#define HEADER + +typedef unsigned char BOOL; + +@interface NSNumber @end + +@interface NSNumber (NSNumberCreation) ++ (NSNumber *)numberWithChar:(char)value; ++ (NSNumber *)numberWithUnsignedChar:(unsigned char)value; ++ (NSNumber *)numberWithShort:(short)value; ++ (NSNumber *)numberWithUnsignedShort:(unsigned short)value; ++ (NSNumber *)numberWithInt:(int)value; ++ (NSNumber *)numberWithUnsignedInt:(unsigned int)value; ++ (NSNumber *)numberWithLong:(long)value; ++ (NSNumber *)numberWithUnsignedLong:(unsigned long)value; ++ (NSNumber *)numberWithLongLong:(long long)value; ++ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value; ++ (NSNumber *)numberWithFloat:(float)value; ++ (NSNumber *)numberWithDouble:(double)value; ++ (NSNumber *)numberWithBool:(BOOL)value; +@end + +@interface NSArray +@end + +@interface NSArray (NSArrayCreation) ++ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt; +@end + +@interface NSDictionary ++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt; +@end + +// CHECK-IR: define internal void @test_numeric_literals() +static inline void test_numeric_literals() { + // CHECK-PRINT: id intlit = @17 + // CHECK-IR: {{call.*17}} + id intlit = @17; + // CHECK-PRINT: id floatlit = @17.45 + // CHECK-IR: {{call.*1.745}} + id floatlit = @17.45; +} + +static inline void test_array_literals() { + // CHECK-PRINT: id arraylit = @[ @17, @17.45 + id arraylit = @[@17, @17.45]; +} + +static inline void test_dictionary_literals() { + // CHECK-PRINT: id dictlit = @{ @17 : {{@17.45[^,]*}}, @"hello" : @"world" }; + id dictlit = @{@17 : @17.45, @"hello" : @"world" }; +} + +#else +void test_all() { + test_numeric_literals(); + test_array_literals(); + test_dictionary_literals(); +} +#endif diff --git a/clang/test/PCH/objc_literals.mm b/clang/test/PCH/objc_literals.mm new file mode 100644 index 0000000..8ef3351 --- /dev/null +++ b/clang/test/PCH/objc_literals.mm @@ -0,0 +1,65 @@ +// RUN: %clang -cc1 -emit-pch -x objective-c++ -std=c++0x -o %t %s +// RUN: %clang -cc1 -include-pch %t -x objective-c++ -std=c++0x -verify %s +// RUN: %clang -cc1 -include-pch %t -x objective-c++ -std=c++0x -ast-print %s | FileCheck -check-prefix=PRINT %s +// RUN: %clang -cc1 -include-pch %t -x objective-c++ -std=c++0x -emit-llvm -o - %s | FileCheck -check-prefix=IR %s + +#ifndef HEADER +#define HEADER + +typedef unsigned char BOOL; + +@interface NSNumber @end + +@interface NSNumber (NSNumberCreation) ++ (NSNumber *)numberWithChar:(char)value; ++ (NSNumber *)numberWithUnsignedChar:(unsigned char)value; ++ (NSNumber *)numberWithShort:(short)value; ++ (NSNumber *)numberWithUnsignedShort:(unsigned short)value; ++ (NSNumber *)numberWithInt:(int)value; ++ (NSNumber *)numberWithUnsignedInt:(unsigned int)value; ++ (NSNumber *)numberWithLong:(long)value; ++ (NSNumber *)numberWithUnsignedLong:(unsigned long)value; ++ (NSNumber *)numberWithLongLong:(long long)value; ++ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value; ++ (NSNumber *)numberWithFloat:(float)value; ++ (NSNumber *)numberWithDouble:(double)value; ++ (NSNumber *)numberWithBool:(BOOL)value; +@end + +@interface NSArray +@end + +@interface NSArray (NSArrayCreation) ++ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt; +@end + +@interface NSDictionary ++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt; +@end + +template +struct pair { + T first; + U second; +}; + +template +pair make_pair(const T& first, const U& second) { + return { first, second }; +} + +// CHECK-IR: define linkonce_odr void @_Z29variadic_dictionary_expansionIJP8NSStringS1_EJP8NSNumberS3_EEvDp4pairIT_T0_E +template +void variadic_dictionary_expansion(pair... key_values) { + // CHECK-PRINT: id dict = @{ key_values.first : key_values.second... }; + // CHECK-IR: {{call.*objc_msgSend}} + // CHECK-IR: ret void + id dict = @{ key_values.first : key_values.second ... }; +} + +#else +void test_all() { + variadic_dictionary_expansion(make_pair(@"Seventeen", @17), + make_pair(@"YES", @true)); +} +#endif diff --git a/clang/test/PCH/objc_methods.h b/clang/test/PCH/objc_methods.h new file mode 100644 index 0000000..c9b1ad4 --- /dev/null +++ b/clang/test/PCH/objc_methods.h @@ -0,0 +1,11 @@ +/* For use with the methods.m test */ + +@interface TestPCH ++ alloc; +- (instancetype)instMethod; +@end + +@class TestForwardClassDecl; + +// FIXME: @compatibility_alias AliasForTestPCH TestPCH; + diff --git a/clang/test/PCH/objc_methods.m b/clang/test/PCH/objc_methods.m new file mode 100644 index 0000000..e90a463 --- /dev/null +++ b/clang/test/PCH/objc_methods.m @@ -0,0 +1,16 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/objc_methods.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -x objective-c -emit-pch -o %t %S/objc_methods.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +void func() { + TestPCH *xx; + TestForwardClassDecl *yy; +// FIXME: +// AliasForTestPCH *zz; + + xx = [TestPCH alloc]; + [xx instMethod]; +} diff --git a/clang/test/PCH/objc_property.h b/clang/test/PCH/objc_property.h new file mode 100644 index 0000000..2432370 --- /dev/null +++ b/clang/test/PCH/objc_property.h @@ -0,0 +1,12 @@ +/* For use with the objc_property.m PCH test */ +@interface TestProperties +{ + int value; + float percentage; +} + ++ alloc; + +@property int value; +@property float percentage; +@end diff --git a/clang/test/PCH/objc_property.m b/clang/test/PCH/objc_property.m new file mode 100644 index 0000000..b51cd90 --- /dev/null +++ b/clang/test/PCH/objc_property.m @@ -0,0 +1,11 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/objc_property.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -x objective-c -emit-pch -o %t %S/objc_property.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +void func() { + TestProperties *xx = [TestProperties alloc]; + xx.value = 5; +} diff --git a/clang/test/PCH/objc_stmts.h b/clang/test/PCH/objc_stmts.h new file mode 100644 index 0000000..5f705df --- /dev/null +++ b/clang/test/PCH/objc_stmts.h @@ -0,0 +1,22 @@ +/* For use with the methods.m test */ + +@interface A +@end + +@interface B +@end + +@interface TestPCH +- (void)instMethod; +@end + +@implementation TestPCH +- (void)instMethod { + @try { + } @catch(A *a) { + } @catch(B *b) { + } @catch(...) { + } @finally { + } +} +@end diff --git a/clang/test/PCH/objc_stmts.m b/clang/test/PCH/objc_stmts.m new file mode 100644 index 0000000..3bc728c --- /dev/null +++ b/clang/test/PCH/objc_stmts.m @@ -0,0 +1,12 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/objc_stmts.h -emit-llvm -fobjc-exceptions -o - %s +// RUN: %clang_cc1 -include %S/objc_stmts.h -ast-dump -fobjc-exceptions -o - %s 2>&1 | FileCheck %s + +// Test with pch. +// RUN: %clang_cc1 -x objective-c -emit-pch -fobjc-exceptions -o %t %S/objc_stmts.h +// RUN: %clang_cc1 -include-pch %t -emit-llvm -fobjc-exceptions -o - %s +// RUN: %clang_cc1 -include-pch %t -ast-dump -fobjc-exceptions -o - %s 2>&1 | FileCheck %s + +// CHECK: catch parm = "A *a" +// CHECK: catch parm = "B *b" +// CHECK: catch all diff --git a/clang/test/PCH/objcxx-ivar-class.h b/clang/test/PCH/objcxx-ivar-class.h new file mode 100644 index 0000000..5e55658 --- /dev/null +++ b/clang/test/PCH/objcxx-ivar-class.h @@ -0,0 +1,16 @@ +struct S { + S(); + S(const S&); + ~S(); + S& operator= (const S&); +}; + +@interface C { + S position; +} +@property(assign, nonatomic) S position; +@end + +@implementation C + @synthesize position; +@end diff --git a/clang/test/PCH/objcxx-ivar-class.mm b/clang/test/PCH/objcxx-ivar-class.mm new file mode 100644 index 0000000..8214957 --- /dev/null +++ b/clang/test/PCH/objcxx-ivar-class.mm @@ -0,0 +1,15 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/objcxx-ivar-class.h -verify %s -emit-llvm -o - | FileCheck %s + +// Test with pch. +// RUN: %clang_cc1 -x objective-c++-header -emit-pch -o %t %S/objcxx-ivar-class.h +// RUN: %clang_cc1 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s + +// CHECK: [C position] +// CHECK: call {{.*}} @_ZN1SC1ERKS_ + +// CHECK: [C setPosition:] +// CHECK: call %struct.S* @_ZN1SaSERKS_ + +// CHECK: [C .cxx_destruct] +// CHECK: [C .cxx_construct] diff --git a/clang/test/PCH/opencl-extensions.cl b/clang/test/PCH/opencl-extensions.cl new file mode 100644 index 0000000..a22b007 --- /dev/null +++ b/clang/test/PCH/opencl-extensions.cl @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -emit-pch -o %t %s +// RUN: %clang_cc1 -include-pch %t -fsyntax-only %s + +#ifndef HEADER +#define HEADER +// Header. + +#pragma OPENCL EXTENSION cl_khr_fp64 : enable + +#else +// Using the header. + +void test(void) { + double d; +} + +#endif diff --git a/clang/test/PCH/pchpch.c b/clang/test/PCH/pchpch.c new file mode 100644 index 0000000..d68a6ad --- /dev/null +++ b/clang/test/PCH/pchpch.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-pch -o %t1 %S/pchpch1.h +// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-pch -o %t2 %S/pchpch2.h -include-pch %t1 +// RUN: %clang_cc1 -triple i386-unknown-unknown -fsyntax-only %s -include-pch %t2 + +// The purpose of this test is to make sure that a PCH created while including +// an existing PCH can be loaded. diff --git a/clang/test/PCH/pchpch1.h b/clang/test/PCH/pchpch1.h new file mode 100644 index 0000000..e69de29 diff --git a/clang/test/PCH/pchpch2.h b/clang/test/PCH/pchpch2.h new file mode 100644 index 0000000..e69de29 diff --git a/clang/test/PCH/pending-ids.m b/clang/test/PCH/pending-ids.m new file mode 100644 index 0000000..b612d89 --- /dev/null +++ b/clang/test/PCH/pending-ids.m @@ -0,0 +1,33 @@ +// Test for rdar://10278815 + +// Without PCH +// RUN: %clang_cc1 -fsyntax-only -verify -include %s %s + +// With PCH +// RUN: %clang_cc1 %s -emit-pch -o %t +// RUN: %clang_cc1 -emit-llvm-only -verify %s -include-pch %t -g + +#ifndef HEADER +#define HEADER +//===----------------------------------------------------------------------===// +// Header + +typedef char BOOL; + +@interface NSString ++ (BOOL)meth; +@end + +static NSString * const cake = @"cake"; + +//===----------------------------------------------------------------------===// +#else +//===----------------------------------------------------------------------===// + +@interface Foo { + BOOL ivar; +} +@end + +//===----------------------------------------------------------------------===// +#endif diff --git a/clang/test/PCH/pr4489.c b/clang/test/PCH/pr4489.c new file mode 100644 index 0000000..033e55b --- /dev/null +++ b/clang/test/PCH/pr4489.c @@ -0,0 +1,48 @@ +// RUN: %clang -x c-header -o %t.pch %s +// RUN: echo > %t.empty.c +// RUN: %clang -include %t -x c %t.empty.c -emit-llvm -S -o - + +// FIXME: This test is forcibly disabled, it is flaky on the clang-i686-xp-msvc9 +// buildbot. +// +// RUN: false +// XFAIL: * + +// PR 4489: Crash with PCH +// PR 4492: Crash with PCH (round two) +// PR 4509: Crash with PCH (round three) +typedef struct _IO_FILE FILE; +extern int fprintf (struct _IO_FILE *__restrict __stream, + __const char *__restrict __format, ...); + +int x(void) +{ + switch (1) { + case 2: ; + int y = 0; + } +} + +void y(void) { + extern char z; + fprintf (0, "a"); +} + +struct y0 { int i; } y0[1] = {}; + +void x0(void) +{ + extern char z0; + fprintf (0, "a"); +} + +void x1(void) +{ + fprintf (0, "asdf"); +} + +void y1(void) +{ + extern char e; + fprintf (0, "asdf"); +} diff --git a/clang/test/PCH/pragma-diag-section.cpp b/clang/test/PCH/pragma-diag-section.cpp new file mode 100644 index 0000000..5b996bb --- /dev/null +++ b/clang/test/PCH/pragma-diag-section.cpp @@ -0,0 +1,29 @@ +// Test this without pch. +// RUN: %clang_cc1 %s -include %s -verify -fsyntax-only + +// Test with pch. +// RUN: %clang_cc1 %s -emit-pch -o %t +// RUN: %clang_cc1 %s -include-pch %t -verify -fsyntax-only + +#ifndef HEADER +#define HEADER + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wtautological-compare" +template +struct TS { + void m() { + T a = 0; + T b = a==a; + } +}; +#pragma clang diagnostic pop + +#else + +void f() { + TS ts; + ts.m(); +} + +#endif diff --git a/clang/test/PCH/pragma-diag.c b/clang/test/PCH/pragma-diag.c new file mode 100644 index 0000000..b304c4b --- /dev/null +++ b/clang/test/PCH/pragma-diag.c @@ -0,0 +1,20 @@ +// Test this without pch. +// RUN: %clang_cc1 %s -include %s -verify -fsyntax-only + +// Test with pch. +// RUN: %clang_cc1 %s -emit-pch -o %t +// RUN: %clang_cc1 %s -include-pch %t -verify -fsyntax-only + +#ifndef HEADER +#define HEADER + +#pragma clang diagnostic ignored "-Wtautological-compare" + +#else + +void f() { + int a = 0; + int b = a==a; +} + +#endif diff --git a/clang/test/PCH/pragma-weak.c b/clang/test/PCH/pragma-weak.c new file mode 100644 index 0000000..18b45c8 --- /dev/null +++ b/clang/test/PCH/pragma-weak.c @@ -0,0 +1,10 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/pragma-weak.h %s -verify -emit-llvm -o - | FileCheck %s + +// Test with pch. +// RUN: %clang_cc1 -x c-header -emit-pch -o %t %S/pragma-weak.h +// RUN: %clang_cc1 -include-pch %t %s -verify -emit-llvm -o - | FileCheck %s + +// CHECK: @weakvar = weak global i32 0 +int weakvar; +// expected-warning {{weak identifier 'undeclaredvar' never declared}} diff --git a/clang/test/PCH/pragma-weak.h b/clang/test/PCH/pragma-weak.h new file mode 100644 index 0000000..42ecd50 --- /dev/null +++ b/clang/test/PCH/pragma-weak.h @@ -0,0 +1,10 @@ +// Header for PCH test pragma-weak.c + +#pragma weak weakvar + + + + + + +#pragma weak undeclaredvar diff --git a/clang/test/PCH/preamble.c b/clang/test/PCH/preamble.c new file mode 100644 index 0000000..6a61fa1 --- /dev/null +++ b/clang/test/PCH/preamble.c @@ -0,0 +1,23 @@ +// Check that using the preamble option actually skips the preamble. + +// RUN: %clang_cc1 -emit-pch -o %t %S/Inputs/preamble.h -DFOO=f +// RUN: %clang_cc1 -include-pch %t -preamble-bytes=317,1 -DFOO=f -verify %s -emit-llvm -o - | FileCheck %s + +float f(int); // Not an error, because we skip this via the preamble! + + + + + + + + + + + + +int g(int x) { + return FOO(x); +} + +// CHECK: call {{.*}} @f( diff --git a/clang/test/PCH/preprocess.c b/clang/test/PCH/preprocess.c new file mode 100644 index 0000000..8bf841f --- /dev/null +++ b/clang/test/PCH/preprocess.c @@ -0,0 +1,8 @@ +// Check that -E mode is invariant when using an implicit PCH. + +// RUN: %clang_cc1 -include %S/preprocess.h -E -o %t.orig %s +// RUN: %clang_cc1 -emit-pch -o %t %S/preprocess.h +// RUN: %clang_cc1 -include-pch %t -E -o %t.from_pch %s +// RUN: diff %t.orig %t.from_pch + +a_typedef a_value; diff --git a/clang/test/PCH/preprocess.h b/clang/test/PCH/preprocess.h new file mode 100644 index 0000000..39fa006 --- /dev/null +++ b/clang/test/PCH/preprocess.h @@ -0,0 +1,7 @@ +// Helper header for preprocess.c PCH test +#ifndef PREPROCESS_H +#define PREPROCESS_H + +typedef int a_typedef; + +#endif // PREPROCESS_H diff --git a/clang/test/PCH/pth.c b/clang/test/PCH/pth.c new file mode 100644 index 0000000..1262f8a --- /dev/null +++ b/clang/test/PCH/pth.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-pth -o %t %S/pth.h +// RUN: %clang_cc1 -triple i386-unknown-unknown -include-pth %t -fsyntax-only %s 2>&1 | FileCheck %s + +#error This is the only diagnostic + +// CHECK: This is the only diagnostic +// CHECK: 1 error generated. \ No newline at end of file diff --git a/clang/test/PCH/pth.h b/clang/test/PCH/pth.h new file mode 100644 index 0000000..9ae7021 --- /dev/null +++ b/clang/test/PCH/pth.h @@ -0,0 +1,12 @@ +// This case came up when using PTH with Boost (). + +# ifndef R8227989_PREPROCESSOR_CONFIG_CONFIG_HPP +# ifndef R8227989_PP_CONFIG_FLAGS +# endif +# +# ifndef R8227989_PP_CONFIG_ERRORS +# ifdef NDEBUG +# endif +# endif +# endif + diff --git a/clang/test/PCH/rdar10830559.cpp b/clang/test/PCH/rdar10830559.cpp new file mode 100644 index 0000000..b9b6437 --- /dev/null +++ b/clang/test/PCH/rdar10830559.cpp @@ -0,0 +1,35 @@ +// Test this without pch. +// RUN: %clang_cc1 -fsyntax-only -emit-llvm-only %s + +// Test with pch. +// RUN: touch %t.empty.cpp +// RUN: %clang_cc1 -emit-pch -o %t %s +// RUN: %clang_cc1 -include-pch %t -emit-llvm-only %t.empty.cpp + +// rdar://10830559 + +#pragma ms_struct on + +template< typename T > +class Templated +{ +public: + struct s; +}; + + +class Foo +{ +private: + + class Bar + { + private: + class BarTypes { public: virtual void Func(); }; + class BarImpl {}; + friend class Foo; + }; + + + friend class Templated< Bar::BarImpl >::s; +}; diff --git a/clang/test/PCH/rdar8852495.c b/clang/test/PCH/rdar8852495.c new file mode 100644 index 0000000..fb465a3 --- /dev/null +++ b/clang/test/PCH/rdar8852495.c @@ -0,0 +1,26 @@ +// Test this without pch. +// RUN: %clang_cc1 %s -include %s -verify -fsyntax-only -Wno-sign-compare -Wtautological-compare + +// Test with pch. +// RUN: %clang_cc1 %s -emit-pch -o %t -Wsign-compare -Wtautological-compare +// RUN: %clang_cc1 %s -include-pch %t -verify -fsyntax-only -Wno-sign-compare -Wtautological-compare + +// This tests that diagnostic mappings from PCH are propagated for #pragma +// diagnostics but not for command-line flags. + +#ifndef HEADER +#define HEADER + +#pragma clang diagnostic ignored "-Wtautological-compare" + +#else + +int f() { + int a; + int b = a==a; + unsigned x; + signed y; + return x == y; +} + +#endif diff --git a/clang/test/PCH/reinclude.cpp b/clang/test/PCH/reinclude.cpp new file mode 100644 index 0000000..97e22cf --- /dev/null +++ b/clang/test/PCH/reinclude.cpp @@ -0,0 +1,10 @@ +// Test without PCH +// RUN: %clang_cc1 %s -include %S/reinclude1.h -include %S/reinclude2.h -fsyntax-only -verify + +// RUN: %clang_cc1 -x c++-header %S/reinclude1.h -emit-pch -o %t1 +// RUN: %clang_cc1 -x c++-header %S/reinclude2.h -include-pch %t1 -emit-pch -o %t2 +// RUN: %clang_cc1 %s -include-pch %t2 -fsyntax-only -verify +// RUN: %clang_cc1 -x c++-header %S/reinclude2.h -include-pch %t1 -emit-pch -o %t2 +// RUN: %clang_cc1 %s -include-pch %t2 -fsyntax-only -verify + +int q2 = A::y; diff --git a/clang/test/PCH/reinclude1.h b/clang/test/PCH/reinclude1.h new file mode 100644 index 0000000..baeb677 --- /dev/null +++ b/clang/test/PCH/reinclude1.h @@ -0,0 +1,7 @@ +namespace A { + int x; + int y; +} + +int foo; +#define foo foo diff --git a/clang/test/PCH/reinclude2.h b/clang/test/PCH/reinclude2.h new file mode 100644 index 0000000..2aa6d31 --- /dev/null +++ b/clang/test/PCH/reinclude2.h @@ -0,0 +1 @@ +int q1 = A::x; diff --git a/clang/test/PCH/reloc.c b/clang/test/PCH/reloc.c new file mode 100644 index 0000000..4c426e4 --- /dev/null +++ b/clang/test/PCH/reloc.c @@ -0,0 +1,14 @@ +// RUN: %clang -target x86_64-apple-darwin10 --relocatable-pch -o %t \ +// RUN: -isysroot %S/libroot %S/libroot/usr/include/reloc.h +// RUN: %clang -target x86_64-apple-darwin10 -fsyntax-only \ +// RUN: -include-pch %t -isysroot %S/libroot %s -Xclang -verify +// RUN: not %clang -target x86_64-apple-darwin10 -include-pch %t %s + +#include + +int x = 2; // expected-error{{redefinition}} +int y = 5; // expected-error{{redefinition}} + + +// expected-note{{previous definition}} +// expected-note{{previous definition}} diff --git a/clang/test/PCH/replaced-decl.m b/clang/test/PCH/replaced-decl.m new file mode 100644 index 0000000..b9fee95 --- /dev/null +++ b/clang/test/PCH/replaced-decl.m @@ -0,0 +1,22 @@ +// Without PCH +// RUN: %clang_cc1 -fsyntax-only -verify %s -include %s -include %s + +// With PCH +// RUN: %clang_cc1 -fsyntax-only -verify %s -chain-include %s -chain-include %s + +#ifndef HEADER1 +#define HEADER1 + +@class I; + +#elif !defined(HEADER2) +#define HEADER2 + +@interface I // expected-note {{previous}} +@end + +#else + +typedef int I; // expected-error {{redefinition}} + +#endif diff --git a/clang/test/PCH/selector-warning.h b/clang/test/PCH/selector-warning.h new file mode 100644 index 0000000..bd41929 --- /dev/null +++ b/clang/test/PCH/selector-warning.h @@ -0,0 +1,24 @@ +typedef struct objc_selector *SEL; + +@interface Foo +- (void) NotOK; +@end + +@implementation Foo +- (void) foo +{ + SEL a = @selector(b1ar); + a = @selector(b1ar); + a = @selector(bar); + a = @selector(ok); // expected-warning {{unimplemented selector 'ok'}} + a = @selector(ok); + a = @selector(NotOK); // expected-warning {{unimplemented selector 'NotOK'}} + a = @selector(NotOK); + + a = @selector(clNotOk); // expected-warning {{unimplemented selector 'clNotOk'}} + + a = @selector (cl1); + a = @selector (cl2); + a = @selector (instNotOk); // expected-warning {{unimplemented selector 'instNotOk'}} +} +@end diff --git a/clang/test/PCH/selector-warning.m b/clang/test/PCH/selector-warning.m new file mode 100644 index 0000000..413f64f --- /dev/null +++ b/clang/test/PCH/selector-warning.m @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -x objective-c -emit-pch -o %t.h.pch %S/selector-warning.h +// RUN: %clang_cc1 -include-pch %t.h.pch %s + +@interface Bar ++ (void) clNotOk; +- (void) instNotOk; ++ (void) cl1; +@end + +@implementation Bar +- (void) bar {} ++ (void) cl1 {} ++ (void) cl2 {} +@end + +@implementation Bar(CAT) +- (void) b1ar {} +@end + diff --git a/clang/test/PCH/single-token-macro.c b/clang/test/PCH/single-token-macro.c new file mode 100644 index 0000000..29edb75 --- /dev/null +++ b/clang/test/PCH/single-token-macro.c @@ -0,0 +1,24 @@ +// rdar://10588825 + +// Test this without pch. +// RUN: %clang_cc1 %s -include %s -verify -fsyntax-only + +// Test with pch. +// RUN: %clang_cc1 %s -emit-pch -o %t +// RUN: %clang_cc1 %s -include-pch %t -verify -fsyntax-only + +#ifndef HEADER +#define HEADER + +#define __stdcall +#define STDCALL __stdcall + +void STDCALL Foo(void); + +#else + +void STDCALL Foo(void) +{ +} + +#endif diff --git a/clang/test/PCH/source-manager-stack.c b/clang/test/PCH/source-manager-stack.c new file mode 100644 index 0000000..8f5da2f --- /dev/null +++ b/clang/test/PCH/source-manager-stack.c @@ -0,0 +1,12 @@ +// Test that the source manager has the "proper" idea about the include stack +// when using PCH. + +// RUN: echo 'int x;' > %t.prefix.h +// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -include %t.prefix.h %s 2> %t.diags.no_pch.txt +// RUN: %clang_cc1 -emit-pch -o %t.prefix.pch %t.prefix.h +// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -include-pch %t.prefix.pch %s 2> %t.diags.pch.txt +// RUN: diff %t.diags.no_pch.txt %t.diags.pch.txt +// XFAIL: * +// PR5662 + +float x; diff --git a/clang/test/PCH/stmts.c b/clang/test/PCH/stmts.c new file mode 100644 index 0000000..6def453 --- /dev/null +++ b/clang/test/PCH/stmts.c @@ -0,0 +1,14 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/stmts.h -fsyntax-only -emit-llvm -o - %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t %S/stmts.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -emit-llvm -o - %s + +void g0(void) { f0(5); } +int g1(int x) { return f1(x); } +const char* query_name(void) { return what_is_my_name(); } + +int use_computed_goto(int x) { return computed_goto(x); } + +int get_weird_max(int x, int y) { return weird_max(x, y); } diff --git a/clang/test/PCH/stmts.h b/clang/test/PCH/stmts.h new file mode 100644 index 0000000..4267e2c --- /dev/null +++ b/clang/test/PCH/stmts.h @@ -0,0 +1,96 @@ +// Header for PCH test stmts.c + +void f0(int x) { + // NullStmt + ; + // IfStmt + if (x) { + } else if (x + 1) { + } + + switch (x) { + case 0: + x = 17; + break; + + case 1: + break; + + default: + switch (x >> 1) { + case 7: + // fall through + case 9: + break; + } + x += 2; + break; + } + + while (x > 20) { + if (x > 30) { + --x; + continue; + } else if (x < 5) + break; + else + goto done; + } + + do { + x++; + } while (x < 10); + + almost_done: + for (int y = x; y < 20; ++y) { + if (x + y == 12) + return; + else if (x - y == 7) + goto almost_done; + } + + done: + x = x + 2; + + int z = x, *y, j = 5; +} + +int f1(int x) { + switch (x) { + case 17: + return 12; + + default: + break; + } + + // variable-length array + int array[x * 17 + 3]; + + return x*2; +} + +const char* what_is_my_name(void) { return __func__; } + +int computed_goto(int x) { + start: + x = x << 1; + void *location = &&start; + + if (x > 17) + location = &&done; + + while (x > 12) { + --x; + if (x == 15) + goto *location; + } + + done: + return 5; +} + +#define maxint(a,b) ({int _a = (a), _b = (b); _a > _b ? _a : _b; }) +int weird_max(int x, int y) { + return maxint(++x, --y); +} diff --git a/clang/test/PCH/struct.c b/clang/test/PCH/struct.c new file mode 100644 index 0000000..3e9d188 --- /dev/null +++ b/clang/test/PCH/struct.c @@ -0,0 +1,28 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/struct.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t %S/struct.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +struct Point *p1; + +float getX(struct Point *p1) { + return p1->x; +} + +void *get_fun_ptr() { + return fun->is_ptr? fun->ptr : 0; +} + +struct Fun2 { + int very_fun; +}; + +int get_very_fun() { + return fun2->very_fun; +} + +int *int_ptr_fail = &fun->is_ptr; // expected-error{{address of bit-field requested}} + +struct Nested nested = { 1, 2 }; diff --git a/clang/test/PCH/struct.h b/clang/test/PCH/struct.h new file mode 100644 index 0000000..2ffdd4a --- /dev/null +++ b/clang/test/PCH/struct.h @@ -0,0 +1,29 @@ +// Used with the struct.c test + +struct Point { + float x, y, z; +}; + +struct Point2 { + float xValue, yValue, zValue; +}; + +struct Fun; + +struct Fun *fun; + +struct Fun { + int is_ptr : 1; + + union { + void *ptr; + int *integer; + }; +}; + +struct Fun2; +struct Fun2 *fun2; + +struct S { + struct Nested { int x, y; } nest; +}; diff --git a/clang/test/PCH/subscripting-literals.m b/clang/test/PCH/subscripting-literals.m new file mode 100644 index 0000000..1675373 --- /dev/null +++ b/clang/test/PCH/subscripting-literals.m @@ -0,0 +1,47 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o %t.nopch.ll %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-pch -o %t.pch %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o %t.pch.ll %s -include-pch %t.pch +// RUN: diff %t.nopch.ll %t.pch.ll + +#ifndef HEADER +#define HEADER + +@interface NSArray +- (id)objectAtIndexedSubscript:(int)index; ++ (id)arrayWithObjects:(id *)objects count:(unsigned)count; +@end + +@interface NSMutableArray : NSArray +- (void)setObject:(id)object atIndexedSubscript:(int)index; +@end + +@interface NSDictionary +- (id)objectForKeyedSubscript:(id)key; ++ (id)dictionaryWithObjects:(id *)objects forKeys:(id *)keys count:(unsigned)count; +@end + +@interface NSMutableDictionary : NSDictionary +- (void)setObject:(id)object forKeyedSubscript:(id)key; +@end + +@interface NSNumber ++ (NSNumber *)numberWithInt:(int)value; +@end + +@class NSString; + +id testArray(int idx, id p) { + NSMutableArray *array; + array[idx] = p; + NSArray *arr = @[ p, @7 ]; + return array[idx]; +} + +void testDict(NSString *key, id newObject, id oldObject) { + NSMutableDictionary *dictionary; + oldObject = dictionary[key]; + dictionary[key] = newObject; + NSDictionary *dict = @{ key: newObject, key: oldObject }; +} + +#endif diff --git a/clang/test/PCH/tentative-defs.c b/clang/test/PCH/tentative-defs.c new file mode 100644 index 0000000..0072818 --- /dev/null +++ b/clang/test/PCH/tentative-defs.c @@ -0,0 +1,9 @@ +// Test with pch. +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -emit-pch -o %t.pch %S/tentative-defs.h +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -include-pch %t.pch -verify -emit-llvm -o %t %s + +// RUN: grep "@variable = common global i32 0" %t | count 1 +// RUN: grep "@incomplete_array = common global .*1 x i32" %t | count 1 + + +// FIXME: tentative-defs.h expected-warning{{tentative}} diff --git a/clang/test/PCH/tentative-defs.h b/clang/test/PCH/tentative-defs.h new file mode 100644 index 0000000..4675d9a --- /dev/null +++ b/clang/test/PCH/tentative-defs.h @@ -0,0 +1,9 @@ +// Header for PCH test tentative-defs.c +int variable; + + + + + + +int incomplete_array[]; diff --git a/clang/test/PCH/types.c b/clang/test/PCH/types.c new file mode 100644 index 0000000..fc37a9c --- /dev/null +++ b/clang/test/PCH/types.c @@ -0,0 +1,73 @@ +// Test this without pch. +// RUN: %clang_cc1 -fblocks -include %S/types.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -fblocks -o %t %S/types.h +// RUN: %clang_cc1 -fblocks -include-pch %t -fsyntax-only -verify %s -ast-print + +typedef int INT; +INT int_value; + +__attribute__((address_space(1))) int int_as_one; + +// TYPE_EXT_QUAL +ASInt *as_int_ptr1 = &int_value; // expected-error{{changes address space of pointer}} +ASInt *as_int_ptr2 = &int_as_one; + +// TYPE_COMPLEX +_Complex float Cfloat_val; +Cfloat *Cfloat_ptr = &Cfloat_val; + +// TYPE_ATOMIC +_Atomic(int) AtomicInt_val; +AtomicInt *AtomicInt_ptr = &AtomicInt_val; + +// TYPE_POINTER +int_ptr int_value_ptr = &int_value; + +// TYPE_BLOCK_POINTER +void test_block_ptr(Block *bl) { + *bl = ^(int x, float f) { return x; }; +} + +// TYPE_CONSTANT_ARRAY +five_ints fvi = { 1, 2, 3, 4, 5 }; + +// TYPE_INCOMPLETE_ARRAY +float_array fa1 = { 1, 2, 3 }; +float_array fa2 = { 1, 2, 3, 4, 5, 6, 7, 8 }; + +// TYPE_VARIABLE_ARRAY in stmts.[ch] + +// TYPE_VECTOR +float4 f4 = { 1.0, 2.0, 3.0, 4.0 }; + +// TYPE_EXT_VECTOR +ext_float4 ef4 = { 1.0, 2.0, 3.0, 4.0 }; + +// TYPE_FUNCTION_NO_PROTO +noproto np1; +int np1(x, y) + int x; + float y; +{ + return x; +} + +// TYPE_FUNCTION_PROTO +proto p1; +float p1(float x, float y, ...) { + return x + y; +} +proto *p2 = p1; + +// TYPE_TYPEDEF +int_ptr_ptr ipp = &int_value_ptr; + +// TYPE_TYPEOF_EXPR +typeof_17 *t17 = &int_value; +struct S { int x, y; }; +typeof_17 t17_2 = (struct S){1, 2}; // expected-error{{initializing 'typeof_17' (aka 'int') with an expression of incompatible type 'struct S'}} + +// TYPE_TYPEOF +int_ptr_ptr2 ipp2 = &int_value_ptr; diff --git a/clang/test/PCH/types.h b/clang/test/PCH/types.h new file mode 100644 index 0000000..7df3f99 --- /dev/null +++ b/clang/test/PCH/types.h @@ -0,0 +1,50 @@ +/* Used with the types.c test */ + +// TYPE_EXT_QUAL +typedef __attribute__((address_space(1))) int ASInt; + +// TYPE_COMPLEX +typedef _Complex float Cfloat; + +// TYPE_ATOMIC +typedef _Atomic(int) AtomicInt; + +// TYPE_POINTER +typedef int * int_ptr; + +// TYPE_BLOCK_POINTER +typedef int (^Block)(int, float); + +// TYPE_CONSTANT_ARRAY +typedef int five_ints[5]; + +// TYPE_INCOMPLETE_ARRAY +typedef float float_array[]; + +// TYPE_VARIABLE_ARRAY in stmts.[ch] + +// TYPE_VECTOR +typedef float float4 __attribute__((vector_size(16))); + +// TYPE_EXT_VECTOR +typedef float ext_float4 __attribute__((ext_vector_type(4))); + +// TYPE_FUNCTION_NO_PROTO +typedef int noproto(); + +// TYPE_FUNCTION_PROTO +typedef float proto(float, float, ...); + +// TYPE_TYPEDEF +typedef int_ptr * int_ptr_ptr; + +// TYPE_TYPEOF_EXPR +typedef typeof(17) typeof_17; + +// TYPE_TYPEOF +typedef typeof(int_ptr *) int_ptr_ptr2; + +struct S2; +struct S2 {}; +enum E; +enum E { myenum }; diff --git a/clang/test/PCH/typo.cpp b/clang/test/PCH/typo.cpp new file mode 100644 index 0000000..f8161d1 --- /dev/null +++ b/clang/test/PCH/typo.cpp @@ -0,0 +1,17 @@ + +// In header: expected-note{{'boost::function' declared here}} + + +// In header: expected-note{{'boost::graph::adjacency_list' declared here}} + + + +adjacent_list g; // expected-error{{no template named 'adjacent_list'; did you mean 'boost::graph::adjacency_list'?}} +Function f; // expected-error{{no template named 'Function'; did you mean 'boost::function'?}} + +// Without PCH +// RUN: %clang_cc1 -include %S/Inputs/typo.hpp -verify %s + +// With PCH +// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/Inputs/typo.hpp +// RUN: %clang_cc1 -include-pch %t -verify %s diff --git a/clang/test/PCH/typo.m b/clang/test/PCH/typo.m new file mode 100644 index 0000000..c6f0275 --- /dev/null +++ b/clang/test/PCH/typo.m @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -x objective-c-header -emit-pch -o %t %S/Inputs/typo.h +// RUN: %clang_cc1 -include-pch %t -verify %s +// In header: expected-note{{declared here}} +void f() { + [NSstring alloc]; // expected-error{{unknown receiver 'NSstring'; did you mean 'NSString'?}} +} diff --git a/clang/test/PCH/typo2.cpp b/clang/test/PCH/typo2.cpp new file mode 100644 index 0000000..f9b4c83 --- /dev/null +++ b/clang/test/PCH/typo2.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -emit-pch %s -o %t.pch +// RUN: %clang_cc1 -include-pch %t.pch %s -verify + +#ifndef HEADER_INCLUDED +#define HEADER_INCLUDED + +void func(struct Test); // expected-note{{'Test' declared here}} + +#else + +::Yest *T; // expected-error{{did you mean 'Test'}} + +#endif diff --git a/clang/test/PCH/va_arg.c b/clang/test/PCH/va_arg.c new file mode 100644 index 0000000..1fb2a83 --- /dev/null +++ b/clang/test/PCH/va_arg.c @@ -0,0 +1,12 @@ +// Test this without pch. +// RUN: %clang_cc1 -triple=x86_64-unknown-freebsd7.0 -include %S/va_arg.h %s -emit-llvm -o - + +// Test with pch. +// RUN: %clang_cc1 -triple=x86_64-unknown-freebsd7.0 -emit-pch -o %t %S/va_arg.h +// RUN: %clang_cc1 -triple=x86_64-unknown-freebsd7.0 -include-pch %t %s -emit-llvm -o - + +char *g0(char** argv, int argc) { return argv[argc]; } + +char *g(char **argv) { + f(g0, argv, 1, 2, 3); +} diff --git a/clang/test/PCH/va_arg.cpp b/clang/test/PCH/va_arg.cpp new file mode 100644 index 0000000..7c8dc6b --- /dev/null +++ b/clang/test/PCH/va_arg.cpp @@ -0,0 +1,16 @@ +// Test this without pch. +// RUN: %clang_cc1 -triple=x86_64-unknown-freebsd7.0 -include %S/Inputs/va_arg.h %s -emit-llvm -o - + +// Test with pch. +// RUN: %clang_cc1 -triple=x86_64-unknown-freebsd7.0 -emit-pch -x c++-header -o %t %S/Inputs/va_arg.h +// RUN: %clang_cc1 -triple=x86_64-unknown-freebsd7.0 -include-pch %t %s -emit-llvm -o - + +typedef __SIZE_TYPE__ size_t; + +extern "C" { +int vsnprintf(char * , size_t, const char * , va_list) ; +} + +void f(char *buffer, unsigned count, const char* format, va_list argptr) { + vsnprintf(buffer, count, format, argptr); +} diff --git a/clang/test/PCH/va_arg.h b/clang/test/PCH/va_arg.h new file mode 100644 index 0000000..4a8e510 --- /dev/null +++ b/clang/test/PCH/va_arg.h @@ -0,0 +1,8 @@ +// Header for PCH test va_arg.c + +typedef __builtin_va_list va_list; +char *f (char * (*g) (char **, int), char **p, ...) { + char *s; + va_list v; + s = g (p, __builtin_va_arg(v, int)); +} diff --git a/clang/test/PCH/variables.c b/clang/test/PCH/variables.c new file mode 100644 index 0000000..9f90b37 --- /dev/null +++ b/clang/test/PCH/variables.c @@ -0,0 +1,47 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %s -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t %s +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +#ifndef HEADER +#define HEADER + +extern float y; +extern int *ip, x; + +float z; // expected-note{{previous}} + +int z2 = 17; // expected-note{{previous}} + +#define MAKE_HAPPY(X) X##Happy +int MAKE_HAPPY(Very); // expected-note{{previous definition is here}} + +#define A_MACRO_IN_THE_PCH 492 +#define FUNCLIKE_MACRO(X, Y) X ## Y + +#define PASTE2(x,y) x##y +#define PASTE1(x,y) PASTE2(x,y) +#define UNIQUE(x) PASTE1(x,__COUNTER__) + +int UNIQUE(a); // a0 +int UNIQUE(a); // a1 + +#else + +int *ip2 = &x; +float *fp = &ip; // expected-warning{{incompatible pointer types}} +double z; // expected-error{{redefinition}} +int z2 = 18; // expected-error{{redefinition}} +double VeryHappy; // expected-error{{redefinition}} + +int Q = A_MACRO_IN_THE_PCH; + +int R = FUNCLIKE_MACRO(A_MACRO_, IN_THE_PCH); + + +int UNIQUE(a); // a2 +int *Arr[] = { &a0, &a1, &a2 }; + +#endif diff --git a/clang/test/PCH/variables.h b/clang/test/PCH/variables.h new file mode 100644 index 0000000..23d2cd3 --- /dev/null +++ b/clang/test/PCH/variables.h @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -emit-pch -o variables.h.pch variables.h +// Do not mess with the whitespace in this file. It's important. + + + + +extern float y; +extern int *ip, x; + +float z; + +int z2 = 17; + +#define MAKE_HAPPY(X) X##Happy +int MAKE_HAPPY(Very); + +#define A_MACRO_IN_THE_PCH 492 +#define FUNCLIKE_MACRO(X, Y) X ## Y + +#define PASTE2(x,y) x##y +#define PASTE1(x,y) PASTE2(x,y) +#define UNIQUE(x) PASTE1(x,__COUNTER__) + +int UNIQUE(a); // a0 +int UNIQUE(a); // a1 diff --git a/clang/test/PCH/working-directory.cpp b/clang/test/PCH/working-directory.cpp new file mode 100644 index 0000000..e77d31b --- /dev/null +++ b/clang/test/PCH/working-directory.cpp @@ -0,0 +1,12 @@ +// Test this without pch. +// RUN: %clang_cc1 -working-directory %S -I. -include working-directory.h %s -Wunused + +// Test with pch. +// RUN: %clang_cc1 -working-directory %S -x c++-header -emit-pch -o %t.pch -I. working-directory.h +// RUN: %clang_cc1 -include-pch %t.pch -fsyntax-only %s -Wunused + +void f() { + // Instantiating A will trigger a warning, which will end up trying to get the path to + // the header that contains A. + A b; +} diff --git a/clang/test/PCH/working-directory.h b/clang/test/PCH/working-directory.h new file mode 100644 index 0000000..02a60e3 --- /dev/null +++ b/clang/test/PCH/working-directory.h @@ -0,0 +1 @@ +#include -- cgit v1.2.3