summaryrefslogtreecommitdiff
path: root/clang/test/Sema
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/Sema')
-rw-r--r--clang/test/Sema/128bitint.c13
-rw-r--r--clang/test/Sema/2007-10-01-BuildArrayRef.c20
-rw-r--r--clang/test/Sema/2009-03-09-WeakDeclarations-1.c16
-rw-r--r--clang/test/Sema/2009-04-22-UnknownSize.c4
-rw-r--r--clang/test/Sema/2009-07-17-VoidParameter.c4
-rw-r--r--clang/test/Sema/2010-05-31-palignr.c22
-rw-r--r--clang/test/Sema/Inputs/conversion.h4
-rw-r--r--clang/test/Sema/Inputs/pragma-arc-cf-code-audited.h16
-rw-r--r--clang/test/Sema/Inputs/unused-expr-system-header.h23
-rw-r--r--clang/test/Sema/MicrosoftCompatibility.c16
-rw-r--r--clang/test/Sema/MicrosoftExtensions.c102
-rw-r--r--clang/test/Sema/PR2727.c8
-rw-r--r--clang/test/Sema/PR2728.c9
-rw-r--r--clang/test/Sema/PR2919-builtin-types-compat-strips-crv.c7
-rw-r--r--clang/test/Sema/PR2923.c12
-rw-r--r--clang/test/Sema/PR2963-enum-constant.c17
-rw-r--r--clang/test/Sema/__try.c172
-rw-r--r--clang/test/Sema/address-constant.c10
-rw-r--r--clang/test/Sema/address_spaces.c50
-rw-r--r--clang/test/Sema/align-arm-apcs.c4
-rw-r--r--clang/test/Sema/align-x86-64.c25
-rw-r--r--clang/test/Sema/align-x86.c48
-rw-r--r--clang/test/Sema/alignas.c19
-rw-r--r--clang/test/Sema/altivec-init.c47
-rw-r--r--clang/test/Sema/annotate.c10
-rw-r--r--clang/test/Sema/anonymous-struct-union-c11.c19
-rw-r--r--clang/test/Sema/anonymous-struct-union.c110
-rw-r--r--clang/test/Sema/arg-duplicate.c15
-rw-r--r--clang/test/Sema/arg-scope-c99.c2
-rw-r--r--clang/test/Sema/arg-scope.c5
-rw-r--r--clang/test/Sema/arm-layout.c53
-rw-r--r--clang/test/Sema/arm-neon-types.c35
-rw-r--r--clang/test/Sema/array-bounds-ptr-arith.c21
-rw-r--r--clang/test/Sema/array-constraint.c52
-rw-r--r--clang/test/Sema/array-declared-as-incorrect-type.c16
-rw-r--r--clang/test/Sema/array-init.c289
-rw-r--r--clang/test/Sema/array-size-64.c7
-rw-r--r--clang/test/Sema/array-size.c10
-rw-r--r--clang/test/Sema/asm.c125
-rw-r--r--clang/test/Sema/assign-null.c10
-rw-r--r--clang/test/Sema/assign.c15
-rw-r--r--clang/test/Sema/ast-print.c8
-rw-r--r--clang/test/Sema/atomic-ops.c165
-rw-r--r--clang/test/Sema/atomic-type.c22
-rw-r--r--clang/test/Sema/attr-alias.c8
-rw-r--r--clang/test/Sema/attr-aligned.c38
-rw-r--r--clang/test/Sema/attr-args.c40
-rw-r--r--clang/test/Sema/attr-availability-ios.c21
-rw-r--r--clang/test/Sema/attr-availability-macosx.c31
-rw-r--r--clang/test/Sema/attr-availability.c26
-rw-r--r--clang/test/Sema/attr-cleanup.c40
-rw-r--r--clang/test/Sema/attr-decl-after-definition.c19
-rw-r--r--clang/test/Sema/attr-declspec-ignored.c12
-rw-r--r--clang/test/Sema/attr-deprecated-message.c31
-rw-r--r--clang/test/Sema/attr-deprecated.c115
-rw-r--r--clang/test/Sema/attr-format.c80
-rw-r--r--clang/test/Sema/attr-format_arg.c13
-rw-r--r--clang/test/Sema/attr-malloc.c28
-rw-r--r--clang/test/Sema/attr-mode.c59
-rw-r--r--clang/test/Sema/attr-naked.c12
-rw-r--r--clang/test/Sema/attr-nodebug.c8
-rw-r--r--clang/test/Sema/attr-noinline.c8
-rw-r--r--clang/test/Sema/attr-noreturn.c44
-rw-r--r--clang/test/Sema/attr-regparm.c11
-rw-r--r--clang/test/Sema/attr-returns-twice.c12
-rw-r--r--clang/test/Sema/attr-section.c15
-rw-r--r--clang/test/Sema/attr-sentinel.c59
-rw-r--r--clang/test/Sema/attr-unavailable-message.c49
-rw-r--r--clang/test/Sema/attr-unknown.c4
-rw-r--r--clang/test/Sema/attr-unused.c43
-rw-r--r--clang/test/Sema/attr-used.c20
-rw-r--r--clang/test/Sema/attr-visibility.c9
-rw-r--r--clang/test/Sema/attr-weak.c18
-rw-r--r--clang/test/Sema/bitfield-layout.c42
-rw-r--r--clang/test/Sema/bitfield-promote.c34
-rw-r--r--clang/test/Sema/bitfield.c41
-rw-r--r--clang/test/Sema/block-args.c47
-rw-r--r--clang/test/Sema/block-call.c52
-rw-r--r--clang/test/Sema/block-explicit-noreturn-type.c15
-rw-r--r--clang/test/Sema/block-labels.c27
-rw-r--r--clang/test/Sema/block-literal.c89
-rw-r--r--clang/test/Sema/block-misc.c228
-rw-r--r--clang/test/Sema/block-printf-attribute-1.c21
-rw-r--r--clang/test/Sema/block-return-1.c6
-rw-r--r--clang/test/Sema/block-return-2.c5
-rw-r--r--clang/test/Sema/block-return-3.c5
-rw-r--r--clang/test/Sema/block-return.c136
-rw-r--r--clang/test/Sema/block-sentinel-attribute.c25
-rw-r--r--clang/test/Sema/block-storageclass.c18
-rw-r--r--clang/test/Sema/builtin-object-size.c28
-rw-r--r--clang/test/Sema/builtin-prefetch.c14
-rw-r--r--clang/test/Sema/builtin-stackaddress.c16
-rw-r--r--clang/test/Sema/builtin-unary-fp.c16
-rw-r--r--clang/test/Sema/builtin_objc_msgSend.c12
-rw-r--r--clang/test/Sema/builtins-arm.c16
-rw-r--r--clang/test/Sema/builtins-decl.c8
-rw-r--r--clang/test/Sema/builtins.c164
-rw-r--r--clang/test/Sema/c11-typedef-redef.c18
-rw-r--r--clang/test/Sema/c89-2.c5
-rw-r--r--clang/test/Sema/c89.c112
-rw-r--r--clang/test/Sema/callingconv.c46
-rw-r--r--clang/test/Sema/carbon.c5
-rw-r--r--clang/test/Sema/cast-incomplete.c14
-rw-r--r--clang/test/Sema/cast-to-union.c20
-rw-r--r--clang/test/Sema/cast.c159
-rw-r--r--clang/test/Sema/check-increment.c10
-rw-r--r--clang/test/Sema/compare.c335
-rw-r--r--clang/test/Sema/complex-imag.c29
-rw-r--r--clang/test/Sema/complex-init-list.c48
-rw-r--r--clang/test/Sema/complex-int.c67
-rw-r--r--clang/test/Sema/complex-promotion.c15
-rw-r--r--clang/test/Sema/compound-literal.c37
-rw-r--r--clang/test/Sema/conditional-expr.c112
-rw-r--r--clang/test/Sema/conditional.c14
-rw-r--r--clang/test/Sema/const-eval-64.c7
-rw-r--r--clang/test/Sema/const-eval.c133
-rw-r--r--clang/test/Sema/const-ptr-int-ptr-cast.c5
-rw-r--r--clang/test/Sema/constant-builtins-2.c56
-rw-r--r--clang/test/Sema/constant-builtins.c24
-rw-r--r--clang/test/Sema/constant-conversion.c82
-rw-r--r--clang/test/Sema/constructor-attribute.c15
-rw-r--r--clang/test/Sema/conversion-64-32.c19
-rw-r--r--clang/test/Sema/conversion.c419
-rw-r--r--clang/test/Sema/crash-invalid-array.c17
-rw-r--r--clang/test/Sema/darwin-align-cast.c24
-rw-r--r--clang/test/Sema/decl-in-prototype.c33
-rw-r--r--clang/test/Sema/decl-invalid.c28
-rw-r--r--clang/test/Sema/decl-type-merging.c16
-rw-r--r--clang/test/Sema/declspec.c38
-rw-r--r--clang/test/Sema/default.c8
-rw-r--r--clang/test/Sema/default1.c2
-rw-r--r--clang/test/Sema/deref.c44
-rw-r--r--clang/test/Sema/designated-initializers.c279
-rw-r--r--clang/test/Sema/dllimport-dllexport.c37
-rw-r--r--clang/test/Sema/enum-packed.c16
-rw-r--r--clang/test/Sema/enum.c121
-rw-r--r--clang/test/Sema/expr-address-of.c120
-rw-r--r--clang/test/Sema/expr-comma-c99.c17
-rw-r--r--clang/test/Sema/expr-comma.c17
-rw-r--r--clang/test/Sema/exprs.c240
-rw-r--r--clang/test/Sema/ext_vector_casts.c52
-rw-r--r--clang/test/Sema/ext_vector_comparisons.c30
-rw-r--r--clang/test/Sema/ext_vector_components.c47
-rw-r--r--clang/test/Sema/extern-redecl.c22
-rw-r--r--clang/test/Sema/flexible-array-init.c91
-rw-r--r--clang/test/Sema/floating-point-compare.c25
-rw-r--r--clang/test/Sema/fn-ptr-as-fn-prototype.c15
-rw-r--r--clang/test/Sema/for.c7
-rw-r--r--clang/test/Sema/format-string-percentm.c7
-rw-r--r--clang/test/Sema/format-strings-c90.c30
-rw-r--r--clang/test/Sema/format-strings-fixit-ssize_t.c18
-rw-r--r--clang/test/Sema/format-strings-fixit.c208
-rw-r--r--clang/test/Sema/format-strings-int-typedefs.c37
-rw-r--r--clang/test/Sema/format-strings-no-fixit.c65
-rw-r--r--clang/test/Sema/format-strings-non-iso.c29
-rw-r--r--clang/test/Sema/format-strings-scanf.c123
-rw-r--r--clang/test/Sema/format-strings-size_t.c15
-rw-r--r--clang/test/Sema/format-strings.c523
-rw-r--r--clang/test/Sema/fp16-sema.c30
-rw-r--r--clang/test/Sema/fpack-struct.c9
-rw-r--r--clang/test/Sema/freemain.c9
-rw-r--r--clang/test/Sema/function-ptr.c11
-rw-r--r--clang/test/Sema/function-redecl.c131
-rw-r--r--clang/test/Sema/function.c94
-rw-r--r--clang/test/Sema/generic-selection.c26
-rw-r--r--clang/test/Sema/gnu89.c5
-rw-r--r--clang/test/Sema/heinous-extensions-off.c10
-rw-r--r--clang/test/Sema/heinous-extensions-on.c9
-rw-r--r--clang/test/Sema/i-c-e.c75
-rw-r--r--clang/test/Sema/illegal-types.c7
-rw-r--r--clang/test/Sema/implicit-builtin-decl.c57
-rw-r--r--clang/test/Sema/implicit-builtin-freestanding.c4
-rw-r--r--clang/test/Sema/implicit-builtin-redecl.c26
-rw-r--r--clang/test/Sema/implicit-cast.c8
-rw-r--r--clang/test/Sema/implicit-decl.c32
-rw-r--r--clang/test/Sema/implicit-def.c8
-rw-r--r--clang/test/Sema/implicit-int.c28
-rw-r--r--clang/test/Sema/incompatible-sign.c5
-rw-r--r--clang/test/Sema/incomplete-call.c13
-rw-r--r--clang/test/Sema/incomplete-decl.c31
-rw-r--r--clang/test/Sema/indirect-goto.c11
-rw-r--r--clang/test/Sema/init-struct-qualified.c12
-rw-r--r--clang/test/Sema/init-vector.c17
-rw-r--r--clang/test/Sema/init.c159
-rw-r--r--clang/test/Sema/initialize-noreturn.c16
-rw-r--r--clang/test/Sema/inline-redef.c24
-rw-r--r--clang/test/Sema/inline.c6
-rw-r--r--clang/test/Sema/int-arith-convert.c12
-rw-r--r--clang/test/Sema/invalid-decl.c22
-rw-r--r--clang/test/Sema/invalid-init-diag.c4
-rw-r--r--clang/test/Sema/invalid-struct-init.c27
-rw-r--r--clang/test/Sema/knr-def-call.c41
-rw-r--r--clang/test/Sema/knr-variadic-def.c29
-rw-r--r--clang/test/Sema/many-logical-ops.c2010
-rw-r--r--clang/test/Sema/many-parameters.c310
-rw-r--r--clang/test/Sema/member-reference.c20
-rw-r--r--clang/test/Sema/memset-invalid.c6
-rw-r--r--clang/test/Sema/merge-decls.c39
-rw-r--r--clang/test/Sema/missing-field-initializers.c52
-rw-r--r--clang/test/Sema/ms_class_layout.cpp335
-rw-r--r--clang/test/Sema/neon-vector-types.c33
-rw-r--r--clang/test/Sema/nested-redef.c22
-rw-r--r--clang/test/Sema/no-format-y2k-turnsoff-format.c9
-rw-r--r--clang/test/Sema/nonnull.c21
-rw-r--r--clang/test/Sema/offsetof.c71
-rw-r--r--clang/test/Sema/overloadable-complex.c50
-rw-r--r--clang/test/Sema/overloadable.c71
-rw-r--r--clang/test/Sema/overloaded-func-transparent-union.c28
-rw-r--r--clang/test/Sema/parentheses.c73
-rw-r--r--clang/test/Sema/parentheses.cpp47
-rw-r--r--clang/test/Sema/pointer-addition.c21
-rw-r--r--clang/test/Sema/pointer-conversion.c10
-rw-r--r--clang/test/Sema/pointer-subtract-compat.c11
-rw-r--r--clang/test/Sema/pragma-align-mac68k-unsupported.c4
-rw-r--r--clang/test/Sema/pragma-align-mac68k.c98
-rw-r--r--clang/test/Sema/pragma-align-packed.c30
-rw-r--r--clang/test/Sema/pragma-arc-cf-code-audited.c18
-rw-r--r--clang/test/Sema/pragma-ms_struct.c55
-rw-r--r--clang/test/Sema/pragma-pack-2.c59
-rw-r--r--clang/test/Sema/pragma-pack-3.c34
-rw-r--r--clang/test/Sema/pragma-pack-4.c19
-rw-r--r--clang/test/Sema/pragma-pack-5.c45
-rw-r--r--clang/test/Sema/pragma-pack-and-options-align.c42
-rw-r--r--clang/test/Sema/pragma-pack-apple.c10
-rw-r--r--clang/test/Sema/pragma-pack.c27
-rw-r--r--clang/test/Sema/pragma-unused.c65
-rw-r--r--clang/test/Sema/predef.c19
-rw-r--r--clang/test/Sema/predefined-function.c38
-rw-r--r--clang/test/Sema/private-extern.c84
-rw-r--r--clang/test/Sema/rdr6094103-unordered-compare-promote.c6
-rw-r--r--clang/test/Sema/recover-goto.c5
-rw-r--r--clang/test/Sema/redefinition.c14
-rw-r--r--clang/test/Sema/return-noreturn.c37
-rw-r--r--clang/test/Sema/return-silent.c9
-rw-r--r--clang/test/Sema/return.c266
-rw-r--r--clang/test/Sema/scope-check.c234
-rw-r--r--clang/test/Sema/self-comparison.c88
-rw-r--r--clang/test/Sema/sentinel-attribute.c15
-rw-r--r--clang/test/Sema/shift.c68
-rw-r--r--clang/test/Sema/short-enums.c5
-rw-r--r--clang/test/Sema/sign-conversion.c8
-rw-r--r--clang/test/Sema/statements.c102
-rw-r--r--clang/test/Sema/static-array.c31
-rw-r--r--clang/test/Sema/static-assert.c11
-rw-r--r--clang/test/Sema/static-init.c24
-rw-r--r--clang/test/Sema/stdcall-fastcall.c21
-rw-r--r--clang/test/Sema/struct-cast.c15
-rw-r--r--clang/test/Sema/struct-compat.c17
-rw-r--r--clang/test/Sema/struct-decl.c59
-rw-r--r--clang/test/Sema/struct-packed-align.c134
-rw-r--r--clang/test/Sema/surpress-deprecated.c7
-rw-r--r--clang/test/Sema/switch.c322
-rw-r--r--clang/test/Sema/tentative-decls.c65
-rw-r--r--clang/test/Sema/text-diag.c4
-rw-r--r--clang/test/Sema/thread-specifier.c21
-rw-r--r--clang/test/Sema/transparent-union-pointer.c14
-rw-r--r--clang/test/Sema/transparent-union.c73
-rw-r--r--clang/test/Sema/type-spec-struct-union.c65
-rw-r--r--clang/test/Sema/typecheck-binop.c27
-rw-r--r--clang/test/Sema/typedef-prototype.c8
-rw-r--r--clang/test/Sema/typedef-redef.c11
-rw-r--r--clang/test/Sema/typedef-retain.c26
-rw-r--r--clang/test/Sema/typedef-variable-type.c8
-rw-r--r--clang/test/Sema/typeof-use-deprecated.c26
-rw-r--r--clang/test/Sema/types.c66
-rw-r--r--clang/test/Sema/ucn-cstring.c16
-rw-r--r--clang/test/Sema/uninit-variables-vectors.c17
-rw-r--r--clang/test/Sema/uninit-variables.c426
-rw-r--r--clang/test/Sema/unnamed-bitfield-init.c6
-rw-r--r--clang/test/Sema/unused-expr-system-header.c10
-rw-r--r--clang/test/Sema/unused-expr.c123
-rw-r--r--clang/test/Sema/usual-float.c12
-rw-r--r--clang/test/Sema/va_arg_x86_32.c6
-rw-r--r--clang/test/Sema/va_arg_x86_64.c15
-rw-r--r--clang/test/Sema/var-redecl.c62
-rw-r--r--clang/test/Sema/varargs-x86-64.c8
-rw-r--r--clang/test/Sema/varargs.c78
-rw-r--r--clang/test/Sema/variadic-block.c41
-rw-r--r--clang/test/Sema/variadic-incomplete-arg-type.c13
-rw-r--r--clang/test/Sema/vector-assign.c53
-rw-r--r--clang/test/Sema/vector-cast.c38
-rw-r--r--clang/test/Sema/vector-init.c44
-rw-r--r--clang/test/Sema/vector-ops.c29
-rw-r--r--clang/test/Sema/vfprintf-invalid-redecl.c6
-rw-r--r--clang/test/Sema/vfprintf-valid-redecl.c6
-rw-r--r--clang/test/Sema/vla-2.c17
-rw-r--r--clang/test/Sema/vla.c67
-rw-r--r--clang/test/Sema/void_arg.c26
-rw-r--r--clang/test/Sema/warn-cast-align.c41
-rw-r--r--clang/test/Sema/warn-char-subscripts.c64
-rw-r--r--clang/test/Sema/warn-freestanding-complex.c4
-rw-r--r--clang/test/Sema/warn-gnu-designators.c2
-rw-r--r--clang/test/Sema/warn-missing-braces.c3
-rw-r--r--clang/test/Sema/warn-missing-prototypes.c37
-rw-r--r--clang/test/Sema/warn-shadow.c61
-rw-r--r--clang/test/Sema/warn-sizeof-arrayarg.c30
-rw-r--r--clang/test/Sema/warn-strlcpycat-size.c55
-rw-r--r--clang/test/Sema/warn-strncat-size.c71
-rw-r--r--clang/test/Sema/warn-unreachable.c134
-rw-r--r--clang/test/Sema/warn-unused-function.c56
-rw-r--r--clang/test/Sema/warn-unused-label.c11
-rw-r--r--clang/test/Sema/warn-unused-parameters.c30
-rw-r--r--clang/test/Sema/warn-unused-value.c90
-rw-r--r--clang/test/Sema/warn-unused-variables.c32
-rw-r--r--clang/test/Sema/warn-write-strings.c10
-rw-r--r--clang/test/Sema/wchar.c22
-rw-r--r--clang/test/Sema/weak-import-on-enum.c8
-rw-r--r--clang/test/Sema/x86-attr-force-align-arg-pointer.c21
-rw-r--r--clang/test/Sema/x86-builtin-palignr.c17
309 files changed, 16526 insertions, 0 deletions
diff --git a/clang/test/Sema/128bitint.c b/clang/test/Sema/128bitint.c
new file mode 100644
index 0000000..89d3ee2
--- /dev/null
+++ b/clang/test/Sema/128bitint.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin9 %s
+typedef int i128 __attribute__((__mode__(TI)));
+typedef unsigned u128 __attribute__((__mode__(TI)));
+
+int a[((i128)-1 ^ (i128)-2) == 1 ? 1 : -1];
+int a[(u128)-1 > 1LL ? 1 : -1];
+
+// PR5435
+__uint128_t b = (__uint128_t)-1;
+
+// PR11916: Support for libstdc++ 4.7
+__int128 i = (__int128)0;
+unsigned __int128 u = (unsigned __int128)-1;
diff --git a/clang/test/Sema/2007-10-01-BuildArrayRef.c b/clang/test/Sema/2007-10-01-BuildArrayRef.c
new file mode 100644
index 0000000..4692731
--- /dev/null
+++ b/clang/test/Sema/2007-10-01-BuildArrayRef.c
@@ -0,0 +1,20 @@
+// RUN: not %clang_cc1_only -c %s -o - > /dev/null
+// PR 1603
+void func()
+{
+ const int *arr;
+ arr[0] = 1; // expected-error {{assignment of read-only location}}
+}
+
+struct foo {
+ int bar;
+};
+struct foo sfoo = { 0 };
+
+int func2()
+{
+ const struct foo *fp;
+ fp = &sfoo;
+ fp[0].bar = 1; // expected-error {{ assignment of read-only member}}
+ return sfoo.bar;
+}
diff --git a/clang/test/Sema/2009-03-09-WeakDeclarations-1.c b/clang/test/Sema/2009-03-09-WeakDeclarations-1.c
new file mode 100644
index 0000000..f219de6
--- /dev/null
+++ b/clang/test/Sema/2009-03-09-WeakDeclarations-1.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -triple i686-apple-darwin
+// Insist upon warnings for inappropriate weak attributes.
+
+// O.K.
+extern int ext_weak_import __attribute__ ((__weak_import__));
+
+// These are inappropriate, and should generate warnings:
+int decl_weak_import __attribute__ ((__weak_import__)); // expected-warning {'weak_import' attribute cannot be specified on a definition}
+int decl_initialized_weak_import __attribute__ ((__weak_import__)) = 13; // expected-warning {'weak_import' attribute cannot be specified on a definition}
+
+// O.K.
+extern int ext_f(void) __attribute__ ((__weak_import__));
+
+// These are inappropriate, and should generate warnings:
+int def_f(void) __attribute__ ((__weak_import__));
+int __attribute__ ((__weak_import__)) decl_f(void) {return 0;};
diff --git a/clang/test/Sema/2009-04-22-UnknownSize.c b/clang/test/Sema/2009-04-22-UnknownSize.c
new file mode 100644
index 0000000..9f71740
--- /dev/null
+++ b/clang/test/Sema/2009-04-22-UnknownSize.c
@@ -0,0 +1,4 @@
+// RUN: not %clang_cc1 %s -emit-llvm -o -
+// PR2958
+static struct foo s; // expected-error { tentative definition has type 'struct foo' that is never completed }
+struct foo *p = &s;
diff --git a/clang/test/Sema/2009-07-17-VoidParameter.c b/clang/test/Sema/2009-07-17-VoidParameter.c
new file mode 100644
index 0000000..68d1b1e
--- /dev/null
+++ b/clang/test/Sema/2009-07-17-VoidParameter.c
@@ -0,0 +1,4 @@
+// RUN: not %clang_cc1 -emit-llvm %s -o -
+// PR4214
+typedef void vt;
+void (*func_ptr)(vt my_vt); // expected-error {argument may not have 'void' type}
diff --git a/clang/test/Sema/2010-05-31-palignr.c b/clang/test/Sema/2010-05-31-palignr.c
new file mode 100644
index 0000000..12be29a
--- /dev/null
+++ b/clang/test/Sema/2010-05-31-palignr.c
@@ -0,0 +1,22 @@
+// RUN: not %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o /dev/null %s
+
+#include <tmmintrin.h>
+
+extern int i;
+
+int main ()
+{
+#if defined( __SSSE3__ )
+
+ typedef int16_t vSInt16 __attribute__ ((__vector_size__ (16)));
+
+ short dtbl[] = {1,2,3,4,5,6,7,8};
+ vSInt16 *vdtbl = (vSInt16*) dtbl;
+
+ vSInt16 v0;
+ v0 = *vdtbl;
+ v0 = _mm_alignr_epi8(v0, v0, i); // expected-error {{argument to '__builtin_ia32_palignr128' must be a constant integer}}
+
+ return 0;
+#endif
+}
diff --git a/clang/test/Sema/Inputs/conversion.h b/clang/test/Sema/Inputs/conversion.h
new file mode 100644
index 0000000..768190f
--- /dev/null
+++ b/clang/test/Sema/Inputs/conversion.h
@@ -0,0 +1,4 @@
+/* Fake system header for Sema/conversion.c */
+
+#define LONG_MAX __LONG_MAX__
+#define SETBIT(set,bit) do { int i = bit; set[i/(8*sizeof(set[0]))] |= (1 << (i%(8*sizeof(set)))); } while(0)
diff --git a/clang/test/Sema/Inputs/pragma-arc-cf-code-audited.h b/clang/test/Sema/Inputs/pragma-arc-cf-code-audited.h
new file mode 100644
index 0000000..6ea360c
--- /dev/null
+++ b/clang/test/Sema/Inputs/pragma-arc-cf-code-audited.h
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#pragma clang arc_cf_code_audited begin
diff --git a/clang/test/Sema/Inputs/unused-expr-system-header.h b/clang/test/Sema/Inputs/unused-expr-system-header.h
new file mode 100644
index 0000000..72b2d95
--- /dev/null
+++ b/clang/test/Sema/Inputs/unused-expr-system-header.h
@@ -0,0 +1,23 @@
+// "System header" for testing that -Wunused-value is properly suppressed in
+// certain cases.
+
+#define POSSIBLY_BAD_MACRO(x) \
+ { int i = x; \
+ i; }
+
+#define STATEMENT_EXPR_MACRO(x) \
+ (__extension__ \
+ ({int i = x; \
+ i;}))
+
+#define COMMA_MACRO_1(x, y) \
+ {x, y;}
+
+#define COMMA_MACRO_2(x, y) \
+ if (x) { 1 == 2, y; }
+
+#define COMMA_MACRO_3(x, y) \
+ (x, y)
+
+#define COMMA_MACRO_4(x, y) \
+ ( 1 == 2, y )
diff --git a/clang/test/Sema/MicrosoftCompatibility.c b/clang/test/Sema/MicrosoftCompatibility.c
new file mode 100644
index 0000000..f148e86
--- /dev/null
+++ b/clang/test/Sema/MicrosoftCompatibility.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-compatibility
+
+enum ENUM1; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}
+enum ENUM1 var1 = 3;
+enum ENUM1* var2 = 0;
+
+
+enum ENUM2 {
+ ENUM2_a = (enum ENUM2) 4,
+ ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
+ ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
+};
+
+__declspec(noreturn) void f6( void ) {
+ return; // expected-warning {{function 'f6' declared 'noreturn' should not return}}
+}
diff --git a/clang/test/Sema/MicrosoftExtensions.c b/clang/test/Sema/MicrosoftExtensions.c
new file mode 100644
index 0000000..fb0c6bd
--- /dev/null
+++ b/clang/test/Sema/MicrosoftExtensions.c
@@ -0,0 +1,102 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions
+
+
+struct A
+{
+ int a[]; /* expected-warning {{flexible array member 'a' in otherwise empty struct is a Microsoft extension}} */
+};
+
+struct C {
+ int l;
+ union {
+ int c1[]; /* expected-warning {{flexible array member 'c1' in a union is a Microsoft extension}} */
+ char c2[]; /* expected-warning {{flexible array member 'c2' in a union is a Microsoft extension}} */
+ };
+};
+
+
+struct D {
+ int l;
+ int D[];
+};
+
+
+
+
+
+
+typedef struct notnested {
+ long bad1;
+ long bad2;
+} NOTNESTED;
+
+
+typedef struct nested1 {
+ long a;
+ struct notnested var1;
+ NOTNESTED var2;
+} NESTED1;
+
+struct nested2 {
+ long b;
+ NESTED1; // expected-warning {{anonymous structs are a Microsoft extension}}
+};
+
+struct test {
+ int c;
+ struct nested2; // expected-warning {{anonymous structs are a Microsoft extension}}
+};
+
+void foo()
+{
+ struct test var;
+ var.a;
+ var.b;
+ var.c;
+ var.bad1; // expected-error {{no member named 'bad1' in 'struct test'}}
+ var.bad2; // expected-error {{no member named 'bad2' in 'struct test'}}
+}
+
+// Enumeration types with a fixed underlying type.
+const int seventeen = 17;
+typedef int Int;
+
+struct X0 {
+ enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
+ enum E1 : seventeen;
+};
+
+enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
+ SomeValue = 0x100000000
+};
+
+
+void pointer_to_integral_type_conv(char* ptr) {
+ char ch = (char)ptr;
+ short sh = (short)ptr;
+ ch = (char)ptr;
+ sh = (short)ptr;
+}
+
+
+typedef struct {
+ UNKNOWN u; // expected-error {{unknown type name 'UNKNOWN'}}
+} AA;
+
+typedef struct {
+ AA; // expected-warning {{anonymous structs are a Microsoft extension}}
+} BB;
+
+__declspec(deprecated("This is deprecated")) enum DE1 { one, two } e1;
+struct __declspec(deprecated) DS1 { int i; float f; };
+
+#define MY_TEXT "This is also deprecated"
+__declspec(deprecated(MY_TEXT)) void Dfunc1( void ) {}
+
+void test( void ) {
+ e1 = one; // expected-warning {{'e1' is deprecated: This is deprecated}}
+ struct DS1 s = { 0 }; // expected-warning {{'DS1' is deprecated}}
+ Dfunc1(); // expected-warning {{'Dfunc1' is deprecated: This is also deprecated}}
+
+ enum DE1 no; // no warning because E1 is not deprecated
+}
diff --git a/clang/test/Sema/PR2727.c b/clang/test/Sema/PR2727.c
new file mode 100644
index 0000000..332b0df
--- /dev/null
+++ b/clang/test/Sema/PR2727.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -std=c90 %s
+// RUN: %clang_cc1 -verify -fsyntax-only -std=c99 %s
+
+int f (int x)
+{
+ // sizeof applied to a type should not delete the type.
+ return sizeof (int[x]);
+}
diff --git a/clang/test/Sema/PR2728.c b/clang/test/Sema/PR2728.c
new file mode 100644
index 0000000..e9f1dea
--- /dev/null
+++ b/clang/test/Sema/PR2728.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -std=c90 %s
+// RUN: %clang_cc1 -verify -fsyntax-only -std=c99 %s
+
+struct s
+{
+ int a;
+};
+
+int a[__builtin_offsetof(struct s, a) == 0];
diff --git a/clang/test/Sema/PR2919-builtin-types-compat-strips-crv.c b/clang/test/Sema/PR2919-builtin-types-compat-strips-crv.c
new file mode 100644
index 0000000..9c13357
--- /dev/null
+++ b/clang/test/Sema/PR2919-builtin-types-compat-strips-crv.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only %s
+
+typedef struct foo T0;
+typedef const struct foo T1;
+
+int a0[__builtin_types_compatible_p(T0,
+ const T1) ? 1 : -1];
diff --git a/clang/test/Sema/PR2923.c b/clang/test/Sema/PR2923.c
new file mode 100644
index 0000000..f22e70d
--- /dev/null
+++ b/clang/test/Sema/PR2923.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// Test for absence of crash reported in PR 2923:
+//
+// http://llvm.org/bugs/show_bug.cgi?id=2923
+//
+// Previously we had a crash when deallocating the FunctionDecl for 'bar'
+// because FunctionDecl::getNumParams() just used the type of foo to determine
+// the number of parameters it has. In the case of 'bar' there are no
+// ParmVarDecls.
+int foo(int x, int y) { return x + y; }
+extern typeof(foo) bar;
diff --git a/clang/test/Sema/PR2963-enum-constant.c b/clang/test/Sema/PR2963-enum-constant.c
new file mode 100644
index 0000000..43daabf
--- /dev/null
+++ b/clang/test/Sema/PR2963-enum-constant.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+typedef short short_fixed;
+
+enum
+{
+ // 8.8 short_fixed
+ SHORT_FIXED_FRACTIONAL_BITS= 8,
+ SHORT_FIXED_ONE= 1<<SHORT_FIXED_FRACTIONAL_BITS
+};
+
+#define FLOAT_TO_SHORT_FIXED(f) ((short_fixed)((f)*SHORT_FIXED_ONE))
+
+enum
+{
+ SOME_VALUE= FLOAT_TO_SHORT_FIXED(0.1) // expected-warning{{expression is not an integer constant expression}}
+};
diff --git a/clang/test/Sema/__try.c b/clang/test/Sema/__try.c
new file mode 100644
index 0000000..1641402
--- /dev/null
+++ b/clang/test/Sema/__try.c
@@ -0,0 +1,172 @@
+// RUN: %clang_cc1 -fborland-extensions -fsyntax-only -verify %s
+
+#define JOIN2(x,y) x ## y
+#define JOIN(x,y) JOIN2(x,y)
+#define TEST2(name) JOIN(name,__LINE__)
+#define TEST TEST2(test)
+typedef int DWORD;
+
+#pragma sysheader begin
+
+struct EXCEPTION_INFO{};
+
+int __exception_code();
+struct EXCEPTION_INFO* __exception_info();
+void __abnormal_termination();
+
+#define GetExceptionCode __exception_code
+#define GetExceptionInformation __exception_info
+#define AbnormalTermination __abnormal_termination
+
+#pragma sysheader end
+
+DWORD FilterExpression(int); // expected-note{{declared here}}
+DWORD FilterExceptionInformation(struct EXCEPTION_INFO*);
+
+const char * NotFilterExpression();
+
+void TEST() {
+ __try {
+ __try {
+ __try {
+ }
+ __finally{
+ }
+ }
+ __finally{
+ }
+ }
+ __finally{
+ }
+}
+
+void TEST() {
+ __try {
+
+ }
+} // expected-error{{expected '__except' or '__finally' block}}
+
+void TEST() {
+ __except ( FilterExpression() ) { // expected-warning{{implicit declaration of function '__except' is invalid in C99}} \
+ // expected-error{{too few arguments to function call, expected 1, have 0}}
+
+ }
+}
+
+void TEST() {
+ __finally { } // expected-error{{}}
+}
+
+void TEST() {
+ __try{
+ int try_scope = 0;
+ } // TODO: expected expression is an extra error
+ __except( try_scope ? 1 : -1 ) // expected-error{{undeclared identifier 'try_scope'}} expected-error{{expected expression}}
+ {}
+}
+
+void TEST() {
+ __try {
+
+ }
+ // TODO: Why are there two errors?
+ __except( ) { // expected-error{{expected expression}} expected-error{{expected expression}}
+ }
+}
+
+void TEST() {
+ __try {
+
+ }
+ __except ( FilterExpression(GetExceptionCode()) ) {
+
+ }
+
+ __try {
+
+ }
+ __except( FilterExpression(__exception_code()) ) {
+
+ }
+
+ __try {
+
+ }
+ __except( FilterExceptionInformation(__exception_info()) ) {
+
+ }
+
+ __try {
+
+ }
+ __except(FilterExceptionInformation( GetExceptionInformation() ) ) {
+
+ }
+}
+
+void TEST() {
+ __try {
+
+ }
+ __except ( NotFilterExpression() ) { // expected-error{{filter expression type should be an integral value not 'const char *'}}
+
+ }
+}
+
+void TEST() {
+ int function_scope = 0;
+ __try {
+ int try_scope = 0;
+ }
+ __except ( FilterExpression(GetExceptionCode()) ) {
+ (void)function_scope;
+ (void)try_scope; // expected-error{{undeclared identifier}}
+ }
+}
+
+void TEST() {
+ int function_scope = 0;
+ __try {
+ int try_scope = 0;
+ }
+ __finally {
+ (void)function_scope;
+ (void)try_scope; // expected-error{{undeclared identifier}}
+ }
+}
+
+void TEST() {
+ int function_scope = 0;
+ __try {
+
+ }
+ __except( function_scope ? 1 : -1 ) {}
+}
+
+void TEST() {
+ __try {
+ (void)AbnormalTermination; // expected-error{{only allowed in __finally block}}
+ (void)__abnormal_termination; // expected-error{{only allowed in __finally block}}
+ }
+ __except( 1 ) {
+ (void)AbnormalTermination; // expected-error{{only allowed in __finally block}}
+ (void)__abnormal_termination; // expected-error{{only allowed in __finally block}}
+ }
+
+ __try {
+ }
+ __finally {
+ AbnormalTermination();
+ __abnormal_termination();
+ }
+}
+
+void TEST() {
+ (void)__exception_code; // expected-error{{only allowed in __except block}}
+ (void)__exception_info; // expected-error{{only allowed in __except filter expression}}
+ (void)__abnormal_termination; // expected-error{{only allowed in __finally block}}
+
+ (void)GetExceptionCode(); // expected-error{{only allowed in __except block}}
+ (void)GetExceptionInformation(); // expected-error{{only allowed in __except filter expression}}
+ (void)AbnormalTermination(); // expected-error{{only allowed in __finally block}}
+}
diff --git a/clang/test/Sema/address-constant.c b/clang/test/Sema/address-constant.c
new file mode 100644
index 0000000..e842a73
--- /dev/null
+++ b/clang/test/Sema/address-constant.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int i;
+int a[] = {0};
+struct { int i; } s;
+
+int *array[] = {&i, a, &s.i};
+
+extern void f(void);
+void (*f_addr)(void) = &f;
diff --git a/clang/test/Sema/address_spaces.c b/clang/test/Sema/address_spaces.c
new file mode 100644
index 0000000..24799da
--- /dev/null
+++ b/clang/test/Sema/address_spaces.c
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+#define _AS1 __attribute__((address_space(1)))
+#define _AS2 __attribute__((address_space(2)))
+#define _AS3 __attribute__((address_space(3)))
+
+void bar(_AS2 int a); // expected-error {{parameter may not be qualified with an address space}}
+
+void foo(_AS3 float *a,
+ _AS1 float b) // expected-error {{parameter may not be qualified with an address space}}
+{
+ _AS2 *x;// expected-warning {{type specifier missing, defaults to 'int'}}
+ _AS1 float * _AS2 *B;
+
+ int _AS1 _AS2 *Y; // expected-error {{multiple address spaces specified for type}}
+ int *_AS1 _AS2 *Z; // expected-error {{multiple address spaces specified for type}}
+
+ _AS1 int local; // expected-error {{automatic variable qualified with an address space}}
+ _AS1 int array[5]; // expected-error {{automatic variable qualified with an address space}}
+ _AS1 int arrarr[5][5]; // expected-error {{automatic variable qualified with an address space}}
+
+ __attribute__((address_space(-1))) int *_boundsA; // expected-error {{address space is negative}}
+ __attribute__((address_space(0xFFFFFF))) int *_boundsB;
+ __attribute__((address_space(0x1000000))) int *_boundsC; // expected-error {{address space is larger than the maximum supported}}
+ // chosen specifically to overflow 32 bits and come out reasonable
+ __attribute__((address_space(4294967500))) int *_boundsD; // expected-error {{address space is larger than the maximum supported}}
+
+ *a = 5.0f + b;
+}
+
+struct _st {
+ int x, y;
+} s __attribute ((address_space(1))) = {1, 1};
+
+
+// rdar://6774906
+__attribute__((address_space(256))) void * * const base = 0;
+void * get_0(void) {
+ return base[0]; // expected-error {{returning '__attribute__((address_space(256))) void *' from a function with result type 'void *' changes address space of pointer}}
+}
+
+__attribute__((address_space(1))) char test3_array[10];
+void test3(void) {
+ extern void test3_helper(char *p); // expected-note {{passing argument to parameter 'p' here}}
+ test3_helper(test3_array); // expected-error {{changes address space of pointer}}
+}
+
+typedef void ft(void);
+_AS1 ft qf; // expected-error {{function type may not be qualified with an address space}}
+typedef _AS1 ft qft; // expected-error {{function type may not be qualified with an address space}}
diff --git a/clang/test/Sema/align-arm-apcs.c b/clang/test/Sema/align-arm-apcs.c
new file mode 100644
index 0000000..0a5d3fe
--- /dev/null
+++ b/clang/test/Sema/align-arm-apcs.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple arm-unknown-unknown -target-abi apcs-gnu -fsyntax-only -verify %s
+
+struct s0 { double f0; int f1; };
+char chk0[__alignof__(struct s0) == 4 ? 1 : -1];
diff --git a/clang/test/Sema/align-x86-64.c b/clang/test/Sema/align-x86-64.c
new file mode 100644
index 0000000..edea5d8
--- /dev/null
+++ b/clang/test/Sema/align-x86-64.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -verify %s
+
+// PR5599
+
+void frob(void *);
+
+void foo(void) {
+ float x[4];
+ char y[__alignof__(x) == 16 ? 1 : -1];
+ frob(y);
+}
+
+// PR5637
+
+typedef __attribute__((aligned(16))) struct {
+ unsigned long long w[3];
+} UINT192;
+
+UINT192 ten2mk192M[] = {
+ {{0xcddd6e04c0592104ULL, 0x0fcf80dc33721d53ULL, 0xa7c5ac471b478423ULL}},
+ {{0xcddd6e04c0592104ULL, 0x0fcf80dc33721d53ULL, 0xa7c5ac471b478423ULL}},
+ {{0xcddd6e04c0592104ULL, 0x0fcf80dc33721d53ULL, 0xa7c5ac471b478423ULL}}
+};
+
+short chk1[sizeof(ten2mk192M) == 80 ? 1 : -1];
diff --git a/clang/test/Sema/align-x86.c b/clang/test/Sema/align-x86.c
new file mode 100644
index 0000000..c6cd754
--- /dev/null
+++ b/clang/test/Sema/align-x86.c
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s
+
+// PR3433
+double g1;
+short chk1[__alignof__(g1) == 8 ? 1 : -1];
+short chk2[__alignof__(double) == 8 ? 1 : -1];
+
+long long g2;
+short chk1[__alignof__(g2) == 8 ? 1 : -1];
+short chk2[__alignof__(long long) == 8 ? 1 : -1];
+
+unsigned long long g5;
+short chk1[__alignof__(g5) == 8 ? 1 : -1];
+short chk2[__alignof__(unsigned long long) == 8 ? 1 : -1];
+
+_Complex double g3;
+short chk1[__alignof__(g3) == 8 ? 1 : -1];
+short chk2[__alignof__(_Complex double) == 8 ? 1 : -1];
+
+// PR6362
+struct __attribute__((packed)) {unsigned int a;} g4;
+short chk1[__alignof__(g4) == 1 ? 1 : -1];
+short chk2[__alignof__(g4.a) == 1 ? 1 : -1];
+
+
+// PR5637
+
+#define ALIGNED(x) __attribute__((aligned(x)))
+
+typedef ALIGNED(2) struct {
+ char a[3];
+} T;
+
+short chk1[sizeof(T) == 3 ? 1 : -1];
+short chk2[sizeof(T[1]) == 4 ? 1 : -1];
+short chk3[sizeof(T[2]) == 6 ? 1 : -1];
+short chk4[sizeof(T[2][1]) == 8 ? 1 : -1];
+short chk5[sizeof(T[1][2]) == 6 ? 1 : -1];
+
+typedef struct ALIGNED(2) {
+ char a[3];
+} T2;
+
+short chk1[sizeof(T2) == 4 ? 1 : -1];
+short chk2[sizeof(T2[1]) == 4 ? 1 : -1];
+short chk3[sizeof(T2[2]) == 8 ? 1 : -1];
+short chk4[sizeof(T2[2][1]) == 8 ? 1 : -1];
+short chk5[sizeof(T2[1][2]) == 8 ? 1 : -1];
diff --git a/clang/test/Sema/alignas.c b/clang/test/Sema/alignas.c
new file mode 100644
index 0000000..5832393
--- /dev/null
+++ b/clang/test/Sema/alignas.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c1x %s
+
+_Alignas(3) int align_illegal; //expected-error {{requested alignment is not a power of 2}}
+_Alignas(int) char align_big;
+_Alignas(1) int align_small; // FIXME: this should be rejected
+_Alignas(1) unsigned _Alignas(8) int _Alignas(1) align_multiple;
+
+struct align_member {
+ _Alignas(8) int member;
+};
+
+typedef _Alignas(8) char align_typedef; // FIXME: this should be rejected
+
+_Static_assert(__alignof(align_big) == __alignof(int), "k's alignment is wrong");
+_Static_assert(__alignof(align_small) == 1, "j's alignment is wrong");
+_Static_assert(__alignof(align_multiple) == 8, "l's alignment is wrong");
+_Static_assert(__alignof(struct align_member) == 8, "quuux's alignment is wrong");
+_Static_assert(sizeof(struct align_member) == 8, "quuux's size is wrong");
+_Static_assert(__alignof(align_typedef) == 8, "typedef's alignment is wrong");
diff --git a/clang/test/Sema/altivec-init.c b/clang/test/Sema/altivec-init.c
new file mode 100644
index 0000000..973aab1
--- /dev/null
+++ b/clang/test/Sema/altivec-init.c
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 %s -triple=powerpc-apple-darwin8 -faltivec -verify -pedantic -fsyntax-only
+
+typedef int v4 __attribute((vector_size(16)));
+typedef short v8 __attribute((vector_size(16)));
+
+v8 foo(void) {
+ v8 a;
+ v4 b;
+ a = (v8){4, 2};
+ b = (v4)(5, 6, 7, 8, 9); // expected-warning {{excess elements in vector initializer}}
+ b = (v4)(5, 6, 8, 8.0f);
+
+ vector int vi;
+ vi = (vector int)(1);
+ vi = (vector int)(1, 2); // expected-error {{number of elements must be either one or match the size of the vector}}
+ vi = (vector int)(1, 2, 3, 4);
+ vi = (vector int)(1, 2, 3, 4, 5); // expected-warning {{excess elements in vector initializer}}
+ vi = (vector int){1};
+ vi = (vector int){1, 2};
+ vi = (vector int){1, 2, 3, 4, 5}; // expected-warning {{excess elements in vector initializer}}
+ vector float vf;
+ vf = (vector float)(1.0);
+
+ return (v8){0, 1, 2, 3, 1, 2, 3, 4};
+
+ // FIXME: test that (type)(fn)(args) still works with -faltivec
+ // FIXME: test that c++ overloaded commas still work -faltivec
+}
+
+void __attribute__((__overloadable__)) f(v4 a)
+{
+}
+
+void __attribute__((__overloadable__)) f(int a)
+{
+}
+
+void test()
+{
+ v4 vGCC;
+ vector int vAltiVec;
+
+ f(vAltiVec);
+ vGCC = vAltiVec;
+ int res = vGCC > vAltiVec;
+ vAltiVec = 0 ? vGCC : vGCC;
+}
diff --git a/clang/test/Sema/annotate.c b/clang/test/Sema/annotate.c
new file mode 100644
index 0000000..5b27277
--- /dev/null
+++ b/clang/test/Sema/annotate.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+void __attribute__((annotate("foo"))) foo(float *a) {
+ __attribute__((annotate("bar"))) int x;
+ __attribute__((annotate(1))) int y; // expected-error {{argument to annotate attribute was not a string literal}}
+ __attribute__((annotate("bar", 1))) int z; // expected-error {{attribute takes one argument}}
+ int u = __builtin_annotation(z, (char*) 0); // expected-error {{__builtin_annotation requires a non wide string constant}}
+ int v = __builtin_annotation(z, (char*) L"bar"); // expected-error {{__builtin_annotation requires a non wide string constant}}
+ int w = __builtin_annotation(z, "foo");
+}
diff --git a/clang/test/Sema/anonymous-struct-union-c11.c b/clang/test/Sema/anonymous-struct-union-c11.c
new file mode 100644
index 0000000..229ee52
--- /dev/null
+++ b/clang/test/Sema/anonymous-struct-union-c11.c
@@ -0,0 +1,19 @@
+// Check for warnings in non-C11 mode:
+// RUN: %clang_cc1 -fsyntax-only -verify -Wc11-extensions %s
+
+// Expect no warnings in C11 mode:
+// RUN: %clang_cc1 -fsyntax-only -pedantic -Werror -std=c11 %s
+
+struct s {
+ int a;
+ struct { // expected-warning{{anonymous structs are a C11 extension}}
+ int b;
+ };
+};
+
+struct t {
+ int a;
+ union { // expected-warning{{anonymous unions are a C11 extension}}
+ int b;
+ };
+};
diff --git a/clang/test/Sema/anonymous-struct-union.c b/clang/test/Sema/anonymous-struct-union.c
new file mode 100644
index 0000000..e082290
--- /dev/null
+++ b/clang/test/Sema/anonymous-struct-union.c
@@ -0,0 +1,110 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+struct X {
+ union {
+ float f3;
+ double d2;
+ } named;
+
+ union {
+ int i;
+ float f;
+
+ union {
+ float f2;
+ double d;
+ };
+ };
+
+ struct {
+ int a;
+ float b;
+ };
+};
+
+void test_unqual_references(struct X x, const struct X xc) {
+ x.i = 0;
+ x.f = 0.0;
+ x.f2 = x.f;
+ x.d = x.f;
+ x.f3 = 0; // expected-error{{no member named 'f3'}}
+ x.a = 0;
+
+ xc.d = 0.0; // expected-error{{read-only variable is not assignable}}
+ xc.f = 0; // expected-error{{read-only variable is not assignable}}
+ xc.a = 0; // expected-error{{read-only variable is not assignable}}
+}
+
+
+struct Redecl {
+ int x; // expected-note{{previous declaration is here}}
+ struct y { };
+
+ union {
+ int x; // expected-error{{member of anonymous union redeclares 'x'}}
+ float y;
+ double z; // expected-note{{previous declaration is here}}
+ double zz; // expected-note{{previous declaration is here}}
+ };
+
+ int z; // expected-error{{duplicate member 'z'}}
+ void zz(); // expected-error{{duplicate member 'zz'}}
+};
+
+union { // expected-warning{{declaration does not declare anything}}
+ int int_val;
+ float float_val;
+};
+
+static union { // expected-warning{{declaration does not declare anything}}
+ int int_val2;
+ float float_val2;
+};
+
+void f() {
+ int_val2 = 0; // expected-error{{use of undeclared identifier}}
+ float_val2 = 0.0; // expected-error{{use of undeclared identifier}}
+}
+
+void g() {
+ union { // expected-warning{{declaration does not declare anything}}
+ int i;
+ float f2;
+ };
+ i = 0; // expected-error{{use of undeclared identifier}}
+ f2 = 0.0; // expected-error{{use of undeclared identifier}}
+}
+
+// <rdar://problem/6483159>
+struct s0 { union { int f0; }; };
+
+// <rdar://problem/6481130>
+typedef struct { }; // expected-warning{{declaration does not declare anything}}
+
+// PR3675
+struct s1 {
+ int f0; // expected-note{{previous declaration is here}}
+ union {
+ int f0; // expected-error{{member of anonymous union redeclares 'f0'}}
+ };
+};
+
+// PR3680
+struct {}; // expected-warning{{declaration does not declare anything}}
+
+struct s2 {
+ union {
+ int a;
+ } // expected-warning{{expected ';' at end of declaration list}}
+}; // expected-error{{expected member name or ';' after declaration specifiers}}
+
+// Make sure we don't a.k.a. anonymous structs.
+typedef struct {
+ int x;
+} a_struct;
+int tmp = (a_struct) { .x = 0 }; // expected-error {{initializing 'int' with an expression of incompatible type 'a_struct'}}
+
+// This example comes out of the C11 standard; make sure we don't accidentally reject it.
+struct s {
+ struct { int i; };
+ int a[];
+};
diff --git a/clang/test/Sema/arg-duplicate.c b/clang/test/Sema/arg-duplicate.c
new file mode 100644
index 0000000..feeb458
--- /dev/null
+++ b/clang/test/Sema/arg-duplicate.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int f3(y, x,
+ x) // expected-error {{redefinition of parameter}}
+ int y,
+ x, // expected-note {{previous declaration is here}}
+ x; // expected-error {{redefinition of parameter}}
+{
+ return x + y;
+}
+
+void f4(void) {
+ f3 (1, 1, 2, 3, 4); // expected-warning{{too many arguments}}
+}
+
diff --git a/clang/test/Sema/arg-scope-c99.c b/clang/test/Sema/arg-scope-c99.c
new file mode 100644
index 0000000..912776a
--- /dev/null
+++ b/clang/test/Sema/arg-scope-c99.c
@@ -0,0 +1,2 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -verify %s
+void bb(int sz, int ar[sz][sz]) { }
diff --git a/clang/test/Sema/arg-scope.c b/clang/test/Sema/arg-scope.c
new file mode 100644
index 0000000..ed92619
--- /dev/null
+++ b/clang/test/Sema/arg-scope.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+void aa(int b, int x[sizeof b]) {}
+
+void foo(int i, int A[i]) {}
+
diff --git a/clang/test/Sema/arm-layout.c b/clang/test/Sema/arm-layout.c
new file mode 100644
index 0000000..d017fdb
--- /dev/null
+++ b/clang/test/Sema/arm-layout.c
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -triple armv7-unknown-unknown -target-abi apcs-gnu %s -verify
+// RUN: %clang_cc1 -triple armv7-unknown-unknown -target-abi aapcs %s -verify
+
+#define check(name, cond) int _##name##_check[(cond) ? 1 : -1]
+
+struct s0 { char field0; double field1; };
+#ifdef __ARM_EABI__
+check(s0_size, sizeof(struct s0) == 16);
+#else
+check(s0_size, sizeof(struct s0) == 12);
+#endif
+
+struct s1 { char field0; long double field1; };
+#ifdef __ARM_EABI__
+check(s1_size, sizeof(struct s1) == 16);
+#else
+check(s1_size, sizeof(struct s1) == 12);
+#endif
+
+struct s2 {
+ short field0;
+ int field1 : 24;
+ char field2;
+};
+#ifdef __ARM_EABI__
+check(s2_size, sizeof(struct s2) == 8);
+check(s2_offset_0, __builtin_offsetof(struct s2, field0) == 0);
+check(s2_offset_1, __builtin_offsetof(struct s2, field2) == 7);
+#else
+check(s2_size, sizeof(struct s2) == 6);
+check(s2_offset_0, __builtin_offsetof(struct s2, field0) == 0);
+check(s2_offset_1, __builtin_offsetof(struct s2, field2) == 5);
+#endif
+
+struct s3 {
+ short field0;
+ int field1 : 24 __attribute__((aligned(4)));
+ char field2;
+};
+check(s3_size, sizeof(struct s3) == 8);
+check(s3_offset_0, __builtin_offsetof(struct s3, field0) == 0);
+check(s3_offset_1, __builtin_offsetof(struct s3, field2) == 7);
+
+struct s4 {
+ int field0 : 4;
+};
+#ifdef __ARM_EABI__
+check(s4_size, sizeof(struct s4) == 4);
+check(s4_align, __alignof(struct s4) == 4);
+#else
+check(s4_size, sizeof(struct s4) == 1);
+check(s4_align, __alignof(struct s4) == 1);
+#endif
diff --git a/clang/test/Sema/arm-neon-types.c b/clang/test/Sema/arm-neon-types.c
new file mode 100644
index 0000000..1a170db
--- /dev/null
+++ b/clang/test/Sema/arm-neon-types.c
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -triple thumbv7-apple-darwin10 -target-cpu cortex-a8 -fsyntax-only -Wvector-conversion -ffreestanding -verify %s
+
+#include <arm_neon.h>
+
+// Radar 8228022: Should not report incompatible vector types.
+int32x2_t test(int32x2_t x) {
+ return vshr_n_s32(x, 31);
+}
+
+// ...but should warn when the types really do not match.
+float32x2_t test2(uint32x2_t x) {
+ return vcvt_n_f32_s32(x, 9); // expected-warning {{incompatible vector types}}
+}
+
+// Check immediate range for vcvt_n intrinsics is 1 to 32. Radar 9558930.
+float32x2_t test3(uint32x2_t x) {
+ // FIXME: The "incompatible result type" error is due to pr10112 and should be
+ // removed when that is fixed.
+ return vcvt_n_f32_u32(x, 0); // expected-error {{argument should be a value from 1 to 32}} expected-error {{incompatible result type}}
+}
+
+typedef signed int vSInt32 __attribute__((__vector_size__(16)));
+int32x4_t test4(int32x4_t a, vSInt32 b) {
+ a += b;
+ b += a;
+ return b += a;
+}
+
+// Warn for incompatible pointer types used with vld/vst intrinsics.
+int16x8_t test5(int *p) {
+ return vld1q_s16(p); // expected-warning {{incompatible pointer types}}
+}
+void test6(float *p, int32x2_t v) {
+ return vst1_s32(p, v); // expected-warning {{incompatible pointer types}}
+}
diff --git a/clang/test/Sema/array-bounds-ptr-arith.c b/clang/test/Sema/array-bounds-ptr-arith.c
new file mode 100644
index 0000000..022335b
--- /dev/null
+++ b/clang/test/Sema/array-bounds-ptr-arith.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -verify -Warray-bounds-pointer-arithmetic %s
+
+// Test case from PR10615
+struct ext2_super_block{
+ unsigned char s_uuid[8]; // expected-note {{declared here}}
+};
+void* ext2_statfs (struct ext2_super_block *es,int a)
+{
+ return (void *)es->s_uuid + sizeof(int); // no-warning
+}
+void* broken (struct ext2_super_block *es,int a)
+{
+ return (void *)es->s_uuid + 80; // expected-warning {{refers past the end of the array}}
+}
+
+// Test case reduced from PR11594
+struct S { int n; };
+void pr11594(struct S *s) {
+ int a[10];
+ int *p = a - s->n;
+}
diff --git a/clang/test/Sema/array-constraint.c b/clang/test/Sema/array-constraint.c
new file mode 100644
index 0000000..bee33c0
--- /dev/null
+++ b/clang/test/Sema/array-constraint.c
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
+
+struct s; // expected-note 2 {{forward declaration of 'struct s'}}
+struct s* t (struct s z[]) { // expected-error {{array has incomplete element type}}
+ return z;
+}
+
+void ff() {
+ struct s v, *p; // expected-error {{variable has incomplete type 'struct s'}}
+
+ p = &v;
+}
+
+void *k (void l[2]) { // expected-error {{array has incomplete element type}}
+ return l;
+}
+
+struct vari {
+ int a;
+ int b[];
+};
+
+struct vari *func(struct vari a[]) { // expected-warning {{'struct vari' may not be used as an array element due to flexible array member}}
+ return a;
+}
+
+int foo[](void); // expected-error {{'foo' declared as array of functions}}
+int foo2[1](void); // expected-error {{'foo2' declared as array of functions}}
+
+typedef int (*pfunc)(void);
+
+pfunc xx(int f[](void)) { // expected-error {{'f' declared as array of functions}}
+ return f;
+}
+
+void check_size() {
+ float f;
+ int size_not_int[f]; // expected-error {{size of array has non-integer type 'float'}}
+ int negative_size[1-2]; // expected-error{{array with a negative size}}
+ int zero_size[0]; // expected-warning{{zero size arrays are an extension}}
+}
+
+static int I;
+typedef int TA[I]; // expected-error {{variable length array declaration not allowed at file scope}}
+
+void strFunc(char *); // expected-note{{passing argument to parameter here}}
+const char staticAry[] = "test";
+void checkStaticAry() {
+ strFunc(staticAry); // expected-warning{{passing 'const char [5]' to parameter of type 'char *' discards qualifiers}}
+}
+
+
diff --git a/clang/test/Sema/array-declared-as-incorrect-type.c b/clang/test/Sema/array-declared-as-incorrect-type.c
new file mode 100644
index 0000000..b93fa9a
--- /dev/null
+++ b/clang/test/Sema/array-declared-as-incorrect-type.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
+
+extern int a1[];
+int a1[1];
+
+extern int a2[]; // expected-note {{previous definition is here}}
+float a2[1]; // expected-error {{redefinition of 'a2'}}
+
+extern int a3[][2];
+int a3[1][2];
+
+extern int a4[][2]; // expected-note {{previous definition is here}}
+int a4[2]; // expected-error {{redefinition of 'a4'}}
+
+extern int a5[1][2][3]; // expected-note {{previous definition is here}}
+int a5[3][2][1]; // expected-error {{redefinition of 'a5'}}
diff --git a/clang/test/Sema/array-init.c b/clang/test/Sema/array-init.c
new file mode 100644
index 0000000..26c0b24
--- /dev/null
+++ b/clang/test/Sema/array-init.c
@@ -0,0 +1,289 @@
+// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
+
+extern int foof() = 1; // expected-error{{illegal initializer (only variables can be initialized)}}
+
+static int x, y, z;
+
+static int ary[] = { x, y, z }; // expected-error{{initializer element is not a compile-time constant}}
+int ary2[] = { x, y, z }; // expected-error{{initializer element is not a compile-time constant}}
+
+extern int fileScopeExtern[3] = { 1, 3, 5 }; // expected-warning{{'extern' variable has an initializer}}
+
+static long ary3[] = { 1, "abc", 3, 4 }; // expected-warning{{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [4]'}}
+
+void func() {
+ int x = 1;
+
+ typedef int TInt = 1; // expected-error{{illegal initializer (only variables can be initialized)}}
+
+ int xComputeSize[] = { 1, 3, 5 };
+
+ int x3[x] = { 1, 2 }; // expected-error{{variable-sized object may not be initialized}}
+
+ int x4 = { 1, 2 }; // expected-warning{{excess elements in scalar initializer}}
+
+ int y[4][3] = {
+ { 1, 3, 5 },
+ { 2, 4, 6 },
+ { 3, 5, 7 },
+ };
+
+ int y2[4][3] = {
+ 1, 3, 5, 2, 4, 6, 3, 5, 7
+ };
+
+ int y3[4][3] = {
+ { 1, 3, 5 },
+ { 2, 4, 6 },
+ { 3, 5, 7 },
+ { 4, 6, 8 },
+ { 5 }, // expected-warning{{excess elements in array initializer}}
+ };
+
+ struct threeElements {
+ int a,b,c;
+ } z = { 1 };
+
+ struct threeElements *p = 7; // expected-warning{{incompatible integer to pointer conversion initializing 'struct threeElements *' with an expression of type 'int'}}
+
+ extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{'extern' variable cannot have an initializer}}
+
+ static long x2[3] = { 1.0,
+ "abc", // expected-warning{{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [4]'}}
+ 5.8 }; // expected-warning {{implicit conversion turns literal floating-point number into integer}}
+}
+
+void test() {
+ int y1[3] = {
+ { 1, 2, 3 } // expected-warning{{excess elements in scalar initializer}}
+ };
+ int y3[4][3] = {
+ { 1, 3, 5 },
+ { 2, 4, 6 },
+ { 3, 5, 7 },
+ { 4, 6, 8 },
+ { }, // expected-warning{{use of GNU empty initializer extension}} expected-warning{{excess elements in array initializer}}
+ };
+ int y4[4][3] = {
+ { 1, 3, 5, 2 }, // expected-warning{{excess elements in array initializer}}
+ { 4, 6 },
+ { 3, 5, 7 },
+ { 4, 6, 8 },
+ };
+}
+
+void allLegalAndSynonymous() {
+ short q[4][3][2] = {
+ { 1 },
+ { 2, 3 },
+ { 4, 5, 6 }
+ };
+ short q2[4][3][2] = {
+ { 1, 0, 0, 0, 0, 0 },
+ { 2, 3, 0, 0, 0, 0 },
+ { 4, 5, 6 }
+ };
+ short q3[4][3][2] = {
+ {
+ { 1 },
+ },
+ {
+ { 2, 3 },
+ },
+ {
+ { 4, 5 },
+ { 6 },
+ },
+ };
+}
+
+void legal() {
+ short q[][3][2] = {
+ { 1 },
+ { 2, 3 },
+ { 4, 5, 6 }
+ };
+ int q_sizecheck[(sizeof(q) / sizeof(short [3][2])) == 3? 1 : -1];
+}
+
+unsigned char asso_values[] = { 34 };
+int legal2() {
+ return asso_values[0];
+}
+
+void illegal() {
+ short q2[4][][2] = { // expected-error{{array has incomplete element type 'short [][2]'}}
+ { 1, 0, 0, 0, 0, 0 },
+ { 2, 3, 0, 0, 0, 0 },
+ { 4, 5, 6 }
+ };
+ short q3[4][3][] = { // expected-error{{array has incomplete element type 'short []'}}
+ {
+ { 1 },
+ },
+ {
+ { 2, 3 },
+ },
+ {
+ { 4, 5 },
+ { 6 },
+ },
+ };
+ int a[][] = { 1, 2 }; // expected-error{{array has incomplete element type 'int []'}}
+}
+
+typedef int AryT[];
+
+void testTypedef()
+{
+ AryT a = { 1, 2 }, b = { 3, 4, 5 };
+ int a_sizecheck[(sizeof(a) / sizeof(int)) == 2? 1 : -1];
+ int b_sizecheck[(sizeof(b) / sizeof(int)) == 3? 1 : -1];
+}
+
+static char const xx[] = "test";
+int xx_sizecheck[(sizeof(xx) / sizeof(char)) == 5? 1 : -1];
+static char const yy[5] = "test";
+static char const zz[3] = "test"; // expected-warning{{initializer-string for char array is too long}}
+
+void charArrays() {
+ static char const test[] = "test";
+ int test_sizecheck[(sizeof(test) / sizeof(char)) == 5? 1 : -1];
+ static char const test2[] = { "weird stuff" };
+ static char const test3[] = { "test", "excess stuff" }; // expected-warning{{excess elements in char array initializer}}
+
+ char* cp[] = { "Hello" };
+
+ char c[] = { "Hello" };
+ int l[sizeof(c) == 6 ? 1 : -1];
+
+ int i[] = { "Hello "}; // expected-warning{{incompatible pointer to integer conversion initializing 'int' with an expression of type 'char [7]'}}
+ char c2[] = { "Hello", "Good bye" }; //expected-warning{{excess elements in char array initializer}}
+
+ int i2[1] = { "Hello" }; //expected-warning{{incompatible pointer to integer conversion initializing 'int' with an expression of type 'char [6]'}}
+ char c3[5] = { "Hello" };
+ char c4[4] = { "Hello" }; //expected-warning{{initializer-string for char array is too long}}
+
+ int i3[] = {}; //expected-warning{{zero size arrays are an extension}} expected-warning{{use of GNU empty initializer extension}}
+}
+
+void variableArrayInit() {
+ int a = 4;
+ char strlit[a] = "foo"; //expected-error{{variable-sized object may not be initialized}}
+ int b[a] = { 1, 2, 4 }; //expected-error{{variable-sized object may not be initialized}}
+}
+
+// Pure array tests
+float r1[10] = {{7}}; //expected-warning{{braces around scalar initializer}}
+float r2[] = {{8}}; //expected-warning{{braces around scalar initializer}}
+char r3[][5] = {1,2,3,4,5,6};
+int r3_sizecheck[(sizeof(r3) / sizeof(char[5])) == 2? 1 : -1];
+char r3_2[sizeof r3 == 10 ? 1 : -1];
+float r4[1][2] = {1,{2},3,4}; //expected-warning{{braces around scalar initializer}} expected-warning{{excess elements in array initializer}}
+char r5[][5] = {"aa", "bbb", "ccccc"};
+char r6[sizeof r5 == 15 ? 1 : -1];
+const char r7[] = "zxcv";
+char r8[5] = "5char";
+char r9[5] = "6chars"; //expected-warning{{initializer-string for char array is too long}}
+
+int r11[0] = {}; //expected-warning{{zero size arrays are an extension}} expected-warning{{use of GNU empty initializer extension}}
+
+// Some struct tests
+void autoStructTest() {
+struct s1 {char a; char b;} t1;
+struct s2 {struct s1 c;} t2 = { t1 };
+// The following is a less than great diagnostic (though it's on par with EDG).
+struct s1 t3[] = {t1, t1, "abc", 0}; //expected-warning{{incompatible pointer to integer conversion initializing 'char' with an expression of type 'char [4]'}}
+int t4[sizeof t3 == 6 ? 1 : -1];
+}
+struct foo { int z; } w;
+int bar (void) {
+ struct foo z = { w }; //expected-error{{initializing 'int' with an expression of incompatible type 'struct foo'}}
+ return z.z;
+}
+struct s3 {void (*a)(void);} t5 = {autoStructTest};
+struct {int a; int b[];} t6 = {1, {1, 2, 3}}; // expected-warning{{flexible array initialization is a GNU extension}} \
+// expected-note{{initialized flexible array member 'b' is here}}
+union {char a; int b;} t7[] = {1, 2, 3};
+int t8[sizeof t7 == (3*sizeof(int)) ? 1 : -1];
+
+struct bittest{int : 31, a, :21, :12, b;};
+struct bittest bittestvar = {1, 2, 3, 4}; //expected-warning{{excess elements in struct initializer}}
+
+// Not completely sure what should happen here...
+int u1 = {}; //expected-warning{{use of GNU empty initializer extension}} expected-error{{scalar initializer cannot be empty}}
+int u2 = {{3}}; //expected-warning{{too many braces around scalar initializer}}
+
+// PR2362
+void varArray() {
+ int c[][x] = { 0 }; //expected-error{{variable-sized object may not be initialized}}
+}
+
+// PR2151
+void emptyInit() {struct {} x[] = {6};} //expected-warning{{empty struct is a GNU extension}} \
+// expected-error{{initializer for aggregate with no elements}}
+
+void noNamedInit() {
+ struct {int:5;} x[] = {6}; //expected-error{{initializer for aggregate with no elements}}
+}
+struct {int a; int:5;} noNamedImplicit[] = {1,2,3};
+int noNamedImplicitCheck[sizeof(noNamedImplicit) == 3 * sizeof(*noNamedImplicit) ? 1 : -1];
+
+
+// ptrs are constant
+struct soft_segment_descriptor {
+ long ssd_base;
+};
+static int dblfault_tss;
+
+union uniao { int ola; } xpto[1];
+
+struct soft_segment_descriptor gdt_segs[] = {
+ {(long) &dblfault_tss},
+ { (long)xpto},
+};
+
+static void sppp_ipv6cp_up();
+const struct {} ipcp = { sppp_ipv6cp_up }; //expected-warning{{empty struct is a GNU extension}} \
+// expected-warning{{excess elements in struct initializer}}
+
+struct _Matrix { union { float m[4][4]; }; }; //expected-warning{{anonymous unions are a C11 extension}}
+typedef struct _Matrix Matrix;
+void test_matrix() {
+ const Matrix mat1 = {
+ { { 1.0f, 2.0f, 3.0f, 4.0f,
+ 5.0f, 6.0f, 7.0f, 8.0f,
+ 9.0f, 10.0f, 11.0f, 12.0f,
+ 13.0f, 14.0f, 15.0f, 16.0f } }
+ };
+
+ const Matrix mat2 = {
+ 1.0f, 2.0f, 3.0f, 4.0f,
+ 5.0f, 6.0f, 7.0f, 8.0f,
+ 9.0f, 10.0f, 11.0f, 12.0f,
+ 13.0f, 14.0f, 15.0f, 16.0f
+ };
+}
+
+char badchararray[1] = { badchararray[0], "asdf" }; // expected-warning {{excess elements in array initializer}} expected-error {{initializer element is not a compile-time constant}}
+
+// Test the GNU extension for initializing an array from an array
+// compound literal. PR9261.
+typedef int int5[5];
+int a1[5] = (int[]){1, 2, 3, 4, 5}; // expected-warning{{initialization of an array of type 'int [5]' from a compound literal of type 'int [5]' is a GNU extension}}
+int a2[5] = (int[5]){1, 2, 3, 4, 5}; // expected-warning{{initialization of an array of type 'int [5]' from a compound literal of type 'int [5]' is a GNU extension}}
+int a3[] = ((int[]){1, 2, 3, 4, 5}); // expected-warning{{initialization of an array of type 'int []' from a compound literal of type 'int [5]' is a GNU extension}}
+int a4[] = (int[5]){1, 2, 3, 4, 5}; // expected-warning{{initialization of an array of type 'int []' from a compound literal of type 'int [5]' is a GNU extension}}
+int a5[] = (int5){1, 2, 3, 4, 5}; // expected-warning{{initialization of an array of type 'int []' from a compound literal of type 'int5' (aka 'int [5]') is a GNU extension}}
+
+int a6[5] = (int[]){1, 2, 3}; // expected-error{{cannot initialize array of type 'int [5]' with array of type 'int [3]'}}
+
+int nonconst_value();
+int a7[5] = (int[5]){ 1, 2, 3, 4, nonconst_value() }; // expected-error{{initializer element is not a compile-time constant}}
+
+// <rdar://problem/10636946>
+__attribute__((weak)) const unsigned int test10_bound = 10;
+char test10_global[test10_bound]; // expected-error {{variable length array declaration not allowed at file scope}}
+void test10() {
+ char test10_local[test10_bound] = "help"; // expected-error {{variable-sized object may not be initialized}}
+}
diff --git a/clang/test/Sema/array-size-64.c b/clang/test/Sema/array-size-64.c
new file mode 100644
index 0000000..f22e8e7
--- /dev/null
+++ b/clang/test/Sema/array-size-64.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -verify %s
+
+void f() {
+ int a[2147483647U][2147483647U]; // expected-error{{array is too large}}
+ int b[1073741825U - 1U][2147483647U];
+ int c[18446744073709551615U/sizeof(int)/2];
+}
diff --git a/clang/test/Sema/array-size.c b/clang/test/Sema/array-size.c
new file mode 100644
index 0000000..7580e3e
--- /dev/null
+++ b/clang/test/Sema/array-size.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple i686-apple-darwin -verify %s
+
+void f() {
+ int x0[1073741824]; // expected-error{{array is too large}}
+ int x1[1073741824 + 1]; // expected-error{{array is too large}}
+ int x2[(unsigned)1073741824]; // expected-error{{array is too large}}
+ int x3[(unsigned)1073741824 + 1]; // expected-error{{array is too large}}
+ int x4[1073741824 - 1];
+}
+
diff --git a/clang/test/Sema/asm.c b/clang/test/Sema/asm.c
new file mode 100644
index 0000000..44d83e9
--- /dev/null
+++ b/clang/test/Sema/asm.c
@@ -0,0 +1,125 @@
+// RUN: %clang_cc1 %s -triple i386-pc-linux-gnu -verify -fsyntax-only
+
+void f() {
+ int i;
+
+ asm ("foo\n" : : "a" (i + 2));
+ asm ("foo\n" : : "a" (f())); // expected-error {{invalid type 'void' in asm input}}
+
+ asm ("foo\n" : "=a" (f())); // expected-error {{invalid lvalue in asm output}}
+ asm ("foo\n" : "=a" (i + 2)); // expected-error {{invalid lvalue in asm output}}
+
+ asm ("foo\n" : [symbolic_name] "=a" (i) : "[symbolic_name]" (i));
+ asm ("foo\n" : "=a" (i) : "[" (i)); // expected-error {{invalid input constraint '[' in asm}}
+ asm ("foo\n" : "=a" (i) : "[foo" (i)); // expected-error {{invalid input constraint '[foo' in asm}}
+ asm ("foo\n" : "=a" (i) : "[symbolic_name]" (i)); // expected-error {{invalid input constraint '[symbolic_name]' in asm}}
+}
+
+void clobbers() {
+ asm ("nop" : : : "ax", "#ax", "%ax");
+ asm ("nop" : : : "eax", "rax", "ah", "al");
+ asm ("nop" : : : "0", "%0", "#0");
+ asm ("nop" : : : "foo"); // expected-error {{unknown register name 'foo' in asm}}
+ asm ("nop" : : : "52");
+ asm ("nop" : : : "104"); // expected-error {{unknown register name '104' in asm}}
+ asm ("nop" : : : "-1"); // expected-error {{unknown register name '-1' in asm}}
+ asm ("nop" : : : "+1"); // expected-error {{unknown register name '+1' in asm}}
+}
+
+// rdar://6094010
+void test3() {
+ int x;
+ asm(L"foo" : "=r"(x)); // expected-error {{wide string}}
+ asm("foo" : L"=r"(x)); // expected-error {{wide string}}
+}
+
+// <rdar://problem/6156893>
+void test4(const volatile void *addr)
+{
+ asm ("nop" : : "r"(*addr)); // expected-error {{invalid type 'const volatile void' in asm input for constraint 'r'}}
+ asm ("nop" : : "m"(*addr));
+
+ asm ("nop" : : "r"(test4(addr))); // expected-error {{invalid type 'void' in asm input for constraint 'r'}}
+ asm ("nop" : : "m"(test4(addr))); // expected-error {{invalid lvalue in asm input for constraint 'm'}}
+
+ asm ("nop" : : "m"(f())); // expected-error {{invalid lvalue in asm input for constraint 'm'}}
+}
+
+// <rdar://problem/6512595>
+void test5() {
+ asm("nop" : : "X" (8));
+}
+
+// PR3385
+void test6(long i) {
+ asm("nop" : : "er"(i));
+}
+
+void asm_string_tests(int i) {
+ asm("%!"); // simple asm string, %! is not an error.
+ asm("%!" : ); // expected-error {{invalid % escape in inline assembly string}}
+ asm("xyz %" : ); // expected-error {{invalid % escape in inline assembly string}}
+
+ asm ("%[somename]" :: [somename] "i"(4)); // ok
+ asm ("%[somename]" :: "i"(4)); // expected-error {{unknown symbolic operand name in inline assembly string}}
+ asm ("%[somename" :: "i"(4)); // expected-error {{unterminated symbolic operand name in inline assembly string}}
+ asm ("%[]" :: "i"(4)); // expected-error {{empty symbolic operand name in inline assembly string}}
+
+ // PR3258
+ asm("%9" :: "i"(4)); // expected-error {{invalid operand number in inline asm string}}
+ asm("%1" : "+r"(i)); // ok, referring to input.
+}
+
+// PR4077
+int test7(unsigned long long b) {
+ int a;
+ asm volatile("foo %0 %1" : "=a" (a) :"0" (b)); // expected-error {{input with type 'unsigned long long' matching output with type 'int'}}
+ return a;
+}
+
+// <rdar://problem/7574870>
+asm volatile (""); // expected-warning {{meaningless 'volatile' on asm outside function}}
+
+// PR3904
+void test8(int i) {
+ // A number in an input constraint can't point to a read-write constraint.
+ asm("" : "+r" (i), "=r"(i) : "0" (i)); // expected-error{{invalid input constraint '0' in asm}}
+}
+
+// PR3905
+void test9(int i) {
+ asm("" : [foo] "=r" (i), "=r"(i) : "1[foo]"(i)); // expected-error{{invalid input constraint '1[foo]' in asm}}
+ asm("" : [foo] "=r" (i), "=r"(i) : "[foo]1"(i)); // expected-error{{invalid input constraint '[foo]1' in asm}}
+}
+
+register int g asm("dx"); // expected-error{{global register variables are not supported}}
+
+void test10(void){
+ static int g asm ("g_asm") = 0;
+ extern int gg asm ("gg_asm");
+ __private_extern__ int ggg asm ("ggg_asm");
+
+ int a asm ("a_asm"); // expected-warning{{ignored asm label 'a_asm' on automatic variable}}
+ auto int aa asm ("aa_asm"); // expected-warning{{ignored asm label 'aa_asm' on automatic variable}}
+
+ register int r asm ("cx");
+ register int rr asm ("rr_asm"); // expected-error{{unknown register name 'rr_asm' in asm}}
+}
+
+// This is just an assert because of the boolean conversion.
+// Feel free to change the assembly to something sensible if it causes a problem.
+// rdar://problem/9414925
+void test11(void) {
+ _Bool b;
+ asm volatile ("movb %%gs:%P2,%b0" : "=q"(b) : "0"(0), "i"(5L));
+}
+
+void test12(void) {
+ register int cc __asm ("cc"); // expected-error{{unknown register name 'cc' in asm}}
+}
+
+// PR10223
+void test13(void) {
+ void *esp;
+ __asm__ volatile ("mov %%esp, %o" : "=r"(esp) : : ); // expected-error {{invalid % escape in inline assembly string}}
+}
diff --git a/clang/test/Sema/assign-null.c b/clang/test/Sema/assign-null.c
new file mode 100644
index 0000000..7f172b1
--- /dev/null
+++ b/clang/test/Sema/assign-null.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#include <stddef.h>
+
+typedef void (*hookfunc)(void *arg);
+hookfunc hook;
+
+void clear_hook() {
+ hook = NULL;
+}
diff --git a/clang/test/Sema/assign.c b/clang/test/Sema/assign.c
new file mode 100644
index 0000000..2d57029
--- /dev/null
+++ b/clang/test/Sema/assign.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void *test1(void) { return 0; }
+
+void test2 (const struct {int a;} *x) {
+ x->a = 10; // expected-error {{read-only variable is not assignable}}
+}
+
+typedef int arr[10];
+void test3() {
+ const arr b;
+ const int b2[10];
+ b[4] = 1; // expected-error {{read-only variable is not assignable}}
+ b2[4] = 1; // expected-error {{read-only variable is not assignable}}
+}
diff --git a/clang/test/Sema/ast-print.c b/clang/test/Sema/ast-print.c
new file mode 100644
index 0000000..ff66d35
--- /dev/null
+++ b/clang/test/Sema/ast-print.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -ast-print
+
+typedef void func_typedef();
+func_typedef xxx;
+
+typedef void func_t(int x);
+func_t a;
+
diff --git a/clang/test/Sema/atomic-ops.c b/clang/test/Sema/atomic-ops.c
new file mode 100644
index 0000000..f769271
--- /dev/null
+++ b/clang/test/Sema/atomic-ops.c
@@ -0,0 +1,165 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -triple=i686-linux-gnu
+
+// Basic parsing/Sema tests for __c11_atomic_*
+
+typedef enum memory_order {
+ memory_order_relaxed, memory_order_consume, memory_order_acquire,
+ memory_order_release, memory_order_acq_rel, memory_order_seq_cst
+} memory_order;
+
+struct S { char c[3]; };
+
+_Static_assert(__GCC_ATOMIC_BOOL_LOCK_FREE == 2, "");
+_Static_assert(__GCC_ATOMIC_CHAR_LOCK_FREE == 2, "");
+_Static_assert(__GCC_ATOMIC_CHAR16_T_LOCK_FREE == 2, "");
+_Static_assert(__GCC_ATOMIC_CHAR32_T_LOCK_FREE == 2, "");
+_Static_assert(__GCC_ATOMIC_WCHAR_T_LOCK_FREE == 2, "");
+_Static_assert(__GCC_ATOMIC_SHORT_LOCK_FREE == 2, "");
+_Static_assert(__GCC_ATOMIC_INT_LOCK_FREE == 2, "");
+_Static_assert(__GCC_ATOMIC_LONG_LOCK_FREE == 2, "");
+_Static_assert(__GCC_ATOMIC_LLONG_LOCK_FREE == 1, "");
+_Static_assert(__GCC_ATOMIC_POINTER_LOCK_FREE == 2, "");
+
+_Static_assert(__c11_atomic_is_lock_free(1), "");
+_Static_assert(__c11_atomic_is_lock_free(2), "");
+_Static_assert(__c11_atomic_is_lock_free(3), ""); // expected-error {{not an integral constant expression}}
+_Static_assert(__c11_atomic_is_lock_free(4), "");
+_Static_assert(__c11_atomic_is_lock_free(8), "");
+_Static_assert(__c11_atomic_is_lock_free(16), ""); // expected-error {{not an integral constant expression}}
+_Static_assert(__c11_atomic_is_lock_free(17), ""); // expected-error {{not an integral constant expression}}
+
+_Static_assert(__atomic_is_lock_free(1, 0), "");
+_Static_assert(__atomic_is_lock_free(2, 0), "");
+_Static_assert(__atomic_is_lock_free(3, 0), ""); // expected-error {{not an integral constant expression}}
+_Static_assert(__atomic_is_lock_free(4, 0), "");
+_Static_assert(__atomic_is_lock_free(8, 0), "");
+_Static_assert(__atomic_is_lock_free(16, 0), ""); // expected-error {{not an integral constant expression}}
+_Static_assert(__atomic_is_lock_free(17, 0), ""); // expected-error {{not an integral constant expression}}
+
+char i8;
+short i16;
+int i32;
+int __attribute__((vector_size(8))) i64;
+struct Incomplete *incomplete;
+
+_Static_assert(__atomic_is_lock_free(1, &i8), "");
+_Static_assert(__atomic_is_lock_free(1, &i64), "");
+_Static_assert(__atomic_is_lock_free(2, &i8), ""); // expected-error {{not an integral constant expression}}
+_Static_assert(__atomic_is_lock_free(2, &i16), "");
+_Static_assert(__atomic_is_lock_free(2, &i64), "");
+_Static_assert(__atomic_is_lock_free(4, &i16), ""); // expected-error {{not an integral constant expression}}
+_Static_assert(__atomic_is_lock_free(4, &i32), "");
+_Static_assert(__atomic_is_lock_free(4, &i64), "");
+_Static_assert(__atomic_is_lock_free(8, &i32), ""); // expected-error {{not an integral constant expression}}
+_Static_assert(__atomic_is_lock_free(8, &i64), "");
+
+_Static_assert(__atomic_always_lock_free(1, 0), "");
+_Static_assert(__atomic_always_lock_free(2, 0), "");
+_Static_assert(!__atomic_always_lock_free(3, 0), "");
+_Static_assert(__atomic_always_lock_free(4, 0), "");
+_Static_assert(__atomic_always_lock_free(8, 0), "");
+_Static_assert(!__atomic_always_lock_free(16, 0), "");
+_Static_assert(!__atomic_always_lock_free(17, 0), "");
+
+_Static_assert(__atomic_always_lock_free(1, incomplete), "");
+_Static_assert(!__atomic_always_lock_free(2, incomplete), "");
+_Static_assert(!__atomic_always_lock_free(4, incomplete), "");
+
+_Static_assert(__atomic_always_lock_free(1, &i8), "");
+_Static_assert(__atomic_always_lock_free(1, &i64), "");
+_Static_assert(!__atomic_always_lock_free(2, &i8), "");
+_Static_assert(__atomic_always_lock_free(2, &i16), "");
+_Static_assert(__atomic_always_lock_free(2, &i64), "");
+_Static_assert(!__atomic_always_lock_free(4, &i16), "");
+_Static_assert(__atomic_always_lock_free(4, &i32), "");
+_Static_assert(__atomic_always_lock_free(4, &i64), "");
+_Static_assert(!__atomic_always_lock_free(8, &i32), "");
+_Static_assert(__atomic_always_lock_free(8, &i64), "");
+
+void f(_Atomic(int) *i, _Atomic(int*) *p, _Atomic(float) *d,
+ int *I, int **P, float *D, struct S *s1, struct S *s2) {
+ __c11_atomic_init(I, 5); // expected-error {{pointer to _Atomic}}
+ __c11_atomic_load(0); // expected-error {{too few arguments to function}}
+ __c11_atomic_load(0,0,0); // expected-error {{too many arguments to function}}
+ __c11_atomic_store(0,0,0); // expected-error {{first argument to atomic builtin must be a pointer}}
+ __c11_atomic_store((int*)0,0,0); // expected-error {{first argument to atomic operation must be a pointer to _Atomic}}
+
+ __c11_atomic_load(i, memory_order_seq_cst);
+ __c11_atomic_load(p, memory_order_seq_cst);
+ __c11_atomic_load(d, memory_order_seq_cst);
+
+ int load_n_1 = __atomic_load_n(I, memory_order_relaxed);
+ int *load_n_2 = __atomic_load_n(P, memory_order_relaxed);
+ float load_n_3 = __atomic_load_n(D, memory_order_relaxed); // expected-error {{must be a pointer to integer or pointer}}
+ __atomic_load_n(s1, memory_order_relaxed); // expected-error {{must be a pointer to integer or pointer}}
+
+ __atomic_load(i, I, memory_order_relaxed); // expected-error {{must be a pointer to a trivially-copyable type}}
+ __atomic_load(I, i, memory_order_relaxed); // expected-warning {{passing '_Atomic(int) *' to parameter of type 'int *'}}
+ __atomic_load(I, *P, memory_order_relaxed);
+ __atomic_load(I, *P, memory_order_relaxed, 42); // expected-error {{too many arguments}}
+ (int)__atomic_load(I, I, memory_order_seq_cst); // expected-error {{operand of type 'void'}}
+ __atomic_load(s1, s2, memory_order_acquire);
+
+ __c11_atomic_store(i, 1, memory_order_seq_cst);
+ __c11_atomic_store(p, 1, memory_order_seq_cst); // expected-warning {{incompatible integer to pointer conversion}}
+ (int)__c11_atomic_store(d, 1, memory_order_seq_cst); // expected-error {{operand of type 'void'}}
+
+ __atomic_store_n(I, 4, memory_order_release);
+ __atomic_store_n(I, 4.0, memory_order_release);
+ __atomic_store_n(I, P, memory_order_release); // expected-warning {{parameter of type 'int'}}
+ __atomic_store_n(i, 1, memory_order_release); // expected-error {{must be a pointer to integer or pointer}}
+ __atomic_store_n(s1, *s2, memory_order_release); // expected-error {{must be a pointer to integer or pointer}}
+
+ __atomic_store(I, *P, memory_order_release);
+ __atomic_store(s1, s2, memory_order_release);
+ __atomic_store(i, I, memory_order_release); // expected-error {{trivially-copyable}}
+
+ int exchange_1 = __c11_atomic_exchange(i, 1, memory_order_seq_cst);
+ int exchange_2 = __c11_atomic_exchange(I, 1, memory_order_seq_cst); // expected-error {{must be a pointer to _Atomic}}
+ int exchange_3 = __atomic_exchange_n(i, 1, memory_order_seq_cst); // expected-error {{must be a pointer to integer or pointer}}
+ int exchange_4 = __atomic_exchange_n(I, 1, memory_order_seq_cst);
+
+ __atomic_exchange(s1, s2, s2, memory_order_seq_cst);
+ __atomic_exchange(s1, I, P, memory_order_seq_cst); // expected-warning 2{{parameter of type 'struct S *'}}
+ (int)__atomic_exchange(s1, s2, s2, memory_order_seq_cst); // expected-error {{operand of type 'void'}}
+
+ __c11_atomic_fetch_add(i, 1, memory_order_seq_cst);
+ __c11_atomic_fetch_add(p, 1, memory_order_seq_cst);
+ __c11_atomic_fetch_add(d, 1, memory_order_seq_cst); // expected-error {{must be a pointer to atomic integer or pointer}}
+
+ __atomic_fetch_add(i, 3, memory_order_seq_cst); // expected-error {{pointer to integer or pointer}}
+ __atomic_fetch_sub(I, 3, memory_order_seq_cst);
+ __atomic_fetch_sub(P, 3, memory_order_seq_cst);
+ __atomic_fetch_sub(D, 3, memory_order_seq_cst); // expected-error {{must be a pointer to integer or pointer}}
+ __atomic_fetch_sub(s1, 3, memory_order_seq_cst); // expected-error {{must be a pointer to integer or pointer}}
+
+ __c11_atomic_fetch_and(i, 1, memory_order_seq_cst);
+ __c11_atomic_fetch_and(p, 1, memory_order_seq_cst); // expected-error {{must be a pointer to atomic integer}}
+ __c11_atomic_fetch_and(d, 1, memory_order_seq_cst); // expected-error {{must be a pointer to atomic integer}}
+
+ __atomic_fetch_and(i, 3, memory_order_seq_cst); // expected-error {{pointer to integer}}
+ __atomic_fetch_or(I, 3, memory_order_seq_cst);
+ __atomic_fetch_xor(P, 3, memory_order_seq_cst); // expected-error {{must be a pointer to integer}}
+ __atomic_fetch_or(D, 3, memory_order_seq_cst); // expected-error {{must be a pointer to integer}}
+ __atomic_fetch_and(s1, 3, memory_order_seq_cst); // expected-error {{must be a pointer to integer}}
+
+ _Bool cmpexch_1 = __c11_atomic_compare_exchange_strong(i, 0, 1, memory_order_seq_cst, memory_order_seq_cst);
+ _Bool cmpexch_2 = __c11_atomic_compare_exchange_strong(p, 0, (int*)1, memory_order_seq_cst, memory_order_seq_cst);
+ _Bool cmpexch_3 = __c11_atomic_compare_exchange_strong(d, (int*)0, 1, memory_order_seq_cst, memory_order_seq_cst); // expected-warning {{incompatible pointer types}}
+
+ _Bool cmpexch_4 = __atomic_compare_exchange_n(I, I, 5, 1, memory_order_seq_cst, memory_order_seq_cst);
+ _Bool cmpexch_5 = __atomic_compare_exchange_n(I, P, 5, 0, memory_order_seq_cst, memory_order_seq_cst); // expected-warning {{; dereference with *}}
+ _Bool cmpexch_6 = __atomic_compare_exchange_n(I, I, P, 0, memory_order_seq_cst, memory_order_seq_cst); // expected-warning {{passing 'int **' to parameter of type 'int'}}
+
+ _Bool cmpexch_7 = __atomic_compare_exchange(I, I, 5, 1, memory_order_seq_cst, memory_order_seq_cst); // expected-warning {{passing 'int' to parameter of type 'int *'}}
+ _Bool cmpexch_8 = __atomic_compare_exchange(I, P, I, 0, memory_order_seq_cst, memory_order_seq_cst); // expected-warning {{; dereference with *}}
+ _Bool cmpexch_9 = __atomic_compare_exchange(I, I, I, 0, memory_order_seq_cst, memory_order_seq_cst);
+
+ const volatile int flag_k = 0;
+ volatile int flag = 0;
+ (void)(int)__atomic_test_and_set(&flag_k, memory_order_seq_cst); // expected-warning {{passing 'const volatile int *' to parameter of type 'volatile void *'}}
+ (void)(int)__atomic_test_and_set(&flag, memory_order_seq_cst);
+ __atomic_clear(&flag_k, memory_order_seq_cst); // expected-warning {{passing 'const volatile int *' to parameter of type 'volatile void *'}}
+ __atomic_clear(&flag, memory_order_seq_cst);
+ (int)__atomic_clear(&flag, memory_order_seq_cst); // expected-error {{operand of type 'void'}}
+}
diff --git a/clang/test/Sema/atomic-type.c b/clang/test/Sema/atomic-type.c
new file mode 100644
index 0000000..a4ac552
--- /dev/null
+++ b/clang/test/Sema/atomic-type.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+// Basic parsing/Sema tests for _Atomic
+// No operations are actually supported on objects of this type yet.
+// The qualifier syntax is not supported yet.
+_Atomic(int) t1;
+_Atomic(int) *t2 = &t1;
+void testf(void*);
+void f(void) {
+ _Atomic(_Atomic(int)*) t3;
+ _Atomic(_Atomic(int)*) *t4[2] = { &t3, 0 };
+ testf(t4);
+}
+extern _Atomic(int (*)(int(*)[], int(*)[10])) mergetest;
+extern _Atomic(int (*)(int(*)[10], int(*)[])) mergetest;
+extern _Atomic(int (*)(int(*)[10], int(*)[10])) mergetest;
+
+_Atomic(int()) error1; // expected-error {{_Atomic cannot be applied to function type}}
+_Atomic(struct ErrorS) error2; // expected-error {{_Atomic cannot be applied to incomplete type}} expected-note {{forward declaration}}
+_Atomic(int[10]) error3; // expected-error {{_Atomic cannot be applied to array type}}
+_Atomic(const int) error4; // expected-error {{_Atomic cannot be applied to qualified type}}
+_Atomic(_Atomic(int)) error5; // expected-error {{_Atomic cannot be applied to atomic type}}
diff --git a/clang/test/Sema/attr-alias.c b/clang/test/Sema/attr-alias.c
new file mode 100644
index 0000000..151052f
--- /dev/null
+++ b/clang/test/Sema/attr-alias.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify %s
+
+void g() {}
+
+// It is important that the following string be in the error message. The gcc
+// testsuite looks for it to decide if a target supports aliases.
+
+void f() __attribute__((alias("g"))); //expected-error {{only weak aliases are supported}}
diff --git a/clang/test/Sema/attr-aligned.c b/clang/test/Sema/attr-aligned.c
new file mode 100644
index 0000000..c094ff1
--- /dev/null
+++ b/clang/test/Sema/attr-aligned.c
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s
+
+int x __attribute__((aligned(3))); // expected-error {{requested alignment is not a power of 2}}
+
+// PR3254
+short g0[3] __attribute__((aligned));
+short g0_chk[__alignof__(g0) == 16 ? 1 : -1];
+
+// <rdar://problem/6840045>
+typedef char ueber_aligned_char __attribute__((aligned(8)));
+
+struct struct_with_ueber_char {
+ ueber_aligned_char c;
+};
+
+char a = 0;
+
+char a0[__alignof__(ueber_aligned_char) == 8? 1 : -1] = { 0 };
+char a1[__alignof__(struct struct_with_ueber_char) == 8? 1 : -1] = { 0 };
+char a2[__alignof__(a) == 1? : -1] = { 0 };
+char a3[sizeof(a) == 1? : -1] = { 0 };
+
+// rdar://problem/8335865
+int b __attribute__((aligned(2)));
+char b1[__alignof__(b) == 2 ?: -1] = {0};
+
+struct C { int member __attribute__((aligned(2))); } c;
+char c1[__alignof__(c) == 4 ?: -1] = {0};
+char c2[__alignof__(c.member) == 4 ?: -1] = {0};
+
+struct D { int member __attribute__((aligned(2))) __attribute__((packed)); } d;
+char d1[__alignof__(d) == 2 ?: -1] = {0};
+char d2[__alignof__(d.member) == 2 ?: -1] = {0};
+
+struct E { int member __attribute__((aligned(2))); } __attribute__((packed));
+struct E e;
+char e1[__alignof__(e) == 2 ?: -1] = {0};
+char e2[__alignof__(e.member) == 2 ?: -1] = {0};
diff --git a/clang/test/Sema/attr-args.c b/clang/test/Sema/attr-args.c
new file mode 100644
index 0000000..6135801
--- /dev/null
+++ b/clang/test/Sema/attr-args.c
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -DATTR=noreturn -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=always_inline -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=cdecl -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=const -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=fastcall -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=malloc -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=nothrow -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=stdcall -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=used -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=unused -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=weak -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+
+#define ATTR_DECL(a) __attribute__((ATTR(a)))
+
+int a;
+
+inline ATTR_DECL(a) void* foo(); // expected-error{{attribute takes no arguments}}
+
+
+
+// RUN: %clang_cc1 -DATTR=noreturn -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=always_inline -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=cdecl -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=const -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=fastcall -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=malloc -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=nothrow -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=stdcall -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=used -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=unused -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+// RUN: %clang_cc1 -DATTR=weak -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+
+#define ATTR_DECL(a) __attribute__((ATTR(a)))
+
+int a;
+
+inline ATTR_DECL(a) void* foo(); // expected-error{{attribute takes no arguments}}
+
+
+
diff --git a/clang/test/Sema/attr-availability-ios.c b/clang/test/Sema/attr-availability-ios.c
new file mode 100644
index 0000000..ea05e17
--- /dev/null
+++ b/clang/test/Sema/attr-availability-ios.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 "-triple" "x86_64-apple-ios3.0" -fsyntax-only -verify %s
+
+void f0(int) __attribute__((availability(ios,introduced=2.0,deprecated=2.1)));
+void f1(int) __attribute__((availability(ios,introduced=2.1)));
+void f2(int) __attribute__((availability(ios,introduced=2.0,deprecated=3.0)));
+void f3(int) __attribute__((availability(ios,introduced=3.0)));
+void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(ios,introduced=2.0,deprecated=2.1,obsoleted=3.0))); // expected-note{{explicitly marked unavailable}}
+
+void f5(int) __attribute__((availability(ios,introduced=2.0))) __attribute__((availability(ios,deprecated=3.0)));
+void f6(int) __attribute__((availability(ios,deprecated=3.0)));
+void f6(int) __attribute__((availability(ios,introduced=2.0)));
+
+void test() {
+ f0(0); // expected-warning{{'f0' is deprecated: first deprecated in iOS 2.1}}
+ f1(0);
+ f2(0); // expected-warning{{'f2' is deprecated: first deprecated in iOS 3.0}}
+ f3(0);
+ f4(0); // expected-error{{f4' is unavailable: obsoleted in iOS 3.0}}
+ f5(0); // expected-warning{{'f5' is deprecated: first deprecated in iOS 3.0}}
+ f6(0); // expected-warning{{'f6' is deprecated: first deprecated in iOS 3.0}}
+}
diff --git a/clang/test/Sema/attr-availability-macosx.c b/clang/test/Sema/attr-availability-macosx.c
new file mode 100644
index 0000000..1de26e9
--- /dev/null
+++ b/clang/test/Sema/attr-availability-macosx.c
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 "-triple" "x86_64-apple-darwin9.0.0" -fsyntax-only -verify %s
+
+void f0(int) __attribute__((availability(macosx,introduced=10.4,deprecated=10.6)));
+void f1(int) __attribute__((availability(macosx,introduced=10.5)));
+void f2(int) __attribute__((availability(macosx,introduced=10.4,deprecated=10.5)));
+void f3(int) __attribute__((availability(macosx,introduced=10.6)));
+void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(ios,introduced=2.0,deprecated=3.0))); // expected-note{{explicitly marked unavailable}}
+void f5(int) __attribute__((availability(ios,introduced=3.2), availability(macosx,unavailable))); // expected-note{{function has been explicitly marked unavailable here}}
+
+void test() {
+ f0(0);
+ f1(0);
+ f2(0); // expected-warning{{'f2' is deprecated: first deprecated in Mac OS X 10.5}}
+ f3(0);
+ f4(0); // expected-error{{f4' is unavailable: obsoleted in Mac OS X 10.5}}
+ f5(0); // expected-error{{'f5' is unavailable: not available on Mac OS X}}
+}
+
+// rdar://10535640
+
+enum {
+ foo __attribute__((availability(macosx,introduced=8.0,deprecated=9.0)))
+};
+
+enum {
+ bar __attribute__((availability(macosx,introduced=8.0,deprecated=9.0))) = foo
+};
+
+enum __attribute__((availability(macosx,introduced=8.0,deprecated=9.0))) {
+ bar1 = foo
+};
diff --git a/clang/test/Sema/attr-availability.c b/clang/test/Sema/attr-availability.c
new file mode 100644
index 0000000..0e6ea96
--- /dev/null
+++ b/clang/test/Sema/attr-availability.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -verify %s
+
+void f0() __attribute__((availability(macosx,introduced=10.4,deprecated=10.2))); // expected-warning{{feature cannot be deprecated in Mac OS X version 10.2 before it was introduced in version 10.4; attribute ignored}}
+void f1() __attribute__((availability(ios,obsoleted=2.1,deprecated=3.0))); // expected-warning{{feature cannot be obsoleted in iOS version 2.1 before it was deprecated in version 3.0; attribute ignored}}
+void f2() __attribute__((availability(ios,introduced=2.1,deprecated=2.1)));
+
+void f3() __attribute__((availability(otheros,introduced=2.2))); // expected-warning{{unknown platform 'otheros' in availability macro}}
+
+// rdar://10095131
+extern void
+ATSFontGetName(const char *oName) __attribute__((availability(macosx,introduced=8.0,deprecated=9.0, message="use CTFontCopyFullName")));
+
+extern void
+ATSFontGetPostScriptName(int flags) __attribute__((availability(macosx,introduced=8.0,obsoleted=9.0, message="use ATSFontGetFullPostScriptName"))); // expected-note {{function has been explicitly marked unavailable here}}
+
+void test_10095131() {
+ ATSFontGetName("Hello"); // expected-warning {{'ATSFontGetName' is deprecated: first deprecated in Mac OS X 9.0 - use CTFontCopyFullName}}
+ ATSFontGetPostScriptName(100); // expected-error {{'ATSFontGetPostScriptName' is unavailable: obsoleted in Mac OS X 9.0 - use ATSFontGetFullPostScriptName}}
+}
+
+// rdar://10711037
+__attribute__((availability(macos, unavailable))) // expected-warning {{attribute 'availability' is ignored}}
+enum {
+ NSDataWritingFileProtectionWriteOnly = 0x30000000,
+ NSDataWritingFileProtectionCompleteUntilUserAuthentication = 0x40000000,
+};
diff --git a/clang/test/Sema/attr-cleanup.c b/clang/test/Sema/attr-cleanup.c
new file mode 100644
index 0000000..59ebbfc
--- /dev/null
+++ b/clang/test/Sema/attr-cleanup.c
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+void c1(int *a);
+
+extern int g1 __attribute((cleanup(c1))); // expected-warning {{cleanup attribute ignored}}
+int g2 __attribute((cleanup(c1))); // expected-warning {{cleanup attribute ignored}}
+static int g3 __attribute((cleanup(c1))); // expected-warning {{cleanup attribute ignored}}
+
+void t1()
+{
+ int v1 __attribute((cleanup)); // expected-error {{attribute takes one argument}}
+ int v2 __attribute((cleanup(1, 2))); // expected-error {{attribute takes one argument}}
+
+ static int v3 __attribute((cleanup(c1))); // expected-warning {{cleanup attribute ignored}}
+
+ int v4 __attribute((cleanup(h))); // expected-error {{'cleanup' argument 'h' not found}}
+
+ int v5 __attribute((cleanup(c1)));
+ int v6 __attribute((cleanup(v3))); // expected-error {{'cleanup' argument 'v3' is not a function}}
+}
+
+struct s {
+ int a, b;
+};
+
+void c2();
+void c3(struct s a);
+
+void t2()
+{
+ int v1 __attribute__((cleanup(c2))); // expected-error {{'cleanup' function 'c2' must take 1 parameter}}
+ int v2 __attribute__((cleanup(c3))); // expected-error {{'cleanup' function 'c3' parameter has type 'struct s' which is incompatible with type 'int *'}}
+}
+
+// This is a manufactured testcase, but gcc accepts it...
+void c4(_Bool a);
+void t4() {
+ __attribute((cleanup(c4))) void* g;
+}
+
diff --git a/clang/test/Sema/attr-decl-after-definition.c b/clang/test/Sema/attr-decl-after-definition.c
new file mode 100644
index 0000000..4d32e00
--- /dev/null
+++ b/clang/test/Sema/attr-decl-after-definition.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void foo();
+void foo() __attribute__((unused));
+void foo() __attribute__((unused));
+void foo(){} // expected-note {{previous definition is here}}
+void foo() __attribute__((constructor)); // expected-warning {{must precede definition}}
+void foo();
+
+int bar;
+extern int bar;
+int bar;
+int bar __attribute__((weak));
+int bar __attribute__((used));
+extern int bar __attribute__((weak));
+int bar = 0; // expected-note {{previous definition is here}}
+int bar __attribute__((weak)); // expected-warning {{must precede definition}}
+int bar;
+
diff --git a/clang/test/Sema/attr-declspec-ignored.c b/clang/test/Sema/attr-declspec-ignored.c
new file mode 100644
index 0000000..6fd35c0
--- /dev/null
+++ b/clang/test/Sema/attr-declspec-ignored.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+__attribute__((visibility("hidden"))) __attribute__((aligned)) struct A; // expected-warning{{attribute 'visibility' is ignored, place it after "struct" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "struct" to apply attribute to type declaration}}
+__attribute__((visibility("hidden"))) __attribute__((aligned)) union B; // expected-warning{{attribute 'visibility' is ignored, place it after "union" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
+__attribute__((visibility("hidden"))) __attribute__((aligned)) enum C {C}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
+
+__attribute__((visibility("hidden"))) __attribute__((aligned)) struct D {} d;
+__attribute__((visibility("hidden"))) __attribute__((aligned)) union E {} e;
+__attribute__((visibility("hidden"))) __attribute__((aligned)) enum F {F} f;
diff --git a/clang/test/Sema/attr-deprecated-message.c b/clang/test/Sema/attr-deprecated-message.c
new file mode 100644
index 0000000..5de31d0
--- /dev/null
+++ b/clang/test/Sema/attr-deprecated-message.c
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+// rdar: // 6734520
+
+typedef int INT1 __attribute__((deprecated("Please avoid INT1")));
+
+typedef INT1 INT2 __attribute__ ((__deprecated__("Please avoid INT2")));
+
+typedef INT1 INT1a; // expected-warning {{'INT1' is deprecated: Please avoid INT1}}
+
+typedef INT1 INT1b __attribute__ ((deprecated("Please avoid INT1b")));
+
+INT1 should_be_unavailable; // expected-warning {{'INT1' is deprecated: Please avoid INT1}}
+INT1a should_not_be_deprecated;
+
+INT1 f1(void) __attribute__ ((deprecated("Please avoid f1")));
+INT1 f2(void); // expected-warning {{'INT1' is deprecated: Please avoid INT1}}
+
+typedef enum {red, green, blue} Color __attribute__((deprecated("Please avoid Color")));
+
+
+Color c1; // expected-warning {{'Color' is deprecated: Please avoid Color}}
+
+int g1;
+int g2 __attribute__ ((deprecated("Please avoid g2")));
+
+int func1()
+{
+ int (*pf)() = f1; // expected-warning {{'f1' is deprecated: Please avoid f1}}
+ int i = f2();
+ return g1 + g2; // expected-warning {{'g2' is deprecated: Please avoid g2}}
+}
diff --git a/clang/test/Sema/attr-deprecated.c b/clang/test/Sema/attr-deprecated.c
new file mode 100644
index 0000000..4760dab
--- /dev/null
+++ b/clang/test/Sema/attr-deprecated.c
@@ -0,0 +1,115 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+int f() __attribute__((deprecated));
+void g() __attribute__((deprecated));
+void g();
+
+extern int var __attribute__((deprecated));
+
+int a() {
+ int (*ptr)() = f; // expected-warning {{'f' is deprecated}}
+ f(); // expected-warning {{'f' is deprecated}}
+
+ // test if attributes propagate to functions
+ g(); // expected-warning {{'g' is deprecated}}
+
+ return var; // expected-warning {{'var' is deprecated}}
+}
+
+// test if attributes propagate to variables
+extern int var;
+int w() {
+ return var; // expected-warning {{'var' is deprecated}}
+}
+
+int old_fn() __attribute__ ((deprecated));
+int old_fn();
+int (*fn_ptr)() = old_fn; // expected-warning {{'old_fn' is deprecated}}
+
+int old_fn() {
+ return old_fn()+1; // no warning, deprecated functions can use deprecated symbols.
+}
+
+
+struct foo {
+ int x __attribute__((deprecated));
+};
+
+void test1(struct foo *F) {
+ ++F->x; // expected-warning {{'x' is deprecated}}
+ struct foo f1 = { .x = 17 }; // expected-warning {{'x' is deprecated}}
+ struct foo f2 = { 17 }; // expected-warning {{'x' is deprecated}}
+}
+
+typedef struct foo foo_dep __attribute__((deprecated));
+foo_dep *test2; // expected-warning {{'foo_dep' is deprecated}}
+
+struct __attribute__((deprecated,
+ invalid_attribute)) bar_dep ; // expected-warning {{unknown attribute 'invalid_attribute' ignored}}
+
+struct bar_dep *test3; // expected-warning {{'bar_dep' is deprecated}}
+
+
+// These should not warn because the actually declaration itself is deprecated.
+// rdar://6756623
+foo_dep *test4 __attribute__((deprecated));
+struct bar_dep *test5 __attribute__((deprecated));
+
+typedef foo_dep test6(struct bar_dep*); // expected-warning {{'foo_dep' is deprecated}} \
+ // expected-warning {{'bar_dep' is deprecated}}
+typedef foo_dep test7(struct bar_dep*) __attribute__((deprecated));
+
+int test8(char *p) {
+ p += sizeof(foo_dep); // expected-warning {{'foo_dep' is deprecated}}
+
+ foo_dep *ptr; // expected-warning {{'foo_dep' is deprecated}}
+ ptr = (foo_dep*) p; // expected-warning {{'foo_dep' is deprecated}}
+
+ int func(foo_dep *foo); // expected-warning {{'foo_dep' is deprecated}}
+ return func(ptr);
+}
+
+foo_dep *test9(void) __attribute__((deprecated));
+foo_dep *test9(void) {
+ void* myalloc(unsigned long);
+
+ foo_dep *ptr
+ = (foo_dep*)
+ myalloc(sizeof(foo_dep));
+ return ptr;
+}
+
+void test10(void) __attribute__((deprecated));
+void test10(void) {
+ if (sizeof(foo_dep) == sizeof(void*)) {
+ }
+ foo_dep *localfunc(void);
+ foo_dep localvar;
+}
+
+char test11[sizeof(foo_dep)] __attribute__((deprecated));
+char test12[sizeof(foo_dep)]; // expected-warning {{'foo_dep' is deprecated}}
+
+int test13(foo_dep *foo) __attribute__((deprecated));
+int test14(foo_dep *foo); // expected-warning {{'foo_dep' is deprecated}}
+
+unsigned long test15 = sizeof(foo_dep); // expected-warning {{'foo_dep' is deprecated}}
+unsigned long test16 __attribute__((deprecated))
+ = sizeof(foo_dep);
+
+foo_dep test17, // expected-warning {{'foo_dep' is deprecated}}
+ test18 __attribute__((deprecated)),
+ test19;
+
+// rdar://problem/8518751
+enum __attribute__((deprecated)) Test20 {
+ test20_a __attribute__((deprecated)),
+ test20_b
+};
+void test20() {
+ enum Test20 f; // expected-warning {{'Test20' is deprecated}}
+ f = test20_a; // expected-warning {{'test20_a' is deprecated}}
+ f = test20_b; // expected-warning {{'test20_b' is deprecated}}
+}
+
+char test21[__has_feature(attribute_deprecated_with_message) ? 1 : -1];
diff --git a/clang/test/Sema/attr-format.c b/clang/test/Sema/attr-format.c
new file mode 100644
index 0000000..a223e08
--- /dev/null
+++ b/clang/test/Sema/attr-format.c
@@ -0,0 +1,80 @@
+//RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#include <stdarg.h>
+
+void a(const char *a, ...) __attribute__((format(printf, 1,2))); // no-error
+void b(const char *a, ...) __attribute__((format(printf, 1,1))); // expected-error {{'format' attribute parameter 3 is out of bounds}}
+void c(const char *a, ...) __attribute__((format(printf, 0,2))); // expected-error {{'format' attribute parameter 2 is out of bounds}}
+void d(const char *a, int c) __attribute__((format(printf, 1,2))); // expected-error {{format attribute requires variadic function}}
+void e(char *str, int c, ...) __attribute__((format(printf, 2,3))); // expected-error {{format argument not a string type}}
+
+typedef const char* xpto;
+void f(xpto c, va_list list) __attribute__((format(printf, 1, 0))); // no-error
+void g(xpto c) __attribute__((format(printf, 1, 0))); // no-error
+
+void y(char *str) __attribute__((format(strftime, 1,0))); // no-error
+void z(char *str, int c, ...) __attribute__((format(strftime, 1,2))); // expected-error {{strftime format attribute requires 3rd parameter to be 0}}
+
+int (*f_ptr)(char*,...) __attribute__((format(printf, 1,2))); // no-error
+int (*f2_ptr)(double,...) __attribute__((format(printf, 1, 2))); // expected-error {{format argument not a string type}}
+
+struct _mystruct {
+ int (*printf)(const char *format, ...) __attribute__((__format__(printf, 1, 2))); // no-error
+ int (*printf2)(double format, ...) __attribute__((__format__(printf, 1, 2))); // expected-error {{format argument not a string type}}
+};
+
+typedef int (*f3_ptr)(char*,...) __attribute__((format(printf,1,0))); // no-error
+
+// <rdar://problem/6623513>
+int rdar6623513(void *, const char*, const char*, ...)
+ __attribute__ ((format (printf, 3, 0)));
+
+int rdar6623513_aux(int len, const char* s) {
+ rdar6623513(0, "hello", "%.*s", len, s);
+}
+
+
+
+// same as format(printf(...))...
+void a2(const char *a, ...) __attribute__((format(printf0, 1,2))); // no-error
+void b2(const char *a, ...) __attribute__((format(printf0, 1,1))); // expected-error {{'format' attribute parameter 3 is out of bounds}}
+void c2(const char *a, ...) __attribute__((format(printf0, 0,2))); // expected-error {{'format' attribute parameter 2 is out of bounds}}
+void d2(const char *a, int c) __attribute__((format(printf0, 1,2))); // expected-error {{format attribute requires variadic function}}
+void e2(char *str, int c, ...) __attribute__((format(printf0, 2,3))); // expected-error {{format argument not a string type}}
+
+// FreeBSD usage
+#define __printf0like(fmt,va) __attribute__((__format__(__printf0__,fmt,va)))
+void null(int i, const char *a, ...) __printf0like(2,0); // no-error
+void null(int i, const char *a, ...) { // expected-note{{passing argument to parameter 'a' here}}
+ if (a)
+ (void)0/* vprintf(...) would go here */;
+}
+
+void callnull(void){
+ null(0, 0); // no error
+ null(0, (char*)0); // no error
+ null(0, (void*)0); // no error
+ null(0, (int*)0); // expected-warning {{incompatible pointer types}}
+}
+
+
+
+// PR4470
+int xx_vprintf(const char *, va_list);
+
+const char *foo(const char *format) __attribute__((format_arg(1)));
+
+void __attribute__((format(printf, 1, 0)))
+foo2(const char *fmt, va_list va) {
+ xx_vprintf(foo(fmt), va);
+}
+
+// PR6542
+extern void gcc_format (const char *, ...)
+ __attribute__ ((__format__(__gcc_diag__, 1, 2)));
+extern void gcc_cformat (const char *, ...)
+ __attribute__ ((__format__(__gcc_cdiag__, 1, 2)));
+extern void gcc_cxxformat (const char *, ...)
+ __attribute__ ((__format__(__gcc_cxxdiag__, 1, 2)));
+extern void gcc_tformat (const char *, ...)
+ __attribute__ ((__format__(__gcc_tdiag__, 1, 2)));
diff --git a/clang/test/Sema/attr-format_arg.c b/clang/test/Sema/attr-format_arg.c
new file mode 100644
index 0000000..64a2387
--- /dev/null
+++ b/clang/test/Sema/attr-format_arg.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int printf(const char *, ...);
+
+const char* f(const char *s) __attribute__((format_arg(1)));
+
+void g(const char *s) {
+ printf("%d", 123);
+ printf("%d %d", 123); // expected-warning{{more '%' conversions than data arguments}}
+
+ printf(f("%d"), 123);
+ printf(f("%d %d"), 123); // expected-warning{{more '%' conversions than data arguments}}
+}
diff --git a/clang/test/Sema/attr-malloc.c b/clang/test/Sema/attr-malloc.c
new file mode 100644
index 0000000..2cec84d
--- /dev/null
+++ b/clang/test/Sema/attr-malloc.c
@@ -0,0 +1,28 @@
+// RUN: %clang -Xclang -verify -fsyntax-only %s
+// RUN: %clang -emit-llvm -S -o %t %s
+
+#include <stddef.h>
+
+// Declare malloc here explicitly so we don't depend on system headers.
+void * malloc(size_t) __attribute((malloc));
+
+int no_vars __attribute((malloc)); // expected-warning {{functions returning a pointer type}}
+
+void returns_void (void) __attribute((malloc)); // expected-warning {{functions returning a pointer type}}
+int returns_int (void) __attribute((malloc)); // expected-warning {{functions returning a pointer type}}
+int * returns_intptr(void) __attribute((malloc)); // no-warning
+typedef int * iptr;
+iptr returns_iptr (void) __attribute((malloc)); // no-warning
+
+__attribute((malloc)) void *(*f)(); // expected-warning{{'malloc' attribute only applies to functions returning a pointer type}}
+__attribute((malloc)) int (*g)(); // expected-warning{{'malloc' attribute only applies to functions returning a pointer type}}
+
+__attribute((malloc))
+void * xalloc(unsigned n) { return malloc(n); } // no-warning
+// RUN: grep 'define noalias .* @xalloc(' %t
+
+#define malloc_like __attribute((__malloc__))
+void * xalloc2(unsigned) malloc_like;
+void * xalloc2(unsigned n) { return malloc(n); }
+// RUN: grep 'define noalias .* @xalloc2(' %t
+
diff --git a/clang/test/Sema/attr-mode.c b/clang/test/Sema/attr-mode.c
new file mode 100644
index 0000000..0c53362
--- /dev/null
+++ b/clang/test/Sema/attr-mode.c
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -DTEST_32BIT_X86 -fsyntax-only \
+// RUN: -verify %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -DTEST_64BIT_X86 -fsyntax-only \
+// RUN: -verify %s
+
+typedef int i16_1 __attribute((mode(HI)));
+int i16_1_test[sizeof(i16_1) == 2 ? 1 : -1];
+typedef int i16_2 __attribute((__mode__(__HI__)));
+int i16_2_test[sizeof(i16_1) == 2 ? 1 : -1];
+
+typedef float f64 __attribute((mode(DF)));
+int f64_test[sizeof(f64) == 8 ? 1 : -1];
+
+typedef int invalid_1 __attribute((mode)); // expected-error{{attribute requires unquoted parameter}}
+typedef int invalid_2 __attribute((mode())); // expected-error{{attribute requires unquoted parameter}}
+typedef int invalid_3 __attribute((mode(II))); // expected-error{{unknown machine mode}}
+typedef struct {int i,j,k;} invalid_4 __attribute((mode(SI))); // expected-error{{mode attribute only supported for integer and floating-point types}}
+typedef float invalid_5 __attribute((mode(SI))); // expected-error{{type of machine mode does not match type of base type}}
+
+int **__attribute((mode(QI)))* i32; // expected-error{{mode attribute}}
+
+typedef _Complex double c32 __attribute((mode(SC)));
+int c32_test[sizeof(c32) == 8 ? 1 : -1];
+typedef _Complex float c64 __attribute((mode(DC)));
+typedef _Complex float c80 __attribute((mode(XC)));
+
+// PR6108: Correctly select 'long' built in type on 64-bit platforms for 64 bit
+// modes. Also test other mode-based conversions.
+typedef int i8_mode_t __attribute__ ((__mode__ (__QI__)));
+typedef unsigned int ui8_mode_t __attribute__ ((__mode__ (__QI__)));
+typedef int i16_mode_t __attribute__ ((__mode__ (__HI__)));
+typedef unsigned int ui16_mode_t __attribute__ ((__mode__ (__HI__)));
+typedef int i32_mode_t __attribute__ ((__mode__ (__SI__)));
+typedef unsigned int ui32_mode_t __attribute__ ((__mode__ (__SI__)));
+typedef int i64_mode_t __attribute__ ((__mode__ (__DI__)));
+typedef unsigned int ui64_mode_t __attribute__ ((__mode__ (__DI__)));
+void f_i8_arg(i8_mode_t* x) { (void)x; }
+void f_ui8_arg(ui8_mode_t* x) { (void)x; }
+void f_i16_arg(i16_mode_t* x) { (void)x; }
+void f_ui16_arg(ui16_mode_t* x) { (void)x; }
+void f_i32_arg(i32_mode_t* x) { (void)x; }
+void f_ui32_arg(ui32_mode_t* x) { (void)x; }
+void f_i64_arg(i64_mode_t* x) { (void)x; }
+void f_ui64_arg(ui64_mode_t* x) { (void)x; }
+void test_char_to_i8(signed char* y) { f_i8_arg(y); }
+void test_char_to_ui8(unsigned char* y) { f_ui8_arg(y); }
+void test_short_to_i16(short* y) { f_i16_arg(y); }
+void test_short_to_ui16(unsigned short* y) { f_ui16_arg(y); }
+void test_int_to_i32(int* y) { f_i32_arg(y); }
+void test_int_to_ui32(unsigned int* y) { f_ui32_arg(y); }
+#if TEST_32BIT_X86
+void test_long_to_i64(long long* y) { f_i64_arg(y); }
+void test_long_to_ui64(unsigned long long* y) { f_ui64_arg(y); }
+#elif TEST_64BIT_X86
+void test_long_to_i64(long* y) { f_i64_arg(y); }
+void test_long_to_ui64(unsigned long* y) { f_ui64_arg(y); }
+#else
+#error Unknown test architecture.
+#endif
diff --git a/clang/test/Sema/attr-naked.c b/clang/test/Sema/attr-naked.c
new file mode 100644
index 0000000..d9fa542
--- /dev/null
+++ b/clang/test/Sema/attr-naked.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+int a __attribute__((naked)); // expected-warning {{'naked' attribute only applies to functions}}
+
+__attribute__((naked)) int t0(void) {
+ __asm__ volatile("mov r0, #0");
+}
+
+void t1() __attribute__((naked));
+
+void t2() __attribute__((naked(2))); // expected-error {{attribute takes no arguments}}
+
diff --git a/clang/test/Sema/attr-nodebug.c b/clang/test/Sema/attr-nodebug.c
new file mode 100644
index 0000000..a66e961
--- /dev/null
+++ b/clang/test/Sema/attr-nodebug.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+int a __attribute__((nodebug)); // expected-warning {{'nodebug' attribute only applies to functions}}
+
+void t1() __attribute__((nodebug));
+
+void t2() __attribute__((nodebug(2))); // expected-error {{attribute takes no arguments}}
+
diff --git a/clang/test/Sema/attr-noinline.c b/clang/test/Sema/attr-noinline.c
new file mode 100644
index 0000000..dfc88a8
--- /dev/null
+++ b/clang/test/Sema/attr-noinline.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+int a __attribute__((noinline)); // expected-warning {{'noinline' attribute only applies to functions}}
+
+void t1() __attribute__((noinline));
+
+void t2() __attribute__((noinline(2))); // expected-error {{attribute takes no arguments}}
+
diff --git a/clang/test/Sema/attr-noreturn.c b/clang/test/Sema/attr-noreturn.c
new file mode 100644
index 0000000..5c643ff
--- /dev/null
+++ b/clang/test/Sema/attr-noreturn.c
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+static void (*fp0)(void) __attribute__((noreturn));
+
+void fatal();
+
+static void __attribute__((noreturn)) f0(void) {
+ fatal();
+} // expected-warning {{function declared 'noreturn' should not return}}
+
+// On K&R
+int f1() __attribute__((noreturn));
+
+int g0 __attribute__((noreturn)); // expected-warning {{'noreturn' only applies to function types; type here is 'int'}}
+
+int f2() __attribute__((noreturn(1, 2))); // expected-error {{attribute takes no arguments}}
+
+void f3() __attribute__((noreturn));
+void f3() {
+ return; // expected-warning {{function 'f3' declared 'noreturn' should not return}}
+}
+
+#pragma clang diagnostic error "-Winvalid-noreturn"
+
+void f4() __attribute__((noreturn));
+void f4() {
+ return; // expected-error {{function 'f4' declared 'noreturn' should not return}}
+}
+
+// PR4685
+extern void f5 (unsigned long) __attribute__ ((__noreturn__));
+
+void
+f5 (unsigned long size)
+{
+
+}
+
+// PR2461
+__attribute__((noreturn)) void f(__attribute__((noreturn)) void (*x)(void)) {
+ x();
+}
+
+typedef void (*Fun)(void) __attribute__ ((noreturn(2))); // expected-error {{attribute takes no arguments}}
diff --git a/clang/test/Sema/attr-regparm.c b/clang/test/Sema/attr-regparm.c
new file mode 100644
index 0000000..642c07e
--- /dev/null
+++ b/clang/test/Sema/attr-regparm.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s
+
+__attribute((regparm(2))) int x0(void);
+__attribute((regparm(1.0))) int x1(void); // expected-error{{'regparm' attribute requires integer constant}}
+__attribute((regparm(-1))) int x2(void); // expected-error{{'regparm' parameter must be between 0 and 3 inclusive}}
+__attribute((regparm(5))) int x3(void); // expected-error{{'regparm' parameter must be between 0 and 3 inclusive}}
+__attribute((regparm(5,3))) int x4(void); // expected-error{{attribute takes one argument}}
+
+void __attribute__((regparm(3))) x5(int);
+void x5(int); // expected-note{{previous declaration is here}}
+void __attribute__((regparm(2))) x5(int); // expected-error{{function declared with with regparm(2) attribute was previously declared with the regparm(3) attribute}}
diff --git a/clang/test/Sema/attr-returns-twice.c b/clang/test/Sema/attr-returns-twice.c
new file mode 100644
index 0000000..13f53e3
--- /dev/null
+++ b/clang/test/Sema/attr-returns-twice.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+int a __attribute__((returns_twice)); // expected-warning {{'returns_twice' attribute only applies to functions}}
+
+__attribute__((returns_twice)) void t0(void) {
+}
+
+void t1() __attribute__((returns_twice));
+
+void t2() __attribute__((returns_twice(2))); // expected-error {{attribute takes no arguments}}
+
+typedef void (*t3)(void) __attribute__((returns_twice)); // expected-warning {{'returns_twice' attribute only applies to functions}}
diff --git a/clang/test/Sema/attr-section.c b/clang/test/Sema/attr-section.c
new file mode 100644
index 0000000..a932525
--- /dev/null
+++ b/clang/test/Sema/attr-section.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -triple x86_64-apple-darwin9 %s
+
+int x __attribute__((section(
+ 42))); // expected-error {{argument to section attribute was not a string literal}}
+
+
+// rdar://4341926
+int y __attribute__((section(
+ "sadf"))); // expected-error {{mach-o section specifier requires a segment and section separated by a comma}}
+
+// PR6007
+void test() {
+ __attribute__((section("NEAR,x"))) int n1; // expected-error {{'section' attribute is not valid on local variables}}
+ __attribute__((section("NEAR,x"))) static int n2; // ok.
+}
diff --git a/clang/test/Sema/attr-sentinel.c b/clang/test/Sema/attr-sentinel.c
new file mode 100644
index 0000000..abc108f
--- /dev/null
+++ b/clang/test/Sema/attr-sentinel.c
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#define NULL (void*)0
+
+#define ATTR __attribute__ ((__sentinel__))
+
+void foo1 (int x, ...) ATTR; // expected-note 3 {{function has been explicitly marked sentinel here}}
+void foo5 (int x, ...) __attribute__ ((__sentinel__(1))); // expected-note {{function has been explicitly marked sentinel here}}
+void foo6 (int x, ...) __attribute__ ((__sentinel__(5))); // expected-note {{function has been explicitly marked sentinel here}}
+void foo7 (int x, ...) __attribute__ ((__sentinel__(0))); // expected-note {{function has been explicitly marked sentinel here}}
+void foo10 (int x, ...) __attribute__ ((__sentinel__(1,1)));
+void foo12 (int x, ... ) ATTR; // expected-note {{function has been explicitly marked sentinel here}}
+
+#define FOOMACRO(...) foo1(__VA_ARGS__)
+
+void test1() {
+ foo1(1, NULL); // OK
+ foo1(1, 0) ; // expected-warning {{missing sentinel in function call}}
+ foo5(1, NULL, 2); // OK
+ foo5(1,2,NULL, 1); // OK
+ foo5(1, NULL, 2, 1); // expected-warning {{missing sentinel in function call}}
+
+ foo6(1,2,3,4,5,6,7); // expected-warning {{missing sentinel in function call}}
+ foo6(1,NULL,3,4,5,6,7); // OK
+ foo7(1); // expected-warning {{not enough variable arguments in 'foo7' declaration to fit a sentinel}}
+ foo7(1, NULL); // OK
+
+ foo12(1); // expected-warning {{not enough variable arguments in 'foo12' declaration to fit a sentinel}}
+
+ // PR 5685
+ struct A {};
+ struct A a, b, c;
+ foo1(3, &a, &b, &c); // expected-warning {{missing sentinel in function call}}
+ foo1(3, &a, &b, &c, (struct A*) 0);
+
+ // PR11002
+ FOOMACRO(1, 2); // expected-warning {{missing sentinel in function call}}
+}
+
+
+
+void (*e) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (1,1)));
+
+void test2() {
+ void (*b) (int arg, const char * format, ...) __attribute__ ((__sentinel__)); // expected-note {{function has been explicitly marked sentinel here}}
+ void (*z) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (2))); // expected-note {{function has been explicitly marked sentinel here}}
+
+
+ void (*y) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (5))); // expected-note {{function has been explicitly marked sentinel here}}
+
+ b(1, "%s", (void*)0); // OK
+ b(1, "%s", 0); // expected-warning {{missing sentinel in function call}}
+ z(1, "%s",4 ,1,0); // expected-warning {{missing sentinel in function call}}
+ z(1, "%s", (void*)0, 1, 0); // OK
+
+ y(1, "%s", 1,2,3,4,5,6,7); // expected-warning {{missing sentinel in function call}}
+
+ y(1, "%s", (void*)0,3,4,5,6,7); // OK
+}
diff --git a/clang/test/Sema/attr-unavailable-message.c b/clang/test/Sema/attr-unavailable-message.c
new file mode 100644
index 0000000..b2956d8
--- /dev/null
+++ b/clang/test/Sema/attr-unavailable-message.c
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// rdar: //6734520
+
+int foo(int) __attribute__((__unavailable__("USE IFOO INSTEAD"))); // expected-note {{function has been explicitly marked unavailable here}}
+double dfoo(double) __attribute__((__unavailable__("NO LONGER"))); // expected-note 2 {{function has been explicitly marked unavailable here}}
+
+void bar() __attribute__((__unavailable__)); // expected-note {{explicitly marked unavailable}}
+
+void test_foo() {
+ int ir = foo(1); // expected-error {{'foo' is unavailable: USE IFOO INSTEAD}}
+ double dr = dfoo(1.0); // expected-error {{'dfoo' is unavailable: NO LONGER}}
+
+ void (*fp)() = &bar; // expected-error {{'bar' is unavailable}}
+
+ double (*fp4)(double) = dfoo; // expected-error {{'dfoo' is unavailable: NO LONGER}}
+}
+
+char test2[__has_feature(attribute_unavailable_with_message) ? 1 : -1];
+
+// rdar://9623855
+void unavail(void) __attribute__((__unavailable__));
+void unavail(void) {
+ // No complains inside an unavailable function.
+ int ir = foo(1);
+ double dr = dfoo(1.0);
+ void (*fp)() = &bar;
+ double (*fp4)(double) = dfoo;
+}
+
+// rdar://10201690
+enum foo {
+ a = 1,
+ b __attribute__((deprecated())) = 2,
+ c = 3
+}__attribute__((deprecated()));
+
+enum fee { // expected-note {{declaration has been explicitly marked unavailable here}}
+ r = 1, // expected-note {{declaration has been explicitly marked unavailable here}}
+ s = 2,
+ t = 3
+}__attribute__((unavailable()));
+
+enum fee f() { // expected-error {{'fee' is unavailable}}
+ int i = a; // expected-warning {{'a' is deprecated}}
+
+ i = b; // expected-warning {{'b' is deprecated}}
+
+ return r; // expected-error {{'r' is unavailable}}
+}
diff --git a/clang/test/Sema/attr-unknown.c b/clang/test/Sema/attr-unknown.c
new file mode 100644
index 0000000..d1a831d
--- /dev/null
+++ b/clang/test/Sema/attr-unknown.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wattributes %s
+
+int x __attribute__((foobar)); // expected-warning {{unknown attribute 'foobar' ignored}}
+void z() __attribute__((bogusattr)); // expected-warning {{unknown attribute 'bogusattr' ignored}}
diff --git a/clang/test/Sema/attr-unused.c b/clang/test/Sema/attr-unused.c
new file mode 100644
index 0000000..07c65cb
--- /dev/null
+++ b/clang/test/Sema/attr-unused.c
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s
+
+static void (*fp0)(void) __attribute__((unused));
+
+static void __attribute__((unused)) f0(void);
+
+// On K&R
+int f1() __attribute__((unused));
+
+int g0 __attribute__((unused));
+
+int f2() __attribute__((unused(1, 2))); // expected-error {{attribute takes no arguments}}
+
+struct Test0_unused {} __attribute__((unused));
+struct Test0_not_unused {};
+typedef int Int_unused __attribute__((unused));
+typedef int Int_not_unused;
+
+void test0() {
+ int x; // expected-warning {{unused variable}}
+
+ Int_not_unused i0; // expected-warning {{unused variable}}
+ Int_unused i1; // expected-warning {{'Int_unused' was marked unused but was used}}
+
+ struct Test0_not_unused s0; // expected-warning {{unused variable}}
+ struct Test0_unused s1; // expected-warning {{'Test0_unused' was marked unused but was used}}
+}
+
+int f3(int x) { // expected-warning{{unused parameter 'x'}}
+ return 0;
+}
+
+int f4(int x) {
+ return x;
+}
+
+int f5(int x __attribute__((__unused__))) {
+ return 0;
+}
+
+int f6(int x __attribute__((__unused__))) {
+ return x; // expected-warning{{'x' was marked unused but was used}}
+}
diff --git a/clang/test/Sema/attr-used.c b/clang/test/Sema/attr-used.c
new file mode 100644
index 0000000..0838816
--- /dev/null
+++ b/clang/test/Sema/attr-used.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+extern int l0 __attribute__((used)); // expected-warning {{used attribute ignored}}
+__private_extern__ int l1 __attribute__((used)); // expected-warning {{used attribute ignored}}
+
+struct __attribute__((used)) s { // expected-warning {{'used' attribute only applies to variables and functions}}
+ int x;
+};
+
+int a __attribute__((used));
+
+static void __attribute__((used)) f0(void) {
+}
+
+void f1() {
+ static int a __attribute__((used));
+ int b __attribute__((used)); // expected-warning {{used attribute ignored}}
+}
+
+
diff --git a/clang/test/Sema/attr-visibility.c b/clang/test/Sema/attr-visibility.c
new file mode 100644
index 0000000..5cf2695
--- /dev/null
+++ b/clang/test/Sema/attr-visibility.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
+
+void test0() __attribute__((visibility("default")));
+void test1() __attribute__((visibility("hidden")));
+void test2() __attribute__((visibility("internal")));
+
+// rdar://problem/10753392
+void test3() __attribute__((visibility("protected"))); // expected-warning {{target does not support 'protected' visibility; using 'default'}}
+
diff --git a/clang/test/Sema/attr-weak.c b/clang/test/Sema/attr-weak.c
new file mode 100644
index 0000000..adedf12
--- /dev/null
+++ b/clang/test/Sema/attr-weak.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+extern int g0 __attribute__((weak));
+extern int g1 __attribute__((weak_import));
+int g2 __attribute__((weak));
+int g3 __attribute__((weak_import)); // expected-warning {{'weak_import' attribute cannot be specified on a definition}}
+int __attribute__((weak_import)) g4(void);
+void __attribute__((weak_import)) g5(void) {
+}
+
+struct __attribute__((weak)) s0 {}; // expected-warning {{'weak' attribute only applies to variables and functions}}
+struct __attribute__((weak_import)) s1 {}; // expected-warning {{'weak_import' attribute only applies to variables and functions}}
+
+static int x __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}}
+
+// rdar://9538608
+int C; // expected-note {{previous definition is here}}
+extern int C __attribute__((weak_import)); // expected-warning {{an already-declared variable is made a weak_import declaration}}
diff --git a/clang/test/Sema/bitfield-layout.c b/clang/test/Sema/bitfield-layout.c
new file mode 100644
index 0000000..2655fc7
--- /dev/null
+++ b/clang/test/Sema/bitfield-layout.c
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=i686-apple-darwin9
+
+#define CHECK_SIZE(kind, name, size) extern int name##1[sizeof(kind name) == size ? 1 : -1];
+#define CHECK_ALIGN(kind, name, size) extern int name##2[__alignof(kind name) == size ? 1 : -1];
+
+// Zero-width bit-fields
+struct a {char x; int : 0; char y;};
+CHECK_SIZE(struct, a, 5)
+CHECK_ALIGN(struct, a, 1)
+
+union b {char x; int : 0; char y;};
+CHECK_SIZE(union, b, 1)
+CHECK_ALIGN(union, b, 1)
+
+// Unnamed bit-field align
+struct c {char x; int : 20;};
+CHECK_SIZE(struct, c, 4)
+CHECK_ALIGN(struct, c, 1)
+
+union d {char x; int : 20;};
+CHECK_SIZE(union, d, 3)
+CHECK_ALIGN(union, d, 1)
+
+// Bit-field packing
+struct __attribute__((packed)) e {int x : 4, y : 30, z : 30;};
+CHECK_SIZE(struct, e, 8)
+CHECK_ALIGN(struct, e, 1)
+
+// Alignment on bit-fields
+struct f {__attribute((aligned(8))) int x : 30, y : 30, z : 30;};
+CHECK_SIZE(struct, f, 24)
+CHECK_ALIGN(struct, f, 8)
+
+// Large structure (overflows i32, in bits).
+struct s0 {
+ char a[0x32100000];
+ int x:30, y:30;
+};
+
+CHECK_SIZE(struct, s0, 0x32100008)
+CHECK_ALIGN(struct, s0, 4)
+
diff --git a/clang/test/Sema/bitfield-promote.c b/clang/test/Sema/bitfield-promote.c
new file mode 100644
index 0000000..4d14ad1
--- /dev/null
+++ b/clang/test/Sema/bitfield-promote.c
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+struct {unsigned x : 2;} x;
+__typeof__((x.x+=1)+1) y;
+__typeof__(x.x<<1) y;
+int y;
+
+
+struct { int x : 8; } x1;
+long long y1;
+__typeof__(((long long)x1.x + 1)) y1;
+
+
+// Check for extensions: variously sized unsigned bit-fields fitting
+// into a signed int promote to signed int.
+enum E { ec1, ec2, ec3 };
+struct S {
+ enum E e : 2;
+ unsigned short us : 4;
+ unsigned long long ul1 : 8;
+ unsigned long long ul2 : 50;
+} s;
+
+__typeof(s.e + s.e) x_e;
+int x_e;
+
+__typeof(s.us + s.us) x_us;
+int x_us;
+
+__typeof(s.ul1 + s.ul1) x_ul1;
+int x_ul1;
+
+__typeof(s.ul2 + s.ul2) x_ul2;
+unsigned long long x_ul2;
+
diff --git a/clang/test/Sema/bitfield.c b/clang/test/Sema/bitfield.c
new file mode 100644
index 0000000..a1ce894
--- /dev/null
+++ b/clang/test/Sema/bitfield.c
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+enum e0; // expected-note{{forward declaration of 'enum e0'}}
+
+struct a {
+ int a : -1; // expected-error{{bit-field 'a' has negative width}}
+
+ // rdar://6081627
+ int b : 33; // expected-error{{size of bit-field 'b' (33 bits) exceeds size of its type (32 bits)}}
+
+ int c : (1 + 0.25); // expected-error{{expression is not an integer constant expression}}
+ int d : (int)(1 + 0.25);
+
+ // rdar://6138816
+ int e : 0; // expected-error {{bit-field 'e' has zero width}}
+
+ float xx : 4; // expected-error {{bit-field 'xx' has non-integral type}}
+
+ // PR3607
+ enum e0 f : 1; // expected-error {{field has incomplete type 'enum e0'}}
+
+ int g : (_Bool)1;
+
+ // PR4017
+ char : 10; // expected-error {{size of anonymous bit-field (10 bits) exceeds size of its type (8 bits)}}
+ unsigned : -2; // expected-error {{anonymous bit-field has negative width (-2)}}
+ float : 12; // expected-error {{anonymous bit-field has non-integral type 'float'}}
+};
+
+struct b {unsigned x : 2;} x;
+__typeof__(x.x+1) y;
+int y;
+
+struct {unsigned x : 2;} x2;
+__typeof__((x.x+=1)+1) y;
+__typeof__((0,x.x)+1) y;
+__typeof__(x.x<<1) y;
+int y;
+
+struct PR8025 {
+ double : 2; // expected-error{{anonymous bit-field has non-integral type 'double'}}
+};
diff --git a/clang/test/Sema/block-args.c b/clang/test/Sema/block-args.c
new file mode 100644
index 0000000..5ee383e
--- /dev/null
+++ b/clang/test/Sema/block-args.c
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks
+
+void take(void*);
+
+void test() {
+ take(^(int x){});
+ take(^(int x, int y){});
+ take(^(int x, int y){});
+ take(^(int x, // expected-note {{previous declaration is here}}
+ int x){}); // expected-error {{redefinition of parameter 'x'}}
+
+
+ take(^(int x) { return x+1; });
+
+ int (^CP)(int) = ^(int x) { return x*x; };
+ take(CP);
+
+ int arg;
+ ^{return 1;}();
+ ^{return 2;}(arg); // expected-error {{too many arguments to block call}}
+ ^(void){return 3;}(1); // expected-error {{too many arguments to block call}}
+ ^(){return 4;}(arg); // expected-error {{too many arguments to block call}}
+ ^(int x, ...){return 5;}(arg, arg); // Explicit varargs, ok.
+}
+
+int main(int argc, char** argv) {
+ ^(int argCount) {
+ argCount = 3;
+ }(argc);
+}
+
+// radar 7528255
+void f0() {
+ ^(int, double d, char) {}(1, 1.34, 'a'); // expected-error {{parameter name omitted}} \
+ // expected-error {{parameter name omitted}}
+}
+
+// rdar://problem/8962770
+void test4() {
+ int (^f)() = ^((x)) { }; // expected-error {{expected ')'}} expected-warning {{type specifier missing}} expected-note {{to match this}}
+}
+
+// rdar://problem/9170609
+void test5_helper(void (^)(int, int[*]));
+void test5(void) {
+ test5_helper(^(int n, int array[n]) {});
+}
diff --git a/clang/test/Sema/block-call.c b/clang/test/Sema/block-call.c
new file mode 100644
index 0000000..2aa1422
--- /dev/null
+++ b/clang/test/Sema/block-call.c
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks
+
+int (*FP)();
+int (^IFP) ();
+int (^II) (int);
+int main() {
+ int (*FPL) (int) = FP; // C doesn't consider this an error.
+
+ // For Blocks, the ASTContext::typesAreBlockCompatible() makes sure this is an error.
+ int (^PFR) (int) = IFP; // OK
+ PFR = II; // OK
+
+ int (^IFP) () = PFR; // OK
+
+
+ const int (^CIC) () = IFP; // OK - initializing 'const int (^)()' with an expression of type 'int (^)()'}}
+
+ const int (^CICC) () = CIC;
+
+
+ int * const (^IPCC) () = 0;
+
+ int * const (^IPCC1) () = IPCC;
+
+ int * (^IPCC2) () = IPCC; // expected-error {{incompatible block pointer types initializing 'int *(^)()' with an expression of type 'int *const (^)()'}}
+
+ int (^IPCC3) (const int) = PFR;
+
+ int (^IPCC4) (int, char (^CArg) (double));
+
+ int (^IPCC5) (int, char (^CArg) (double)) = IPCC4;
+
+ int (^IPCC6) (int, char (^CArg) (float)) = IPCC4; // expected-error {{incompatible block pointer types initializing 'int (^)(int, char (^)(float))' with an expression of type 'int (^)(int, char (^)(double))'}}
+
+ IPCC2 = 0;
+ IPCC2 = 1; // expected-error {{invalid block pointer conversion assigning to 'int *(^)()' from 'int'}}
+ int (^x)() = 0;
+ int (^y)() = 3; // expected-error {{invalid block pointer conversion initializing 'int (^)()' with an expression of type 'int'}}
+ int a = 1;
+ int (^z)() = a+4; // expected-error {{invalid block pointer conversion initializing 'int (^)()' with an expression of type 'int'}}
+}
+
+int blah() {
+ int (^IFP) (float);
+ char (^PCP)(double, double, char);
+
+ IFP(1.0);
+ IFP (1.0, 2.0); // expected-error {{too many arguments to block call}}
+
+ char ch = PCP(1.0, 2.0, 'a');
+ return PCP(1.0, 2.0); // expected-error {{too few arguments to block}}
+}
diff --git a/clang/test/Sema/block-explicit-noreturn-type.c b/clang/test/Sema/block-explicit-noreturn-type.c
new file mode 100644
index 0000000..12f4f4f
--- /dev/null
+++ b/clang/test/Sema/block-explicit-noreturn-type.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks
+// rdar://10466373
+
+typedef short SHORT;
+
+void f0() {
+ (void) ^{
+ if (1)
+ return (float)1.0;
+ else if (2)
+ return (double)2.0; // expected-error {{return type 'double' must match previous return type 'float' when block literal has}}
+ else
+ return (SHORT)3; // expected-error {{return type 'SHORT' (aka 'short') must match previous return type 'float' when}}
+ };
+}
diff --git a/clang/test/Sema/block-labels.c b/clang/test/Sema/block-labels.c
new file mode 100644
index 0000000..d1b60cc
--- /dev/null
+++ b/clang/test/Sema/block-labels.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 %s -verify -fblocks -fsyntax-only
+
+void xx();
+
+int a() {
+ A:
+
+ if (1) xx();
+ return ^{
+ A: return 1;
+ }();
+}
+int b() {
+ A: return ^{int a; A:return 1;}();
+}
+
+int d() {
+ A: return ^{int a; A: a = ^{int a; A:return 1;}() + ^{int b; A:return 2;}(); return a; }();
+}
+
+int c() {
+ goto A; // expected-error {{use of undeclared label 'A'}}
+ return ^{
+ A:
+ return 1;
+ }();
+}
diff --git a/clang/test/Sema/block-literal.c b/clang/test/Sema/block-literal.c
new file mode 100644
index 0000000..c303b84
--- /dev/null
+++ b/clang/test/Sema/block-literal.c
@@ -0,0 +1,89 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks
+
+void I( void (^)(void));
+void (^noop)(void);
+
+void nothing();
+int printf(const char*, ...);
+
+typedef void (^T) (void);
+
+void takeblock(T);
+int takeintint(int (^C)(int)) { return C(4); }
+
+T somefunction() {
+ if (^{ })
+ nothing();
+
+ noop = ^{};
+
+ noop = ^{printf("\nClosure\n"); };
+
+ I(^{ });
+
+ return ^{printf("\nClosure\n"); };
+}
+void test2() {
+ int x = 4;
+
+ takeblock(^{ printf("%d\n", x); });
+
+ while (1) {
+ takeblock(^{
+ break; // expected-error {{'break' statement not in loop or switch statement}}
+ continue; // expected-error {{'continue' statement not in loop statement}}
+ while(1) break; // ok
+ goto foo; // expected-error {{use of undeclared label 'foo'}}
+ a: goto a; // ok
+ });
+ break;
+ }
+
+ foo:
+ takeblock(^{ x = 4; }); // expected-error {{variable is not assignable (missing __block type specifier)}}
+ __block y = 7; // expected-warning {{type specifier missing, defaults to 'int'}}
+ takeblock(^{ y = 8; });
+}
+
+
+void (^test3())(void) {
+ return ^{};
+}
+
+void test4() {
+ void (^noop)(void) = ^{};
+ void (*noop2)() = 0;
+}
+
+void myfunc(int (^block)(int)) {}
+
+void myfunc3(const int *x);
+
+void test5() {
+ int a;
+
+ myfunc(^(int abcd) {
+ myfunc3(&a);
+ return 1;
+ });
+}
+
+void *X;
+
+void test_arguments() {
+ int y;
+ int (^c)(char);
+ (1 ? c : 0)('x');
+ (1 ? 0 : c)('x');
+
+ (1 ? c : c)('x');
+}
+
+static int global_x = 10;
+void (^global_block)(void) = ^{ printf("global x is %d\n", global_x); };
+
+typedef void (^void_block_t)(void);
+
+static const void_block_t myBlock = ^{ };
+
+static const void_block_t myBlock2 = ^ void(void) { };
diff --git a/clang/test/Sema/block-misc.c b/clang/test/Sema/block-misc.c
new file mode 100644
index 0000000..2260458
--- /dev/null
+++ b/clang/test/Sema/block-misc.c
@@ -0,0 +1,228 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks
+void donotwarn();
+
+int (^IFP) ();
+int (^II) (int);
+int test1() {
+ int (^PFR) (int) = 0; // OK
+ PFR = II; // OK
+
+ if (PFR == II) // OK
+ donotwarn();
+
+ if (PFR == IFP) // OK
+ donotwarn();
+
+ if (PFR == (int (^) (int))IFP) // OK
+ donotwarn();
+
+ if (PFR == 0) // OK
+ donotwarn();
+
+ if (PFR) // OK
+ donotwarn();
+
+ if (!PFR) // OK
+ donotwarn();
+
+ return PFR != IFP; // OK
+}
+
+int test2(double (^S)()) {
+ double (^I)(int) = (void*) S;
+ (void*)I = (void *)S; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
+
+ void *pv = I;
+
+ pv = S;
+
+ I(1);
+
+ return (void*)I == (void *)S;
+}
+
+int^ x; // expected-error {{block pointer to non-function type is invalid}}
+int^^ x1; // expected-error {{block pointer to non-function type is invalid}} expected-error {{block pointer to non-function type is invalid}}
+
+void test3() {
+ char *^ y; // expected-error {{block pointer to non-function type is invalid}}
+}
+
+
+
+enum {NSBIRLazilyAllocated = 0};
+
+int test4(int argc) { // rdar://6251437
+ ^{
+ switch (argc) {
+ case NSBIRLazilyAllocated: // is an integer constant expression.
+ default:
+ break;
+ }
+ }();
+ return 0;
+}
+
+
+void bar(void*);
+// rdar://6257721 - reference to static/global is byref by default.
+static int test5g;
+void test5() {
+ bar(^{ test5g = 1; });
+}
+
+// rdar://6405429 - __func__ in a block refers to the containing function name.
+const char*test6() {
+ return ^{
+ return __func__;
+ } ();
+}
+
+// radr://6732116 - block comparisons
+void (^test7a)();
+int test7(void (^p)()) {
+ return test7a == p;
+}
+
+
+void test8() {
+somelabel:
+ ^{ goto somelabel; }(); // expected-error {{use of undeclared label 'somelabel'}}
+}
+
+void test9() {
+ goto somelabel; // expected-error {{use of undeclared label 'somelabel'}}
+ ^{ somelabel: ; }();
+}
+
+void test10(int i) {
+ switch (i) {
+ case 41: ;
+ ^{ case 42: ; }(); // expected-error {{'case' statement not in switch statement}}
+ }
+}
+
+void test11(int i) {
+ switch (i) {
+ case 41: ;
+ ^{ break; }(); // expected-error {{'break' statement not in loop or switch statement}}
+ }
+
+ for (; i < 100; ++i)
+ ^{ break; }(); // expected-error {{'break' statement not in loop or switch statement}}
+}
+
+void (^test12f)(void);
+void test12() {
+ test12f = ^test12f; // expected-error {{type name requires a specifier or qualifier}} expected-error {{expected expression}}
+}
+
+// rdar://6808730
+void *test13 = ^{
+ int X = 32;
+
+ void *P = ^{
+ return X+4; // References outer block's "X", so outer block is constant.
+ };
+};
+
+void test14() {
+ int X = 32;
+ static void *P = ^{ // expected-error {{initializer element is not a compile-time constant}}
+
+ void *Q = ^{
+ // References test14's "X": outer block is non constant.
+ return X+4;
+ };
+ };
+}
+
+enum { LESS };
+
+void foo(long (^comp)()) { // expected-note{{passing argument to parameter 'comp' here}}
+}
+
+void (^test15f)(void);
+void test15() {
+ foo(^{ return LESS; }); // expected-error {{incompatible block pointer types passing 'int (^)(void)' to parameter of type 'long (^)()'}}
+}
+
+__block int test16i; // expected-error {{__block attribute not allowed, only allowed on local variables}}
+
+void test16(__block int i) { // expected-error {{__block attribute not allowed, only allowed on local variables}}
+ int size = 5;
+ extern __block double extern_var; // expected-error {{__block attribute not allowed, only allowed on local variables}}
+ static __block char * pch; // expected-error {{__block attribute not allowed, only allowed on local variables}}
+ __block int a[size]; // expected-error {{__block attribute not allowed on declaration with a variably modified type}}
+ __block int (*ap)[size]; // expected-error {{__block attribute not allowed on declaration with a variably modified type}}
+}
+
+void f();
+
+void test17() {
+ void (^bp)(int);
+ void (*rp)(int);
+ void (^bp1)();
+ void *vp = bp;
+
+ f(1 ? bp : vp);
+ f(1 ? vp : bp);
+ f(1 ? bp : bp1);
+ (void)(bp > rp); // expected-error {{invalid operands}}
+ (void)(bp > 0); // expected-error {{invalid operands}}
+ (void)(bp > bp); // expected-error {{invalid operands}}
+ (void)(bp > vp); // expected-error {{invalid operands}}
+ f(1 ? bp : rp); // expected-error {{incompatible operand types ('void (^)(int)' and 'void (*)(int)')}}
+ (void)(bp == 1); // expected-error {{invalid operands to binary expression}}
+ (void)(bp == 0);
+ (void)(1 == bp); // expected-error {{invalid operands to binary expression}}
+ (void)(0 == bp);
+ (void)(bp < 1); // expected-error {{invalid operands to binary expression}}
+ (void)(bp < 0); // expected-error {{invalid operands to binary expression}}
+ (void)(1 < bp); // expected-error {{invalid operands to binary expression}}
+ (void)(0 < bp); // expected-error {{invalid operands to binary expression}}
+}
+
+void test18() {
+ void (^const blockA)(void) = ^{ };
+ blockA = ^{ }; // expected-error {{read-only variable is not assignable}}
+}
+
+// rdar://7072507
+int test19() {
+ goto L0; // expected-error {{goto into protected scope}}
+
+ __block int x; // expected-note {{jump bypasses setup of __block variable}}
+L0:
+ x = 0;
+ ^(){ ++x; }();
+ return x;
+}
+
+// radr://7438948
+void test20() {
+ int n = 7;
+ int vla[n]; // expected-note {{declared here}}
+ int (*vm)[n] = 0; // expected-note {{declared here}}
+ vla[1] = 4341;
+ ^{
+ (void)vla[1]; // expected-error {{cannot refer to declaration with a variably modified type inside block}}
+ (void)(vm+1); // expected-error {{cannot refer to declaration with a variably modified type inside block}}
+ }();
+}
+
+// radr://7438948
+void test21() {
+ int a[7]; // expected-note {{declared here}}
+ __block int b[10]; // expected-note {{declared here}}
+ a[1] = 1;
+ ^{
+ (void)a[1]; // expected-error {{cannot refer to declaration with an array type inside block}}
+ (void)b[1]; // expected-error {{cannot refer to declaration with an array type inside block}}
+ }();
+}
+
+// rdar ://8218839
+const char * (^func)(void) = ^{ return __func__; };
+const char * (^function)(void) = ^{ return __FUNCTION__; };
+const char * (^pretty)(void) = ^{ return __PRETTY_FUNCTION__; };
diff --git a/clang/test/Sema/block-printf-attribute-1.c b/clang/test/Sema/block-printf-attribute-1.c
new file mode 100644
index 0000000..dd678a5
--- /dev/null
+++ b/clang/test/Sema/block-printf-attribute-1.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks
+
+#include <stdarg.h>
+
+int main() {
+ void (^b) (int arg, const char * format, ...) __attribute__ ((__format__ (__printf__, 1, 3))) = // expected-error {{format argument not a string type}}
+ ^ __attribute__ ((__format__ (__printf__, 1, 3))) (int arg, const char * format, ...) {}; // expected-error {{format argument not a string type}}
+
+ void (^z) (int arg, const char * format, ...) __attribute__ ((__format__ (__printf__, 2, 3))) = ^ __attribute__ ((__format__ (__printf__, 2, 3))) (int arg, const char * format, ...) {};
+
+ z(1, "%s", 1); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
+ z(1, "%s", "HELLO"); // no-warning
+}
+
+void multi_attr(va_list ap, int *x, long *y) {
+ // Handle block with multiple format attributes.
+ void (^vprintf_scanf) (const char *, va_list, const char *, ...) __attribute__((__format__(__printf__, 1, 0))) __attribute__((__format__(__scanf__, 3, 4))) =
+ ^ __attribute__((__format__(__printf__, 1, 0))) __attribute__((__format__(__scanf__, 3, 4))) (const char *str, va_list args, const char *fmt, ...) {};
+
+ vprintf_scanf("%", ap, "%d"); // expected-warning {{incomplete format specifier}}, expected-warning {{more '%' conversions than data arguments}}
+}
diff --git a/clang/test/Sema/block-return-1.c b/clang/test/Sema/block-return-1.c
new file mode 100644
index 0000000..631a2d4
--- /dev/null
+++ b/clang/test/Sema/block-return-1.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks
+
+int j;
+void foo() {
+ ^ (void) { if (j) return 1; }(); // expected-error {{control may reach end of non-void block}}
+}
diff --git a/clang/test/Sema/block-return-2.c b/clang/test/Sema/block-return-2.c
new file mode 100644
index 0000000..d5fbc6f
--- /dev/null
+++ b/clang/test/Sema/block-return-2.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks
+
+void foo() {
+ ^ (void) __attribute__((noreturn)) { }(); // expected-error {{block declared 'noreturn' should not return}}
+}
diff --git a/clang/test/Sema/block-return-3.c b/clang/test/Sema/block-return-3.c
new file mode 100644
index 0000000..cd942a7
--- /dev/null
+++ b/clang/test/Sema/block-return-3.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks
+
+void foo() {
+ ^ int (void) { }(); // expected-error {{control reaches end of non-void block}}
+}
diff --git a/clang/test/Sema/block-return.c b/clang/test/Sema/block-return.c
new file mode 100644
index 0000000..6967955
--- /dev/null
+++ b/clang/test/Sema/block-return.c
@@ -0,0 +1,136 @@
+// RUN: %clang_cc1 -pedantic -fsyntax-only %s -verify -fblocks
+
+typedef void (^CL)(void);
+
+CL foo() {
+ short y;
+ short (^add1)(void) = ^{ return y+1; }; // expected-error {{incompatible block pointer types initializing 'short (^)(void)' with an expression of type 'int (^)(void)'}}
+
+ CL X = ^{
+ if (2)
+ return;
+ return 1; // expected-error {{return type 'int' must match previous return type 'void' when block literal has unspecified explicit return type}}
+ };
+
+ int (^Y) (void) = ^{
+ if (3)
+ return 1;
+ else
+ return; // expected-error {{return type 'void' must match previous return type 'int' when block literal has unspecified explicit return type}}
+ };
+
+ char *(^Z)(void) = ^{
+ if (3)
+ return "";
+ else
+ return (char*)0;
+ };
+
+ double (^A)(void) = ^ { // expected-error {{incompatible block pointer types initializing 'double (^)(void)' with an expression of type 'float (^)(void)'}}
+ if (1)
+ return (float)1.0;
+ else
+ if (2)
+ return (double)2.0; // expected-error {{return type 'double' must match previous return type 'float' when block literal has unspecified explicit return type}}
+ return 1; // expected-error {{return type 'int' must match previous return type 'float' when block literal has unspecified explicit return type}}
+ };
+ char *(^B)(void) = ^{
+ if (3)
+ return "";
+ else
+ return 2; // expected-error {{return type 'int' must match previous return type 'char *' when block literal has unspecified explicit return type}}
+ };
+
+ return ^{ return 1; }; // expected-error {{incompatible block pointer types returning 'int (^)(void)' from a function with result type 'CL' (aka 'void (^)(void)')}}
+}
+
+typedef int (^CL2)(void);
+
+CL2 foo2() {
+ return ^{ return 1; };
+}
+
+typedef unsigned int * uintptr_t;
+typedef char Boolean;
+typedef int CFBasicHash;
+
+#define INVOKE_CALLBACK2(P, A, B) (P)(A, B)
+
+typedef struct {
+ Boolean (^isEqual)(const CFBasicHash *, uintptr_t stack_value_or_key1, uintptr_t stack_value_or_key2, Boolean is_key);
+} CFBasicHashCallbacks;
+
+int foo3() {
+ CFBasicHashCallbacks cb;
+
+ Boolean (*value_equal)(uintptr_t, uintptr_t) = 0;
+
+ cb.isEqual = ^(const CFBasicHash *table, uintptr_t stack_value_or_key1, uintptr_t stack_value_or_key2, Boolean is_key) {
+ return (Boolean)(uintptr_t)INVOKE_CALLBACK2(value_equal, (uintptr_t)stack_value_or_key1, (uintptr_t)stack_value_or_key2);
+ };
+}
+
+static int funk(char *s) {
+ if (^{} == ((void*)0))
+ return 1;
+ else
+ return 0;
+}
+void next();
+void foo4() {
+ int (^xx)(const char *s) = ^(char *s) { return 1; }; // expected-error {{incompatible block pointer types initializing 'int (^)(const char *)' with an expression of type 'int (^)(char *)'}}
+ int (*yy)(const char *s) = funk; // expected-warning {{incompatible pointer types initializing 'int (*)(const char *)' with an expression of type 'int (char *)'}}
+
+ int (^nested)(char *s) = ^(char *str) { void (^nest)(void) = ^(void) { printf("%s\n", str); }; next(); return 1; }; // expected-warning{{implicitly declaring library function 'printf' with type 'int (const char *, ...)'}} \
+ // expected-note{{please include the header <stdio.h> or explicitly provide a declaration for 'printf'}}
+}
+
+typedef void (^bptr)(void);
+
+bptr foo5(int j) {
+ __block int i;
+ if (j)
+ return ^{ ^{ i=0; }(); }; // expected-error {{returning block that lives on the local stack}}
+ return ^{ i=0; }; // expected-error {{returning block that lives on the local stack}}
+ return (^{ i=0; }); // expected-error {{returning block that lives on the local stack}}
+ return (void*)(^{ i=0; }); // expected-error {{returning block that lives on the local stack}}
+}
+
+int (*funcptr3[5])(long);
+int sz8 = sizeof(^int (*[5])(long) {return funcptr3;}); // expected-error {{block cannot return array type}} expected-warning {{incompatible pointer to integer conversion}}
+int sz9 = sizeof(^int(*())()[3]{ }); // expected-error {{function cannot return array type}}
+
+void foo6() {
+ int (^b)(int) __attribute__((noreturn));
+ b = ^ (int i) __attribute__((noreturn)) { return 1; }; // expected-error {{block declared 'noreturn' should not return}}
+ b(1);
+ int (^c)(void) __attribute__((noreturn)) = ^ __attribute__((noreturn)) { return 100; }; // expected-error {{block declared 'noreturn' should not return}}
+}
+
+
+void foo7()
+{
+ const int (^BB) (void) = ^{ const int i = 1; return i; }; // OK - initializing 'const int (^)(void)' with an expression of type 'int (^)(void)'
+
+ const int (^CC) (void) = ^const int{ const int i = 1; return i; };
+
+
+ int i;
+ int (^FF) (void) = ^{ return i; }; // OK
+ int (^EE) (void) = ^{ return i+1; }; // OK
+
+ __block int j;
+ int (^JJ) (void) = ^{ return j; }; // OK
+ int (^KK) (void) = ^{ return j+1; }; // OK
+
+ __block const int k;
+ const int cint = 100;
+
+ int (^MM) (void) = ^{ return k; };
+ int (^NN) (void) = ^{ return cint; };
+}
+
+// rdar://11069896
+void (^blk)(void) = ^{
+ return (void)0; // expected-warning {{void block literal should not return void expression}}
+};
diff --git a/clang/test/Sema/block-sentinel-attribute.c b/clang/test/Sema/block-sentinel-attribute.c
new file mode 100644
index 0000000..daf0a95
--- /dev/null
+++ b/clang/test/Sema/block-sentinel-attribute.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s
+
+void (^e) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (1,1)));
+
+int main() {
+ void (^bbad) (int arg, const char * format) __attribute__ ((__sentinel__)) ; // expected-warning {{'sentinel' attribute only supported for variadic blocks}}
+ bbad = ^void (int arg, const char * format) __attribute__ ((__sentinel__)) {} ; // expected-warning {{'sentinel' attribute only supported for variadic blocks}}
+ void (^b) (int arg, const char * format, ...) __attribute__ ((__sentinel__)) = // expected-note {{block has been explicitly marked sentinel here}}
+ ^ __attribute__ ((__sentinel__)) (int arg, const char * format, ...) {};
+ void (^z) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (2))) = ^ __attribute__ ((__sentinel__ (2))) (int arg, const char * format, ...) {}; // expected-note {{block has been explicitly marked sentinel here}}
+
+
+ void (^y) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (5))) = ^ __attribute__ ((__sentinel__ (5))) (int arg, const char * format, ...) {}; // expected-note {{block has been explicitly marked sentinel here}}
+
+ b(1, "%s", (void*)0); // OK
+ b(1, "%s", 0); // expected-warning {{missing sentinel in block call}}
+ z(1, "%s",4 ,1,0); // expected-warning {{missing sentinel in block call}}
+ z(1, "%s", (void*)0, 1, 0); // OK
+
+ y(1, "%s", 1,2,3,4,5,6,7); // expected-warning {{missing sentinel in block call}}
+
+ y(1, "%s", (void*)0,3,4,5,6,7); // OK
+
+}
+
diff --git a/clang/test/Sema/block-storageclass.c b/clang/test/Sema/block-storageclass.c
new file mode 100644
index 0000000..9bfbfbd
--- /dev/null
+++ b/clang/test/Sema/block-storageclass.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks
+
+int printf(const char *, ...);
+void _Block_byref_release(void*src){}
+
+int main() {
+ __block int X = 1234;
+ __block const char * message = "HELLO";
+
+ X = X - 1234;
+
+ X += 1;
+
+ printf ("%s(%d)\n", message, X);
+ X -= 1;
+
+ return X;
+}
diff --git a/clang/test/Sema/builtin-object-size.c b/clang/test/Sema/builtin-object-size.c
new file mode 100644
index 0000000..0abc27b
--- /dev/null
+++ b/clang/test/Sema/builtin-object-size.c
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin9 -verify %s
+
+int a[10];
+
+int f0() {
+ return __builtin_object_size(&a); // expected-error {{too few arguments to function}}
+}
+int f1() {
+ return (__builtin_object_size(&a, 0) +
+ __builtin_object_size(&a, 1) +
+ __builtin_object_size(&a, 2) +
+ __builtin_object_size(&a, 3));
+}
+int f2() {
+ return __builtin_object_size(&a, -1); // expected-error {{argument should be a value from 0 to 3}}
+}
+int f3() {
+ return __builtin_object_size(&a, 4); // expected-error {{argument should be a value from 0 to 3}}
+}
+
+
+// rdar://6252231 - cannot call vsnprintf with va_list on x86_64
+void f4(const char *fmt, ...) {
+ __builtin_va_list args;
+ __builtin___vsnprintf_chk (0, 42, 0, 11, fmt, args);
+}
+
diff --git a/clang/test/Sema/builtin-prefetch.c b/clang/test/Sema/builtin-prefetch.c
new file mode 100644
index 0000000..c5fa792
--- /dev/null
+++ b/clang/test/Sema/builtin-prefetch.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void foo() {
+ int a;
+ __builtin_prefetch(&a);
+ __builtin_prefetch(&a, 1);
+ __builtin_prefetch(&a, 1, 2);
+ __builtin_prefetch(&a, 1, 9, 3); // expected-error{{too many arguments to function}}
+ __builtin_prefetch(&a, "hello", 2); // expected-error{{argument to '__builtin_prefetch' must be a constant integer}}
+ __builtin_prefetch(&a, a, 2); // expected-error{{argument to '__builtin_prefetch' must be a constant integer}}
+ __builtin_prefetch(&a, 2); // expected-error{{argument should be a value from 0 to 1}}
+ __builtin_prefetch(&a, 0, 4); // expected-error{{argument should be a value from 0 to 3}}
+ __builtin_prefetch(&a, -1, 4); // expected-error{{argument should be a value from 0 to 1}}
+}
diff --git a/clang/test/Sema/builtin-stackaddress.c b/clang/test/Sema/builtin-stackaddress.c
new file mode 100644
index 0000000..5f63bb1
--- /dev/null
+++ b/clang/test/Sema/builtin-stackaddress.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+void* a(unsigned x) {
+return __builtin_return_address(0);
+}
+
+void b(unsigned x) {
+return __builtin_return_address(x); // expected-error{{argument to '__builtin_return_address' must be a constant integer}}
+}
+
+void* c(unsigned x) {
+return __builtin_frame_address(0);
+}
+
+void d(unsigned x) {
+return __builtin_frame_address(x); // expected-error{{argument to '__builtin_frame_address' must be a constant integer}}
+}
diff --git a/clang/test/Sema/builtin-unary-fp.c b/clang/test/Sema/builtin-unary-fp.c
new file mode 100644
index 0000000..57568db
--- /dev/null
+++ b/clang/test/Sema/builtin-unary-fp.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
+void check(int);
+void a() {
+ check(__builtin_isfinite(1.0f));
+ check(__builtin_isinf(1.0));
+ check(__builtin_isinf_sign(1.0L));
+ check(__builtin_isnan(1.0f));
+ check(__builtin_isnormal(1.0f));
+ check(__builtin_isfinite(1)); // expected-error{{requires argument of floating point type}}
+ check(__builtin_isinf()); // expected-error{{too few arguments}}
+ check(__builtin_isnan(1,2)); // expected-error{{too many arguments}}
+ check(__builtin_fpclassify(0, 0, 0, 0, 0, 1.0));
+ check(__builtin_fpclassify(0, 0, 0, 0, 0, 1)); // expected-error{{requires argument of floating point type}}
+ check(__builtin_fpclassify(0, 0, 0, 0, 1)); // expected-error{{too few arguments}}
+ check(__builtin_fpclassify(0, 0, 0, 0, 0, 1, 0)); // expected-error{{too many arguments}}
+}
diff --git a/clang/test/Sema/builtin_objc_msgSend.c b/clang/test/Sema/builtin_objc_msgSend.c
new file mode 100644
index 0000000..357a5bc
--- /dev/null
+++ b/clang/test/Sema/builtin_objc_msgSend.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+// rdar://8632525
+
+typedef struct objc_class *Class;
+typedef struct objc_object {
+ Class isa;
+} *id;
+
+
+typedef struct objc_selector *SEL;
+extern id objc_msgSend(id self, SEL op, ...);
+
diff --git a/clang/test/Sema/builtins-arm.c b/clang/test/Sema/builtins-arm.c
new file mode 100644
index 0000000..4077240
--- /dev/null
+++ b/clang/test/Sema/builtins-arm.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple armv7 -fsyntax-only -verify -DTEST0 %s
+// RUN: %clang_cc1 -triple armv7 -fsyntax-only -verify -DTEST1 %s
+
+#ifdef TEST0
+void __clear_cache(char*, char*);
+#endif
+
+#ifdef TEST1
+void __clear_cache(void*, void*);
+#endif
+
+// va_list on ARM is void*.
+void test2() {
+ __builtin_va_list ptr = "x";
+ *ptr = '0'; // expected-error {{incomplete type 'void' is not assignable}}
+}
diff --git a/clang/test/Sema/builtins-decl.c b/clang/test/Sema/builtins-decl.c
new file mode 100644
index 0000000..19bdb84
--- /dev/null
+++ b/clang/test/Sema/builtins-decl.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=i686-mingw32
+// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=x86_64-mingw32
+
+// mingw-w64's intrin.h has decls below.
+// we should accept them.
+extern unsigned int __builtin_ia32_crc32qi (unsigned int, unsigned char);
+extern unsigned int __builtin_ia32_crc32hi (unsigned int, unsigned short);
+extern unsigned int __builtin_ia32_crc32si (unsigned int, unsigned int);
diff --git a/clang/test/Sema/builtins.c b/clang/test/Sema/builtins.c
new file mode 100644
index 0000000..b8b0367
--- /dev/null
+++ b/clang/test/Sema/builtins.c
@@ -0,0 +1,164 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wno-string-plus-int -triple=i686-apple-darwin9
+// This test needs to set the target because it uses __builtin_ia32_vec_ext_v4si
+
+int test1(float a, int b) {
+ return __builtin_isless(a, b);
+}
+int test2(int a, int b) {
+ return __builtin_islessequal(a, b); // expected-error {{floating point type}}
+}
+
+int test3(double a, float b) {
+ return __builtin_isless(a, b);
+}
+int test4(int* a, double b) {
+ return __builtin_islessequal(a, b); // expected-error {{floating point type}}
+}
+
+int test5(float a, long double b) {
+ return __builtin_isless(a, b, b); // expected-error {{too many arguments}}
+}
+int test6(float a, long double b) {
+ return __builtin_islessequal(a); // expected-error {{too few arguments}}
+}
+
+
+#define CFSTR __builtin___CFStringMakeConstantString
+void test7() {
+ const void *X;
+ X = CFSTR("\242"); // expected-warning {{input conversion stopped}}
+ X = CFSTR("\0"); // no-warning
+ X = CFSTR(242); // expected-error {{CFString literal is not a string constant}} expected-warning {{incompatible integer to pointer conversion}}
+ X = CFSTR("foo", "bar"); // expected-error {{too many arguments to function call}}
+}
+
+
+// atomics.
+
+void test9(short v) {
+ unsigned i, old;
+
+ old = __sync_fetch_and_add(); // expected-error {{too few arguments to function call}}
+ old = __sync_fetch_and_add(&old); // expected-error {{too few arguments to function call}}
+ old = __sync_fetch_and_add((unsigned*)0, 42i); // expected-warning {{imaginary constants are an extension}}
+
+ // PR7600: Pointers are implicitly casted to integers and back.
+ void *old_ptr = __sync_val_compare_and_swap((void**)0, 0, 0);
+
+ // Ensure the return type is correct even when implicit casts are stripped
+ // away. This triggers an assertion while checking the comparison otherwise.
+ if (__sync_fetch_and_add(&old, 1) == 1) {
+ }
+}
+
+
+// rdar://7236819
+void test10(void) __attribute__((noreturn));
+
+void test10(void) {
+ __asm__("int3");
+ __builtin_unreachable();
+
+ // No warning about falling off the end of a noreturn function.
+}
+
+void test11(int X) {
+ switch (X) {
+ case __builtin_eh_return_data_regno(0): // constant foldable.
+ break;
+ }
+
+ __builtin_eh_return_data_regno(X); // expected-error {{argument to '__builtin_eh_return_data_regno' must be a constant integer}}
+}
+
+// PR5062
+void test12(void) __attribute__((__noreturn__));
+void test12(void) {
+ __builtin_trap(); // no warning because trap is noreturn.
+}
+
+void test_unknown_builtin(int a, int b) {
+ __builtin_isles(a, b); // expected-error{{use of unknown builtin}} \
+ // expected-note{{did you mean '__builtin_isless'?}}
+}
+
+int test13() {
+ __builtin_eh_return(0, 0); // no warning, eh_return never returns.
+}
+
+// <rdar://problem/8228293>
+void test14() {
+ int old;
+ old = __sync_fetch_and_min((volatile int *)&old, 1);
+}
+
+// <rdar://problem/8336581>
+void test15(const char *s) {
+ __builtin_printf("string is %s\n", s);
+}
+
+// PR7885
+int test16() {
+ return __builtin_constant_p() + // expected-error{{too few arguments}}
+ __builtin_constant_p(1, 2); // expected-error {{too many arguments}}
+}
+
+const int test17_n = 0;
+const char test17_c[] = {1, 2, 3, 0};
+const char test17_d[] = {1, 2, 3, 4};
+typedef int __attribute__((vector_size(16))) IntVector;
+struct Aggregate { int n; char c; };
+enum Enum { EnumValue1, EnumValue2 };
+
+typedef __typeof(sizeof(int)) size_t;
+size_t strlen(const char *);
+
+void test17() {
+#define ASSERT(...) { int arr[(__VA_ARGS__) ? 1 : -1]; }
+#define T(...) ASSERT(__builtin_constant_p(__VA_ARGS__))
+#define F(...) ASSERT(!__builtin_constant_p(__VA_ARGS__))
+
+ // __builtin_constant_p returns 1 if the argument folds to:
+ // - an arithmetic constant with value which is known at compile time
+ T(test17_n);
+ T(&test17_c[3] - test17_c);
+ T(3i + 5); // expected-warning {{imaginary constant}}
+ T(4.2 * 7.6);
+ T(EnumValue1);
+ T((enum Enum)(int)EnumValue2);
+
+ // - the address of the first character of a string literal, losslessly cast
+ // to any type
+ T("string literal");
+ T((double*)"string literal");
+ T("string literal" + 0);
+ T((long)"string literal");
+
+ // ... and otherwise returns 0.
+ F("string literal" + 1);
+ F(&test17_n);
+ F(test17_c);
+ F(&test17_c);
+ F(&test17_d);
+ F((struct Aggregate){0, 1});
+ F((IntVector){0, 1, 2, 3});
+
+ // Ensure that a technique used in glibc is handled correctly.
+#define OPT(...) (__builtin_constant_p(__VA_ARGS__) && strlen(__VA_ARGS__) < 4)
+ // FIXME: These are incorrectly treated as ICEs because strlen is treated as
+ // a builtin.
+ ASSERT(OPT("abc"));
+ ASSERT(!OPT("abcd"));
+ // In these cases, the strlen is non-constant, but the __builtin_constant_p
+ // is 0: the array size is not an ICE but is foldable.
+ ASSERT(!OPT(test17_c)); // expected-warning {{folded}}
+ ASSERT(!OPT(&test17_c[0])); // expected-warning {{folded}}
+ ASSERT(!OPT((char*)test17_c)); // expected-warning {{folded}}
+ ASSERT(!OPT(test17_d)); // expected-warning {{folded}}
+ ASSERT(!OPT(&test17_d[0])); // expected-warning {{folded}}
+ ASSERT(!OPT((char*)test17_d)); // expected-warning {{folded}}
+
+#undef OPT
+#undef T
+#undef F
+}
diff --git a/clang/test/Sema/c11-typedef-redef.c b/clang/test/Sema/c11-typedef-redef.c
new file mode 100644
index 0000000..b899f15
--- /dev/null
+++ b/clang/test/Sema/c11-typedef-redef.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c11 %s -verify
+
+typedef int type;
+typedef type type;
+typedef int type;
+
+void f(int N) {
+ typedef int type2;
+ typedef type type2;
+ typedef int type2;
+
+ typedef int vla[N]; // expected-note{{previous definition is here}}
+ typedef int vla[N]; // expected-error{{redefinition of typedef for variably-modified type 'int [N]'}}
+
+ typedef int vla2[N];
+ typedef vla2 vla3; // expected-note{{previous definition is here}}
+ typedef vla2 vla3; // expected-error{{redefinition of typedef for variably-modified type 'vla2' (aka 'int [N]')}}
+}
diff --git a/clang/test/Sema/c89-2.c b/clang/test/Sema/c89-2.c
new file mode 100644
index 0000000..f6f6bd9
--- /dev/null
+++ b/clang/test/Sema/c89-2.c
@@ -0,0 +1,5 @@
+/* RUN: %clang_cc1 %s -std=c89 -pedantic-errors -verify
+ */
+
+#if 1LL /* expected-error {{long long}} */
+#endif
diff --git a/clang/test/Sema/c89.c b/clang/test/Sema/c89.c
new file mode 100644
index 0000000..110d7e1
--- /dev/null
+++ b/clang/test/Sema/c89.c
@@ -0,0 +1,112 @@
+/* RUN: %clang_cc1 %s -std=c89 -pedantic -fsyntax-only -verify -Wimplicit-function-declaration
+ */
+void test1() {
+ {
+ int i;
+ i = i + 1;
+ int j; /* expected-warning {{mixing declarations and code}} */
+ }
+ {
+ __extension__ int i;
+ i = i + 1;
+ int j; /* expected-warning {{mixing declarations and code}} */
+ }
+ {
+ int i;
+ i = i + 1;
+ __extension__ int j; /* expected-warning {{mixing declarations and code}} */
+ }
+}
+
+long long test2; /* expected-warning {{extension}} */
+
+
+void test3(int i) {
+ int A[i]; /* expected-warning {{variable length array}} */
+}
+
+int test4 = 0LL; /* expected-warning {{long long}} */
+
+/* PR1999 */
+void test5(register);
+
+/* PR2041 */
+int *restrict;
+int *__restrict; /* expected-error {{expected identifier}} */
+
+
+/* Implicit int, always ok */
+test6() { return 0; }
+
+/* PR2012 */
+test7; /* expected-warning {{declaration specifier missing, defaulting to 'int'}} */
+
+void test8(int, x); /* expected-warning {{declaration specifier missing, defaulting to 'int'}} */
+
+typedef int sometype;
+int a(sometype, y) {return 0;} /* expected-warning {{declaration specifier missing, defaulting to 'int'}} \
+ expected-error {{parameter name omitted}}*/
+
+
+
+
+void bar (void *);
+void f11 (z) /* expected-error {{may not have 'void' type}} */
+void z;
+{ bar (&z); }
+
+typedef void T;
+void foo(T); /* typedef for void is allowed */
+
+void foo(void) {}
+
+/* PR2759 */
+void test10 (int x[*]); /* expected-warning {{variable length arrays are a C99 feature}} */
+void test11 (int x[static 4]); /* expected-warning {{static array size is a C99 feature}} */
+
+void test12 (int x[const 4]) { /* expected-warning {{qualifier in array size is a C99 feature}} */
+ int Y[x[1]]; /* expected-warning {{variable length arrays are a C99 feature}} */
+}
+
+/* PR4074 */
+struct test13 {
+ int X[23];
+} test13a();
+
+void test13b() {
+ int a = test13a().X[1]; /* expected-warning {{ISO C90 does not allow subscripting non-lvalue array}} */
+ int b = 1[test13a().X]; /* expected-warning {{ISO C90 does not allow subscripting non-lvalue array}} */
+}
+
+/* Make sure we allow *test14 as a "function designator" */
+int test14() { return (&*test14)(); }
+
+int test15[5] = { [2] = 1 }; /* expected-warning {{designated initializers are a C99 feature}} */
+
+extern int printf(__const char *__restrict __format, ...);
+
+/* Warn, but don't suggest typo correction. */
+void test16() {
+ printg("Hello, world!\n"); /* expected-warning {{implicit declaration of function 'printg'}} */
+}
+
+struct x { int x,y[]; }; /* expected-warning {{Flexible array members are a C99-specific feature}} */
+
+/* Duplicated type-qualifiers aren't allowed by C90 */
+const const int c_i; /* expected-warning {{duplicate 'const' declaration specifier}} */
+typedef volatile int vol_int;
+volatile vol_int volvol_i; /* expected-warning {{duplicate 'volatile' declaration specifier}} */
+typedef volatile vol_int volvol_int; /* expected-warning {{duplicate 'volatile' declaration specifier}} */
+const int * const c;
+
+typedef const int CI;
+
+const CI mine1[5][5]; /* expected-warning {{duplicate 'const' declaration specifier}} */
+
+typedef CI array_of_CI[5];
+const array_of_CI mine2; /* expected-warning {{duplicate 'const' declaration specifier}} */
+
+typedef CI *array_of_pointer_to_CI[5];
+const array_of_pointer_to_CI mine3;
+
+void main() {} /* expected-error {{'main' must return 'int'}} */
diff --git a/clang/test/Sema/callingconv.c b/clang/test/Sema/callingconv.c
new file mode 100644
index 0000000..25669f0
--- /dev/null
+++ b/clang/test/Sema/callingconv.c
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+void __attribute__((fastcall)) foo(float *a) {
+}
+
+void __attribute__((stdcall)) bar(float *a) {
+}
+
+void __attribute__((fastcall(1))) baz(float *a) { // expected-error {{attribute takes no arguments}}
+}
+
+void __attribute__((fastcall)) test0() { // expected-error {{function with no prototype cannot use fastcall calling convention}}
+}
+
+void __attribute__((fastcall)) test1(void) {
+}
+
+void __attribute__((fastcall)) test2(int a, ...) { // expected-error {{variadic function cannot use fastcall calling convention}}
+}
+
+void __attribute__((cdecl)) ctest0() {}
+
+void __attribute__((cdecl(1))) ctest1(float x) {} // expected-error {{attribute takes no arguments}}
+
+void (__attribute__((fastcall)) *pfoo)(float*) = foo;
+
+void (__attribute__((stdcall)) *pbar)(float*) = bar;
+
+void (__attribute__((cdecl)) *ptest1)(void) = test1; // expected-warning {{incompatible pointer types}}
+
+void (*pctest0)() = ctest0;
+
+void ctest2() {}
+void (__attribute__((cdecl)) *pctest2)() = ctest2;
+
+typedef void (__attribute__((fastcall)) *Handler) (float *);
+Handler H = foo;
+
+// PR6361
+void ctest3();
+void __attribute__((cdecl)) ctest3() {}
+
+// PR6408
+typedef __attribute__((stdcall)) void (*PROC)();
+PROC __attribute__((cdecl)) ctest4(const char *x) {}
+
diff --git a/clang/test/Sema/carbon.c b/clang/test/Sema/carbon.c
new file mode 100644
index 0000000..045d72c
--- /dev/null
+++ b/clang/test/Sema/carbon.c
@@ -0,0 +1,5 @@
+// RUN: %clang -fsyntax-only %s -print-stats
+#ifdef __APPLE__
+#include <Carbon/Carbon.h>
+#endif
+
diff --git a/clang/test/Sema/cast-incomplete.c b/clang/test/Sema/cast-incomplete.c
new file mode 100644
index 0000000..dd10e00
--- /dev/null
+++ b/clang/test/Sema/cast-incomplete.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+// PR5692
+
+enum x; // expected-note {{forward declaration}}
+extern struct y a; // expected-note {{forward declaration}}
+extern union z b; // expected-note 2 {{forward declaration}}
+
+void foo() {
+ (enum x)1; // expected-error {{cast to incomplete type}}
+ (struct y)a; // expected-error {{cast to incomplete type}}
+ (union z)b; // expected-error {{cast to incomplete type}}
+ (union z)1; // expected-error {{cast to incomplete type}}
+}
+
diff --git a/clang/test/Sema/cast-to-union.c b/clang/test/Sema/cast-to-union.c
new file mode 100644
index 0000000..c32964d
--- /dev/null
+++ b/clang/test/Sema/cast-to-union.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
+
+union u { int i; unsigned : 3; };
+void f(union u);
+
+void test(int x) {
+ f((union u)x); // expected-warning {{C99 forbids casts to union type}}
+ f((union u)&x); // expected-error {{cast to union type from type 'int *' not present in union}}
+ f((union u)2U); // expected-error {{cast to union type from type 'unsigned int' not present in union}}
+}
+
+union u w = (union u)2; // expected-warning {{C99 forbids casts to union type}}
+union u ww = (union u)1.0; // expected-error{{cast to union type from type 'double' not present in union}}
+union u x = 7; // expected-error{{initializing 'union u' with an expression of incompatible type 'int'}}
+int i;
+union u zz = (union u)i; // expected-error{{initializer element is not a compile-time constant}} expected-warning {{C99 forbids casts to union type}}
+
+struct s {int a, b;};
+struct s y = { 1, 5 };
+struct s z = (struct s){ 1, 5 };
diff --git a/clang/test/Sema/cast.c b/clang/test/Sema/cast.c
new file mode 100644
index 0000000..71c44b4
--- /dev/null
+++ b/clang/test/Sema/cast.c
@@ -0,0 +1,159 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+
+typedef struct { unsigned long bits[(((1) + (64) - 1) / (64))]; } cpumask_t;
+cpumask_t x;
+void foo() {
+ (void)x;
+}
+void bar() {
+ char* a;
+ double b;
+ b = (double)a; // expected-error {{pointer cannot be cast to type}}
+ a = (char*)b; // expected-error {{cannot be cast to a pointer type}}
+}
+
+long bar1(long *next) {
+ return (long)(*next)++;
+}
+
+typedef _Bool Bool;
+typedef int Int;
+typedef long Long;
+typedef float Float;
+typedef double Double;
+typedef _Complex int CInt;
+typedef _Complex long CLong;
+typedef _Complex float CFloat;
+typedef _Complex double CDouble;
+typedef void *VoidPtr;
+typedef char *CharPtr;
+
+void testBool(Bool v) {
+ (void) (Bool) v;
+ (void) (Int) v;
+ (void) (Long) v;
+ (void) (Float) v;
+ (void) (Double) v;
+ (void) (CInt) v;
+ (void) (CLong) v;
+ (void) (CFloat) v;
+ (void) (CDouble) v;
+ (void) (VoidPtr) v;
+ (void) (CharPtr) v;
+}
+
+void testInt(Int v) {
+ (void) (Bool) v;
+ (void) (Int) v;
+ (void) (Long) v;
+ (void) (Float) v;
+ (void) (Double) v;
+ (void) (CInt) v;
+ (void) (CLong) v;
+ (void) (CFloat) v;
+ (void) (CDouble) v;
+ (void) (VoidPtr) v;
+ (void) (CharPtr) v;
+}
+
+void testLong(Long v) {
+ (void) (Bool) v;
+ (void) (Int) v;
+ (void) (Long) v;
+ (void) (Float) v;
+ (void) (Double) v;
+ (void) (CInt) v;
+ (void) (CLong) v;
+ (void) (CFloat) v;
+ (void) (CDouble) v;
+ (void) (VoidPtr) v;
+ (void) (CharPtr) v;
+}
+
+void testFloat(Float v) {
+ (void) (Bool) v;
+ (void) (Int) v;
+ (void) (Long) v;
+ (void) (Float) v;
+ (void) (Double) v;
+ (void) (CInt) v;
+ (void) (CLong) v;
+ (void) (CFloat) v;
+ (void) (CDouble) v;
+}
+
+void testDouble(Double v) {
+ (void) (Bool) v;
+ (void) (Int) v;
+ (void) (Long) v;
+ (void) (Float) v;
+ (void) (Double) v;
+ (void) (CInt) v;
+ (void) (CLong) v;
+ (void) (CFloat) v;
+ (void) (CDouble) v;
+}
+
+void testCI(CInt v) {
+ (void) (Bool) v;
+ (void) (Int) v;
+ (void) (Long) v;
+ (void) (Float) v;
+ (void) (Double) v;
+ (void) (CInt) v;
+ (void) (CLong) v;
+ (void) (CFloat) v;
+ (void) (CDouble) v;
+}
+
+void testCLong(CLong v) {
+ (void) (Bool) v;
+ (void) (Int) v;
+ (void) (Long) v;
+ (void) (Float) v;
+ (void) (Double) v;
+ (void) (CInt) v;
+ (void) (CLong) v;
+ (void) (CFloat) v;
+ (void) (CDouble) v;
+}
+
+void testCFloat(CFloat v) {
+ (void) (Bool) v;
+ (void) (Int) v;
+ (void) (Long) v;
+ (void) (Float) v;
+ (void) (Double) v;
+ (void) (CInt) v;
+ (void) (CLong) v;
+ (void) (CFloat) v;
+ (void) (CDouble) v;
+}
+
+void testCDouble(CDouble v) {
+ (void) (Bool) v;
+ (void) (Int) v;
+ (void) (Long) v;
+ (void) (Float) v;
+ (void) (Double) v;
+ (void) (CInt) v;
+ (void) (CLong) v;
+ (void) (CFloat) v;
+ (void) (CDouble) v;
+}
+
+void testVoidPtr(VoidPtr v) {
+ (void) (Bool) v;
+ (void) (Int) v;
+ (void) (Long) v;
+ (void) (VoidPtr) v;
+ (void) (CharPtr) v;
+}
+
+void testCharPtr(CharPtr v) {
+ (void) (Bool) v;
+ (void) (Int) v;
+ (void) (Long) v;
+ (void) (VoidPtr) v;
+ (void) (CharPtr) v;
+}
diff --git a/clang/test/Sema/check-increment.c b/clang/test/Sema/check-increment.c
new file mode 100644
index 0000000..070ea74
--- /dev/null
+++ b/clang/test/Sema/check-increment.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int printf(const char *, ...);
+typedef int *pint;
+int main() {
+ int a[5] = {0};
+ pint p = a;
+ p++;
+ printf("%d\n", *p);
+}
diff --git a/clang/test/Sema/compare.c b/clang/test/Sema/compare.c
new file mode 100644
index 0000000..03aebb3
--- /dev/null
+++ b/clang/test/Sema/compare.c
@@ -0,0 +1,335 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare %s -Wno-unreachable-code
+
+int test(char *C) { // nothing here should warn.
+ return C != ((void*)0);
+ return C != (void*)0;
+ return C != 0;
+ return C != 1; // expected-warning {{comparison between pointer and integer ('char *' and 'int')}}
+}
+
+int ints(long a, unsigned long b) {
+ enum EnumA {A};
+ enum EnumB {B};
+ enum EnumC {C = 0x10000};
+ return
+ // (a,b)
+ (a == (unsigned long) b) + // expected-warning {{comparison of integers of different signs}}
+ (a == (unsigned int) b) +
+ (a == (unsigned short) b) +
+ (a == (unsigned char) b) +
+ ((long) a == b) + // expected-warning {{comparison of integers of different signs}}
+ ((int) a == b) + // expected-warning {{comparison of integers of different signs}}
+ ((short) a == b) + // expected-warning {{comparison of integers of different signs}}
+ ((signed char) a == b) + // expected-warning {{comparison of integers of different signs}}
+ ((long) a == (unsigned long) b) + // expected-warning {{comparison of integers of different signs}}
+ ((int) a == (unsigned int) b) + // expected-warning {{comparison of integers of different signs}}
+ ((short) a == (unsigned short) b) +
+ ((signed char) a == (unsigned char) b) +
+ (a < (unsigned long) b) + // expected-warning {{comparison of integers of different signs}}
+ (a < (unsigned int) b) +
+ (a < (unsigned short) b) +
+ (a < (unsigned char) b) +
+ ((long) a < b) + // expected-warning {{comparison of integers of different signs}}
+ ((int) a < b) + // expected-warning {{comparison of integers of different signs}}
+ ((short) a < b) + // expected-warning {{comparison of integers of different signs}}
+ ((signed char) a < b) + // expected-warning {{comparison of integers of different signs}}
+ ((long) a < (unsigned long) b) + // expected-warning {{comparison of integers of different signs}}
+ ((int) a < (unsigned int) b) + // expected-warning {{comparison of integers of different signs}}
+ ((short) a < (unsigned short) b) +
+ ((signed char) a < (unsigned char) b) +
+
+ // (A,b)
+ (A == (unsigned long) b) +
+ (A == (unsigned int) b) +
+ (A == (unsigned short) b) +
+ (A == (unsigned char) b) +
+ ((long) A == b) +
+ ((int) A == b) +
+ ((short) A == b) +
+ ((signed char) A == b) +
+ ((long) A == (unsigned long) b) +
+ ((int) A == (unsigned int) b) +
+ ((short) A == (unsigned short) b) +
+ ((signed char) A == (unsigned char) b) +
+ (A < (unsigned long) b) +
+ (A < (unsigned int) b) +
+ (A < (unsigned short) b) +
+ (A < (unsigned char) b) +
+ ((long) A < b) +
+ ((int) A < b) +
+ ((short) A < b) +
+ ((signed char) A < b) +
+ ((long) A < (unsigned long) b) +
+ ((int) A < (unsigned int) b) +
+ ((short) A < (unsigned short) b) +
+ ((signed char) A < (unsigned char) b) +
+
+ // (a,B)
+ (a == (unsigned long) B) +
+ (a == (unsigned int) B) +
+ (a == (unsigned short) B) +
+ (a == (unsigned char) B) +
+ ((long) a == B) +
+ ((int) a == B) +
+ ((short) a == B) +
+ ((signed char) a == B) +
+ ((long) a == (unsigned long) B) +
+ ((int) a == (unsigned int) B) +
+ ((short) a == (unsigned short) B) +
+ ((signed char) a == (unsigned char) B) +
+ (a < (unsigned long) B) + // expected-warning {{comparison of integers of different signs}}
+ (a < (unsigned int) B) +
+ (a < (unsigned short) B) +
+ (a < (unsigned char) B) +
+ ((long) a < B) +
+ ((int) a < B) +
+ ((short) a < B) +
+ ((signed char) a < B) +
+ ((long) a < (unsigned long) B) + // expected-warning {{comparison of integers of different signs}}
+ ((int) a < (unsigned int) B) + // expected-warning {{comparison of integers of different signs}}
+ ((short) a < (unsigned short) B) +
+ ((signed char) a < (unsigned char) B) +
+
+ // (C,b)
+ (C == (unsigned long) b) +
+ (C == (unsigned int) b) +
+ (C == (unsigned short) b) +
+ (C == (unsigned char) b) +
+ ((long) C == b) +
+ ((int) C == b) +
+ ((short) C == b) +
+ ((signed char) C == b) +
+ ((long) C == (unsigned long) b) +
+ ((int) C == (unsigned int) b) +
+ ((short) C == (unsigned short) b) +
+ ((signed char) C == (unsigned char) b) +
+ (C < (unsigned long) b) +
+ (C < (unsigned int) b) +
+ (C < (unsigned short) b) +
+ (C < (unsigned char) b) +
+ ((long) C < b) +
+ ((int) C < b) +
+ ((short) C < b) +
+ ((signed char) C < b) +
+ ((long) C < (unsigned long) b) +
+ ((int) C < (unsigned int) b) +
+ ((short) C < (unsigned short) b) +
+ ((signed char) C < (unsigned char) b) +
+
+ // (a,C)
+ (a == (unsigned long) C) +
+ (a == (unsigned int) C) +
+ (a == (unsigned short) C) +
+ (a == (unsigned char) C) +
+ ((long) a == C) +
+ ((int) a == C) +
+ ((short) a == C) +
+ ((signed char) a == C) +
+ ((long) a == (unsigned long) C) +
+ ((int) a == (unsigned int) C) +
+ ((short) a == (unsigned short) C) +
+ ((signed char) a == (unsigned char) C) +
+ (a < (unsigned long) C) + // expected-warning {{comparison of integers of different signs}}
+ (a < (unsigned int) C) +
+ (a < (unsigned short) C) +
+ (a < (unsigned char) C) +
+ ((long) a < C) +
+ ((int) a < C) +
+ ((short) a < C) +
+ ((signed char) a < C) +
+ ((long) a < (unsigned long) C) + // expected-warning {{comparison of integers of different signs}}
+ ((int) a < (unsigned int) C) + // expected-warning {{comparison of integers of different signs}}
+ ((short) a < (unsigned short) C) +
+ ((signed char) a < (unsigned char) C) +
+
+ // (0x80000,b)
+ (0x80000 == (unsigned long) b) +
+ (0x80000 == (unsigned int) b) +
+ (0x80000 == (unsigned short) b) +
+ (0x80000 == (unsigned char) b) +
+ ((long) 0x80000 == b) +
+ ((int) 0x80000 == b) +
+ ((short) 0x80000 == b) +
+ ((signed char) 0x80000 == b) +
+ ((long) 0x80000 == (unsigned long) b) +
+ ((int) 0x80000 == (unsigned int) b) +
+ ((short) 0x80000 == (unsigned short) b) +
+ ((signed char) 0x80000 == (unsigned char) b) +
+ (0x80000 < (unsigned long) b) +
+ (0x80000 < (unsigned int) b) +
+ (0x80000 < (unsigned short) b) +
+ (0x80000 < (unsigned char) b) +
+ ((long) 0x80000 < b) +
+ ((int) 0x80000 < b) +
+ ((short) 0x80000 < b) +
+ ((signed char) 0x80000 < b) +
+ ((long) 0x80000 < (unsigned long) b) +
+ ((int) 0x80000 < (unsigned int) b) +
+ ((short) 0x80000 < (unsigned short) b) +
+ ((signed char) 0x80000 < (unsigned char) b) +
+
+ // (a,0x80000)
+ (a == (unsigned long) 0x80000) +
+ (a == (unsigned int) 0x80000) +
+ (a == (unsigned short) 0x80000) +
+ (a == (unsigned char) 0x80000) +
+ ((long) a == 0x80000) +
+ ((int) a == 0x80000) +
+ ((short) a == 0x80000) +
+ ((signed char) a == 0x80000) +
+ ((long) a == (unsigned long) 0x80000) +
+ ((int) a == (unsigned int) 0x80000) +
+ ((short) a == (unsigned short) 0x80000) +
+ ((signed char) a == (unsigned char) 0x80000) +
+ (a < (unsigned long) 0x80000) + // expected-warning {{comparison of integers of different signs}}
+ (a < (unsigned int) 0x80000) +
+ (a < (unsigned short) 0x80000) +
+ (a < (unsigned char) 0x80000) +
+ ((long) a < 0x80000) +
+ ((int) a < 0x80000) +
+ ((short) a < 0x80000) +
+ ((signed char) a < 0x80000) +
+ ((long) a < (unsigned long) 0x80000) + // expected-warning {{comparison of integers of different signs}}
+ ((int) a < (unsigned int) 0x80000) + // expected-warning {{comparison of integers of different signs}}
+ ((short) a < (unsigned short) 0x80000) +
+ ((signed char) a < (unsigned char) 0x80000) +
+
+ // We should be able to avoid warning about this.
+ (b != (a < 4 ? 1 : 2)) +
+
+ 10
+ ;
+}
+
+int equal(char *a, const char *b) {
+ return a == b;
+}
+
+int arrays(char (*a)[5], char(*b)[10], char(*c)[5]) {
+ int d = (a == c);
+ return a == b; // expected-warning {{comparison of distinct pointer types}}
+}
+
+int pointers(int *a) {
+ return a > 0; // expected-warning {{ordered comparison between pointer and zero ('int *' and 'int') is an extension}}
+ return a > 42; // expected-warning {{ordered comparison between pointer and integer ('int *' and 'int')}}
+ return a > (void *)0; // expected-warning {{comparison of distinct pointer types}}
+}
+
+int function_pointers(int (*a)(int), int (*b)(int), void (*c)(int)) {
+ return a > b; // expected-warning {{ordered comparison of function pointers}}
+ return function_pointers > function_pointers; // expected-warning {{self-comparison always evaluates to false}} expected-warning{{ordered comparison of function pointers}}
+ return a > c; // expected-warning {{comparison of distinct pointer types}}
+ return a == (void *) 0;
+ return a == (void *) 1; // expected-warning {{equality comparison between function pointer and void pointer}}
+}
+
+int void_pointers(void* foo) {
+ return foo == (void*) 0;
+ return foo == (void*) 1;
+}
+
+
+int test1(int i) {
+ enum en { zero };
+ return i > zero;
+}
+
+// PR5937
+int test2(int i32) {
+ struct foo {
+ unsigned int u8 : 8;
+ unsigned long long u31 : 31;
+ unsigned long long u32 : 32;
+ unsigned long long u63 : 63;
+ unsigned long long u64 : 64;
+ } *x;
+
+ if (x->u8 == i32) { // comparison in int32, exact
+ return 0;
+ } else if (x->u31 == i32) { // comparison in int32, exact
+ return 1;
+ } else if (x->u32 == i32) { // expected-warning {{comparison of integers of different signs}}
+ return 2;
+ } else if (x->u63 == i32) { // comparison in uint64, exact because ==
+ return 3;
+ } else if (x->u64 == i32) { // expected-warning {{comparison of integers of different signs}}
+ return 4;
+ } else {
+ return 5;
+ }
+}
+
+// PR5887
+void test3() {
+ unsigned short x, y;
+ unsigned int z;
+ if ((x > y ? x : y) > z)
+ (void) 0;
+}
+
+// PR5961
+extern char *ptr4;
+void test4() {
+ long value;
+ if (value < (unsigned long) &ptr4) // expected-warning {{comparison of integers of different signs}}
+ return;
+}
+
+// PR4807
+int test5(unsigned int x) {
+ return (x < 0) // expected-warning {{comparison of unsigned expression < 0 is always false}}
+ && (0 > x) // expected-warning {{comparison of 0 > unsigned expression is always false}}
+ && (x >= 0) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
+ && (0 <= x); // expected-warning {{comparison of 0 <= unsigned expression is always true}}
+}
+
+int test6(unsigned i, unsigned power) {
+ unsigned x = (i < (1 << power) ? i : 0);
+ return x != 3 ? 1 << power : i;
+}
+
+// <rdar://problem/8414119> enum >= (enum)0 comparison should not generate any warnings
+enum rdar8414119_Vals { X, Y, Z };
+#define ZERO 0
+#define CHECK(x) (x >= X)
+void rdar8414119_foo(enum rdar8414119_Vals v) {
+ if (CHECK(v)) // no-warning
+ return;
+ if (v >= X) // no-warning
+ return;
+}
+int rdar8414119_bar(unsigned x) {
+ return x >= ZERO; // no-warning
+}
+#undef ZERO
+#undef CHECK
+
+int rdar8511238() {
+ enum A { A_foo, A_bar };
+ enum A a;
+ if (a < 0) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
+ return 0;
+ return 20;
+}
+
+// PR10336
+int test9(int sv, unsigned uv, long slv) {
+ return sv == (uv ^= slv); // expected-warning {{comparison of integers of different signs: 'int' and 'unsigned int'}}
+}
+
+void test10(void) {
+ int si;
+ unsigned int ui;
+ long sl;
+
+ _Bool b;
+ b = (si == (ui = sl)); // expected-warning {{comparison of integers of different signs: 'int' and 'unsigned int'}}
+ b = (si == (ui = sl&15));
+}
+
+// PR11572
+struct test11S { unsigned x : 30; };
+int test11(unsigned y, struct test11S *p) {
+ return y > (p->x >> 24); // no-warning
+}
diff --git a/clang/test/Sema/complex-imag.c b/clang/test/Sema/complex-imag.c
new file mode 100644
index 0000000..1c6fb15
--- /dev/null
+++ b/clang/test/Sema/complex-imag.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -verify %s
+
+void f1() {
+ int a = 1;
+ int b = __imag a;
+ int *c = &__real a;
+ int *d = &__imag a; // expected-error {{must be an lvalue}}
+}
+
+void f2() {
+ _Complex int a = 1;
+ int b = __imag a;
+ int *c = &__real a;
+ int *d = &__imag a;
+}
+
+void f3() {
+ double a = 1;
+ double b = __imag a;
+ double *c = &__real a;
+ double *d = &__imag a; // expected-error {{must be an lvalue}}
+}
+
+void f4() {
+ _Complex double a = 1;
+ double b = __imag a;
+ double *c = &__real a;
+ double *d = &__imag a;
+}
diff --git a/clang/test/Sema/complex-init-list.c b/clang/test/Sema/complex-init-list.c
new file mode 100644
index 0000000..bfc6899
--- /dev/null
+++ b/clang/test/Sema/complex-init-list.c
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic
+
+// This file tests the clang extension which allows initializing the components
+// of a complex number individually using an initialization list. Basically,
+// if you have an explicit init list for a complex number that contains two
+// initializers, this extension kicks in to turn it into component-wise
+// initialization.
+//
+// This extension is useful because there isn't any way to accurately build
+// a complex number at the moment besides setting the components with
+// __real__ and __imag__, which is inconvenient and not usable for constants.
+// (Of course, there are other extensions we could implement that would
+// allow this, like some sort of __builtin_build_complex.)
+//
+// FIXME: It would be a good idea to have a warnings for implicit
+// real->complex and complex->real conversions; as-is, it's way too easy
+// to get implicit conversions when they are not intended.
+
+// Basic testcase
+_Complex float valid1 = { 1.0f, 2.0f }; // expected-warning {{specifying real and imaginary components is an extension}}
+
+
+// Struct for nesting tests
+struct teststruct { _Complex float x; };
+
+
+// Random other valid stuff
+_Complex int valid2 = { 1, 2 }; // expected-warning {{complex integer}} expected-warning {{specifying real and imaginary components is an extension}}
+struct teststruct valid3 = { { 1.0f, 2.0f} }; // expected-warning {{specifying real and imaginary components is an extension}}
+_Complex float valid4[2] = { {1.0f, 1.0f}, {1.0f, 1.0f} }; // expected-warning 2 {{specifying real and imaginary components is an extension}}
+// FIXME: We need some sort of warning for valid5
+_Complex float valid5 = {1.0f, 1.0fi}; // expected-warning {{imaginary constants}} expected-warning {{specifying real and imaginary components is an extension}}
+
+
+// Random invalid stuff
+struct teststruct invalid1 = { 1, 2 }; // expected-warning {{excess elements}}
+_Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{excess elements}}
+_Complex float invalid3 = {}; // expected-error {{scalar initializer cannot be empty}} expected-warning {{GNU empty initializer}}
+
+
+// Check incomplete array sizing
+_Complex float sizetest1[] = { {1.0f, 1.0f}, {1.0f, 1.0f} }; // expected-warning 2 {{specifying real and imaginary components is an extension}}
+_Complex float sizecheck1[(sizeof(sizetest1) == sizeof(*sizetest1)*2) ? 1 : -1];
+_Complex float sizetest2[] = { 1.0f, 1.0f, {1.0f, 1.0f} }; // expected-warning {{specifying real and imaginary components is an extension}}
+_Complex float sizecheck2[(sizeof(sizetest2) == sizeof(*sizetest2)*3) ? 1 : -1];
+
+// Constant-folding with init list.
+_Complex float x = 2 + (_Complex float) { 1, 2 }; // expected-warning {{specifying real and imaginary components is an extension}}
diff --git a/clang/test/Sema/complex-int.c b/clang/test/Sema/complex-int.c
new file mode 100644
index 0000000..32249b3
--- /dev/null
+++ b/clang/test/Sema/complex-int.c
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+void a() {
+__complex__ int arr;
+__complex__ short brr;
+__complex__ unsigned xx;
+__complex__ signed yy;
+__complex__ int result;
+int ii;
+int aa = 1 + 1.0iF;
+
+result = arr*ii;
+result = ii*brr;
+
+result = arr*brr;
+result = xx*yy;
+
+switch (arr) { // expected-error{{statement requires expression of integer type ('_Complex int' invalid)}}
+ case brr: ; // expected-error{{expression is not an integer constant expression}}
+ case xx: ; // expected-error{{expression is not an integer constant expression}}
+}
+}
+
+void Tester() {
+__complex short a1;
+__complex int a2;
+__complex float a3;
+__complex double a4;
+short a5;
+int a6;
+float a7;
+double a8;
+#define TestPair(m,n) int x##m##n = a##m+a##n;
+#define TestPairs(m) TestPair(m,1) TestPair(m,2) \
+ TestPair(m,3) TestPair(m,4) \
+ TestPair(m,5) TestPair(m,6) \
+ TestPair(m,7) TestPair(m,8)
+TestPairs(1); TestPairs(2);
+TestPairs(3); TestPairs(4);
+TestPairs(5); TestPairs(6);
+TestPairs(7); TestPairs(8);
+}
+
+// rdar://6097730
+void test3(_Complex int *x) {
+ *x = ~*x;
+}
+
+void test4(_Complex float *x) {
+ *x = ~*x;
+}
+
+void test5(_Complex int *x) {
+ (*x)++;
+}
+
+int i1[(2+3i)*(5+7i) == 29i-11 ? 1 : -1];
+int i2[(29i-11)/(5+7i) == 2+3i ? 1 : -1];
+int i3[-(2+3i) == +(-3i-2) ? 1 : -1];
+int i4[~(2+3i) == 2-3i ? 1 : -1];
+int i5[(3i == -(-3i) ? ((void)3, 1i - 1) : 0) == 1i - 1 ? 1 : -1];
+
+int f1[(2.0+3.0i)*(5.0+7.0i) == 29.0i-11.0 ? 1 : -1];
+int f2[(29.0i-11.0)/(5.0+7.0i) == 2.0+3.0i ? 1 : -1];
+int f3[-(2.0+3.0i) == +(-3.0i-2.0) ? 1 : -1];
+int f4[~(2.0+3.0i) == 2.0-3.0i ? 1 : -1];
+int f5[(3.0i == -(-3.0i) ? ((void)3.0, __extension__ (1.0i - 1.0)) : 0) == 1.0i - 1.0 ? 1 : -1];
diff --git a/clang/test/Sema/complex-promotion.c b/clang/test/Sema/complex-promotion.c
new file mode 100644
index 0000000..23c3b68
--- /dev/null
+++ b/clang/test/Sema/complex-promotion.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+float a;
+
+int b[__builtin_classify_type(a + 1i) == 9 ? 1 : -1];
+int c[__builtin_classify_type(1i + a) == 9 ? 1 : -1];
+
+double d;
+__typeof__ (d + 1i) e;
+
+int f[sizeof(e) == 2 * sizeof(double) ? 1 : -1];
+
+int g;
+int h[__builtin_classify_type(g + 1.0i) == 9 ? 1 : -1];
+int i[__builtin_classify_type(1.0i + a) == 9 ? 1 : -1];
diff --git a/clang/test/Sema/compound-literal.c b/clang/test/Sema/compound-literal.c
new file mode 100644
index 0000000..beec6ca
--- /dev/null
+++ b/clang/test/Sema/compound-literal.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
+
+struct foo { int a, b; };
+
+static struct foo t = (struct foo){0,0};
+static struct foo t1 = __builtin_choose_expr(0, (struct foo){0,0}, (struct foo){0,0});
+static struct foo t2 = {0,0};
+static struct foo t3 = t2; // -expected-error {{initializer element is not a compile-time constant}}
+static int *p = (int []){2,4};
+static int x = (int){1};
+
+static int *p2 = (int []){2,x}; // -expected-error {{initializer element is not a compile-time constant}}
+static long *p3 = (long []){2,"x"}; // -expected-warning {{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [2]'}}
+
+typedef struct { } cache_t; // -expected-warning{{empty struct is a GNU extension}}
+static cache_t clo_I1_cache = ((cache_t) { } ); // -expected-warning{{use of GNU empty initializer extension}}
+
+typedef struct Test {int a;int b;} Test;
+static Test* ll = &(Test) {0,0};
+
+extern void fooFunc(struct foo *pfoo);
+
+int main(int argc, char **argv) {
+ int *l = (int []){x, *p, *p2};
+ fooFunc(&(struct foo){ 1, 2 });
+}
+
+struct Incomplete; // expected-note{{forward declaration of 'struct Incomplete'}}
+struct Incomplete* I1 = &(struct Incomplete){1, 2, 3}; // -expected-error {{variable has incomplete type}}
+void IncompleteFunc(unsigned x) {
+ struct Incomplete* I2 = (struct foo[x]){1, 2, 3}; // -expected-error {{variable-sized object may not be initialized}}
+ (void){1,2,3}; // -expected-error {{variable has incomplete type}}
+ (void(void)) { 0 }; // -expected-error{{illegal initializer type 'void (void)'}}
+}
+
+// PR6080
+int array[(sizeof(int[3]) == sizeof( (int[]) {0,1,2} )) ? 1 : -1];
diff --git a/clang/test/Sema/conditional-expr.c b/clang/test/Sema/conditional-expr.c
new file mode 100644
index 0000000..184ac4a
--- /dev/null
+++ b/clang/test/Sema/conditional-expr.c
@@ -0,0 +1,112 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wsign-conversion %s
+void foo() {
+ *(0 ? (double *)0 : (void *)0) = 0;
+ // FIXME: GCC doesn't consider the the following two statements to be errors.
+ *(0 ? (double *)0 : (void *)(int *)0) = 0; // expected-error {{incomplete type 'void' is not assignable}}
+ *(0 ? (double *)0 : (void *)(double *)0) = 0; // expected-error {{incomplete type 'void' is not assignable}}
+ *(0 ? (double *)0 : (int *)(void *)0) = 0; // expected-error {{incomplete type 'void' is not assignable}} expected-warning {{pointer type mismatch ('double *' and 'int *')}}
+ *(0 ? (double *)0 : (double *)(void *)0) = 0;
+ *((void *) 0) = 0; // expected-error {{incomplete type 'void' is not assignable}}
+ double *dp;
+ int *ip;
+ void *vp;
+
+ dp = vp;
+ vp = dp;
+ ip = dp; // expected-warning {{incompatible pointer types assigning to 'int *' from 'double *'}}
+ dp = ip; // expected-warning {{incompatible pointer types assigning to 'double *' from 'int *'}}
+ dp = 0 ? (double *)0 : (void *)0;
+ vp = 0 ? (double *)0 : (void *)0;
+ ip = 0 ? (double *)0 : (void *)0; // expected-warning {{incompatible pointer types assigning to 'int *' from 'double *'}}
+
+ const int *cip;
+ vp = (0 ? vp : cip); // expected-warning {{discards qualifiers}}
+ vp = (0 ? cip : vp); // expected-warning {{discards qualifiers}}
+
+ int i = 2;
+ int (*pf)[2];
+ int (*pv)[i];
+ pf = (i ? pf : pv);
+
+ enum {xxx,yyy,zzz} e, *ee;
+ short x;
+ ee = ee ? &x : ee ? &i : &e; // expected-warning {{pointer type mismatch}}
+
+ typedef void *asdf;
+ *(0 ? (asdf) 0 : &x) = 10;
+
+ unsigned long test0 = 5;
+ test0 = test0 ? (long) test0 : test0; // expected-warning {{operand of ? changes signedness: 'long' to 'unsigned long'}}
+ test0 = test0 ? (int) test0 : test0; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}}
+ test0 = test0 ? (short) test0 : test0; // expected-warning {{operand of ? changes signedness: 'short' to 'unsigned long'}}
+ test0 = test0 ? test0 : (long) test0; // expected-warning {{operand of ? changes signedness: 'long' to 'unsigned long'}}
+ test0 = test0 ? test0 : (int) test0; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}}
+ test0 = test0 ? test0 : (short) test0; // expected-warning {{operand of ? changes signedness: 'short' to 'unsigned long'}}
+ test0 = test0 ? test0 : (long) 10;
+ test0 = test0 ? test0 : (int) 10;
+ test0 = test0 ? test0 : (short) 10;
+ test0 = test0 ? (long) 10 : test0;
+ test0 = test0 ? (int) 10 : test0;
+ test0 = test0 ? (short) 10 : test0;
+
+ int test1;
+ enum Enum { EVal };
+ test0 = test0 ? EVal : test0;
+ test1 = test0 ? EVal : (int) test0;
+ test0 = test0 ?
+ (unsigned) EVal
+ : (int) test0; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}}
+
+ test0 = test0 ? EVal : test1; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}}
+ test0 = test0 ? test1 : EVal; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}}
+
+ const int *const_int;
+ int *nonconst_int;
+ *(test0 ? const_int : nonconst_int) = 42; // expected-error {{read-only variable is not assignable}}
+ *(test0 ? nonconst_int : const_int) = 42; // expected-error {{read-only variable is not assignable}}
+
+ // The composite type here should be "int (*)[12]", fine for the sizeof
+ int (*incomplete)[];
+ int (*complete)[12];
+ sizeof(*(test0 ? incomplete : complete)); // expected-warning {{expression result unused}}
+ sizeof(*(test0 ? complete : incomplete)); // expected-warning {{expression result unused}}
+
+ int __attribute__((address_space(2))) *adr2;
+ int __attribute__((address_space(3))) *adr3;
+ test0 ? adr2 : adr3; // expected-warning {{pointer type mismatch}} expected-warning {{expression result unused}}
+
+ // Make sure address-space mask ends up in the result type
+ (test0 ? (test0 ? adr2 : adr2) : nonconst_int); // expected-warning {{pointer type mismatch}} expected-warning {{expression result unused}}
+}
+
+int Postgresql() {
+ char x;
+ return ((((&x) != ((void *) 0)) ? (*(&x) = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional expressions with only one void side}}
+}
+
+#define nil ((void*) 0)
+
+extern int f1(void);
+
+int f0(int a) {
+ // GCC considers this a warning.
+ return a ? f1() : nil; // expected-warning {{pointer/integer type mismatch in conditional expression ('int' and 'void *')}} expected-warning {{incompatible pointer to integer conversion returning 'void *' from a function with result type 'int'}}
+}
+
+int f2(int x) {
+ // We can suppress this because the immediate context wants an int.
+ return (x != 0) ? 0U : x;
+}
+
+#define NULL (void*)0
+
+void PR9236() {
+ struct A {int i;} A1;
+ (void)(1 ? A1 : NULL); // expected-error{{non-pointer operand type 'struct A' incompatible with NULL}}
+ (void)(1 ? NULL : A1); // expected-error{{non-pointer operand type 'struct A' incompatible with NULL}}
+ (void)(1 ? 0 : A1); // expected-error{{incompatible operand types}}
+ (void)(1 ? (void*)0 : A1); // expected-error{{incompatible operand types}}
+ (void)(1 ? A1: (void*)0); // expected-error{{incompatible operand types}}
+ (void)(1 ? A1 : (NULL)); // expected-error{{non-pointer operand type 'struct A' incompatible with NULL}}
+}
+
diff --git a/clang/test/Sema/conditional.c b/clang/test/Sema/conditional.c
new file mode 100644
index 0000000..3d7bcca
--- /dev/null
+++ b/clang/test/Sema/conditional.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+const char* test1 = 1 ? "i" : 1 == 1 ? "v" : "r";
+
+void _efree(void *ptr);
+void free(void *ptr);
+
+int _php_stream_free1() {
+ return (1 ? free(0) : _efree(0)); // expected-error {{returning 'void' from a function with incompatible result type 'int'}}
+}
+
+int _php_stream_free2() {
+ return (1 ? _efree(0) : free(0)); // expected-error {{returning 'void' from a function with incompatible result type 'int'}}
+}
diff --git a/clang/test/Sema/const-eval-64.c b/clang/test/Sema/const-eval-64.c
new file mode 100644
index 0000000..5727a93
--- /dev/null
+++ b/clang/test/Sema/const-eval-64.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux %s
+
+#define EVAL_EXPR(testno, expr) int test##testno = sizeof(struct{char qq[expr];});
+
+// <rdar://problem/10962435>
+EVAL_EXPR(1, ((char*)-1LL) + 1 == 0 ? 1 : -1)
+EVAL_EXPR(2, ((char*)-1LL) + 1 < (char*) -1 ? 1 : -1)
diff --git a/clang/test/Sema/const-eval.c b/clang/test/Sema/const-eval.c
new file mode 100644
index 0000000..bc8b227
--- /dev/null
+++ b/clang/test/Sema/const-eval.c
@@ -0,0 +1,133 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux %s
+
+#define EVAL_EXPR(testno, expr) int test##testno = sizeof(struct{char qq[expr];});
+int x;
+EVAL_EXPR(1, (_Bool)&x)
+EVAL_EXPR(2, (int)(1.0+(double)4))
+EVAL_EXPR(3, (int)(1.0+(float)4.0))
+EVAL_EXPR(4, (_Bool)(1 ? (void*)&x : 0))
+EVAL_EXPR(5, (_Bool)(int[]){0})
+struct y {int x,y;};
+EVAL_EXPR(6, (int)(1+(struct y*)0))
+EVAL_EXPR(7, (int)&((struct y*)0)->y)
+EVAL_EXPR(8, (_Bool)"asdf")
+EVAL_EXPR(9, !!&x)
+EVAL_EXPR(10, ((void)1, 12))
+void g0(void);
+EVAL_EXPR(11, (g0(), 12)) // expected-error {{must have a constant size}}
+EVAL_EXPR(12, 1.0&&2.0)
+EVAL_EXPR(13, x || 3.0) // expected-error {{must have a constant size}}
+
+unsigned int l_19 = 1;
+EVAL_EXPR(14, (1 ^ l_19) && 1); // expected-error {{fields must have a constant size}}
+
+void f()
+{
+ int a;
+ EVAL_EXPR(15, (_Bool)&a);
+}
+
+// FIXME: Turn into EVAL_EXPR test once we have more folding.
+_Complex float g16 = (1.0f + 1.0fi);
+
+// ?: in constant expressions.
+int g17[(3?:1) - 2];
+
+EVAL_EXPR(18, ((int)((void*)10 + 10)) == 20 ? 1 : -1);
+
+struct s {
+ int a[(int)-1.0f]; // expected-error {{'a' declared as an array with a negative size}}
+};
+
+EVAL_EXPR(19, ((int)&*(char*)10 == 10 ? 1 : -1));
+
+EVAL_EXPR(20, __builtin_constant_p(*((int*) 10)));
+
+EVAL_EXPR(21, (__imag__ 2i) == 2 ? 1 : -1);
+
+EVAL_EXPR(22, (__real__ (2i+3)) == 3 ? 1 : -1);
+
+int g23[(int)(1.0 / 1.0)] = { 1 };
+int g24[(int)(1.0 / 1.0)] = { 1 , 2 }; // expected-warning {{excess elements in array initializer}}
+int g25[(int)(1.0 + 1.0)], g26 = sizeof(g25);
+
+EVAL_EXPR(26, (_Complex double)0 ? -1 : 1)
+EVAL_EXPR(27, (_Complex int)0 ? -1 : 1)
+EVAL_EXPR(28, (_Complex double)1 ? 1 : -1)
+EVAL_EXPR(29, (_Complex int)1 ? 1 : -1)
+
+
+// PR4027 + rdar://6808859
+struct a { int x, y; };
+static struct a V2 = (struct a)(struct a){ 1, 2};
+static const struct a V1 = (struct a){ 1, 2};
+
+EVAL_EXPR(30, (int)(_Complex float)((1<<30)-1) == (1<<30) ? 1 : -1)
+EVAL_EXPR(31, (int*)0 == (int*)0 ? 1 : -1)
+EVAL_EXPR(32, (int*)0 != (int*)0 ? -1 : 1)
+EVAL_EXPR(33, (void*)0 - (void*)0 == 0 ? 1 : -1)
+void foo(void) {}
+EVAL_EXPR(34, (foo == (void *)0) ? -1 : 1)
+
+// No PR. Mismatched bitwidths lead to a crash on second evaluation.
+const _Bool constbool = 0;
+EVAL_EXPR(35, constbool)
+EVAL_EXPR(36, constbool)
+
+EVAL_EXPR(37, (1,2.0) == 2.0 ? 1 : -1)
+EVAL_EXPR(38, __builtin_expect(1,1) == 1 ? 1 : -1)
+
+// PR7884
+EVAL_EXPR(39, __real__(1.f) == 1 ? 1 : -1)
+EVAL_EXPR(40, __imag__(1.f) == 0 ? 1 : -1)
+
+// From gcc testsuite
+EVAL_EXPR(41, (int)(1+(_Complex unsigned)2))
+
+// rdar://8875946
+void rdar8875946() {
+ double _Complex P;
+ float _Complex P2 = 3.3f + P;
+}
+
+double d = (d = 0.0); // expected-error {{not a compile-time constant}}
+double d2 = ++d; // expected-error {{not a compile-time constant}}
+
+int n = 2;
+int intLvalue[*(int*)((long)&n ?: 1)] = { 1, 2 }; // expected-error {{variable length array}}
+
+union u { int a; char b[4]; };
+char c = ((union u)(123456)).b[0]; // expected-error {{not a compile-time constant}}
+
+extern const int weak_int __attribute__((weak));
+const int weak_int = 42;
+int weak_int_test = weak_int; // expected-error {{not a compile-time constant}}
+
+int literalVsNull1 = "foo" == 0;
+int literalVsNull2 = 0 == "foo";
+
+// PR11385.
+int castViaInt[*(int*)(unsigned long)"test"]; // expected-error {{variable length array}}
+
+// PR11391.
+struct PR11391 { _Complex float f; } pr11391;
+EVAL_EXPR(42, __builtin_constant_p(pr11391.f = 1))
+
+// PR12043
+float varfloat;
+const float constfloat = 0;
+EVAL_EXPR(43, varfloat && constfloat) // expected-error {{must have a constant size}}
+
+// <rdar://problem/11205586>
+// (Make sure we continue to reject this.)
+EVAL_EXPR(44, "x"[0]); // expected-error {{variable length array}}
+
+// <rdar://problem/10962435>
+EVAL_EXPR(45, ((char*)-1) + 1 == 0 ? 1 : -1)
+EVAL_EXPR(46, ((char*)-1) + 1 < (char*) -1 ? 1 : -1)
+EVAL_EXPR(47, &x < &x + 1 ? 1 : -1)
+EVAL_EXPR(48, &x != &x - 1 ? 1 : -1)
+EVAL_EXPR(49, &x < &x - 100 ? 1 : -1) // expected-error {{must have a constant size}}
+
+extern struct Test50S Test50;
+EVAL_EXPR(50, &Test50 < (struct Test50S*)((unsigned)&Test50 + 10)) // expected-error {{must have a constant size}}
diff --git a/clang/test/Sema/const-ptr-int-ptr-cast.c b/clang/test/Sema/const-ptr-int-ptr-cast.c
new file mode 100644
index 0000000..8beaf9d
--- /dev/null
+++ b/clang/test/Sema/const-ptr-int-ptr-cast.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -ffreestanding %s
+
+#include <stdint.h>
+
+char *a = (void*)(uintptr_t)(void*)&a;
diff --git a/clang/test/Sema/constant-builtins-2.c b/clang/test/Sema/constant-builtins-2.c
new file mode 100644
index 0000000..68b46bf
--- /dev/null
+++ b/clang/test/Sema/constant-builtins-2.c
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -fsyntax-only %s
+
+// Math stuff
+
+double g0 = __builtin_huge_val();
+float g1 = __builtin_huge_valf();
+long double g2 = __builtin_huge_vall();
+
+double g3 = __builtin_inf();
+float g4 = __builtin_inff();
+long double g5 = __builtin_infl();
+
+double g6 = __builtin_nan("");
+float g7 = __builtin_nanf("");
+long double g8 = __builtin_nanl("");
+
+// GCC constant folds these too (via native strtol):
+//double g6_1 = __builtin_nan("1");
+//float g7_1 = __builtin_nanf("1");
+//long double g8_1 = __builtin_nanl("1");
+
+// APFloat doesn't have signalling NaN functions.
+//double g9 = __builtin_nans("");
+//float g10 = __builtin_nansf("");
+//long double g11 = __builtin_nansl("");
+
+//int g12 = __builtin_abs(-12);
+
+double g13 = __builtin_fabs(-12.);
+double g13_0 = __builtin_fabs(-0.);
+double g13_1 = __builtin_fabs(-__builtin_inf());
+float g14 = __builtin_fabsf(-12.f);
+// GCC doesn't eat this one.
+//long double g15 = __builtin_fabsfl(-12.0L);
+
+float g16 = __builtin_copysign(1.0, -1.0);
+double g17 = __builtin_copysignf(1.0f, -1.0f);
+long double g18 = __builtin_copysignl(1.0L, -1.0L);
+
+//double g19 = __builtin_powi(2.0, 4);
+//float g20 = __builtin_powif(2.0f, 4);
+//long double g21 = __builtin_powil(2.0L, 4);
+
+// GCC misc stuff
+
+extern int f();
+
+int h0 = __builtin_types_compatible_p(int, float);
+//int h1 = __builtin_choose_expr(1, 10, f());
+//int h2 = __builtin_expect(0, 0);
+extern long int bi0;
+extern __typeof__(__builtin_expect(0, 0)) bi0;
+
+// Strings
+int array1[__builtin_strlen("ab\0cd")];
+int array2[(sizeof(array1)/sizeof(int)) == 2? 1 : -1];
diff --git a/clang/test/Sema/constant-builtins.c b/clang/test/Sema/constant-builtins.c
new file mode 100644
index 0000000..5d67fc7
--- /dev/null
+++ b/clang/test/Sema/constant-builtins.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify -pedantic
+
+// Math stuff
+
+float g0 = __builtin_huge_val();
+double g1 = __builtin_huge_valf();
+long double g2 = __builtin_huge_vall();
+float g3 = __builtin_inf();
+double g4 = __builtin_inff();
+long double g5 = __builtin_infl();
+
+// GCC misc stuff
+
+extern int f();
+
+int h0 = __builtin_types_compatible_p(int,float);
+//int h1 = __builtin_choose_expr(1, 10, f());
+//int h2 = __builtin_expect(0, 0);
+
+short somefunc();
+
+short t = __builtin_constant_p(5353) ? 42 : somefunc();
+
+
diff --git a/clang/test/Sema/constant-conversion.c b/clang/test/Sema/constant-conversion.c
new file mode 100644
index 0000000..1376333
--- /dev/null
+++ b/clang/test/Sema/constant-conversion.c
@@ -0,0 +1,82 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin %s
+
+// This file tests -Wconstant-conversion, a subcategory of -Wconversion
+// which is on by default.
+
+// rdar://problem/6792488
+void test_6792488(void) {
+ int x = 0x3ff0000000000000U; // expected-warning {{implicit conversion from 'unsigned long' to 'int' changes value from 4607182418800017408 to 0}}
+}
+
+void test_7809123(void) {
+ struct { int i5 : 5; } a;
+
+ a.i5 = 36; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 36 to 4}}
+}
+
+void test() {
+ struct { int bit : 1; } a;
+ a.bit = 1; // shouldn't warn
+}
+
+enum Test2 { K_zero, K_one };
+enum Test2 test2(enum Test2 *t) {
+ *t = 20;
+ return 10; // shouldn't warn
+}
+
+void test3() {
+ struct A {
+ unsigned int foo : 2;
+ int bar : 2;
+ };
+
+ struct A a = { 0, 10 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to -2}}
+ struct A b[] = { 0, 10, 0, 0 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to -2}}
+ struct A c[] = {{10, 0}}; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}}
+ struct A d = (struct A) { 10, 0 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}}
+ struct A e = { .foo = 10 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}}
+}
+
+void test4() {
+ struct A {
+ char c : 2;
+ } a;
+
+ a.c = 0x101; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 257 to 1}}
+}
+
+void test5() {
+ struct A {
+ _Bool b : 1;
+ } a;
+
+ // Don't warn about this implicit conversion to bool, or at least
+ // don't warn about it just because it's a bitfield.
+ a.b = 100;
+}
+
+void test6() {
+ // Test that unreachable code doesn't trigger the truncation warning.
+ unsigned char x = 0 ? 65535 : 1; // no-warning
+ unsigned char y = 1 ? 65535 : 1; // expected-warning {{changes value}}
+}
+
+void test7() {
+ struct {
+ unsigned int twoBits1:2;
+ unsigned int twoBits2:2;
+ unsigned int reserved:28;
+ } f;
+
+ f.twoBits1 = ~1; // expected-warning {{implicit truncation from 'int' to bitfield changes value from -2 to 2}}
+ f.twoBits2 = ~2; // expected-warning {{implicit truncation from 'int' to bitfield changes value from -3 to 1}}
+ f.twoBits1 &= ~1; // no-warning
+ f.twoBits2 &= ~2; // no-warning
+}
+
+void test8() {
+ enum E { A, B, C };
+ struct { enum E x : 1; } f;
+ f.x = C; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 2 to 0}}
+}
diff --git a/clang/test/Sema/constructor-attribute.c b/clang/test/Sema/constructor-attribute.c
new file mode 100644
index 0000000..3825916
--- /dev/null
+++ b/clang/test/Sema/constructor-attribute.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int x __attribute__((constructor)); // expected-warning {{'constructor' attribute only applies to functions}}
+int f() __attribute__((constructor));
+int f() __attribute__((constructor(1)));
+int f() __attribute__((constructor(1,2))); // expected-error {{attribute takes no more than 1 argument}}
+int f() __attribute__((constructor(1.0))); // expected-error {{'constructor' attribute requires parameter 1 to be an integer constant}}
+
+int x __attribute__((destructor)); // expected-warning {{'destructor' attribute only applies to functions}}
+int f() __attribute__((destructor));
+int f() __attribute__((destructor(1)));
+int f() __attribute__((destructor(1,2))); // expected-error {{attribute takes no more than 1 argument}}
+int f() __attribute__((destructor(1.0))); // expected-error {{'destructor' attribute requires parameter 1 to be an integer constant}}
+
+
diff --git a/clang/test/Sema/conversion-64-32.c b/clang/test/Sema/conversion-64-32.c
new file mode 100644
index 0000000..3de20cb
--- /dev/null
+++ b/clang/test/Sema/conversion-64-32.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wshorten-64-to-32 -triple x86_64-apple-darwin %s
+
+int test0(long v) {
+ return v; // expected-warning {{implicit conversion loses integer precision}}
+}
+
+
+// rdar://9546171
+typedef int int4 __attribute__ ((vector_size(16)));
+typedef long long long2 __attribute__((__vector_size__(16)));
+
+int4 test1(long2 a) {
+ int4 v127 = a; // no warning.
+ return v127;
+}
+
+int test2(long v) {
+ return v / 2; // expected-warning {{implicit conversion loses integer precision: 'long' to 'int'}}
+}
diff --git a/clang/test/Sema/conversion.c b/clang/test/Sema/conversion.c
new file mode 100644
index 0000000..a591ac0
--- /dev/null
+++ b/clang/test/Sema/conversion.c
@@ -0,0 +1,419 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wconversion \
+// RUN: -nostdsysteminc -nobuiltininc -isystem %S/Inputs \
+// RUN: -triple x86_64-apple-darwin %s -Wno-unreachable-code
+
+#include <conversion.h>
+
+#define BIG 0x7f7f7f7f7f7f7f7fL
+
+void test0(char c, short s, int i, long l, long long ll) {
+ c = c;
+ c = s; // expected-warning {{implicit conversion loses integer precision}}
+ c = i; // expected-warning {{implicit conversion loses integer precision}}
+ c = l; // expected-warning {{implicit conversion loses integer precision}}
+ s = c;
+ s = s;
+ s = i; // expected-warning {{implicit conversion loses integer precision}}
+ s = l; // expected-warning {{implicit conversion loses integer precision}}
+ i = c;
+ i = s;
+ i = i;
+ i = l; // expected-warning {{implicit conversion loses integer precision}}
+ l = c;
+ l = s;
+ l = i;
+ l = l;
+
+ c = (char) 0;
+ c = (short) 0;
+ c = (int) 0;
+ c = (long) 0;
+ s = (char) 0;
+ s = (short) 0;
+ s = (int) 0;
+ s = (long) 0;
+ i = (char) 0;
+ i = (short) 0;
+ i = (int) 0;
+ i = (long) 0;
+ l = (char) 0;
+ l = (short) 0;
+ l = (int) 0;
+ l = (long) 0;
+
+ c = (char) BIG;
+ c = (short) BIG; // expected-warning {{implicit conversion from 'short' to 'char' changes value}}
+ c = (int) BIG; // expected-warning {{implicit conversion from 'int' to 'char' changes value}}
+ c = (long) BIG; // expected-warning {{implicit conversion from 'long' to 'char' changes value}}
+ s = (char) BIG;
+ s = (short) BIG;
+ s = (int) BIG; // expected-warning {{implicit conversion from 'int' to 'short' changes value}}
+ s = (long) BIG; // expected-warning {{implicit conversion from 'long' to 'short' changes value}}
+ i = (char) BIG;
+ i = (short) BIG;
+ i = (int) BIG;
+ i = (long) BIG; // expected-warning {{implicit conversion from 'long' to 'int' changes value}}
+ l = (char) BIG;
+ l = (short) BIG;
+ l = (int) BIG;
+ l = (long) BIG;
+}
+
+char test1(long long ll) {
+ return (long long) ll; // expected-warning {{implicit conversion loses integer precision}}
+}
+char test1_a(long long ll) {
+ return (long) ll; // expected-warning {{implicit conversion loses integer precision}}
+}
+char test1_b(long long ll) {
+ return (int) ll; // expected-warning {{implicit conversion loses integer precision}}
+}
+char test1_c(long long ll) {
+ return (short) ll; // expected-warning {{implicit conversion loses integer precision}}
+}
+char test1_d(long long ll) {
+ return (char) ll;
+}
+char test1_e(long long ll) {
+ return (long long) BIG; // expected-warning {{implicit conversion from 'long long' to 'char' changes value}}
+}
+char test1_f(long long ll) {
+ return (long) BIG; // expected-warning {{implicit conversion from 'long' to 'char' changes value}}
+}
+char test1_g(long long ll) {
+ return (int) BIG; // expected-warning {{implicit conversion from 'int' to 'char' changes value}}
+}
+char test1_h(long long ll) {
+ return (short) BIG; // expected-warning {{implicit conversion from 'short' to 'char' changes value}}
+}
+char test1_i(long long ll) {
+ return (char) BIG;
+}
+
+short test2(long long ll) {
+ return (long long) ll; // expected-warning {{implicit conversion loses integer precision}}
+}
+short test2_a(long long ll) {
+ return (long) ll; // expected-warning {{implicit conversion loses integer precision}}
+}
+short test2_b(long long ll) {
+ return (int) ll; // expected-warning {{implicit conversion loses integer precision}}
+}
+short test2_c(long long ll) {
+ return (short) ll;
+}
+short test2_d(long long ll) {
+ return (char) ll;
+}
+short test2_e(long long ll) {
+ return (long long) BIG; // expected-warning {{implicit conversion from 'long long' to 'short' changes value}}
+}
+short test2_f(long long ll) {
+ return (long) BIG; // expected-warning {{implicit conversion from 'long' to 'short' changes value}}
+}
+short test2_g(long long ll) {
+ return (int) BIG; // expected-warning {{implicit conversion from 'int' to 'short' changes value}}
+}
+short test2_h(long long ll) {
+ return (short) BIG;
+}
+short test2_i(long long ll) {
+ return (char) BIG;
+}
+
+int test3(long long ll) {
+ return (long long) ll; // expected-warning {{implicit conversion loses integer precision}}
+}
+int test3_b(long long ll) {
+ return (long) ll; // expected-warning {{implicit conversion loses integer precision}}
+}
+int test3_c(long long ll) {
+ return (int) ll;
+}
+int test3_d(long long ll) {
+ return (short) ll;
+}
+int test3_e(long long ll) {
+ return (char) ll;
+}
+int test3_f(long long ll) {
+ return (long long) BIG; // expected-warning {{implicit conversion from 'long long' to 'int' changes value}}
+}
+int test3_g(long long ll) {
+ return (long) BIG; // expected-warning {{implicit conversion from 'long' to 'int' changes value}}
+}
+int test3_h(long long ll) {
+ return (int) BIG;
+}
+int test3_i(long long ll) {
+ return (short) BIG;
+}
+int test3_j(long long ll) {
+ return (char) BIG;
+}
+
+long test4(long long ll) {
+ return (long long) ll;
+}
+long test4_a(long long ll) {
+ return (long) ll;
+}
+long test4_b(long long ll) {
+ return (int) ll;
+}
+long test4_c(long long ll) {
+ return (short) ll;
+}
+long test4_d(long long ll) {
+ return (char) ll;
+}
+long test4_e(long long ll) {
+ return (long long) BIG;
+}
+long test4_f(long long ll) {
+ return (long) BIG;
+}
+long test4_g(long long ll) {
+ return (int) BIG;
+}
+long test4_h(long long ll) {
+ return (short) BIG;
+}
+long test4_i(long long ll) {
+ return (char) BIG;
+}
+
+long long test5(long long ll) {
+ return (long long) ll;
+ return (long) ll;
+ return (int) ll;
+ return (short) ll;
+ return (char) ll;
+ return (long long) BIG;
+ return (long) BIG;
+ return (int) BIG;
+ return (short) BIG;
+ return (char) BIG;
+}
+
+void takes_char(char);
+void takes_short(short);
+void takes_int(int);
+void takes_long(long);
+void takes_longlong(long long);
+void takes_float(float);
+void takes_double(double);
+void takes_longdouble(long double);
+
+void test6(char v) {
+ takes_char(v);
+ takes_short(v);
+ takes_int(v);
+ takes_long(v);
+ takes_longlong(v);
+ takes_float(v);
+ takes_double(v);
+ takes_longdouble(v);
+}
+
+void test7(short v) {
+ takes_char(v); // expected-warning {{implicit conversion loses integer precision}}
+ takes_short(v);
+ takes_int(v);
+ takes_long(v);
+ takes_longlong(v);
+ takes_float(v);
+ takes_double(v);
+ takes_longdouble(v);
+}
+
+void test8(int v) {
+ takes_char(v); // expected-warning {{implicit conversion loses integer precision}}
+ takes_short(v); // expected-warning {{implicit conversion loses integer precision}}
+ takes_int(v);
+ takes_long(v);
+ takes_longlong(v);
+ takes_float(v);
+ takes_double(v);
+ takes_longdouble(v);
+}
+
+void test9(long v) {
+ takes_char(v); // expected-warning {{implicit conversion loses integer precision}}
+ takes_short(v); // expected-warning {{implicit conversion loses integer precision}}
+ takes_int(v); // expected-warning {{implicit conversion loses integer precision}}
+ takes_long(v);
+ takes_longlong(v);
+ takes_float(v);
+ takes_double(v);
+ takes_longdouble(v);
+}
+
+void test10(long long v) {
+ takes_char(v); // expected-warning {{implicit conversion loses integer precision}}
+ takes_short(v); // expected-warning {{implicit conversion loses integer precision}}
+ takes_int(v); // expected-warning {{implicit conversion loses integer precision}}
+ takes_long(v);
+ takes_longlong(v);
+ takes_float(v);
+ takes_double(v);
+ takes_longdouble(v);
+}
+
+void test11(float v) {
+ takes_char(v); // expected-warning {{implicit conversion turns floating-point number into integer}}
+ takes_short(v); // expected-warning {{implicit conversion turns floating-point number into integer}}
+ takes_int(v); // expected-warning {{implicit conversion turns floating-point number into integer}}
+ takes_long(v); // expected-warning {{implicit conversion turns floating-point number into integer}}
+ takes_longlong(v); // expected-warning {{implicit conversion turns floating-point number into integer}}
+ takes_float(v);
+ takes_double(v);
+ takes_longdouble(v);
+}
+
+void test12(double v) {
+ takes_char(v); // expected-warning {{implicit conversion turns floating-point number into integer}}
+ takes_short(v); // expected-warning {{implicit conversion turns floating-point number into integer}}
+ takes_int(v); // expected-warning {{implicit conversion turns floating-point number into integer}}
+ takes_long(v); // expected-warning {{implicit conversion turns floating-point number into integer}}
+ takes_longlong(v); // expected-warning {{implicit conversion turns floating-point number into integer}}
+ takes_float(v); // expected-warning {{implicit conversion loses floating-point precision}}
+ takes_double(v);
+ takes_longdouble(v);
+}
+
+void test13(long double v) {
+ takes_char(v); // expected-warning {{implicit conversion turns floating-point number into integer}}
+ takes_short(v); // expected-warning {{implicit conversion turns floating-point number into integer}}
+ takes_int(v); // expected-warning {{implicit conversion turns floating-point number into integer}}
+ takes_long(v); // expected-warning {{implicit conversion turns floating-point number into integer}}
+ takes_longlong(v); // expected-warning {{implicit conversion turns floating-point number into integer}}
+ takes_float(v); // expected-warning {{implicit conversion loses floating-point precision}}
+ takes_double(v); // expected-warning {{implicit conversion loses floating-point precision}}
+ takes_longdouble(v);
+}
+
+void test14(long l) {
+ // Fine because of the boolean whitelist.
+ char c;
+ c = (l == 4);
+ c = ((l <= 4) && (l >= 0));
+ c = ((l <= 4) && (l >= 0)) || (l > 20);
+}
+
+void test15(char c) {
+ c = c + 1 + c * 2;
+ c = (short) c + 1 + c * 2; // expected-warning {{implicit conversion loses integer precision}}
+}
+
+// PR 5422
+extern void *test16_external;
+void test16(void) {
+ int a = (unsigned long) &test16_external; // expected-warning {{implicit conversion loses integer precision}}
+}
+
+// PR 5938
+void test17() {
+ union {
+ unsigned long long a : 8;
+ unsigned long long b : 32;
+ unsigned long long c;
+ } U;
+
+ unsigned int x;
+ x = U.a;
+ x = U.b;
+ x = U.c; // expected-warning {{implicit conversion loses integer precision}}
+}
+
+// PR 5939
+void test18() {
+ union {
+ unsigned long long a : 1;
+ unsigned long long b;
+ } U;
+
+ int x;
+ x = (U.a ? 0 : 1);
+ x = (U.b ? 0 : 1);
+}
+
+// None of these should warn.
+unsigned char test19(unsigned long u64) {
+ unsigned char x1 = u64 & 0xff;
+ unsigned char x2 = u64 >> 56;
+
+ unsigned char mask = 0xee;
+ unsigned char x3 = u64 & mask;
+ return x1 + x2 + x3;
+}
+
+// <rdar://problem/7631400>
+void test_7631400(void) {
+ // This should show up despite the caret being inside a macro substitution
+ char s = LONG_MAX; // expected-warning {{implicit conversion from 'long' to 'char' changes value}}
+}
+
+// <rdar://problem/7676608>: assertion for compound operators with non-integral RHS
+void f7676608(int);
+void test_7676608(void) {
+ float q = 0.7f;
+ char c = 5;
+ f7676608(c *= q);
+}
+
+// <rdar://problem/7904686>
+void test_7904686(void) {
+ const int i = -1;
+ unsigned u1 = i; // expected-warning {{implicit conversion changes signedness}}
+ u1 = i; // expected-warning {{implicit conversion changes signedness}}
+
+ unsigned u2 = -1; // expected-warning {{implicit conversion changes signedness}}
+ u2 = -1; // expected-warning {{implicit conversion changes signedness}}
+}
+
+// <rdar://problem/8232669>: don't warn about conversions required by
+// contexts in system headers
+void test_8232669(void) {
+ unsigned bitset[20];
+ SETBIT(bitset, 0);
+
+ unsigned y = 50;
+ SETBIT(bitset, y);
+
+#define USER_SETBIT(set,bit) do { int i = bit; set[i/(8*sizeof(set[0]))] |= (1 << (i%(8*sizeof(set)))); } while(0)
+ USER_SETBIT(bitset, 0); // expected-warning 2 {{implicit conversion changes signedness}}
+}
+
+// <rdar://problem/8559831>
+enum E8559831a { E8559831a_val };
+enum E8559831b { E8559831b_val };
+typedef enum { E8559831c_val } E8559831c;
+enum { E8559831d_val } value_d;
+
+void test_8559831_a(enum E8559831a value);
+void test_8559831(enum E8559831b value_a, E8559831c value_c) {
+ test_8559831_a(value_a); // expected-warning{{implicit conversion from enumeration type 'enum E8559831b' to different enumeration type 'enum E8559831a'}}
+ enum E8559831a a1 = value_a; // expected-warning{{implicit conversion from enumeration type 'enum E8559831b' to different enumeration type 'enum E8559831a'}}
+ a1 = value_a; // expected-warning{{implicit conversion from enumeration type 'enum E8559831b' to different enumeration type 'enum E8559831a'}}
+
+ test_8559831_a(E8559831b_val); // expected-warning{{implicit conversion from enumeration type 'enum E8559831b' to different enumeration type 'enum E8559831a'}}
+ enum E8559831a a1a = E8559831b_val; // expected-warning{{implicit conversion from enumeration type 'enum E8559831b' to different enumeration type 'enum E8559831a'}}
+ a1 = E8559831b_val; // expected-warning{{implicit conversion from enumeration type 'enum E8559831b' to different enumeration type 'enum E8559831a'}}
+
+ test_8559831_a(value_c); // expected-warning{{implicit conversion from enumeration type 'E8559831c' to different enumeration type 'enum E8559831a'}}
+ enum E8559831a a2 = value_c; // expected-warning{{implicit conversion from enumeration type 'E8559831c' to different enumeration type 'enum E8559831a'}}
+ a2 = value_c; // expected-warning{{implicit conversion from enumeration type 'E8559831c' to different enumeration type 'enum E8559831a'}}
+
+ test_8559831_a(value_d);
+ enum E8559831a a3 = value_d;
+ a3 = value_d;
+}
+
+void test26(int si, long sl) {
+ si = sl % sl; // expected-warning {{implicit conversion loses integer precision: 'long' to 'int'}}
+ si = sl % si;
+ si = si % sl;
+ si = si / sl;
+ si = sl / si; // expected-warning {{implicit conversion loses integer precision: 'long' to 'int'}}
+}
diff --git a/clang/test/Sema/crash-invalid-array.c b/clang/test/Sema/crash-invalid-array.c
new file mode 100644
index 0000000..a3bc03b
--- /dev/null
+++ b/clang/test/Sema/crash-invalid-array.c
@@ -0,0 +1,17 @@
+// RUN: not %clang_cc1 -O1 %s -emit-llvm
+// PR6913
+
+#include <stdio.h>
+
+int main()
+{
+ int x[10][10];
+ int (*p)[] = x; // expected-error {{invalid use of array with unspecified bounds}
+
+ int i;
+
+ for(i = 0; i < 10; ++i)
+ {
+ p[i][i] = i;
+ }
+}
diff --git a/clang/test/Sema/darwin-align-cast.c b/clang/test/Sema/darwin-align-cast.c
new file mode 100644
index 0000000..2080974
--- /dev/null
+++ b/clang/test/Sema/darwin-align-cast.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+typedef long unsigned int __darwin_size_t;
+typedef long __darwin_ssize_t;
+typedef __darwin_size_t size_t;
+typedef __darwin_ssize_t ssize_t;
+
+struct cmsghdr {};
+
+#if 0
+This code below comes from the following system headers:
+sys/socket.h:#define CMSG_SPACE(l) (__DARWIN_ALIGN(sizeof(struct
+cmsghdr)) + __DARWIN_ALIGN(l))
+
+i386/_param.h:#define __DARWIN_ALIGN(p) ((__darwin_size_t)((char *)(p)
++ __DARWIN_ALIGNBYTES) &~ __DARWIN_ALIGNBYTES)
+#endif
+
+ssize_t sendFileDescriptor(int fd, void *data, size_t nbytes, int sendfd) {
+ union {
+ char control[(((__darwin_size_t)((char *)(sizeof(struct cmsghdr)) + (sizeof(__darwin_size_t) - 1)) &~ (sizeof(__darwin_size_t) - 1)) + ((__darwin_size_t)((char *)(sizeof(int)) + (sizeof(__darwin_size_t) - 1)) &~ (sizeof(__darwin_size_t) - 1)))];
+ } control_un;
+ return 0;
+}
+
diff --git a/clang/test/Sema/decl-in-prototype.c b/clang/test/Sema/decl-in-prototype.c
new file mode 100644
index 0000000..05b8e0a
--- /dev/null
+++ b/clang/test/Sema/decl-in-prototype.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1_only -verify %s
+
+const int AA = 5;
+
+int f1(enum {AA,BB} E) {
+ return BB;
+}
+
+int f2(enum {AA=7,BB} E) {
+ return AA;
+}
+
+struct a {
+};
+
+int f3(struct a { } *); // expected-warning {{will not be visible outside of this function}}
+
+struct A { struct b { int j; } t; }; // expected-note {{previous definition is here}}
+
+int f4(struct A { struct b { int j; } t; } *); // expected-warning {{declaration of 'struct A' will not be visible outside of this function}} expected-warning {{redefinition of 'b' will not be visible outside of this function}}
+
+struct aA {
+ struct ab { // expected-note {{previous definition is here}} expected-note {{previous definition is here}}
+ int j;
+ } b;
+};
+
+int f5(struct aA { struct ab { int j; } b; struct ab { char glorx; } glorx; } *); // expected-warning {{declaration of 'struct aA' will not be visible}} expected-warning {{redefinition of 'ab' will not be visible}} expected-warning {{redefinition of 'ab' will not be visible}}
+
+void f6(struct z {int b;} c) { // expected-warning {{declaration of 'struct z' will not be visible outside of this function}}
+ struct z d;
+ d.b = 4;
+}
diff --git a/clang/test/Sema/decl-invalid.c b/clang/test/Sema/decl-invalid.c
new file mode 100644
index 0000000..f6fed3c
--- /dev/null
+++ b/clang/test/Sema/decl-invalid.c
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+// See Sema::ParsedFreeStandingDeclSpec about the double diagnostic
+typedef union <anonymous> __mbstate_t; // expected-error {{declaration of anonymous union must be a definition}} expected-warning {{declaration does not declare anything}}
+
+
+// PR2017
+void x();
+int a() {
+ int r[x()]; // expected-error {{size of array has non-integer type 'void'}}
+
+ static y ?; // expected-error{{unknown type name 'y'}} \
+ expected-error{{expected identifier or '('}}
+}
+
+int; // expected-warning {{declaration does not declare anything}}
+typedef int; // expected-warning {{declaration does not declare anything}}
+const int; // expected-warning {{declaration does not declare anything}}
+struct; // expected-error {{declaration of anonymous struct must be a definition}} // expected-warning {{declaration does not declare anything}}
+typedef int I;
+I; // expected-warning {{declaration does not declare anything}}
+
+
+
+// rdar://6880449
+register int test1; // expected-error {{illegal storage class on file-scoped variable}}
+register int test2 __asm__("edi"); // expected-error {{global register variables are not supported}}
+
diff --git a/clang/test/Sema/decl-type-merging.c b/clang/test/Sema/decl-type-merging.c
new file mode 100644
index 0000000..259b0dd
--- /dev/null
+++ b/clang/test/Sema/decl-type-merging.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -verify -pedantic %s
+
+int x[10];
+int x[] = {1,2,3};
+int testx[(sizeof(x) == sizeof(int) * 10) ? 1 : -1];
+
+int (*a)(int (*x)[10], int (*y)[]);
+int (*a)(int (*x)[], int (*y)[5]);
+void b() {
+ int x[10], y[5];
+ a(&x, &y);
+ a(&y, &y); // expected-warning {{incompatible pointer}}
+ a(&x, &x); // expected-warning {{incompatible pointer}}
+}
+
+
diff --git a/clang/test/Sema/declspec.c b/clang/test/Sema/declspec.c
new file mode 100644
index 0000000..7354028
--- /dev/null
+++ b/clang/test/Sema/declspec.c
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+typedef char T[4];
+
+T foo(int n, int m) { } // expected-error {{cannot return array type}}
+
+void foof(const char *, ...) __attribute__((__format__(__printf__, 1, 2))), barf (void);
+
+int typedef validTypeDecl() { } // expected-error {{function definition declared 'typedef'}}
+
+struct _zend_module_entry { } // expected-error {{expected ';' after struct}}
+int gv1;
+typedef struct _zend_function_entry { } // expected-error {{expected ';' after struct}} \
+ // expected-warning {{declaration does not declare anything}}
+int gv2;
+
+static void buggy(int *x) { }
+
+// Type qualifiers.
+typedef int f(void);
+typedef f* fptr;
+const f* v1; // expected-warning {{qualifier on function type 'f' (aka 'int (void)') has unspecified behavior}}
+__restrict__ f* v2; // expected-error {{restrict requires a pointer or reference ('f' (aka 'int (void)') is invalid)}}
+__restrict__ fptr v3; // expected-error {{pointer to function type 'f' (aka 'int (void)') may not be 'restrict' qualified}}
+f *__restrict__ v4; // expected-error {{pointer to function type 'f' (aka 'int (void)') may not be 'restrict' qualified}}
+
+restrict struct hallo; // expected-error {{restrict requires a pointer or reference}}
+
+// PR6180
+struct test1 {
+} // expected-error {{expected ';' after struct}}
+
+void test2() {}
+
+
+// PR6423
+struct test3s {
+} // expected-error {{expected ';' after struct}}
+typedef int test3g;
diff --git a/clang/test/Sema/default.c b/clang/test/Sema/default.c
new file mode 100644
index 0000000..429e63a
--- /dev/null
+++ b/clang/test/Sema/default.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void f5 (int z) {
+ if (z)
+ default: // expected-error {{not in switch statement}}
+ ;
+}
+
diff --git a/clang/test/Sema/default1.c b/clang/test/Sema/default1.c
new file mode 100644
index 0000000..631e848
--- /dev/null
+++ b/clang/test/Sema/default1.c
@@ -0,0 +1,2 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+void f(int i = 0); // expected-error {{C does not support default arguments}}
diff --git a/clang/test/Sema/deref.c b/clang/test/Sema/deref.c
new file mode 100644
index 0000000..845b286
--- /dev/null
+++ b/clang/test/Sema/deref.c
@@ -0,0 +1,44 @@
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c90 -pedantic %s
+ */
+void
+foo (void)
+{
+ struct b;
+ struct b* x = 0;
+ struct b* y = &*x;
+}
+
+void foo2 (void)
+{
+ typedef int (*arrayptr)[];
+ arrayptr x = 0;
+ arrayptr y = &*x;
+}
+
+void foo3 (void)
+{
+ void* x = 0;
+ void* y = &*x; /* expected-warning{{address of an expression of type 'void'}} */
+}
+
+extern const void cv1;
+
+const void *foo4 (void)
+{
+ return &cv1;
+}
+
+extern void cv2;
+void *foo5 (void)
+{
+ return &cv2; /* expected-warning{{address of an expression of type 'void'}} */
+}
+
+typedef const void CVT;
+extern CVT cv3;
+
+const void *foo6 (void)
+{
+ return &cv3;
+}
+
diff --git a/clang/test/Sema/designated-initializers.c b/clang/test/Sema/designated-initializers.c
new file mode 100644
index 0000000..c9a8482
--- /dev/null
+++ b/clang/test/Sema/designated-initializers.c
@@ -0,0 +1,279 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-unknown %s
+
+int complete_array_from_init[] = { 1, 2, [10] = 5, 1, 2, [5] = 2, 6 };
+
+int complete_array_from_init_check[((sizeof(complete_array_from_init) / sizeof(int)) == 13)? 1 : -1];
+
+int iarray[10] = {
+ [0] = 1,
+ [1 ... 5] = 2,
+ [ 6 ... 6 ] = 3,
+ [ 8 ... 7 ] = 4, // expected-error{{array designator range [8, 7] is empty}}
+ [10] = 5,
+ [-1] = 6 // expected-error{{array designator value '-1' is negative}}
+};
+
+int iarray2[10] = {
+ [10] = 1, // expected-error{{array designator index (10) exceeds array bounds (10)}}
+};
+
+int iarray3[10] = {
+ [3] 2, // expected-warning{{use of GNU 'missing =' extension in designator}}
+ [5 ... 12] = 2 // expected-error{{array designator index (12) exceeds array bounds (10)}}
+};
+
+struct point {
+ double x;
+ double y;
+};
+
+struct point p1 = {
+ .y = 1.0,
+ x: 2.0, // expected-warning{{}}
+ .a = 4.0, // expected-error{{field designator 'a' does not refer to any field in type 'struct point'}}
+};
+
+struct point p2 = {
+ [1] = 1.0 // expected-error{{array designator cannot initialize non-array type}}
+};
+
+struct point array[10] = {
+ [0].x = 1.0,
+ [1].y = 2.0,
+ [2].z = 3.0, // expected-error{{field designator 'z' does not refer to any field in type 'struct point'}}
+};
+
+struct point array2[10] = {
+ [10].x = 2.0, // expected-error{{array designator index (10) exceeds array bounds (10)}}
+ [4 ... 5].y = 2.0,
+ [4 ... 6] = { .x = 3, .y = 4.0 }
+};
+
+struct point array3[10] = {
+ .x = 5 // expected-error{{field designator cannot initialize a non-struct, non-union type}}
+};
+
+struct rect {
+ struct point top_left;
+ struct point bottom_right;
+};
+
+struct rect window = { .top_left.x = 1.0 };
+
+struct rect windows[] = {
+ [2].top_left = { 1.0, 2.0 },
+ [4].bottom_right = { .y = 1.0 },
+ { { .y = 7.0, .x = 8.0 }, { .x = 5.0 } },
+ [3] = { .top_left = { 1.1, 2.2 }, .bottom_right = { .y = 1.1 } }
+};
+
+int windows_size[((sizeof(windows) / sizeof(struct rect)) == 6)? 1 : -1];
+
+struct rect windows_bad[3] = {
+ [2].top_left = { { .x = 1.1 } }, // expected-error{{designator in initializer for scalar type}}
+ [1].top_left = { .x = 1.1 }
+};
+
+struct gui {
+ struct rect windows[10];
+};
+
+struct gui gui[] = {
+ [5].windows[3].top_left.x = { 7.0 } // expected-warning{{braces around scalar initializer}}
+};
+
+struct translator {
+ struct wonky { int * ptr; } wonky ;
+ struct rect window;
+ struct point offset;
+} tran = {
+ .window = { .top_left = { 1.0, 2.0 } },
+ { .x = 5.0, .y = 6.0 },
+ .wonky = { 0 }
+};
+
+int anint;
+struct {int x,*y;} z[] = {[0].x = 2, &z[0].x};
+
+struct outer { struct inner { int x, *y; } in, *inp; } zz[] = {
+ [0].in.x = 2, &zz[0].in.x, &zz[0].in,
+ 0, &anint, &zz[1].in,
+ [3].in = { .y = &anint, .x = 17 },
+ [7].in.y = &anint, &zz[0].in,
+ [4].in.y = &anint, [5].in.x = 12
+};
+
+int zz_sizecheck[sizeof(zz) / sizeof(struct outer) == 8? 1 : -1 ];
+
+struct disklabel_ops {
+ struct {} type;
+ int labelsize;
+};
+
+struct disklabel_ops disklabel64_ops = {
+ .labelsize = sizeof(struct disklabel_ops)
+};
+
+// PR clang/3378
+int bitwidth[] = { [(long long int)1] = 5, [(short int)2] = 2 };
+int a[]= { [sizeof(int)] = 0 };
+int a2[]= { [0 ... sizeof(int)] = 0 };
+
+// Test warnings about initializers overriding previous initializers
+struct X {
+ int a, b, c;
+};
+
+int counter = 0;
+int get8() { ++counter; return 8; }
+
+void test() {
+ struct X xs[] = {
+ [0] = (struct X){1, 2}, // expected-note{{previous initialization is here}}
+ [0].c = 3, // expected-warning{{subobject initialization overrides initialization of other fields within its enclosing subobject}}
+ (struct X) {4, 5, 6}, // expected-note{{previous initialization is here}}
+ [1].b = get8(), // expected-warning{{subobject initialization overrides initialization of other fields within its enclosing subobject}}
+ [0].b = 8
+ };
+}
+
+// FIXME: How do we test that this initializes the long properly?
+union { char c; long l; } u1 = { .l = 0xFFFF };
+
+extern float global_float;
+
+struct XX { int a, *b; };
+struct XY { int before; struct XX xx, *xp; float* after; } xy[] = {
+ 0, 0, &xy[0].xx.a, &xy[0].xx, &global_float,
+ [1].xx = 0, &xy[1].xx.a, &xy[1].xx, &global_float,
+ 0, // expected-note{{previous initialization is here}}
+ 0, // expected-note{{previous initialization is here}}
+ [2].before = 0, // expected-warning{{initializer overrides prior initialization of this subobject}}
+ 0, // expected-warning{{initializer overrides prior initialization of this subobject}}
+ &xy[2].xx.a, &xy[2].xx, &global_float
+};
+
+// PR3519
+struct foo {
+ int arr[10];
+};
+
+struct foo Y[10] = {
+ [1] .arr [1] = 2,
+ [4] .arr [2] = 4
+};
+
+struct bar {
+ struct foo f;
+ float *arr[10];
+};
+
+extern float f;
+struct bar saloon = {
+ .f.arr[3] = 1,
+ .arr = { &f }
+};
+
+typedef unsigned char u_char;
+typedef unsigned short u_short;
+
+union wibble {
+ u_char arr1[6];
+ u_short arr2[3];
+};
+
+const union wibble wobble = { .arr2[0] = 0xffff,
+ .arr2[1] = 0xffff,
+ .arr2[2] = 0xffff };
+
+const union wibble wobble2 = { .arr2 = {4, 5, 6}, 7 }; // expected-warning{{excess elements in union initializer}}
+
+// PR3778
+struct s {
+ union { int i; };
+};
+struct s si = {
+ { .i = 1 }
+};
+
+double d0;
+char c0;
+float f0;
+int i0;
+
+struct Enigma {
+ union {
+ struct {
+ struct {
+ double *double_ptr;
+ char *string;
+ };
+ float *float_ptr;
+ };
+ int *int_ptr;
+ };
+ char *string2;
+};
+
+struct Enigma enigma = {
+ .double_ptr = &d0, &c0,
+ &f0, // expected-note{{previous}}
+ &c0,
+ .float_ptr = &f0 // expected-warning{{overrides}}
+};
+
+
+/// PR4073
+/// Should use evaluate to fold aggressively and emit a warning if not an ice.
+extern int crazy_x;
+
+int crazy_Y[] = {
+ [ 0 ? crazy_x : 4] = 1
+};
+
+// PR5843
+struct expr {
+ int nargs;
+ union {
+ unsigned long int num;
+ struct expr *args[3];
+ } val;
+};
+
+struct expr expr0 = {
+ .nargs = 2,
+ .val = {
+ .args = {
+ [0] = (struct expr *)0,
+ [1] = (struct expr *)0
+ }
+ }
+};
+
+// PR6955
+
+struct ds {
+ struct {
+ struct {
+ unsigned int a;
+ };
+ unsigned int b;
+ struct {
+ unsigned int c;
+ };
+ };
+};
+
+// C1X lookup-based anonymous member init cases
+struct ds ds0 = {
+ { {
+ .a = 1 // expected-note{{previous initialization is here}}
+ } },
+ .a = 2, // expected-warning{{initializer overrides prior initialization of this subobject}}
+ .b = 3
+};
+struct ds ds1 = { .c = 0 };
+struct ds ds2 = { { {
+ .a = 0,
+ .b = 1 // expected-error{{field designator 'b' does not refer to any field}}
+} } };
diff --git a/clang/test/Sema/dllimport-dllexport.c b/clang/test/Sema/dllimport-dllexport.c
new file mode 100644
index 0000000..610059e
--- /dev/null
+++ b/clang/test/Sema/dllimport-dllexport.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple i386-mingw32 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -verify %s
+
+inline void __attribute__((dllexport)) foo1(){} // expected-warning{{dllexport attribute ignored}}
+inline void __attribute__((dllimport)) foo2(){} // expected-warning{{dllimport attribute ignored}}
+
+void __attribute__((dllimport)) foo3(){} // expected-error{{dllimport attribute can be applied only to symbol declaration}}
+
+void __attribute__((dllimport, dllexport)) foo4(); // expected-warning{{dllimport attribute ignored}}
+
+void __attribute__((dllexport)) foo5();
+void __attribute__((dllimport)) foo5(); // expected-warning{{dllimport attribute ignored}}
+
+typedef int __attribute__((dllexport)) type6; // expected-warning{{'dllexport' attribute only applies to variables and functions}}
+
+typedef int __attribute__((dllimport)) type7; // expected-warning{{'dllimport' attribute only applies to variables and functions}}
+
+void __attribute__((dllimport)) foo6();
+void foo6(){} // expected-warning {{'foo6' redeclared without dllimport attribute: previous dllimport ignored}}
+
+// PR6269
+inline void __declspec(dllexport) foo7(){} // expected-warning{{dllexport attribute ignored}}
+inline void __declspec(dllimport) foo8(){} // expected-warning{{dllimport attribute ignored}}
+
+void __declspec(dllimport) foo9(){} // expected-error{{dllimport attribute can be applied only to symbol declaration}}
+
+void __declspec(dllimport) __declspec(dllexport) foo10(); // expected-warning{{dllimport attribute ignored}}
+
+void __declspec(dllexport) foo11();
+void __declspec(dllimport) foo11(); // expected-warning{{dllimport attribute ignored}}
+
+typedef int __declspec(dllexport) type1; // expected-warning{{'dllexport' attribute only applies to variables and functions}}
+
+typedef int __declspec(dllimport) type2; // expected-warning{{'dllimport' attribute only applies to variables and functions}}
+
+void __declspec(dllimport) foo12();
+void foo12(){} // expected-warning {{'foo12' redeclared without dllimport attribute: previous dllimport ignored}}
diff --git a/clang/test/Sema/enum-packed.c b/clang/test/Sema/enum-packed.c
new file mode 100644
index 0000000..0eb6c14
--- /dev/null
+++ b/clang/test/Sema/enum-packed.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// PR7477
+enum __attribute__((packed)) E {
+ Ea, Eb, Ec, Ed
+};
+
+void test_E(enum E e) {
+ switch (e) {
+ case Ea:
+ case Eb:
+ case Ec:
+ case Ed:
+ break;
+ }
+}
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
new file mode 100644
index 0000000..fc2b491
--- /dev/null
+++ b/clang/test/Sema/enum.c
@@ -0,0 +1,121 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
+enum e {A,
+ B = 42LL << 32, // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+ C = -4, D = 12456 };
+
+enum f { a = -2147483648, b = 2147483647 }; // ok.
+
+enum g { // too negative
+ c = -2147483649, // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+ d = 2147483647 };
+enum h { e = -2147483648, // too pos
+ f = 2147483648, // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+ i = 0xFFFF0000 // expected-warning {{too large}}
+};
+
+// minll maxull
+enum x // expected-warning {{enumeration values exceed range of largest integer}}
+{ y = -9223372036854775807LL-1, // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+z = 9223372036854775808ULL }; // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+
+int test() {
+ return sizeof(enum e) ;
+}
+
+enum gccForwardEnumExtension ve; // expected-warning{{ISO C forbids forward references to 'enum' types}} \
+// expected-error{{tentative definition has type 'enum gccForwardEnumExtension' that is never completed}} \
+// expected-note{{forward declaration of 'enum gccForwardEnumExtension'}}
+
+int test2(int i)
+{
+ ve + i; // expected-error{{invalid operands to binary expression}}
+}
+
+// PR2020
+union u0; // expected-note {{previous use is here}}
+enum u0 { U0A }; // expected-error {{use of 'u0' with tag type that does not match previous declaration}}
+
+
+// rdar://6095136
+extern enum some_undefined_enum ve2; // expected-warning {{ISO C forbids forward references to 'enum' types}}
+
+void test4() {
+ for (; ve2;) // expected-error {{statement requires expression of scalar type}}
+ ;
+ (_Bool)ve2; // expected-error {{arithmetic or pointer type is required}}
+
+ for (; ;ve2) // expected-warning {{expression result unused}}
+ ;
+ (void)ve2;
+ ve2; // expected-warning {{expression result unused}}
+}
+
+// PR2416
+enum someenum {}; // expected-error {{use of empty enum}}
+
+// <rdar://problem/6093889>
+enum e0 { // expected-note {{previous definition is here}}
+ E0 = sizeof(enum e0 { E1 }), // expected-error {{nested redefinition}}
+};
+
+// PR3173
+enum { PR3173A, PR3173B = PR3173A+50 };
+
+// PR2753
+void foo() {
+ enum xpto; // expected-warning{{ISO C forbids forward references to 'enum' types}}
+ enum xpto; // expected-warning{{ISO C forbids forward references to 'enum' types}}
+}
+
+// <rdar://problem/6503878>
+typedef enum { X = 0 }; // expected-warning{{typedef requires a name}}
+
+
+enum NotYetComplete { // expected-note{{definition of 'enum NotYetComplete' is not complete until the closing '}'}}
+ NYC1 = sizeof(enum NotYetComplete) // expected-error{{invalid application of 'sizeof' to an incomplete type 'enum NotYetComplete'}}
+};
+
+/// PR3688
+struct s1 {
+ enum e1 (*bar)(void); // expected-warning{{ISO C forbids forward references to 'enum' types}}
+};
+
+enum e1 { YES, NO };
+
+static enum e1 badfunc(struct s1 *q) {
+ return q->bar();
+}
+
+
+// Make sure we don't a.k.a. anonymous enums.
+typedef enum {
+ an_enumerator = 20
+} an_enum;
+char * s = (an_enum) an_enumerator; // expected-warning {{incompatible integer to pointer conversion initializing 'char *' with an expression of type 'an_enum'}}
+
+// PR4515
+enum PR4515 {PR4515a=1u,PR4515b=(PR4515a-2)/2};
+int CheckPR4515[PR4515b==0?1:-1];
+
+// PR7911
+extern enum PR7911T PR7911V; // expected-warning{{ISO C forbids forward references to 'enum' types}}
+void PR7911F() {
+ switch (PR7911V); // expected-error {{statement requires expression of integer type}}
+}
+
+char test5[__has_feature(enumerator_attributes) ? 1 : -1];
+
+// PR8694
+// rdar://8707031
+void PR8694(int* e) // expected-note {{passing argument to parameter 'e' here}}
+{
+}
+
+void crash(enum E* e) // expected-warning {{declaration of 'enum E' will not be visible outside of this function}} \
+ // expected-warning {{ISO C forbids forward references to 'enum' types}}
+{
+ PR8694(e); // expected-warning {{incompatible pointer types passing 'enum E *' to parameter of type 'int *'}}
+}
+
+typedef enum { NegativeShort = (short)-1 } NegativeShortEnum;
+int NegativeShortTest[NegativeShort == -1 ? 1 : -1];
diff --git a/clang/test/Sema/expr-address-of.c b/clang/test/Sema/expr-address-of.c
new file mode 100644
index 0000000..2b8cfbf
--- /dev/null
+++ b/clang/test/Sema/expr-address-of.c
@@ -0,0 +1,120 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+struct xx { int bitf:1; };
+
+struct entry { struct xx *whatever;
+ int value;
+ int bitf:1; };
+void add_one(int *p) { (*p)++; }
+
+void test() {
+ register struct entry *p;
+ add_one(&p->value);
+ struct entry pvalue;
+ add_one(&p->bitf); // expected-error {{address of bit-field requested}}
+ add_one(&pvalue.bitf); // expected-error {{address of bit-field requested}}
+ add_one(&p->whatever->bitf); // expected-error {{address of bit-field requested}}
+}
+
+void foo() {
+ register int x[10];
+ &x[10]; // expected-error {{address of register variable requested}}
+
+ register int *y;
+
+ int *x2 = &y; // expected-error {{address of register variable requested}}
+ int *x3 = &y[10];
+}
+
+void testVectorComponentAccess() {
+ typedef float v4sf __attribute__ ((vector_size (16)));
+ static v4sf q;
+ float* r = &q[0]; // expected-error {{address of vector element requested}}
+}
+
+typedef __attribute__(( ext_vector_type(4) )) float float4;
+
+float *testExtVectorComponentAccess(float4 x) {
+ return &x.w; // expected-error {{address of vector element requested}}
+}
+
+void f0() {
+ register int *x0;
+ int *_dummy0 = &(*x0);
+
+ register int *x1;
+ int *_dummy1 = &(*(x1 + 1));
+}
+
+// FIXME: The checks for this function are broken; we should error
+// on promoting a register array to a pointer! (C99 6.3.2.1p3)
+void f1() {
+ register int x0[10];
+ int *_dummy00 = x0; // fixme-error {{address of register variable requested}}
+ int *_dummy01 = &(*x0); // fixme-error {{address of register variable requested}}
+
+ register int x1[10];
+ int *_dummy1 = &(*(x1 + 1)); // fixme-error {{address of register variable requested}}
+
+ register int *x2;
+ int *_dummy2 = &(*(x2 + 1));
+
+ register int x3[10][10][10];
+ int (*_dummy3)[10] = &x3[0][0]; // expected-error {{address of register variable requested}}
+
+ register struct { int f0[10]; } x4;
+ int *_dummy4 = &x4.f0[2]; // expected-error {{address of register variable requested}}
+}
+
+void f2() {
+ register int *y;
+
+ int *_dummy0 = &y; // expected-error {{address of register variable requested}}
+ int *_dummy1 = &y[10];
+}
+
+void f3() {
+ extern void f4();
+ void (*_dummy0)() = &****f4;
+}
+
+void f4() {
+ register _Complex int x;
+
+ int *_dummy0 = &__real__ x; // expected-error {{address of register variable requested}}
+}
+
+void f5() {
+ register int arr[2];
+
+ /* This is just here because if we happened to support this as an
+ lvalue we would need to give a warning. Note that gcc warns about
+ this as a register before it warns about it as an invalid
+ lvalue. */
+ int *_dummy0 = &(int*) arr; // expected-error {{address expression must be an lvalue or a function designator}}
+ int *_dummy1 = &(arr + 1); // expected-error {{address expression must be an lvalue or a function designator}}
+}
+
+void f6(register int x) {
+ int * dummy0 = &x; // expected-error {{address of register variable requested}}
+}
+
+char* f7() {
+ register struct {char* x;} t1 = {"Hello"};
+ char* dummy1 = &(t1.x[0]);
+
+ struct {int a : 10;} t2;
+ int* dummy2 = &(t2.a); // expected-error {{address of bit-field requested}}
+
+ void* t3 = &(*(void*)0);
+}
+
+void f8() {
+ void *dummy0 = &f8(); // expected-error {{address expression must be an lvalue or a function designator}}
+
+ extern void v;
+ void *dummy1 = &(1 ? v : f8()); // expected-error {{address expression must be an lvalue or a function designator}}
+
+ void *dummy2 = &(f8(), v); // expected-error {{address expression must be an lvalue or a function designator}}
+
+ void *dummy3 = &({ ; }); // expected-error {{address expression must be an lvalue or a function designator}}
+}
diff --git a/clang/test/Sema/expr-comma-c99.c b/clang/test/Sema/expr-comma-c99.c
new file mode 100644
index 0000000..d0883ba
--- /dev/null
+++ b/clang/test/Sema/expr-comma-c99.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c99
+// rdar://6095180
+
+struct s { char c[17]; };
+extern struct s foo(void);
+
+struct s a, b, c;
+
+int A[sizeof((foo().c)) == 17 ? 1 : -1];
+int B[sizeof((a.c)) == 17 ? 1 : -1];
+
+
+// comma does array/function promotion in c99.
+int X[sizeof(0, (foo().c)) == sizeof(char*) ? 1 : -1];
+int Y[sizeof(0, (a,b).c) == sizeof(char*) ? 1 : -1];
+int Z[sizeof(0, (a=b).c) == sizeof(char*) ? 1 : -1];
+
diff --git a/clang/test/Sema/expr-comma.c b/clang/test/Sema/expr-comma.c
new file mode 100644
index 0000000..d3e4020
--- /dev/null
+++ b/clang/test/Sema/expr-comma.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c89
+// rdar://6095180
+
+struct s { char c[17]; };
+extern struct s foo(void);
+
+struct s a, b, c;
+
+int A[sizeof((foo().c)) == 17 ? 1 : -1];
+int B[sizeof((a.c)) == 17 ? 1 : -1];
+
+
+// comma does not promote array/function in c90 unless they are lvalues.
+int W[sizeof(0, a.c) == sizeof(char*) ? 1 : -1];
+int X[sizeof(0, (foo().c)) == 17 ? 1 : -1];
+int Y[sizeof(0, (a,b).c) == 17 ? 1 : -1];
+int Z[sizeof(0, (a=b).c) == 17 ? 1 : -1];
diff --git a/clang/test/Sema/exprs.c b/clang/test/Sema/exprs.c
new file mode 100644
index 0000000..72cff65
--- /dev/null
+++ b/clang/test/Sema/exprs.c
@@ -0,0 +1,240 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+// PR 8876 - don't warn about trivially unreachable null derefs. Note that
+// we put this here because the reachability analysis only kicks in for
+// suppressing false positives when code has no errors.
+#define PR8876(err_ptr) do {\
+ if (err_ptr) *(int*)(err_ptr) = 1;\
+ } while (0)
+
+#define PR8876_pos(err_ptr) do {\
+ if (!err_ptr) *(int*)(err_ptr) = 1;\
+ } while (0)
+
+
+// Test that we don't report divide-by-zero errors in unreachable code.
+// This test should be left as is, as it also tests CFG functionality.
+void radar9171946() {
+ if (0) {
+ 0 / (0 ? 1 : 0); // expected-warning {{expression result unused}}
+ }
+}
+
+int test_pr8876() {
+ PR8876(0); // no-warning
+ PR8876_pos(0); // expected-warning{{indirection of non-volatile null pointer will be deleted, not trap}} expected-note{{consider using __builtin_trap() or qualifying pointer with 'volatile'}}
+ return 0;
+}
+
+// PR 8183 - Handle null pointer constants on the left-side of the '&&', and reason about
+// this when determining the reachability of the null pointer dereference on the right side.
+void pr8183(unsigned long long test)
+{
+ (void)((((void*)0)) && (*((unsigned long long*)(((void*)0))) = ((unsigned long long)((test)) % (unsigned long long)((1000000000))))); // no-warning
+ (*((unsigned long long*)(((void*)0))) = ((unsigned long long)((test)) % (unsigned long long)((1000000000)))); // expected-warning {{indirection of non-volatile null pointer will be deleted, not trap}} expected-note {{consider using __builtin_trap() or qualifying pointer with 'volatile'}}
+}
+
+// PR1966
+_Complex double test1() {
+ return __extension__ 1.0if;
+}
+
+_Complex double test2() {
+ return 1.0if; // expected-warning {{imaginary constants are an extension}}
+}
+
+// rdar://6097308
+void test3() {
+ int x;
+ (__extension__ x) = 10;
+}
+
+// rdar://6162726
+void test4() {
+ static int var;
+ var =+ 5; // expected-warning {{use of unary operator that may be intended as compound assignment (+=)}}
+ var =- 5; // expected-warning {{use of unary operator that may be intended as compound assignment (-=)}}
+ var = +5; // no warning when space between the = and +.
+ var = -5;
+
+ var =+5; // no warning when the subexpr of the unary op has no space before it.
+ var =-5;
+
+#define FIVE 5
+ var=-FIVE; // no warning with macros.
+ var=-FIVE;
+}
+
+// rdar://6319320
+void test5(int *X, float *P) {
+ (float*)X = P; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
+#define FOO ((float*) X)
+ FOO = P; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
+}
+
+void test6() {
+ int X;
+ X(); // expected-error {{called object type 'int' is not a function or function pointer}}
+}
+
+void test7(int *P, _Complex float Gamma) {
+ P = (P-42) + Gamma*4; // expected-error {{invalid operands to binary expression ('int *' and '_Complex float')}}
+}
+
+
+// rdar://6095061
+int test8(void) {
+ int i;
+ __builtin_choose_expr (0, 42, i) = 10;
+ return i;
+}
+
+
+// PR3386
+struct f { int x : 4; float y[]; };
+int test9(struct f *P) {
+ int R;
+ R = __alignof(P->x); // expected-error {{invalid application of '__alignof' to bit-field}}
+ R = __alignof(P->y); // ok.
+ R = sizeof(P->x); // expected-error {{invalid application of 'sizeof' to bit-field}}
+ return R;
+}
+
+// PR3562
+void test10(int n,...) {
+ struct S {
+ double a[n]; // expected-error {{fields must have a constant size}}
+ } s;
+ double x = s.a[0]; // should not get another error here.
+}
+
+
+#define MYMAX(A,B) __extension__ ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
+
+struct mystruct {int A; };
+void test11(struct mystruct P, float F) {
+ MYMAX(P, F); // expected-error {{invalid operands to binary expression ('typeof (P)' (aka 'struct mystruct') and 'typeof (F)' (aka 'float'))}}
+}
+
+// PR3753
+int test12(const char *X) {
+ return X == "foo"; // expected-warning {{comparison against a string literal is unspecified (use strncmp instead)}}
+}
+
+int test12b(const char *X) {
+ return sizeof(X == "foo"); // no-warning
+}
+
+// rdar://6719156
+void test13(
+ void (^P)()) { // expected-error {{blocks support disabled - compile with -fblocks}}
+ P();
+ P = ^(){}; // expected-error {{blocks support disabled - compile with -fblocks}}
+}
+
+void test14() {
+ typedef long long __m64 __attribute__((__vector_size__(8)));
+ typedef short __v4hi __attribute__((__vector_size__(8)));
+
+ // Ok.
+ __v4hi a;
+ __m64 mask = (__m64)((__v4hi)a > (__v4hi)a);
+}
+
+
+// PR5242
+typedef unsigned long *test15_t;
+
+test15_t test15(void) {
+ return (test15_t)0 + (test15_t)0; // expected-error {{invalid operands to binary expression ('test15_t' (aka 'unsigned long *') and 'test15_t')}}
+}
+
+// rdar://7446395
+void test16(float x) { x == ((void*) 0); } // expected-error {{invalid operands to binary expression}}
+
+// PR6004
+void test17(int x) {
+ x = x / 0; // expected-warning {{division by zero is undefined}}
+ x = x % 0; // expected-warning {{remainder by zero is undefined}}
+ x /= 0; // expected-warning {{division by zero is undefined}}
+ x %= 0; // expected-warning {{remainder by zero is undefined}}
+
+ x = sizeof(x/0); // no warning.
+}
+
+// PR6501
+void test18_a(int a); // expected-note 2 {{'test18_a' declared here}}
+void test18(int b) {
+ test18_a(b, b); // expected-error {{too many arguments to function call, expected 1, have 2}}
+ test18_a(); // expected-error {{too few arguments to function call, expected 1, have 0}}
+}
+
+// PR7569
+void test19() {
+ *(int*)0 = 0; // expected-warning {{indirection of non-volatile null pointer}} \
+ // expected-note {{consider using __builtin_trap}}
+ *(volatile int*)0 = 0; // Ok.
+
+ // rdar://9269271
+ int x = *(int*)0; // expected-warning {{indirection of non-volatile null pointer}} \
+ // expected-note {{consider using __builtin_trap}}
+ int x2 = *(volatile int*)0; // Ok.
+ int *p = &(*(int*)0); // Ok;
+}
+
+int test20(int x) {
+ return x && 4; // expected-warning {{use of logical '&&' with constant operand}} \
+ // expected-note {{use '&' for a bitwise operation}} \
+ // expected-note {{remove constant to silence this warning}}
+
+ return x && sizeof(int) == 4; // no warning, RHS is logical op.
+
+ // no warning, this is an idiom for "true" in old C style.
+ return x && (signed char)1;
+
+ return x || 0;
+ return x || 1;
+ return x || -1; // expected-warning {{use of logical '||' with constant operand}} \
+ // expected-note {{use '|' for a bitwise operation}}
+ return x || 5; // expected-warning {{use of logical '||' with constant operand}} \
+ // expected-note {{use '|' for a bitwise operation}}
+ return x && 0;
+ return x && 1;
+ return x && -1; // expected-warning {{use of logical '&&' with constant operand}} \
+ // expected-note {{use '&' for a bitwise operation}} \
+ // expected-note {{remove constant to silence this warning}}
+ return x && 5; // expected-warning {{use of logical '&&' with constant operand}} \
+ // expected-note {{use '&' for a bitwise operation}} \
+ // expected-note {{remove constant to silence this warning}}
+ return x || (0);
+ return x || (1);
+ return x || (-1); // expected-warning {{use of logical '||' with constant operand}} \
+ // expected-note {{use '|' for a bitwise operation}}
+ return x || (5); // expected-warning {{use of logical '||' with constant operand}} \
+ // expected-note {{use '|' for a bitwise operation}}
+ return x && (0);
+ return x && (1);
+ return x && (-1); // expected-warning {{use of logical '&&' with constant operand}} \
+ // expected-note {{use '&' for a bitwise operation}} \
+ // expected-note {{remove constant to silence this warning}}
+ return x && (5); // expected-warning {{use of logical '&&' with constant operand}} \
+ // expected-note {{use '&' for a bitwise operation}} \
+ // expected-note {{remove constant to silence this warning}}
+
+}
+
+struct Test21; // expected-note 2 {{forward declaration}}
+void test21(volatile struct Test21 *ptr) {
+ void test21_help(void);
+ (test21_help(), *ptr); // expected-error {{incomplete type 'struct Test21' where a complete type is required}}
+ (*ptr, test21_help()); // expected-error {{incomplete type 'struct Test21' where a complete type is required}}
+}
+
+// Make sure we do function/array decay.
+void test22() {
+ if ("help")
+ (void) 0;
+
+ if (test22)
+ (void) 0;
+}
diff --git a/clang/test/Sema/ext_vector_casts.c b/clang/test/Sema/ext_vector_casts.c
new file mode 100644
index 0000000..848ec1f
--- /dev/null
+++ b/clang/test/Sema/ext_vector_casts.c
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fno-lax-vector-conversions %s
+
+typedef __attribute__(( ext_vector_type(2) )) float float2;
+typedef __attribute__(( ext_vector_type(4) )) int int4;
+typedef __attribute__(( ext_vector_type(8) )) short short8;
+typedef __attribute__(( ext_vector_type(4) )) float float4;
+typedef float t3 __attribute__ ((vector_size (16)));
+
+static void test() {
+ float2 vec2;
+ float4 vec4, vec4_2;
+ int4 ivec4;
+ short8 ish8;
+ t3 vec4_3;
+ int *ptr;
+ int i;
+
+ vec4 = 5.0f;
+ vec4 = (float4)5.0f;
+ vec4 = (float4)5;
+ vec4 = (float4)vec4_3;
+
+ ivec4 = (int4)5.0f;
+ ivec4 = (int4)5;
+ ivec4 = (int4)vec4_3;
+
+ i = (int)ivec4; // expected-error {{invalid conversion between vector type 'int4' and integer type 'int' of different size}}
+ i = ivec4; // expected-error {{assigning to 'int' from incompatible type 'int4'}}
+
+ ivec4 = (int4)ptr; // expected-error {{invalid conversion between vector type 'int4' and scalar type 'int *'}}
+
+ vec4 = (float4)vec2; // expected-error {{invalid conversion between ext-vector type 'float4' and 'float2'}}
+
+ ish8 += 5; // expected-error {{can't convert between vector values of different size ('short8' and 'int')}}
+ ish8 += (short)5;
+ ivec4 *= 5;
+ vec4 /= 5.2f;
+ vec4 %= 4; // expected-error {{invalid operands to binary expression ('float4' and 'int')}}
+ ivec4 %= 4;
+ ivec4 += vec4; // expected-error {{can't convert between vector values of different size ('int4' and 'float4')}}
+ ivec4 += (int4)vec4;
+ ivec4 -= ivec4;
+ ivec4 |= ivec4;
+ ivec4 += ptr; // expected-error {{can't convert between vector values of different size ('int4' and 'int *')}}
+}
+
+typedef __attribute__(( ext_vector_type(2) )) float2 vecfloat2; // expected-error{{invalid vector element type 'float2'}}
+
+void inc(float2 f2) {
+ f2++; // expected-error{{cannot increment value of type 'float2'}}
+ __real f2; // expected-error{{invalid type 'float2' to __real operator}}
+}
diff --git a/clang/test/Sema/ext_vector_comparisons.c b/clang/test/Sema/ext_vector_comparisons.c
new file mode 100644
index 0000000..605ba6c
--- /dev/null
+++ b/clang/test/Sema/ext_vector_comparisons.c
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unreachable-code %s
+
+typedef __attribute__(( ext_vector_type(4) )) int int4;
+
+static int4 test1() {
+ int4 vec, rv;
+
+ // comparisons to self...
+ return vec == vec; // expected-warning{{self-comparison always evaluates to a constant}}
+ return vec != vec; // expected-warning{{self-comparison always evaluates to a constant}}
+ return vec < vec; // expected-warning{{self-comparison always evaluates to a constant}}
+ return vec <= vec; // expected-warning{{self-comparison always evaluates to a constant}}
+ return vec > vec; // expected-warning{{self-comparison always evaluates to a constant}}
+ return vec >= vec; // expected-warning{{self-comparison always evaluates to a constant}}
+}
+
+
+typedef __attribute__(( ext_vector_type(4) )) float float4;
+
+static int4 test2() {
+ float4 vec, rv;
+
+ // comparisons to self. no warning, they're floats
+ return vec == vec; // no-warning
+ return vec != vec; // no-warning
+ return vec < vec; // no-warning
+ return vec <= vec; // no-warning
+ return vec > vec; // no-warning
+ return vec >= vec; // no-warning
+}
diff --git a/clang/test/Sema/ext_vector_components.c b/clang/test/Sema/ext_vector_components.c
new file mode 100644
index 0000000..7d3d52a
--- /dev/null
+++ b/clang/test/Sema/ext_vector_components.c
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+typedef __attribute__(( ext_vector_type(2) )) float float2;
+typedef __attribute__(( ext_vector_type(3) )) float float3;
+typedef __attribute__(( ext_vector_type(4) )) float float4;
+typedef __attribute__(( ext_vector_type(16) )) float float16;
+
+static float4 vec4_0 = (float4)0.5f;
+
+static void test() {
+ float2 vec2, vec2_2;
+ float3 vec3;
+ float4 vec4, vec4_2, *vec4p;
+ float16 vec16;
+ float f;
+
+ vec2.z; // expected-error {{vector component access exceeds type 'float2'}}
+ vec2.xyzw; // expected-error {{vector component access exceeds type 'float2'}}
+ vec4.xyzw; // expected-warning {{expression result unused}}
+ vec4.xyzc; // expected-error {{illegal vector component name 'c'}}
+ vec4.s01z; // expected-error {{illegal vector component name 'z'}}
+ vec2 = vec4.s01; // legal, shorten
+ vec2 = vec4.S01; // legal, shorten
+
+ vec3 = vec4.xyz; // legal, shorten
+ f = vec2.x; // legal, shorten
+ f = vec4.xy.x; // legal, shorten
+
+ vec4_2.xyzx = vec4.xyzw; // expected-error {{vector is not assignable (contains duplicate components)}}
+ vec4_2.xyzz = vec4.xyzw; // expected-error {{vector is not assignable (contains duplicate components)}}
+ vec4_2.xyyw = vec4.xyzw; // expected-error {{vector is not assignable (contains duplicate components)}}
+ vec2.x = f;
+ vec2.xx = vec2_2.xy; // expected-error {{vector is not assignable (contains duplicate components)}}
+ vec2.yx = vec2_2.xy;
+ vec4 = (float4){ 1,2,3,4 };
+ vec4.xy.w; // expected-error {{vector component access exceeds type 'float2'}}
+ vec4.s06; // expected-error {{vector component access exceeds type 'float4'}}
+ vec4.x = vec16.sf;
+ vec4.x = vec16.sF;
+
+ vec4p->yz = vec4p->xy;
+}
+
+float2 lo(float3 x) { return x.lo; }
+float2 hi(float3 x) { return x.hi; }
+float2 ev(float3 x) { return x.even; }
+float2 od(float3 x) { return x.odd; }
diff --git a/clang/test/Sema/extern-redecl.c b/clang/test/Sema/extern-redecl.c
new file mode 100644
index 0000000..c176725
--- /dev/null
+++ b/clang/test/Sema/extern-redecl.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// rdar: // 8125274
+static int a16[]; // expected-warning {{tentative array definition assumed to have one element}}
+
+void f16(void) {
+ extern int a16[];
+}
+
+
+// PR10013: Scope of extern declarations extend past enclosing block
+extern int PR10013_x;
+int PR10013(void) {
+ int *PR10013_x = 0;
+ {
+ extern int PR10013_x;
+ extern int PR10013_x;
+ }
+
+ return PR10013_x; // expected-warning{{incompatible pointer to integer conversion}}
+}
+
diff --git a/clang/test/Sema/flexible-array-init.c b/clang/test/Sema/flexible-array-init.c
new file mode 100644
index 0000000..78fc7c5
--- /dev/null
+++ b/clang/test/Sema/flexible-array-init.c
@@ -0,0 +1,91 @@
+// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
+struct one {
+ int a;
+ int values[]; // expected-note 4{{initialized flexible array member 'values' is here}}
+} x = {5, {1, 2, 3}}; // expected-warning{{flexible array initialization is a GNU extension}}
+
+struct one x2 = { 5, 1, 2, 3 }; // expected-warning{{flexible array initialization is a GNU extension}}
+
+void test() {
+ struct one x3 = {5, {1, 2, 3}}; // expected-error{{initialization of flexible array member is not allowed}}
+ struct one x3a = { 5 };
+ struct one x3b = { .a = 5 };
+ struct one x3c = { 5, {} }; // expected-warning{{use of GNU empty initializer extension}} \
+ // expected-warning{{flexible array initialization is a GNU extension}} \
+ // expected-warning{{zero size arrays are an extension}}
+}
+
+struct foo {
+ int x;
+ int y[]; // expected-note 8 {{initialized flexible array member 'y' is here}}
+};
+struct bar { struct foo z; }; // expected-warning {{'z' may not be nested in a struct due to flexible array member}}
+
+struct foo a = { 1, { 2, 3, 4 } }; // expected-warning{{flexible array initialization is a GNU extension}}
+struct bar b = { { 1, { 2, 3, 4 } } }; // expected-error{{initialization of flexible array member is not allowed}}
+struct bar c = { { 1, { } } }; // // expected-warning{{flexible array initialization is a GNU extension}} \
+ // expected-warning{{use of GNU empty initializer extension}} \
+ // expected-warning{{zero size arrays are an extension}}
+struct foo d[1] = { { 1, { 2, 3, 4 } } }; // expected-warning{{'struct foo' may not be used as an array element due to flexible array member}} \
+ // expected-error{{initialization of flexible array member is not allowed}}
+
+struct foo desig_foo = { .y = {2, 3, 4} }; // expected-warning{{flexible array initialization is a GNU extension}}
+struct bar desig_bar = { .z.y = { } }; // expected-warning{{use of GNU empty initializer extension}} \
+ // expected-warning{{zero size arrays are an extension}} \
+ // expected-warning{{flexible array initialization is a GNU extension}}
+struct bar desig_bar2 = { .z.y = { 2, 3, 4} }; // expected-error{{initialization of flexible array member is not allowed}}
+struct foo design_foo2 = { .y = 2 }; // expected-error{{flexible array requires brace-enclosed initializer}}
+
+struct point {
+ int x, y;
+};
+
+struct polygon {
+ int numpoints;
+ struct point points[]; // expected-note{{initialized flexible array member 'points' is here}}
+};
+struct polygon poly = {
+ .points[2] = { 1, 2} }; // expected-error{{designator into flexible array member subobject}}
+
+// PR3540
+struct X {
+ int a;
+ int b;
+ char data[];
+};
+
+struct Y {
+ int a:4;
+ int b:4;
+ int c;
+ int d;
+ int e;
+ struct X xs[]; // expected-warning{{'struct X' may not be used as an array element due to flexible array member}}
+};
+
+
+// PR8217
+struct PR8217a {
+ int i;
+ char v[]; // expected-note 2 {{initialized flexible array member 'v' is here}}
+};
+
+void PR8217() {
+ struct PR8217a foo1 = { .i = 0, .v = "foo" }; // expected-error {{initialization of flexible array member is not allowed}}
+ struct PR8217a foo2 = { .i = 0 };
+ struct PR8217a foo3 = { .i = 0, .v = { 'b', 'a', 'r', '\0' } }; // expected-error {{initialization of flexible array member is not allowed}}
+ struct PR8217a bar;
+}
+
+typedef struct PR10648 {
+ unsigned long n;
+ int v[]; // expected-note {{initialized flexible array member 'v' is here}}
+} PR10648;
+int f10648() {
+ return (PR10648){2, {3, 4}}.v[1]; // expected-error {{initialization of flexible array member is not allowed}}
+}
+
+struct FlexWithUnnamedBitfield { int : 10; int x; int y[]; }; // expected-note {{initialized flexible array member 'y' is here}}
+void TestFlexWithUnnamedBitfield() {
+ struct FlexWithUnnamedBitfield x = {10, {3}}; // expected-error {{initialization of flexible array member is not allowed}}
+}
diff --git a/clang/test/Sema/floating-point-compare.c b/clang/test/Sema/floating-point-compare.c
new file mode 100644
index 0000000..60f971c
--- /dev/null
+++ b/clang/test/Sema/floating-point-compare.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -Wfloat-equal -verify %s
+
+int f1(float x, float y) {
+ return x == y; // expected-warning {{comparing floating point with ==}}
+}
+
+int f2(float x, float y) {
+ return x != y; // expected-warning {{comparing floating point with ==}}
+}
+
+int f3(float x) {
+ return x == x; // no-warning
+}
+
+int f4(float x) {
+ return x == 0.0; // no-warning {{comparing}}
+}
+
+int f5(float x) {
+ return x == __builtin_inf(); // no-warning
+}
+
+int f7(float x) {
+ return x == 3.14159; // expected-warning {{comparing}}
+}
diff --git a/clang/test/Sema/fn-ptr-as-fn-prototype.c b/clang/test/Sema/fn-ptr-as-fn-prototype.c
new file mode 100644
index 0000000..cf95c97
--- /dev/null
+++ b/clang/test/Sema/fn-ptr-as-fn-prototype.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1_only -ast-print %s | FileCheck %s
+
+// This testcase checks the functionality of
+// Sema::ActOn{Start,End}FunctionDeclarator, specifically checking that
+// ActOnEndFunctionDeclarator is called after the typedef so the enum
+// is in the global scope, not the scope of f().
+
+// CHECK: typedef void (*g)();
+typedef void (*g) ();
+// CHECK: enum {
+enum {
+ k = -1
+};
+// CHECK: void f() {
+void f() {}
diff --git a/clang/test/Sema/for.c b/clang/test/Sema/for.c
new file mode 100644
index 0000000..b998f4b
--- /dev/null
+++ b/clang/test/Sema/for.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// Check C99 6.8.5p3
+void b1 (void) { for (void (*f) (void);;); }
+void b2 (void) { for (void f (void);;); } // expected-error {{declaration of non-local variable}}
+void b3 (void) { for (static int f;;); } // expected-error {{declaration of non-local variable}}
+void b4 (void) { for (typedef int f;;); } // expected-error {{declaration of non-local variable}}
diff --git a/clang/test/Sema/format-string-percentm.c b/clang/test/Sema/format-string-percentm.c
new file mode 100644
index 0000000..1ffc439
--- /dev/null
+++ b/clang/test/Sema/format-string-percentm.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple i686-pc-linux-gnu
+
+// PR 4142 - support glibc extension to printf: '%m' (which prints strerror(errno)).
+int printf(char const*,...);
+void percentm(void) {
+ printf("%m");
+}
diff --git a/clang/test/Sema/format-strings-c90.c b/clang/test/Sema/format-strings-c90.c
new file mode 100644
index 0000000..66ca507
--- /dev/null
+++ b/clang/test/Sema/format-strings-c90.c
@@ -0,0 +1,30 @@
+/* RUN: %clang_cc1 -fsyntax-only -verify -triple i386-apple-darwin9 -pedantic -std=c89 %s
+ */
+
+int scanf(const char * restrict, ...);
+int printf(const char *restrict, ...);
+
+void foo(char **sp, float *fp, int *ip) {
+ scanf("%as", sp); /* expected-warning{{'a' length modifier is not supported by ISO C}} */
+ scanf("%a[abc]", sp); /* expected-warning{{'a' length modifier is not supported by ISO C}} */
+
+ /* TODO: Warn that the 'a' conversion specifier is a C99 feature. */
+ scanf("%a", fp);
+ scanf("%afoobar", fp);
+ printf("%a", 1.0);
+ printf("%as", 1.0);
+ printf("%aS", 1.0);
+ printf("%a[", 1.0);
+ printf("%afoo", 1.0);
+
+ scanf("%da", ip);
+
+ /* Test argument type check for the 'a' length modifier. */
+ scanf("%as", fp); /* expected-warning{{format specifies type 'char **' but the argument has type 'float *'}}
+ expected-warning{{'a' length modifier is not supported by ISO C}} */
+ scanf("%aS", fp); /* expected-warning{{format specifies type 'wchar_t **' (aka 'int **') but the argument has type 'float *'}}
+ expected-warning{{'a' length modifier is not supported by ISO C}}
+ expected-warning{{'S' conversion specifier is not supported by ISO C}} */
+ scanf("%a[abc]", fp); /* expected-warning{{format specifies type 'char **' but the argument has type 'float *'}}
+ expected-warning{{'a' length modifier is not supported by ISO C}} */
+}
diff --git a/clang/test/Sema/format-strings-fixit-ssize_t.c b/clang/test/Sema/format-strings-fixit-ssize_t.c
new file mode 100644
index 0000000..5208a29
--- /dev/null
+++ b/clang/test/Sema/format-strings-fixit-ssize_t.c
@@ -0,0 +1,18 @@
+// RUN: cp %s %t
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -pedantic -Wall -fixit %t
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -pedantic -Wall -Werror %t
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -E -o - %t | FileCheck %s
+
+/* This is a test of the various code modification hints that are
+ provided as part of warning or extension diagnostics. All of the
+ warnings will be fixed by -fixit, and the resulting file should
+ compile cleanly with -Werror -pedantic. */
+
+int printf(char const *, ...);
+
+void test() {
+ typedef signed long int ssize_t;
+ printf("%f", (ssize_t) 42);
+}
+
+// CHECK: printf("%zd", (ssize_t) 42);
diff --git a/clang/test/Sema/format-strings-fixit.c b/clang/test/Sema/format-strings-fixit.c
new file mode 100644
index 0000000..800691e
--- /dev/null
+++ b/clang/test/Sema/format-strings-fixit.c
@@ -0,0 +1,208 @@
+// RUN: cp %s %t
+// RUN: %clang_cc1 -pedantic -Wall -fixit %t
+// RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror %t
+// RUN: %clang_cc1 -E -o - %t | FileCheck %s
+
+/* This is a test of the various code modification hints that are
+ provided as part of warning or extension diagnostics. All of the
+ warnings will be fixed by -fixit, and the resulting file should
+ compile cleanly with -Werror -pedantic. */
+
+int printf(char const *, ...);
+
+typedef __SIZE_TYPE__ size_t;
+typedef __INTMAX_TYPE__ intmax_t;
+typedef __UINTMAX_TYPE__ uintmax_t;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+
+void test() {
+ // Basic types
+ printf("%s", (int) 123);
+ printf("abc%0f", "testing testing 123");
+ printf("%u", (long) -12);
+ printf("%p", 123);
+ printf("%c\n", "x");
+ printf("%c\n", 1.23);
+
+ // Larger types
+ printf("%+.2d", (unsigned long long) 123456);
+ printf("%1d", (long double) 1.23);
+
+ // Flag handling
+ printf("%0+s", (unsigned) 31337); // 0 flag should stay
+ printf("%#p", (void *) 0);
+ printf("% +f", 1.23); // + flag should stay
+ printf("%0-f", 1.23); // - flag should stay
+
+ // Positional arguments
+#pragma clang diagnostic push // Don't warn about using positional arguments.
+#pragma clang diagnostic ignored "-Wformat-non-iso"
+ printf("%1$f:%2$.*3$f:%4$.*3$f\n", 1, 2, 3, 4);
+#pragma clang diagnostic pop
+
+ // Precision
+ printf("%10.5d", 1l); // (bug 7394)
+ printf("%.2c", 'a');
+
+ // Ignored flags
+ printf("%0-f", 1.23);
+
+ // Bad length modifiers
+ printf("%hhs", "foo");
+#pragma clang diagnostic push // Don't warn about using positional arguments.
+#pragma clang diagnostic ignored "-Wformat-non-iso"
+ printf("%1$zp", (void *)0);
+#pragma clang diagnostic pop
+
+ // Preserve the original formatting for unsigned integers.
+ unsigned long val = 42;
+ printf("%X", val);
+
+ // size_t, etc.
+ printf("%f", (size_t) 42);
+ printf("%f", (intmax_t) 42);
+ printf("%f", (uintmax_t) 42);
+ printf("%f", (ptrdiff_t) 42);
+
+ // string
+ printf("%ld", "foo");
+
+ // Preserve the original choice of conversion specifier.
+ printf("%o", (long) 42);
+ printf("%u", (long) 42);
+ printf("%x", (long) 42);
+ printf("%X", (long) 42);
+ printf("%i", (unsigned long) 42);
+ printf("%d", (unsigned long) 42);
+ printf("%F", (long double) 42);
+ printf("%e", (long double) 42);
+ printf("%E", (long double) 42);
+ printf("%g", (long double) 42);
+ printf("%G", (long double) 42);
+ printf("%a", (long double) 42);
+ printf("%A", (long double) 42);
+}
+
+int scanf(char const *, ...);
+
+void test2() {
+ char str[100];
+ short shortVar;
+ unsigned short uShortVar;
+ int intVar;
+ unsigned uIntVar;
+ float floatVar;
+ double doubleVar;
+ long double longDoubleVar;
+ long longVar;
+ unsigned long uLongVar;
+ long long longLongVar;
+ unsigned long long uLongLongVar;
+ size_t sizeVar;
+ intmax_t intmaxVar;
+ uintmax_t uIntmaxVar;
+ ptrdiff_t ptrdiffVar;
+
+ scanf("%lf", str);
+ scanf("%f", &shortVar);
+ scanf("%f", &uShortVar);
+ scanf("%p", &intVar);
+ scanf("%Lf", &uIntVar);
+ scanf("%ld", &floatVar);
+ scanf("%f", &doubleVar);
+ scanf("%d", &longDoubleVar);
+ scanf("%f", &longVar);
+ scanf("%f", &uLongVar);
+ scanf("%f", &longLongVar);
+ scanf("%f", &uLongLongVar);
+
+ // Some named ints.
+ scanf("%f", &sizeVar);
+ scanf("%f", &intmaxVar);
+ scanf("%f", &uIntmaxVar);
+ scanf("%f", &ptrdiffVar);
+
+ // Preserve the original formatting.
+ scanf("%o", &longVar);
+ scanf("%u", &longVar);
+ scanf("%x", &longVar);
+ scanf("%X", &longVar);
+ scanf("%i", &uLongVar);
+ scanf("%d", &uLongVar);
+ scanf("%F", &longDoubleVar);
+ scanf("%e", &longDoubleVar);
+ scanf("%E", &longDoubleVar);
+ scanf("%g", &longDoubleVar);
+ scanf("%G", &longDoubleVar);
+ scanf("%a", &longDoubleVar);
+ scanf("%A", &longDoubleVar);
+}
+
+// Validate the fixes.
+// CHECK: printf("%d", (int) 123);
+// CHECK: printf("abc%s", "testing testing 123");
+// CHECK: printf("%lu", (long) -12);
+// CHECK: printf("%d", 123);
+// CHECK: printf("%s\n", "x");
+// CHECK: printf("%f\n", 1.23);
+// CHECK: printf("%+.2lld", (unsigned long long) 123456);
+// CHECK: printf("%1Lf", (long double) 1.23);
+// CHECK: printf("%0u", (unsigned) 31337);
+// CHECK: printf("%p", (void *) 0);
+// CHECK: printf("%+f", 1.23);
+// CHECK: printf("%-f", 1.23);
+// CHECK: printf("%1$d:%2$.*3$d:%4$.*3$d\n", 1, 2, 3, 4);
+// CHECK: printf("%10.5ld", 1l);
+// CHECK: printf("%c", 'a');
+// CHECK: printf("%-f", 1.23);
+// CHECK: printf("%s", "foo");
+// CHECK: printf("%1$p", (void *)0);
+// CHECK: printf("%lX", val);
+// CHECK: printf("%zu", (size_t) 42);
+// CHECK: printf("%jd", (intmax_t) 42);
+// CHECK: printf("%ju", (uintmax_t) 42);
+// CHECK: printf("%td", (ptrdiff_t) 42);
+// CHECK: printf("%s", "foo");
+// CHECK: printf("%lo", (long) 42);
+// CHECK: printf("%lu", (long) 42);
+// CHECK: printf("%lx", (long) 42);
+// CHECK: printf("%lX", (long) 42);
+// CHECK: printf("%li", (unsigned long) 42);
+// CHECK: printf("%ld", (unsigned long) 42);
+// CHECK: printf("%LF", (long double) 42);
+// CHECK: printf("%Le", (long double) 42);
+// CHECK: printf("%LE", (long double) 42);
+// CHECK: printf("%Lg", (long double) 42);
+// CHECK: printf("%LG", (long double) 42);
+// CHECK: printf("%La", (long double) 42);
+// CHECK: printf("%LA", (long double) 42);
+
+// CHECK: scanf("%s", str);
+// CHECK: scanf("%hd", &shortVar);
+// CHECK: scanf("%hu", &uShortVar);
+// CHECK: scanf("%d", &intVar);
+// CHECK: scanf("%u", &uIntVar);
+// CHECK: scanf("%f", &floatVar);
+// CHECK: scanf("%lf", &doubleVar);
+// CHECK: scanf("%Lf", &longDoubleVar);
+// CHECK: scanf("%ld", &longVar);
+// CHECK: scanf("%lu", &uLongVar);
+// CHECK: scanf("%lld", &longLongVar);
+// CHECK: scanf("%llu", &uLongLongVar);
+// CHECK: scanf("%zu", &sizeVar);
+// CHECK: scanf("%jd", &intmaxVar);
+// CHECK: scanf("%ju", &uIntmaxVar);
+// CHECK: scanf("%td", &ptrdiffVar);
+// CHECK: scanf("%lo", &longVar);
+// CHECK: scanf("%lu", &longVar);
+// CHECK: scanf("%lx", &longVar);
+// CHECK: scanf("%lX", &longVar);
+// CHECK: scanf("%li", &uLongVar);
+// CHECK: scanf("%ld", &uLongVar);
+// CHECK: scanf("%LF", &longDoubleVar);
+// CHECK: scanf("%Le", &longDoubleVar);
+// CHECK: scanf("%LE", &longDoubleVar);
+// CHECK: scanf("%Lg", &longDoubleVar);
+// CHECK: scanf("%LG", &longDoubleVar);
+// CHECK: scanf("%La", &longDoubleVar);
+// CHECK: scanf("%LA", &longDoubleVar);
diff --git a/clang/test/Sema/format-strings-int-typedefs.c b/clang/test/Sema/format-strings-int-typedefs.c
new file mode 100644
index 0000000..341d49c
--- /dev/null
+++ b/clang/test/Sema/format-strings-int-typedefs.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s
+
+int printf(char const *, ...);
+int scanf(char const *, ...);
+
+void test(void) {
+ printf("%jd", 42.0); // expected-warning {{format specifies type 'intmax_t' (aka 'long long')}}
+ printf("%ju", 42.0); // expected-warning {{format specifies type 'uintmax_t' (aka 'unsigned long long')}}
+ printf("%zu", 42.0); // expected-warning {{format specifies type 'size_t' (aka 'unsigned long')}}
+ printf("%td", 42.0); // expected-warning {{format specifies type 'ptrdiff_t' (aka 'int')}}
+ printf("%lc", 42.0); // expected-warning {{format specifies type 'wint_t' (aka 'int')}}
+ printf("%ls", 42.0); // expected-warning {{format specifies type 'wchar_t *' (aka 'int *')}}
+ printf("%S", 42.0); // expected-warning {{format specifies type 'wchar_t *' (aka 'int *')}}
+ printf("%C", 42.0); // expected-warning {{format specifies type 'wchar_t' (aka 'int')}}
+
+ scanf("%jd", 0); // expected-warning {{format specifies type 'intmax_t *' (aka 'long long *')}}
+ scanf("%ju", 0); // expected-warning {{format specifies type 'uintmax_t *' (aka 'unsigned long long *')}}
+ scanf("%zu", 0); // expected-warning {{format specifies type 'size_t *' (aka 'unsigned long *')}}
+ scanf("%td", 0); // expected-warning {{format specifies type 'ptrdiff_t *' (aka 'int *')}}
+ scanf("%lc", 0); // expected-warning {{format specifies type 'wchar_t *' (aka 'int *')}}
+ scanf("%ls", 0); // expected-warning {{format specifies type 'wchar_t *' (aka 'int *')}}
+ scanf("%S", 0); // expected-warning {{format specifies type 'wchar_t *' (aka 'int *')}}
+ scanf("%C", 0); // expected-warning {{format specifies type 'wchar_t *' (aka 'int *')}}
+
+
+ // typedef size_t et al. to something crazy.
+ typedef void *size_t;
+ typedef void *intmax_t;
+ typedef void *uintmax_t;
+ typedef void *ptrdiff_t;
+
+ // The warning still fires, because it checks the underlying type.
+ printf("%jd", (intmax_t)42); // expected-warning {{format specifies type 'intmax_t' (aka 'long long') but the argument has type 'intmax_t' (aka 'void *')}}
+ printf("%ju", (uintmax_t)42); // expected-warning {{format specifies type 'uintmax_t' (aka 'unsigned long long') but the argument has type 'uintmax_t' (aka 'void *')}}
+ printf("%zu", (size_t)42); // expected-warning {{format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'size_t' (aka 'void *')}}
+ printf("%td", (ptrdiff_t)42); // expected-warning {{format specifies type 'ptrdiff_t' (aka 'int') but the argument has type 'ptrdiff_t' (aka 'void *')}}
+}
diff --git a/clang/test/Sema/format-strings-no-fixit.c b/clang/test/Sema/format-strings-no-fixit.c
new file mode 100644
index 0000000..701e945
--- /dev/null
+++ b/clang/test/Sema/format-strings-no-fixit.c
@@ -0,0 +1,65 @@
+// RUN: cp %s %t
+// RUN: %clang_cc1 -fsyntax-only -fixit %t
+// RUN: %clang_cc1 -E -o - %t | FileCheck %s
+
+/* This is a test of the various code modification hints that are
+ provided as part of warning or extension diagnostics. Only
+ warnings for format strings within the function call will be
+ fixed by -fixit. Other format strings will be left alone. */
+
+int printf(char const *, ...);
+int scanf(char const *, ...);
+
+void pr9751() {
+ const char kFormat1[] = "%s";
+ printf(kFormat1, 5);
+ printf("%s", 5);
+
+ const char kFormat2[] = "%.3p";
+ void *p;
+ printf(kFormat2, p);
+ printf("%.3p", p);
+
+ const char kFormat3[] = "%0s";
+ printf(kFormat3, "a");
+ printf("%0s", "a");
+
+ const char kFormat4[] = "%hhs";
+ printf(kFormat4, "a");
+ printf("%hhs", "a");
+
+ const char kFormat5[] = "%-0d";
+ printf(kFormat5, 5);
+ printf("%-0d", 5);
+
+ const char kFormat6[] = "%00d";
+ int *i;
+ scanf(kFormat6, i);
+ scanf("%00d", i);
+}
+
+// CHECK: const char kFormat1[] = "%s";
+// CHECK: printf(kFormat1, 5);
+// CHECK: printf("%d", 5);
+
+// CHECK: const char kFormat2[] = "%.3p";
+// CHECK: void *p;
+// CHECK: printf(kFormat2, p);
+// CHECK: printf("%p", p);
+
+// CHECK: const char kFormat3[] = "%0s";
+// CHECK: printf(kFormat3, "a");
+// CHECK: printf("%s", "a");
+
+// CHECK: const char kFormat4[] = "%hhs";
+// CHECK: printf(kFormat4, "a");
+// CHECK: printf("%s", "a");
+
+// CHECK: const char kFormat5[] = "%-0d";
+// CHECK: printf(kFormat5, 5);
+// CHECK: printf("%-d", 5);
+
+// CHECK: const char kFormat6[] = "%00d";
+// CHECK: int *i;
+// CHECK: scanf(kFormat6, i);
+// CHECK: scanf("%d", i);
diff --git a/clang/test/Sema/format-strings-non-iso.c b/clang/test/Sema/format-strings-non-iso.c
new file mode 100644
index 0000000..ed8095f
--- /dev/null
+++ b/clang/test/Sema/format-strings-non-iso.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -pedantic %s
+
+int printf(const char *restrict, ...);
+int scanf(const char * restrict, ...);
+
+void f(void) {
+ char *cp;
+
+ // The 'q' length modifier.
+ printf("%qd", (long long)42); // expected-warning{{'q' length modifier is not supported by ISO C}}
+ scanf("%qd", (long long *)0); // expected-warning{{'q' length modifier is not supported by ISO C}}
+
+ // The 'm' length modifier.
+ scanf("%ms", &cp); // expected-warning{{'m' length modifier is not supported by ISO C}}
+
+ // The 'S' and 'C' conversion specifiers.
+ printf("%S", L"foo"); // expected-warning{{'S' conversion specifier is not supported by ISO C}}
+ printf("%C", L'x'); // expected-warning{{'C' conversion specifier is not supported by ISO C}}
+
+ // Combining 'L' with an integer conversion specifier.
+ printf("%Li", (long long)42); // expected-warning{{using length modifier 'L' with conversion specifier 'i' is not supported by ISO C}}
+ printf("%Lo", (long long)42); // expected-warning{{using length modifier 'L' with conversion specifier 'o' is not supported by ISO C}}
+ printf("%Lu", (long long)42); // expected-warning{{using length modifier 'L' with conversion specifier 'u' is not supported by ISO C}}
+ printf("%Lx", (long long)42); // expected-warning{{using length modifier 'L' with conversion specifier 'x' is not supported by ISO C}}
+ printf("%LX", (long long)42); // expected-warning{{using length modifier 'L' with conversion specifier 'X' is not supported by ISO C}}
+
+ // Positional arguments.
+ printf("%1$d", 42); // expected-warning{{positional arguments are not supported by ISO C}}
+}
diff --git a/clang/test/Sema/format-strings-scanf.c b/clang/test/Sema/format-strings-scanf.c
new file mode 100644
index 0000000..e94af5a
--- /dev/null
+++ b/clang/test/Sema/format-strings-scanf.c
@@ -0,0 +1,123 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -triple i386-apple-darwin9 -Wformat-nonliteral %s
+
+// Test that -Wformat=0 works:
+// RUN: %clang_cc1 -fsyntax-only -Werror -Wformat=0 %s
+
+#include <stdarg.h>
+typedef __typeof(sizeof(int)) size_t;
+typedef struct _FILE FILE;
+typedef __WCHAR_TYPE__ wchar_t;
+
+int fscanf(FILE * restrict, const char * restrict, ...) ;
+int scanf(const char * restrict, ...) ;
+int sscanf(const char * restrict, const char * restrict, ...) ;
+int my_scanf(const char * restrict, ...) __attribute__((__format__(__scanf__, 1, 2)));
+
+int vscanf(const char * restrict, va_list);
+int vfscanf(FILE * restrict, const char * restrict, va_list);
+int vsscanf(const char * restrict, const char * restrict, va_list);
+
+void test(const char *s, int *i) {
+ scanf(s, i); // expected-warning{{ormat string is not a string literal}}
+ scanf("%0d", i); // expected-warning{{zero field width in scanf format string is unused}}
+ scanf("%00d", i); // expected-warning{{zero field width in scanf format string is unused}}
+ scanf("%d%[asdfasdfd", i, s); // expected-warning{{no closing ']' for '%[' in scanf format string}}
+
+ unsigned short s_x;
+ scanf ("%" "hu" "\n", &s_x); // no-warning
+ scanf("%y", i); // expected-warning{{invalid conversion specifier 'y'}}
+ scanf("%%"); // no-warning
+ scanf("%%%1$d", i); // no-warning
+ scanf("%1$d%%", i); // no-warning
+ scanf("%d", i, i); // expected-warning{{data argument not used by format string}}
+ scanf("%*d", i); // // expected-warning{{data argument not used by format string}}
+ scanf("%*d", i); // // expected-warning{{data argument not used by format string}}
+ scanf("%*d%1$d", i); // no-warning
+}
+
+void bad_length_modifiers(char *s, void *p, wchar_t *ws, long double *ld) {
+ scanf("%hhs", "foo"); // expected-warning{{length modifier 'hh' results in undefined behavior or no effect with 's' conversion specifier}}
+ scanf("%1$zp", &p); // expected-warning{{length modifier 'z' results in undefined behavior or no effect with 'p' conversion specifier}}
+ scanf("%ls", ws); // no-warning
+ scanf("%#.2Lf", ld); // expected-warning{{invalid conversion specifier '#'}}
+}
+
+// Test that the scanf call site is where the warning is attached. If the
+// format string is somewhere else, point to it in a note.
+void pr9751() {
+ int *i;
+ char str[100];
+ const char kFormat1[] = "%00d"; // expected-note{{format string is defined here}}}
+ scanf(kFormat1, i); // expected-warning{{zero field width in scanf format string is unused}}
+ scanf("%00d", i); // expected-warning{{zero field width in scanf format string is unused}}
+ const char kFormat2[] = "%["; // expected-note{{format string is defined here}}}
+ scanf(kFormat2, str); // expected-warning{{no closing ']' for '%[' in scanf format string}}
+ scanf("%[", str); // expected-warning{{no closing ']' for '%[' in scanf format string}}
+ const char kFormat3[] = "%hu"; // expected-note{{format string is defined here}}}
+ scanf(kFormat3, &i); // expected-warning {{format specifies type 'unsigned short *' but the argument}}
+ const char kFormat4[] = "%lp"; // expected-note{{format string is defined here}}}
+ scanf(kFormat4, &i); // expected-warning {{length modifier 'l' results in undefined behavior or no effect with 'p' conversion specifier}}
+}
+
+void test_variants(int *i, const char *s, ...) {
+ FILE *f = 0;
+ char buf[100];
+
+ fscanf(f, "%ld", i); // expected-warning{{format specifies type 'long *' but the argument has type 'int *'}}
+ sscanf(buf, "%ld", i); // expected-warning{{format specifies type 'long *' but the argument has type 'int *'}}
+ my_scanf("%ld", i); // expected-warning{{format specifies type 'long *' but the argument has type 'int *'}}
+
+ va_list ap;
+ va_start(ap, s);
+
+ vscanf("%[abc", ap); // expected-warning{{no closing ']' for '%[' in scanf format string}}
+ vfscanf(f, "%[abc", ap); // expected-warning{{no closing ']' for '%[' in scanf format string}}
+ vsscanf(buf, "%[abc", ap); // expected-warning{{no closing ']' for '%[' in scanf format string}}
+}
+
+void test_scanlist(int *ip, char *sp, wchar_t *ls) {
+ scanf("%[abc]", ip); // expected-warning{{format specifies type 'char *' but the argument has type 'int *'}}
+ scanf("%h[abc]", sp); // expected-warning{{length modifier 'h' results in undefined behavior or no effect with '[' conversion specifier}}
+ scanf("%l[xyx]", ls); // no-warning
+ scanf("%ll[xyx]", ls); // expected-warning {{length modifier 'll' results in undefined behavior or no effect with '[' conversion specifier}}
+}
+
+void test_alloc_extension(char **sp, wchar_t **lsp, float *fp) {
+ /* Make sure "%a" gets parsed as a conversion specifier for float,
+ * even when followed by an 's', 'S' or '[', which would cause it to be
+ * parsed as a length modifier in C90. */
+ scanf("%as", sp); // expected-warning{{format specifies type 'float *' but the argument has type 'char **'}}
+ scanf("%aS", lsp); // expected-warning{{format specifies type 'float *' but the argument has type 'wchar_t **'}}
+ scanf("%a[bcd]", sp); // expected-warning{{format specifies type 'float *' but the argument has type 'char **'}}
+
+ // Test that the 'm' length modifier is only allowed with s, S, c, C or [.
+ // TODO: Warn that 'm' is an extension.
+ scanf("%ms", sp); // No warning.
+ scanf("%mS", lsp); // No warning.
+ scanf("%mc", sp); // No warning.
+ scanf("%mC", lsp); // No warning.
+ scanf("%m[abc]", sp); // No warning.
+ scanf("%md", sp); // expected-warning{{length modifier 'm' results in undefined behavior or no effect with 'd' conversion specifier}}
+
+ // Test argument type check for the 'm' length modifier.
+ scanf("%ms", fp); // expected-warning{{format specifies type 'char **' but the argument has type 'float *'}}
+ scanf("%mS", fp); // expected-warning{{format specifies type 'wchar_t **' (aka 'int **') but the argument has type 'float *'}}
+ scanf("%mc", fp); // expected-warning{{format specifies type 'char **' but the argument has type 'float *'}}
+ scanf("%mC", fp); // expected-warning{{format specifies type 'wchar_t **' (aka 'int **') but the argument has type 'float *'}}
+ scanf("%m[abc]", fp); // expected-warning{{format specifies type 'char **' but the argument has type 'float *'}}
+}
+
+void test_longlong(long long *x, unsigned long long *y) {
+ scanf("%Ld", y); // no-warning
+ scanf("%Lu", y); // no-warning
+ scanf("%Lx", y); // no-warning
+ scanf("%Ld", x); // no-warning
+ scanf("%Lu", x); // no-warning
+ scanf("%Lx", x); // no-warning
+ scanf("%Ls", "hello"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}}
+}
+
+void test_quad(int *x, long long *llx) {
+ scanf("%qd", x); // expected-warning{{format specifies type 'long long *' but the argument has type 'int *'}}
+ scanf("%qd", llx); // no-warning
+}
diff --git a/clang/test/Sema/format-strings-size_t.c b/clang/test/Sema/format-strings-size_t.c
new file mode 100644
index 0000000..7f88ff3
--- /dev/null
+++ b/clang/test/Sema/format-strings-size_t.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
+
+int printf(char const *, ...);
+
+void test(void) {
+ // size_t
+ printf("%zu", (double)42); // expected-warning {{format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'double'}}
+
+ // intmax_t / uintmax_t
+ printf("%jd", (double)42); // expected-warning {{format specifies type 'intmax_t' (aka 'long') but the argument has type 'double'}}
+ printf("%ju", (double)42); // expected-warning {{format specifies type 'uintmax_t' (aka 'unsigned long') but the argument has type 'double'}}
+
+ // ptrdiff_t
+ printf("%td", (double)42); // expected-warning {{format specifies type 'ptrdiff_t' (aka 'long') but the argument has type 'double'}}
+}
diff --git a/clang/test/Sema/format-strings.c b/clang/test/Sema/format-strings.c
new file mode 100644
index 0000000..086c5c6
--- /dev/null
+++ b/clang/test/Sema/format-strings.c
@@ -0,0 +1,523 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral %s
+
+#include <stdarg.h>
+typedef __typeof(sizeof(int)) size_t;
+typedef struct _FILE FILE;
+int fprintf(FILE *, const char *restrict, ...);
+int printf(const char *restrict, ...); // expected-note{{passing argument to parameter here}}
+int snprintf(char *restrict, size_t, const char *restrict, ...);
+int sprintf(char *restrict, const char *restrict, ...);
+int vasprintf(char **, const char *, va_list);
+int asprintf(char **, const char *, ...);
+int vfprintf(FILE *, const char *restrict, va_list);
+int vprintf(const char *restrict, va_list);
+int vsnprintf(char *, size_t, const char *, va_list);
+int vsprintf(char *restrict, const char *restrict, va_list); // expected-note{{passing argument to parameter here}}
+
+int vscanf(const char *restrict format, va_list arg);
+
+char * global_fmt;
+
+void check_string_literal( FILE* fp, const char* s, char *buf, ... ) {
+
+ char * b;
+ va_list ap;
+ va_start(ap,buf);
+
+ printf(s); // expected-warning {{format string is not a string literal}}
+ vprintf(s,ap); // expected-warning {{format string is not a string literal}}
+ fprintf(fp,s); // expected-warning {{format string is not a string literal}}
+ vfprintf(fp,s,ap); // expected-warning {{format string is not a string literal}}
+ asprintf(&b,s); // expected-warning {{format string is not a string lit}}
+ vasprintf(&b,s,ap); // expected-warning {{format string is not a string literal}}
+ sprintf(buf,s); // expected-warning {{format string is not a string literal}}
+ snprintf(buf,2,s); // expected-warning {{format string is not a string lit}}
+ __builtin___sprintf_chk(buf,0,-1,s); // expected-warning {{format string is not a string literal}}
+ __builtin___snprintf_chk(buf,2,0,-1,s); // expected-warning {{format string is not a string lit}}
+ vsprintf(buf,s,ap); // expected-warning {{format string is not a string lit}}
+ vsnprintf(buf,2,s,ap); // expected-warning {{format string is not a string lit}}
+ vsnprintf(buf,2,global_fmt,ap); // expected-warning {{format string is not a string literal}}
+ __builtin___vsnprintf_chk(buf,2,0,-1,s,ap); // expected-warning {{format string is not a string lit}}
+ __builtin___vsnprintf_chk(buf,2,0,-1,global_fmt,ap); // expected-warning {{format string is not a string literal}}
+
+ vscanf(s, ap); // expected-warning {{format string is not a string literal}}
+
+ // rdar://6079877
+ printf("abc"
+ "%*d", 1, 1); // no-warning
+ printf("abc\
+def"
+ "%*d", 1, 1); // no-warning
+
+ // <rdar://problem/6079850>, allow 'unsigned' (instead of 'int') to be used for both
+ // the field width and precision. This deviates from C99, but is reasonably safe
+ // and is also accepted by GCC.
+ printf("%*d", (unsigned) 1, 1); // no-warning
+}
+
+__attribute__((__format__ (__printf__, 2, 4)))
+void check_string_literal2( FILE* fp, const char* s, char *buf, ... ) {
+ char * b;
+ va_list ap;
+ va_start(ap,buf);
+
+ printf(s); // expected-warning {{format string is not a string literal}}
+ vprintf(s,ap); // no-warning
+ fprintf(fp,s); // expected-warning {{format string is not a string literal}}
+ vfprintf(fp,s,ap); // no-warning
+ asprintf(&b,s); // expected-warning {{format string is not a string lit}}
+ vasprintf(&b,s,ap); // no-warning
+ sprintf(buf,s); // expected-warning {{format string is not a string literal}}
+ snprintf(buf,2,s); // expected-warning {{format string is not a string lit}}
+ __builtin___vsnprintf_chk(buf,2,0,-1,s,ap); // no-warning
+
+ vscanf(s, ap); // expected-warning {{format string is not a string literal}}
+}
+
+void check_conditional_literal(const char* s, int i) {
+ printf(i == 1 ? "yes" : "no"); // no-warning
+ printf(i == 0 ? (i == 1 ? "yes" : "no") : "dont know"); // no-warning
+ printf(i == 0 ? (i == 1 ? s : "no") : "dont know"); // expected-warning{{format string is not a string literal}}
+ printf("yes" ?: "no %d", 1); // expected-warning{{data argument not used by format string}}
+}
+
+void check_writeback_specifier()
+{
+ int x;
+ char *b;
+
+ printf("%n",&x); // expected-warning {{'%n' in format string discouraged}}
+ sprintf(b,"%d%%%n",1, &x); // expected-warning {{'%n' in format string dis}}
+}
+
+void check_invalid_specifier(FILE* fp, char *buf)
+{
+ printf("%s%lb%d","unix",10,20); // expected-warning {{invalid conversion specifier 'b'}}
+ fprintf(fp,"%%%l"); // expected-warning {{incomplete format specifier}}
+ sprintf(buf,"%%%%%ld%d%d", 1, 2, 3); // expected-warning{{format specifies type 'long' but the argument has type 'int'}}
+ snprintf(buf, 2, "%%%%%ld%;%d", 1, 2, 3); // expected-warning{{format specifies type 'long' but the argument has type 'int'}} expected-warning {{invalid conversion specifier ';'}}
+}
+
+void check_null_char_string(char* b)
+{
+ printf("\0this is bogus%d",1); // expected-warning {{string contains '\0'}}
+ snprintf(b,10,"%%%%%d\0%d",1,2); // expected-warning {{string contains '\0'}}
+ printf("%\0d",1); // expected-warning {{string contains '\0'}}
+}
+
+void check_empty_format_string(char* buf, ...)
+{
+ va_list ap;
+ va_start(ap,buf);
+ vprintf("",ap); // expected-warning {{format string is empty}}
+ sprintf(buf, "", 1); // expected-warning {{format string is empty}}
+
+ // Don't warn about empty format strings when there are no data arguments.
+ // This can arise from macro expansions and non-standard format string
+ // functions.
+ sprintf(buf, ""); // no-warning
+}
+
+void check_wide_string(char* b, ...)
+{
+ va_list ap;
+ va_start(ap,b);
+
+ printf(L"foo %d",2); // expected-warning {{incompatible pointer types}}, expected-warning {{should not be a wide string}}
+ vsprintf(b,L"bar %d",ap); // expected-warning {{incompatible pointer types}}, expected-warning {{should not be a wide string}}
+}
+
+void check_asterisk_precision_width(int x) {
+ printf("%*d"); // expected-warning {{'*' specified field width is missing a matching 'int' argument}}
+ printf("%.*d"); // expected-warning {{'.*' specified field precision is missing a matching 'int' argument}}
+ printf("%*d",12,x); // no-warning
+ printf("%*d","foo",x); // expected-warning {{field width should have type 'int', but argument has type 'char *'}}
+ printf("%.*d","foo",x); // expected-warning {{field precision should have type 'int', but argument has type 'char *'}}
+}
+
+void __attribute__((format(printf,1,3))) myprintf(const char*, int blah, ...);
+
+void test_myprintf() {
+ myprintf("%d", 17, 18); // okay
+}
+
+void test_constant_bindings(void) {
+ const char * const s1 = "hello";
+ const char s2[] = "hello";
+ const char *s3 = "hello";
+ char * const s4 = "hello";
+ extern const char s5[];
+
+ printf(s1); // no-warning
+ printf(s2); // no-warning
+ printf(s3); // expected-warning{{not a string literal}}
+ printf(s4); // expected-warning{{not a string literal}}
+ printf(s5); // expected-warning{{not a string literal}}
+}
+
+
+// Test what happens when -Wformat-security only.
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+#pragma GCC diagnostic warning "-Wformat-security"
+
+void test9(char *P) {
+ int x;
+ printf(P); // expected-warning {{format string is not a string literal (potentially insecure)}}
+ printf(P, 42);
+ printf("%n", &x); // expected-warning {{use of '%n' in format string discouraged }}
+}
+
+void torture(va_list v8) {
+ vprintf ("%*.*d", v8); // no-warning
+
+}
+
+void test10(int x, float f, int i, long long lli) {
+ printf("%s"); // expected-warning{{more '%' conversions than data arguments}}
+ printf("%@", 12); // expected-warning{{invalid conversion specifier '@'}}
+ printf("\0"); // expected-warning{{format string contains '\0' within the string body}}
+ printf("xs\0"); // expected-warning{{format string contains '\0' within the string body}}
+ printf("%*d\n"); // expected-warning{{'*' specified field width is missing a matching 'int' argument}}
+ printf("%*.*d\n", x); // expected-warning{{'.*' specified field precision is missing a matching 'int' argument}}
+ printf("%*d\n", f, x); // expected-warning{{field width should have type 'int', but argument has type 'double'}}
+ printf("%*.*d\n", x, f, x); // expected-warning{{field precision should have type 'int', but argument has type 'double'}}
+ printf("%**\n"); // expected-warning{{invalid conversion specifier '*'}}
+ printf("%n", &i); // expected-warning{{use of '%n' in format string discouraged (potentially insecure)}}
+ printf("%d%d\n", x); // expected-warning{{more '%' conversions than data arguments}}
+ printf("%d\n", x, x); // expected-warning{{data argument not used by format string}}
+ printf("%W%d%Z\n", x, x, x); // expected-warning{{invalid conversion specifier 'W'}} expected-warning{{invalid conversion specifier 'Z'}}
+ printf("%"); // expected-warning{{incomplete format specifier}}
+ printf("%.d", x); // no-warning
+ printf("%.", x); // expected-warning{{incomplete format specifier}}
+ printf("%f", 4); // expected-warning{{format specifies type 'double' but the argument has type 'int'}}
+ printf("%qd", lli); // no-warning
+ printf("%qd", x); // expected-warning{{format specifies type 'long long' but the argument has type 'int'}}
+ printf("%qp", (void *)0); // expected-warning{{length modifier 'q' results in undefined behavior or no effect with 'p' conversion specifier}}
+ printf("hhX %hhX", (unsigned char)10); // no-warning
+ printf("llX %llX", (long long) 10); // no-warning
+ // This is fine, because there is an implicit conversion to an int.
+ printf("%d", (unsigned char) 10); // no-warning
+ printf("%d", (long long) 10); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
+ printf("%Lf\n", (long double) 1.0); // no-warning
+ printf("%f\n", (long double) 1.0); // expected-warning{{format specifies type 'double' but the argument has type 'long double'}}
+ // The man page says that a zero precision is okay.
+ printf("%.0Lf", (long double) 1.0); // no-warning
+ printf("%c\n", "x"); // expected-warning{{format specifies type 'int' but the argument has type 'char *'}}
+ printf("%c\n", 1.23); // expected-warning{{format specifies type 'int' but the argument has type 'double'}}
+ printf("Format %d, is %! %f", 1, 2, 4.4); // expected-warning{{invalid conversion specifier '!'}}
+}
+
+typedef unsigned char uint8_t;
+
+void should_understand_small_integers() {
+ printf("%hhu", (short) 10); // expected-warning{{format specifies type 'unsigned char' but the argument has type 'short'}}
+ printf("%hu\n", (unsigned char) 1); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'unsigned char'}}
+ printf("%hu\n", (uint8_t)1); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'uint8_t'}}
+}
+
+void test11(void *p, char *s) {
+ printf("%p", p); // no-warning
+ printf("%p", 123); // expected-warning{{format specifies type 'void *' but the argument has type 'int'}}
+ printf("%.4p", p); // expected-warning{{precision used with 'p' conversion specifier, resulting in undefined behavior}}
+ printf("%+p", p); // expected-warning{{flag '+' results in undefined behavior with 'p' conversion specifier}}
+ printf("% p", p); // expected-warning{{flag ' ' results in undefined behavior with 'p' conversion specifier}}
+ printf("%0p", p); // expected-warning{{flag '0' results in undefined behavior with 'p' conversion specifier}}
+ printf("%s", s); // no-warning
+ printf("%+s", p); // expected-warning{{flag '+' results in undefined behavior with 's' conversion specifier}}
+ printf("% s", p); // expected-warning{{flag ' ' results in undefined behavior with 's' conversion specifier}}
+ printf("%0s", p); // expected-warning{{flag '0' results in undefined behavior with 's' conversion specifier}}
+}
+
+void test12(char *b) {
+ unsigned char buf[4];
+ printf ("%.4s\n", buf); // no-warning
+ printf ("%.4s\n", &buf); // expected-warning{{format specifies type 'char *' but the argument has type 'unsigned char (*)[4]'}}
+
+ // Verify that we are checking asprintf
+ asprintf(&b, "%d", "asprintf"); // expected-warning{{format specifies type 'int' but the argument has type 'char *'}}
+}
+
+void test13(short x) {
+ char bel = 007;
+ printf("bel: '0%hhd'\n", bel); // no-warning
+ printf("x: '0%hhd'\n", x); // expected-warning {{format specifies type 'char' but the argument has type 'short'}}
+}
+
+typedef struct __aslclient *aslclient;
+typedef struct __aslmsg *aslmsg;
+int asl_log(aslclient asl, aslmsg msg, int level, const char *format, ...) __attribute__((__format__ (__printf__, 4, 5)));
+void test_asl(aslclient asl) {
+ // Test case from <rdar://problem/7341605>.
+ asl_log(asl, 0, 3, "Error: %m"); // no-warning
+ asl_log(asl, 0, 3, "Error: %W"); // expected-warning{{invalid conversion specifier 'W'}}
+}
+
+// <rdar://problem/7595366>
+typedef enum { A } int_t;
+void f0(int_t x) { printf("%d\n", x); }
+
+// Unicode test cases. These are possibly specific to Mac OS X. If so, they should
+// eventually be moved into a separate test.
+typedef __WCHAR_TYPE__ wchar_t;
+
+void test_unicode_conversions(wchar_t *s) {
+ printf("%S", s); // no-warning
+ printf("%s", s); // expected-warning{{format specifies type 'char *' but the argument has type 'wchar_t *'}}
+ printf("%C", s[0]); // no-warning
+ printf("%c", s[0]);
+ // FIXME: This test reports inconsistent results. On Windows, '%C' expects
+ // 'unsigned short'.
+ // printf("%C", 10);
+ printf("%S", "hello"); // expected-warning{{but the argument has type 'char *'}}
+}
+
+// Mac OS X supports positional arguments in format strings.
+// This is an IEEE extension (IEEE Std 1003.1).
+// FIXME: This is probably not portable everywhere.
+void test_positional_arguments() {
+ printf("%0$", (int)2); // expected-warning{{position arguments in format strings start counting at 1 (not 0)}}
+ printf("%1$*0$d", (int) 2); // expected-warning{{position arguments in format strings start counting at 1 (not 0)}}
+ printf("%1$d", (int) 2); // no-warning
+ printf("%1$d", (int) 2, 2); // expected-warning{{data argument not used by format string}}
+ printf("%1$d%1$f", (int) 2); // expected-warning{{format specifies type 'double' but the argument has type 'int'}}
+ printf("%1$2.2d", (int) 2); // no-warning
+ printf("%2$*1$.2d", (int) 2, (int) 3); // no-warning
+ printf("%2$*8$d", (int) 2, (int) 3); // expected-warning{{specified field width is missing a matching 'int' argument}}
+ printf("%%%1$d", (int) 2); // no-warning
+ printf("%1$d%%", (int) 2); // no-warning
+}
+
+// PR 6697 - Handle format strings where the data argument is not adjacent to the format string
+void myprintf_PR_6697(const char *format, int x, ...) __attribute__((__format__(printf,1, 3)));
+void test_pr_6697() {
+ myprintf_PR_6697("%s\n", 1, "foo"); // no-warning
+ myprintf_PR_6697("%s\n", 1, (int)0); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
+ // FIXME: Not everything should clearly support positional arguments,
+ // but we need a way to identify those cases.
+ myprintf_PR_6697("%1$s\n", 1, "foo"); // no-warning
+ myprintf_PR_6697("%2$s\n", 1, "foo"); // expected-warning{{data argument position '2' exceeds the number of data arguments (1)}}
+ myprintf_PR_6697("%18$s\n", 1, "foo"); // expected-warning{{data argument position '18' exceeds the number of data arguments (1)}}
+ myprintf_PR_6697("%1$s\n", 1, (int) 0); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
+}
+
+void rdar8026030(FILE *fp) {
+ fprintf(fp, "\%"); // expected-warning{{incomplete format specifier}}
+}
+
+void bug7377_bad_length_mod_usage() {
+ // Bad length modifiers
+ printf("%hhs", "foo"); // expected-warning{{length modifier 'hh' results in undefined behavior or no effect with 's' conversion specifier}}
+ printf("%1$zp", (void *)0); // expected-warning{{length modifier 'z' results in undefined behavior or no effect with 'p' conversion specifier}}
+ printf("%ls", L"foo"); // no-warning
+ printf("%#.2Lf", (long double)1.234); // no-warning
+
+ // Bad flag usage
+ printf("%#p", (void *) 0); // expected-warning{{flag '#' results in undefined behavior with 'p' conversion specifier}}
+ printf("%0d", -1); // no-warning
+ printf("%#n", (void *) 0); // expected-warning{{flag '#' results in undefined behavior with 'n' conversion specifier}} expected-warning{{use of '%n' in format string discouraged (potentially insecure)}}
+ printf("%-n", (void *) 0); // expected-warning{{flag '-' results in undefined behavior with 'n' conversion specifier}} expected-warning{{use of '%n' in format string discouraged (potentially insecure)}}
+ printf("%-p", (void *) 0); // no-warning
+
+ // Bad optional amount use
+ printf("%.2c", 'a'); // expected-warning{{precision used with 'c' conversion specifier, resulting in undefined behavior}}
+ printf("%1n", (void *) 0); // expected-warning{{field width used with 'n' conversion specifier, resulting in undefined behavior}} expected-warning{{use of '%n' in format string discouraged (potentially insecure)}}
+ printf("%.9n", (void *) 0); // expected-warning{{precision used with 'n' conversion specifier, resulting in undefined behavior}} expected-warning{{use of '%n' in format string discouraged (potentially insecure)}}
+
+ // Ignored flags
+ printf("% +f", 1.23); // expected-warning{{flag ' ' is ignored when flag '+' is present}}
+ printf("%+ f", 1.23); // expected-warning{{flag ' ' is ignored when flag '+' is present}}
+ printf("%0-f", 1.23); // expected-warning{{flag '0' is ignored when flag '-' is present}}
+ printf("%-0f", 1.23); // expected-warning{{flag '0' is ignored when flag '-' is present}}
+ printf("%-+f", 1.23); // no-warning
+}
+
+// PR 7981 - handle '%lc' (wint_t)
+#ifndef wint_t
+typedef int __darwin_wint_t;
+typedef __darwin_wint_t wint_t;
+#endif
+
+void pr7981(wint_t c, wchar_t c2) {
+ printf("%lc", c); // no-warning
+ printf("%lc", 1.0); // expected-warning{{the argument has type 'double'}}
+ printf("%lc", (char) 1); // no-warning
+ printf("%lc", &c); // expected-warning{{the argument has type 'wint_t *' (aka 'int *')}}
+ printf("%lc", c2); // no-warning
+}
+
+// <rdar://problem/8269537> -Wformat-security says NULL is not a string literal
+void rdar8269537() {
+ // This is likely to crash in most cases, but -Wformat-nonliteral technically
+ // doesn't warn in this case.
+ printf(0); // no-warning
+}
+
+// Handle functions with multiple format attributes.
+extern void rdar8332221_vprintf_scanf(const char *, va_list, const char *, ...)
+ __attribute__((__format__(__printf__, 1, 0)))
+ __attribute__((__format__(__scanf__, 3, 4)));
+
+void rdar8332221(va_list ap, int *x, long *y) {
+ rdar8332221_vprintf_scanf("%", ap, "%d", x); // expected-warning{{incomplete format specifier}}
+}
+
+// PR8641
+void pr8641() {
+ printf("%#x\n", 10);
+ printf("%#X\n", 10);
+}
+
+void posix_extensions() {
+ // Test %'d, "thousands grouping".
+ // <rdar://problem/8816343>
+ printf("%'d\n", 123456789); // no-warning
+ printf("%'i\n", 123456789); // no-warning
+ printf("%'f\n", (float) 1.0); // no-warning
+ printf("%'p\n", (void*) 0); // expected-warning{{results in undefined behavior with 'p' conversion specifier}}
+}
+
+// PR8486
+//
+// Test what happens when -Wformat is on, but -Wformat-security is off.
+#pragma GCC diagnostic warning "-Wformat"
+#pragma GCC diagnostic ignored "-Wformat-security"
+
+void pr8486() {
+ printf("%s", 1); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
+}
+
+// PR9314
+// Don't warn about string literals that are PreDefinedExprs, e.g. __func__.
+void pr9314() {
+ printf(__PRETTY_FUNCTION__); // no-warning
+ printf(__func__); // no-warning
+}
+
+int printf(const char * restrict, ...) __attribute__((__format__ (__printf__, 1, 2)));
+
+void rdar9612060(void) {
+ printf("%s", 2); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
+}
+
+void check_char(unsigned char x, signed char y) {
+ printf("%c", y); // no-warning
+ printf("%hhu", x); // no-warning
+ printf("%hhi", y); // no-warning
+ printf("%hhi", x); // no-warning
+ printf("%c", x); // no-warning
+ printf("%hhu", y); // no-warning
+}
+
+// Test suppression of individual warnings.
+
+void test_suppress_invalid_specifier() {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-invalid-specifier"
+ printf("%@", 12); // no-warning
+#pragma clang diagnostic pop
+}
+
+// Make sure warnings are on for next test.
+#pragma GCC diagnostic warning "-Wformat"
+#pragma GCC diagnostic warning "-Wformat-security"
+
+// Test that the printf call site is where the warning is attached. If the
+// format string is somewhere else, point to it in a note.
+void pr9751() {
+ const char kFormat1[] = "%d %d \n"; // expected-note{{format string is defined here}}}
+ printf(kFormat1, 0); // expected-warning{{more '%' conversions than data arguments}}
+ printf("%d %s\n", 0); // expected-warning{{more '%' conversions than data arguments}}
+
+ const char kFormat2[] = "%18$s\n"; // expected-note{{format string is defined here}}
+ printf(kFormat2, 1, "foo"); // expected-warning{{data argument position '18' exceeds the number of data arguments (2)}}
+ printf("%18$s\n", 1, "foo"); // expected-warning{{data argument position '18' exceeds the number of data arguments (2)}}
+
+ const char kFormat3[] = "%n"; // expected-note{{format string is defined here}}
+ printf(kFormat3, "as"); // expected-warning{{use of '%n' in format string discouraged}}
+ printf("%n", "as"); // expected-warning{{use of '%n' in format string discouraged}}
+
+ const char kFormat4[] = "%y"; // expected-note{{format string is defined here}}
+ printf(kFormat4, 5); // expected-warning{{invalid conversion specifier 'y'}}
+ printf("%y", 5); // expected-warning{{invalid conversion specifier 'y'}}
+
+ const char kFormat5[] = "%."; // expected-note{{format string is defined here}}
+ printf(kFormat5, 5); // expected-warning{{incomplete format specifier}}
+ printf("%.", 5); // expected-warning{{incomplete format specifier}}
+
+ const char kFormat6[] = "%s"; // expected-note{{format string is defined here}}
+ printf(kFormat6, 5); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
+ printf("%s", 5); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
+
+ const char kFormat7[] = "%0$"; // expected-note{{format string is defined here}}
+ printf(kFormat7, 5); // expected-warning{{position arguments in format strings start counting at 1 (not 0)}}
+ printf("%0$", 5); // expected-warning{{position arguments in format strings start counting at 1 (not 0)}}
+
+ const char kFormat8[] = "%1$d %d"; // expected-note{{format string is defined here}}
+ printf(kFormat8, 4, 4); // expected-warning{{cannot mix positional and non-positional arguments in format string}}
+ printf("%1$d %d", 4, 4); // expected-warning{{cannot mix positional and non-positional arguments in format string}}
+
+ const char kFormat9[] = ""; // expected-note{{format string is defined here}}
+ printf(kFormat9, 4, 4); // expected-warning{{format string is empty}}
+ printf("", 4, 4); // expected-warning{{format string is empty}}
+
+ const char kFormat10[] = "\0%d"; // expected-note{{format string is defined here}}
+ printf(kFormat10, 4); // expected-warning{{format string contains '\0' within the string body}}
+ printf("\0%d", 4); // expected-warning{{format string contains '\0' within the string body}}
+
+ const char kFormat11[] = "%*d"; // expected-note{{format string is defined here}}
+ printf(kFormat11); // expected-warning{{'*' specified field width is missing a matching 'int' argument}}
+ printf("%*d"); // expected-warning{{'*' specified field width is missing a matching 'int' argument}}
+
+ const char kFormat12[] = "%*d"; // expected-note{{format string is defined here}}
+ printf(kFormat12, 4.4); // expected-warning{{field width should have type 'int', but argument has type 'double'}}
+ printf("%*d", 4.4); // expected-warning{{field width should have type 'int', but argument has type 'double'}}
+
+ const char kFormat13[] = "%.3p"; // expected-note{{format string is defined here}}
+ void *p;
+ printf(kFormat13, p); // expected-warning{{precision used with 'p' conversion specifier, resulting in undefined behavior}}
+ printf("%.3p", p); // expected-warning{{precision used with 'p' conversion specifier, resulting in undefined behavior}}
+
+ const char kFormat14[] = "%0s"; // expected-note{{format string is defined here}}
+ printf(kFormat14, "a"); // expected-warning{{flag '0' results in undefined behavior with 's' conversion specifier}}
+ printf("%0s", "a"); // expected-warning{{flag '0' results in undefined behavior with 's' conversion specifier}}
+
+ const char kFormat15[] = "%hhs"; // expected-note{{format string is defined here}}
+ printf(kFormat15, "a"); // expected-warning{{length modifier 'hh' results in undefined behavior or no effect with 's' conversion specifier}}
+ printf("%hhs", "a"); // expected-warning{{length modifier 'hh' results in undefined behavior or no effect with 's' conversion specifier}}
+
+ const char kFormat16[] = "%-0d"; // expected-note{{format string is defined here}}
+ printf(kFormat16, 5); // expected-warning{{flag '0' is ignored when flag '-' is present}}
+ printf("%-0d", 5); // expected-warning{{flag '0' is ignored when flag '-' is present}}
+
+ // Make sure that the "format string is defined here" note is not emitted
+ // when the original string is within the argument expression.
+ printf(1 ? "yes %d" : "no %d"); // expected-warning 2{{more '%' conversions than data arguments}}
+
+ const char kFormat17[] = "%hu"; // expected-note{{format string is defined here}}}
+ printf(kFormat17, (int[]){0}); // expected-warning{{format specifies type 'unsigned short' but the argument}}
+
+ printf("%a", (long double)0); // expected-warning{{format specifies type 'double' but the argument has type 'long double'}}
+}
+
+// PR 9466: clang: doesn't know about %Lu, %Ld, and %Lx
+void printf_longlong(long long x, unsigned long long y) {
+ printf("%Ld", y); // no-warning
+ printf("%Lu", y); // no-warning
+ printf("%Lx", y); // no-warning
+ printf("%Ld", x); // no-warning
+ printf("%Lu", x); // no-warning
+ printf("%Lx", x); // no-warning
+ printf("%Ls", "hello"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}}
+}
+
+void __attribute__((format(strfmon,1,2))) monformat(const char *fmt, ...);
+void __attribute__((format(strftime,1,0))) dateformat(const char *fmt);
+
+// Other formats
+void test_other_formats() {
+ char *str = "";
+ monformat("", 1); // expected-warning{{format string is empty}}
+ monformat(str); // expected-warning{{format string is not a string literal (potentially insecure)}}
+ dateformat(""); // expected-warning{{format string is empty}}
+ dateformat(str); // no-warning (using strftime non literal is not unsafe)
+}
diff --git a/clang/test/Sema/fp16-sema.c b/clang/test/Sema/fp16-sema.c
new file mode 100644
index 0000000..e678f9a
--- /dev/null
+++ b/clang/test/Sema/fp16-sema.c
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// Functions cannot have parameters of type __fp16.
+extern void f (__fp16); // expected-error {{parameters cannot have __fp16 type; did you forget * ?}}
+extern void g (__fp16 *);
+
+extern void (*pf) (__fp16); // expected-error {{parameters cannot have __fp16 type; did you forget * ?}}
+extern void (*pg) (__fp16*);
+
+typedef void(*tf) (__fp16); // expected-error {{parameters cannot have __fp16 type; did you forget * ?}}
+typedef void(*tg) (__fp16*);
+
+void kf(a)
+ __fp16 a; { // expected-error {{parameters cannot have __fp16 type; did you forget * ?}}
+}
+
+void kg(a)
+ __fp16 *a; {
+}
+
+// Functions cannot return type __fp16.
+extern __fp16 f1 (void); // expected-error {{function return value cannot have __fp16 type; did you forget * ?}}
+extern __fp16 *g1 (void);
+
+extern __fp16 (*pf1) (void); // expected-error {{function return value cannot have __fp16 type; did you forget * ?}}
+extern __fp16 *(*gf1) (void);
+
+typedef __fp16 (*tf1) (void); // expected-error {{function return value cannot have __fp16 type; did you forget * ?}}
+typedef __fp16 *(*tg1) (void);
+
diff --git a/clang/test/Sema/fpack-struct.c b/clang/test/Sema/fpack-struct.c
new file mode 100644
index 0000000..37c8444
--- /dev/null
+++ b/clang/test/Sema/fpack-struct.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -DEXPECTED_STRUCT_SIZE=5 -fpack-struct 1 %s
+// RUN: %clang_cc1 -DEXPECTED_STRUCT_SIZE=6 -fpack-struct 2 %s
+
+struct s0 {
+ int x;
+ char c;
+};
+
+int t0[sizeof(struct s0) == EXPECTED_STRUCT_SIZE ?: -1];
diff --git a/clang/test/Sema/freemain.c b/clang/test/Sema/freemain.c
new file mode 100644
index 0000000..eed644d
--- /dev/null
+++ b/clang/test/Sema/freemain.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -ffreestanding %s
+
+// Tests that -ffreestanding disables all special treatment of main().
+
+void* allocate(long size);
+
+void* main(void* context, long size) {
+ if (context) return allocate(size);
+} // expected-warning {{control may reach end of non-void function}}
diff --git a/clang/test/Sema/function-ptr.c b/clang/test/Sema/function-ptr.c
new file mode 100644
index 0000000..ff85272
--- /dev/null
+++ b/clang/test/Sema/function-ptr.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -verify -pedantic
+typedef int unary_int_func(int arg);
+unary_int_func *func;
+
+unary_int_func *set_func(void *p) {
+ func = p; // expected-warning {{converts between void pointer and function pointer}}
+ p = func; // expected-warning {{converts between void pointer and function pointer}}
+
+ return p; // expected-warning {{converts between void pointer and function pointer}}
+}
+
diff --git a/clang/test/Sema/function-redecl.c b/clang/test/Sema/function-redecl.c
new file mode 100644
index 0000000..7076bdf
--- /dev/null
+++ b/clang/test/Sema/function-redecl.c
@@ -0,0 +1,131 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// PR3588
+void g0(int, int);
+void g0(); // expected-note{{previous declaration is here}} expected-note{{'g0' declared here}}
+
+void f0() {
+ g0(1, 2, 3); // expected-error{{too many arguments to function call}}
+}
+
+void g0(int); // expected-error{{conflicting types for 'g0'}}
+
+int g1(int, int);
+
+typedef int INT;
+
+INT g1(x, y)
+ int x;
+ int y;
+{
+ return x + y;
+}
+
+int g2(int, int); // expected-note{{previous declaration is here}}
+
+INT g2(x) // expected-error{{conflicting types for 'g2'}}
+ int x;
+{
+ return x;
+}
+
+void test() {
+ int f1;
+ {
+ void f1(double);
+ {
+ void f1(double); // expected-note{{previous declaration is here}}
+ {
+ int f1(int); // expected-error{{conflicting types for 'f1'}}
+ }
+ }
+ }
+}
+
+extern void g3(int); // expected-note{{previous declaration is here}}
+static void g3(int x) { } // expected-error{{static declaration of 'g3' follows non-static declaration}}
+
+void test2() {
+ extern int f2; // expected-note 2 {{previous definition is here}}
+ {
+ void f2(int); // expected-error{{redefinition of 'f2' as different kind of symbol}}
+ }
+
+ {
+ int f2;
+ {
+ void f2(int); // expected-error{{redefinition of 'f2' as different kind of symbol}}
+ }
+ }
+}
+
+// <rdar://problem/6127293>
+int outer1(int); // expected-note{{previous declaration is here}}
+struct outer3 { };
+int outer4(int);
+int outer5; // expected-note{{previous definition is here}}
+int *outer7(int);
+
+void outer_test() {
+ int outer1(float); // expected-error{{conflicting types for 'outer1'}}
+ int outer2(int); // expected-note{{previous declaration is here}}
+ int outer3(int); // expected-note{{previous declaration is here}}
+ int outer4(int); // expected-note{{previous declaration is here}}
+ int outer5(int); // expected-error{{redefinition of 'outer5' as different kind of symbol}}
+ int* outer6(int); // expected-note{{previous declaration is here}}
+ int *outer7(int);
+ int outer8(int);
+
+ int *ip7 = outer7(6);
+}
+
+int outer2(float); // expected-error{{conflicting types for 'outer2'}}
+int outer3(float); // expected-error{{conflicting types for 'outer3'}}
+int outer4(float); // expected-error{{conflicting types for 'outer4'}}
+
+void outer_test2(int x) {
+ int* ip = outer6(x); // expected-warning{{use of out-of-scope declaration of 'outer6'}}
+ int *ip2 = outer7(x);
+}
+
+void outer_test3() {
+ int *(*fp)(int) = outer8; // expected-error{{use of undeclared identifier 'outer8'}}
+}
+
+static float outer8(float); // okay
+
+enum e { e1, e2 };
+
+// GNU extension: prototypes and K&R function definitions
+int isroot(short x, // expected-note{{previous declaration is here}}
+ enum e);
+
+int isroot(x, y)
+ short x; // expected-warning{{promoted type 'int' of K&R function parameter is not compatible with the parameter type 'short' declared in a previous prototype}}
+ unsigned int y;
+{
+ return x == 1;
+}
+
+// PR3817
+void *h0(unsigned a0, ...);
+extern __typeof (h0) h1 __attribute__((__sentinel__));
+extern __typeof (h1) h1 __attribute__((__sentinel__));
+
+// PR3840
+void i0 (unsigned short a0);
+extern __typeof (i0) i1;
+extern __typeof (i1) i1;
+
+typedef int a();
+typedef int a2(int*);
+a x;
+a2 x2; // expected-note{{passing argument to parameter here}}
+void test_x() {
+ x(5);
+ x2(5); // expected-warning{{incompatible integer to pointer conversion passing 'int' to parameter of type 'int *'}}
+}
+
+enum e0 {one};
+void f3();
+void f3(enum e0 x) {}
diff --git a/clang/test/Sema/function.c b/clang/test/Sema/function.c
new file mode 100644
index 0000000..1b0dc2a
--- /dev/null
+++ b/clang/test/Sema/function.c
@@ -0,0 +1,94 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
+
+// PR1892, PR11354
+void f(double a[restrict][5]) { __typeof(a) x = 10; } // expected-warning {{(aka 'double (*restrict)[5]')}}
+
+int foo (__const char *__path);
+int foo(__const char *__restrict __file);
+
+void func(const char*); // expected-note {{previous declaration is here}}
+void func(char*); // expected-error{{conflicting types for 'func'}}
+
+void g(int (*)(const void **, const void **));
+void g(int (*compar)()) {
+}
+
+void h(); // expected-note {{previous declaration is here}}
+void h (const char *fmt, ...) {} // expected-error{{conflicting types for 'h'}}
+
+// PR1965
+int t5(b); // expected-error {{parameter list without types}}
+int t6(int x, g); // expected-warning {{type specifier missing, defaults to 'int'}}
+
+int t7(, ); // expected-error {{expected parameter declarator}} expected-error {{expected parameter declarator}}
+int t8(, int a); // expected-error {{expected parameter declarator}}
+int t9(int a, ); // expected-error {{expected parameter declarator}}
+
+
+// PR2042
+void t10(){}
+void t11(){t10(1);} // expected-warning{{too many arguments}}
+
+// PR3208
+void t12(int) {} // expected-error{{parameter name omitted}}
+
+// PR2790
+void t13() {
+ return 0; // expected-error {{void function 't13' should not return a value}}
+}
+int t14() {
+ return; // expected-error {{non-void function 't14' should return a value}}
+}
+
+// <rdar://problem/6097326>
+y(y) { return y; } // expected-warning{{parameter 'y' was not declared, defaulting to type 'int'}} \
+ // expected-warning{{type specifier missing, defaults to 'int'}}
+
+
+// PR3137, <rdar://problem/6127293>
+extern int g0_3137(void);
+void f0_3137() {
+ int g0_3137(void);
+}
+void f1_3137() {
+ int (*fp)(void) = g0_3137;
+}
+
+void f1static() {
+ static void f2static(int); // expected-error{{function declared in block scope cannot have 'static' storage class}}
+ register void f2register(int); // expected-error{{illegal storage class on function}}
+}
+
+struct incomplete_test a(void) {} // expected-error{{incomplete result type 'struct incomplete_test' in function definition}} \
+ // expected-note{{forward declaration of 'struct incomplete_test'}}
+
+
+extern __inline
+__attribute__((__gnu_inline__))
+void gnu_inline1() {}
+
+void
+__attribute__((__gnu_inline__)) // expected-warning {{'gnu_inline' attribute requires function to be marked 'inline', attribute ignored}}
+gnu_inline2() {}
+
+
+// rdar://6802350
+inline foo_t invalid_type() { // expected-error {{unknown type name 'foo_t'}}
+}
+
+typedef void fn_t(void);
+fn_t t17;
+
+// PR4049
+unknown_type t18(void*) { // expected-error {{unknown type name 'unknown_type'}} expected-error{{parameter name omitted}}
+}
+
+unknown_type t19(int* P) { // expected-error {{unknown type name 'unknown_type'}}
+ P = P+1; // no warning.
+}
+
+// missing ',' before '...'
+void t20(int i...) { } // expected-error {{requires a comma}}
+
+int n;
+void t21(int n, int (*array)[n]);
diff --git a/clang/test/Sema/generic-selection.c b/clang/test/Sema/generic-selection.c
new file mode 100644
index 0000000..8cef975
--- /dev/null
+++ b/clang/test/Sema/generic-selection.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -std=c1x -fsyntax-only -verify %s
+
+void foo(int n) {
+ (void) _Generic(0,
+ struct A: 0, // expected-error {{type 'struct A' in generic association incomplete}}
+ void(): 0, // expected-error {{type 'void ()' in generic association not an object type}}
+ int[n]: 0); // expected-error {{type 'int [n]' in generic association is a variably modified type}}
+
+ (void) _Generic(0,
+ void (*)(): 0, // expected-note {{compatible type 'void (*)()' specified here}}
+ void (*)(void): 0); // expected-error {{type 'void (*)(void)' in generic association compatible with previously specified type 'void (*)()'}}
+
+ (void) _Generic((void (*)()) 0, // expected-error {{controlling expression type 'void (*)()' compatible with 2 generic association types}}
+ void (*)(int): 0, // expected-note {{compatible type 'void (*)(int)' specified here}}
+ void (*)(void): 0); // expected-note {{compatible type 'void (*)(void)' specified here}}
+
+ (void) _Generic(0, // expected-error {{controlling expression type 'int' not compatible with any generic association type}}
+ char: 0, short: 0, long: 0);
+
+ int a1[_Generic(0, int: 1, short: 2, float: 3, default: 4) == 1 ? 1 : -1];
+ int a2[_Generic(0, default: 1, short: 2, float: 3, int: 4) == 4 ? 1 : -1];
+ int a3[_Generic(0L, int: 1, short: 2, float: 3, default: 4) == 4 ? 1 : -1];
+ int a4[_Generic(0L, default: 1, short: 2, float: 3, int: 4) == 1 ? 1 : -1];
+ int a5[_Generic(0, int: 1, short: 2, float: 3) == 1 ? 1 : -1];
+ int a6[_Generic(0, short: 1, float: 2, int: 3) == 3 ? 1 : -1];
+}
diff --git a/clang/test/Sema/gnu89.c b/clang/test/Sema/gnu89.c
new file mode 100644
index 0000000..189e6b0
--- /dev/null
+++ b/clang/test/Sema/gnu89.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 %s -std=gnu89 -pedantic -fsyntax-only -verify
+
+int f(int restrict);
+
+void main() {} // expected-warning {{return type of 'main' is not 'int'}}
diff --git a/clang/test/Sema/heinous-extensions-off.c b/clang/test/Sema/heinous-extensions-off.c
new file mode 100644
index 0000000..9b80d34
--- /dev/null
+++ b/clang/test/Sema/heinous-extensions-off.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -verify
+
+int foo() {
+ int a;
+ // PR3788
+ asm("nop" : : "m"((int)(a))); // expected-error {{cast in a inline asm context requiring an l-value}}
+ // PR3794
+ asm("nop" : "=r"((unsigned)a)); // expected-error {{cast in a inline asm context requiring an l-value}}
+}
+
diff --git a/clang/test/Sema/heinous-extensions-on.c b/clang/test/Sema/heinous-extensions-on.c
new file mode 100644
index 0000000..176f472
--- /dev/null
+++ b/clang/test/Sema/heinous-extensions-on.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -verify -fheinous-gnu-extensions
+
+void foo() {
+ int a;
+ // PR3788
+ asm("nop" : : "m"((int)(a))); // expected-warning {{cast in a inline asm context requiring an l-value}}
+ // PR3794
+ asm("nop" : "=r"((unsigned)a)); // expected-warning {{cast in a inline asm context requiring an l-value}}
+}
diff --git a/clang/test/Sema/i-c-e.c b/clang/test/Sema/i-c-e.c
new file mode 100644
index 0000000..ee61ac3
--- /dev/null
+++ b/clang/test/Sema/i-c-e.c
@@ -0,0 +1,75 @@
+// RUN: %clang %s -ffreestanding -fsyntax-only -Xclang -verify -pedantic -fpascal-strings -std=c99
+
+#include <stdint.h>
+#include <limits.h>
+
+int a() {int p; *(1 ? &p : (void*)(0 && (a(),1))) = 10;} // expected-error {{incomplete type 'void' is not assignable}}
+
+// rdar://6091492 - ?: with __builtin_constant_p as the operand is an i-c-e.
+int expr;
+char w[__builtin_constant_p(expr) ? expr : 1];
+
+char v[sizeof(__builtin_constant_p(0)) == sizeof(int) ? 1 : -1];
+
+int implicitConversion = 1.0;
+char floatArith[(int)(1.0+2.0)]; // expected-warning {{must be an integer constant expression}}
+
+// __builtin_constant_p as the condition of ?: allows arbitrary foldable
+// constants to be transmogrified into i-c-e's.
+char b[__builtin_constant_p((int)(1.0+2.0)) ? (int)(1.0+2.0) : -1];
+
+struct c {
+ int a : (
+ __builtin_constant_p((int)(1.0+2.0)) ? (int)(1.0+
+ expr // expected-error {{expression is not an integer constant expression}}
+ ) : -1);
+};
+
+
+
+
+void test1(int n, int* p) { *(n ? p : (void *)(7-7)) = 1; }
+void test2(int n, int* p) { *(n ? p : (void *)0) = 1; }
+
+
+
+char array[1024/(sizeof (long))];
+
+int x['\xBb' == (char) 187 ? 1: -1];
+
+// PR1992
+void func(int x)
+{
+ switch (x) {
+ case sizeof("abc"): break;
+ case sizeof("loooong"): func(4);
+ case sizeof("\ploooong"): func(4);
+ }
+}
+
+
+// rdar://4213768
+int expr;
+char y[__builtin_constant_p(expr) ? -1 : 1];
+char z[__builtin_constant_p(4) ? 1 : -1];
+
+// Comma tests
+int comma1[0?1,2:3];
+int comma2[1||(1,2)]; // expected-warning {{use of logical '||' with constant operand}} \
+ // expected-note {{use '|' for a bitwise operation}}
+int comma3[(1,2)]; // expected-warning {{size of static array must be an integer constant expression}}
+
+// Pointer + __builtin_constant_p
+char pbcp[__builtin_constant_p(4) ? (intptr_t)&expr : 0]; // expected-error {{variable length array declaration not allowed at file scope}}
+
+int illegaldiv1a[1 || 1/0];
+int illegaldiv1b[1 && 1/0]; //expected-error{{variable length array declaration not allowed at file scope}}
+
+int illegaldiv2[1/0]; // expected-error {{variable length array declaration not allowed at file scope}}
+int illegaldiv3[INT_MIN / -1]; // expected-error {{variable length array declaration not allowed at file scope}}
+// PR9262
+int illegaldiv4[0 / (1 / 0)]; // expected-error {{variable length array declaration not allowed at file scope}}
+
+int chooseexpr[__builtin_choose_expr(1, 1, expr)];
+int realop[(__real__ 4) == 4 ? 1 : -1];
+int imagop[(__imag__ 4) == 0 ? 1 : -1];
diff --git a/clang/test/Sema/illegal-types.c b/clang/test/Sema/illegal-types.c
new file mode 100644
index 0000000..819b38a
--- /dev/null
+++ b/clang/test/Sema/illegal-types.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -x c++ -std=c++98 %s
+
+void a (void []()); // expected-error{{'type name' declared as array of functions}}
+void b (void p[]()); // expected-error{{'p' declared as array of functions}}
+void c (int &[]); // expected-error{{'type name' declared as array of references}}
+void d (int &p[]); // expected-error{{'p' declared as array of references}}
+
diff --git a/clang/test/Sema/implicit-builtin-decl.c b/clang/test/Sema/implicit-builtin-decl.c
new file mode 100644
index 0000000..8cdd365
--- /dev/null
+++ b/clang/test/Sema/implicit-builtin-decl.c
@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+void f() {
+ int *ptr = malloc(sizeof(int) * 10); // expected-warning{{implicitly declaring library function 'malloc' with type}} \
+ // expected-note{{please include the header <stdlib.h> or explicitly provide a declaration for 'malloc'}} \
+ // expected-note{{'malloc' is a builtin with type 'void *}}
+}
+
+void *alloca(__SIZE_TYPE__); // redeclaration okay
+
+int *calloc(__SIZE_TYPE__, __SIZE_TYPE__); // expected-warning{{incompatible redeclaration of library function 'calloc'}} \
+ // expected-note{{'calloc' is a builtin with type 'void *}}
+
+
+void g(int malloc) { // okay: these aren't functions
+ int calloc = 1;
+}
+
+void h() {
+ int malloc(int); // expected-warning{{incompatible redeclaration of library function 'malloc'}}
+ int strcpy(int); // expected-warning{{incompatible redeclaration of library function 'strcpy'}} \
+ // expected-note{{'strcpy' is a builtin with type 'char *(char *, const char *)'}}
+}
+
+void f2() {
+ fprintf(0, "foo"); // expected-warning{{declaration of built-in function 'fprintf' requires inclusion of the header <stdio.h>}} \
+ expected-warning {{implicit declaration of function 'fprintf' is invalid in C99}}
+}
+
+// PR2892
+void __builtin_object_size(); // expected-error{{conflicting types}} \
+// expected-note{{'__builtin_object_size' is a builtin with type}}
+
+int a[10];
+
+int f0() {
+ return __builtin_object_size(&a); // expected-error {{too few arguments to function}}
+}
+
+void * realloc(void *p, int size) { // expected-warning{{incompatible redeclaration of library function 'realloc'}} \
+// expected-note{{'realloc' is a builtin with type 'void *(void *,}}
+ return p;
+}
+
+// PR3855
+void snprintf(); // expected-warning{{incompatible redeclaration of library function 'snprintf'}} \
+ // expected-note{{'snprintf' is a builtin}}
+
+int
+main(int argc, char *argv[])
+{
+ snprintf();
+}
+
+void snprintf() { }
+
+// PR8316
+void longjmp(); // expected-warning{{declaration of built-in function 'longjmp' requires inclusion of the header <setjmp.h>}}
diff --git a/clang/test/Sema/implicit-builtin-freestanding.c b/clang/test/Sema/implicit-builtin-freestanding.c
new file mode 100644
index 0000000..505e522
--- /dev/null
+++ b/clang/test/Sema/implicit-builtin-freestanding.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -ffreestanding %s
+
+int malloc(int a) { return a; }
+
diff --git a/clang/test/Sema/implicit-builtin-redecl.c b/clang/test/Sema/implicit-builtin-redecl.c
new file mode 100644
index 0000000..9fb7e62
--- /dev/null
+++ b/clang/test/Sema/implicit-builtin-redecl.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// PR3592
+static void* malloc(int);
+static void* malloc(int size) {
+ return ((void*)0); /*do not use heap in this file*/
+}
+
+void *calloc(int, int, int); // expected-warning{{incompatible redeclaration of library function 'calloc'}} \
+// expected-note{{'calloc' is a builtin with type 'void *}}
+
+void f1(void) {
+ calloc(0, 0, 0);
+}
+
+void f2() {
+ int index = 1;
+}
+
+static int index;
+
+int f3() {
+ return index << 2;
+}
+
+typedef int rindex;
diff --git a/clang/test/Sema/implicit-cast.c b/clang/test/Sema/implicit-cast.c
new file mode 100644
index 0000000..088b195
--- /dev/null
+++ b/clang/test/Sema/implicit-cast.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only %s
+
+static char *test1(int cf) {
+ return cf ? "abc" : 0;
+}
+static char *test2(int cf) {
+ return cf ? 0 : "abc";
+}
diff --git a/clang/test/Sema/implicit-decl.c b/clang/test/Sema/implicit-decl.c
new file mode 100644
index 0000000..ffab9a6
--- /dev/null
+++ b/clang/test/Sema/implicit-decl.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -Werror
+
+typedef int int32_t;
+typedef unsigned char Boolean;
+
+extern int printf(__const char *__restrict __format, ...); // expected-note{{'printf' declared here}}
+
+void func() {
+ int32_t *vector[16];
+ const char compDesc[16 + 1];
+ int32_t compCount = 0;
+ if (_CFCalendarDecomposeAbsoluteTimeV(compDesc, vector, compCount)) { // expected-note {{previous implicit declaration is here}} \
+ expected-error {{implicit declaration of function '_CFCalendarDecomposeAbsoluteTimeV' is invalid in C99}}
+ }
+
+ printg("Hello, World!\n"); // expected-error{{implicit declaration of function 'printg' is invalid in C99}} \
+ // expected-note{{did you mean 'printf'?}}
+
+ __builtin_is_les(1, 3); // expected-error{{use of unknown builtin '__builtin_is_les'}}
+}
+Boolean _CFCalendarDecomposeAbsoluteTimeV(const char *componentDesc, int32_t **vector, int32_t count) { // expected-error{{conflicting types for '_CFCalendarDecomposeAbsoluteTimeV'}}
+ return 0;
+}
+
+
+// Test the typo-correction callback in Sema::ImplicitlyDefineFunction
+extern int sformatf(char *str, __const char *__restrict __format, ...); // expected-note{{'sformatf' declared here}}
+void test_implicit() {
+ int formats = 0;
+ formatd("Hello, World!\n"); // expected-error{{implicit declaration of function 'formatd' is invalid in C99}} \
+ // expected-note{{did you mean 'sformatf'?}}
+}
diff --git a/clang/test/Sema/implicit-def.c b/clang/test/Sema/implicit-def.c
new file mode 100644
index 0000000..6caa090
--- /dev/null
+++ b/clang/test/Sema/implicit-def.c
@@ -0,0 +1,8 @@
+/* RUN: %clang_cc1 -fsyntax-only %s -std=c89
+ * RUN: not %clang_cc1 -fsyntax-only %s -std=c99 -pedantic-errors
+ */
+
+int A() {
+ return X();
+}
+
diff --git a/clang/test/Sema/implicit-int.c b/clang/test/Sema/implicit-int.c
new file mode 100644
index 0000000..3063db6
--- /dev/null
+++ b/clang/test/Sema/implicit-int.c
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify -pedantic
+
+foo() { // expected-warning {{type specifier missing, defaults to 'int'}}
+ return 0;
+}
+
+y; // expected-warning {{type specifier missing, defaults to 'int'}}
+
+// rdar://6131634
+void f((x)); // expected-warning {{type specifier missing, defaults to 'int'}}
+
+
+// PR3702
+#define PAD(ms10) { \
+ register i; \
+}
+
+#define ILPAD() PAD((NROW - tt.tt_row) * 10) /* 1 ms per char */
+
+void
+h19_insline(n) // expected-warning {{parameter 'n' was not declared, defaulting to type 'int'}}
+{
+ ILPAD(); // expected-warning {{type specifier missing, defaults to 'int'}}
+}
+
+struct foo {
+ __extension__ __attribute__((packed)) x : 4; // expected-warning {{type specifier missing, defaults to 'int'}}
+};
diff --git a/clang/test/Sema/incompatible-sign.c b/clang/test/Sema/incompatible-sign.c
new file mode 100644
index 0000000..6249feb
--- /dev/null
+++ b/clang/test/Sema/incompatible-sign.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+int a(int* x); // expected-note{{passing argument to parameter 'x' here}}
+int b(unsigned* y) { return a(y); } // expected-warning {{passing 'unsigned int *' to parameter of type 'int *' converts between pointers to integer types with different sign}}
+
diff --git a/clang/test/Sema/incomplete-call.c b/clang/test/Sema/incomplete-call.c
new file mode 100644
index 0000000..d34bda5
--- /dev/null
+++ b/clang/test/Sema/incomplete-call.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct foo; // expected-note 3 {{forward declaration of 'struct foo'}}
+
+struct foo a(); // expected-note {{'a' declared here}}
+void b(struct foo);
+void c();
+
+void func(void *p) {
+ a(); // expected-error{{calling 'a' with incomplete return type 'struct foo'}}
+ b(*(struct foo*)p); // expected-error{{argument type 'struct foo' is incomplete}}
+ c(*(struct foo*)p); // expected-error{{argument type 'struct foo' is incomplete}}
+}
diff --git a/clang/test/Sema/incomplete-decl.c b/clang/test/Sema/incomplete-decl.c
new file mode 100644
index 0000000..0214a0c
--- /dev/null
+++ b/clang/test/Sema/incomplete-decl.c
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct foo; // expected-note 5 {{forward declaration of 'struct foo'}}
+
+void b; // expected-error {{variable has incomplete type 'void'}}
+struct foo f; // expected-error{{tentative definition has type 'struct foo' that is never completed}}
+
+static void c; // expected-error {{variable has incomplete type 'void'}}
+static struct foo g; // expected-warning {{tentative definition of variable with internal linkage has incomplete non-array type 'struct foo'}} \
+ expected-error{{tentative definition has type 'struct foo' that is never completed}}
+
+extern void d;
+extern struct foo e;
+
+int ary[]; // expected-warning {{tentative array definition assumed to have one element}}
+struct foo bary[]; // expected-error {{array has incomplete element type 'struct foo'}}
+
+void func() {
+ int ary[]; // expected-error{{definition of variable with array type needs an explicit size or an initializer}}
+ void b; // expected-error {{variable has incomplete type 'void'}}
+ struct foo f; // expected-error {{variable has incomplete type 'struct foo'}}
+}
+
+int h[]; // expected-warning {{tentative array definition assumed to have one element}}
+int (*i)[] = &h+1; // expected-error {{arithmetic on a pointer to an incomplete type 'int []'}}
+
+struct bar j = {1}; // expected-error {{variable has incomplete type 'struct bar'}} \
+ expected-note {{forward declaration of 'struct bar'}}
+struct bar k;
+struct bar { int a; };
+
diff --git a/clang/test/Sema/indirect-goto.c b/clang/test/Sema/indirect-goto.c
new file mode 100644
index 0000000..4c1c6c3
--- /dev/null
+++ b/clang/test/Sema/indirect-goto.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct c {int x;};
+int a(struct c x, long long y) {
+ void const* l1_ptr = &&l1;
+ goto *l1_ptr;
+l1:
+ goto *x; // expected-error{{incompatible type}}
+ goto *y; // expected-warning{{incompatible integer to pointer conversion}}
+}
+
diff --git a/clang/test/Sema/init-struct-qualified.c b/clang/test/Sema/init-struct-qualified.c
new file mode 100644
index 0000000..49ec7cc
--- /dev/null
+++ b/clang/test/Sema/init-struct-qualified.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify < %s
+typedef float CGFloat;
+typedef struct _NSPoint { CGFloat x; CGFloat y; } NSPoint;
+typedef struct _NSSize { CGFloat width; CGFloat height; } NSSize;
+typedef struct _NSRect { NSPoint origin; NSSize size; } NSRect;
+
+extern const NSPoint NSZeroPoint;
+
+extern NSSize canvasSize();
+void func() {
+ const NSRect canvasRect = { NSZeroPoint, canvasSize() };
+}
diff --git a/clang/test/Sema/init-vector.c b/clang/test/Sema/init-vector.c
new file mode 100644
index 0000000..f0cf32b
--- /dev/null
+++ b/clang/test/Sema/init-vector.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+typedef float __attribute__((vector_size (16))) v4f_t;
+
+typedef union {
+ struct {
+ float x, y, z, w;
+ }s;
+ v4f_t v;
+} vector_t;
+
+
+vector_t foo(v4f_t p)
+{
+ vector_t v = {.v = p};
+ return v;
+}
diff --git a/clang/test/Sema/init.c b/clang/test/Sema/init.c
new file mode 100644
index 0000000..81a665d
--- /dev/null
+++ b/clang/test/Sema/init.c
@@ -0,0 +1,159 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -ffreestanding
+
+#include <stddef.h>
+#include <stdint.h>
+
+typedef void (* fp)(void);
+void foo(void);
+
+// PR clang/3377
+fp a[(short int)1] = { foo };
+
+int myArray[5] = {1, 2, 3, 4, 5};
+int *myPointer2 = myArray;
+int *myPointer = &(myArray[2]);
+
+
+extern int x;
+void *g = &x;
+int *h = &x;
+
+struct union_crash
+{
+ union
+ {
+ };
+};
+
+int test() {
+ int a[10];
+ int b[10] = a; // expected-error {{array initializer must be an initializer list}}
+ int +; // expected-error {{expected identifier or '('}}
+
+ struct union_crash u = { .d = 1 }; // expected-error {{field designator 'd' does not refer to any field in type 'struct union_crash'}}
+}
+
+
+// PR2050
+struct cdiff_cmd {
+ const char *name;
+ unsigned short argc;
+ int (*handler)();
+};
+int cdiff_cmd_open();
+struct cdiff_cmd commands[] = {
+ {"OPEN", 1, &cdiff_cmd_open }
+};
+
+// PR2348
+static struct { int z; } s[2];
+int *t = &(*s).z;
+
+// PR2349
+short *a2(void)
+{
+ short int b;
+ static short *bp = &b; // expected-error {{initializer element is not a compile-time constant}}
+
+ return bp;
+}
+
+int pbool(void) {
+ typedef const _Bool cbool;
+ _Bool pbool1 = (void *) 0;
+ cbool pbool2 = &pbool;
+ return pbool2;
+}
+
+
+// rdar://5870981
+union { float f; unsigned u; } u = { 1.0f };
+
+// rdar://6156694
+int f3(int x) { return x; }
+typedef void (*vfunc)(void);
+void *bar = (vfunc) f3;
+
+// PR2747
+struct sym_reg {
+ char nc_gpreg;
+};
+int sym_fw1a_scr[] = {
+ ((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0,
+ 8 * ((int)(&((struct sym_reg *)0)->nc_gpreg))
+};
+
+// PR3001
+struct s1 s2 = { // expected-error {{variable has incomplete type 'struct s1'}} \
+ // expected-note {{forward declaration of 'struct s1'}}
+ .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \
+ // expected-note{{forward declaration of 'struct s3'}}
+ .b = bogus // expected-error {{use of undeclared identifier 'bogus'}}
+}
+
+// PR3382
+char t[] = ("Hello");
+
+// <rdar://problem/6094855>
+typedef struct { } empty;
+
+typedef struct {
+ empty e;
+ int i2;
+} st;
+
+st st1 = { .i2 = 1 };
+
+// <rdar://problem/6096826>
+struct {
+ int a;
+ int z[2];
+} y = { .z = {} };
+
+int bbb[10];
+
+struct foo2 {
+ uintptr_t a;
+};
+
+struct foo2 bar2[] = {
+ { (intptr_t)bbb }
+};
+
+struct foo2 bar3 = { 1, 2 }; // expected-warning{{excess elements in struct initializer}}
+
+int* ptest1 = __builtin_choose_expr(1, (int*)0, (int*)0);
+
+typedef int32_t ivector4 __attribute((vector_size(16)));
+ivector4 vtest1 = 1 ? (ivector4){1} : (ivector4){1};
+ivector4 vtest2 = __builtin_choose_expr(1, (ivector4){1}, (ivector4){1});
+
+uintptr_t ptrasintadd1 = (uintptr_t)&a - 4;
+uintptr_t ptrasintadd2 = (uintptr_t)&a + 4;
+uintptr_t ptrasintadd3 = 4 + (uintptr_t)&a;
+
+// PR4285
+const wchar_t widestr[] = L"asdf";
+
+// PR5447
+const double pr5447 = (0.05 < -1.0) ? -1.0 : 0.0499878;
+
+// PR4386
+
+// None of these are constant initializers, but we implement GCC's old
+// behaviour of accepting bar and zed but not foo. GCC's behaviour was
+// changed in 2007 (rev 122551), so we should be able to change too one
+// day.
+int PR4386_bar();
+int PR4386_foo() __attribute((weak));
+int PR4386_zed();
+
+int PR4386_a = ((void *) PR4386_bar) != 0;
+int PR4386_b = ((void *) PR4386_foo) != 0; // expected-error{{initializer element is not a compile-time constant}}
+int PR4386_c = ((void *) PR4386_zed) != 0;
+int PR4386_zed() __attribute((weak));
+
+// <rdar://problem/10185490> (derived from SPEC vortex benchmark)
+typedef char strty[10];
+struct vortexstruct { strty s; };
+struct vortexstruct vortexvar = { "asdf" };
diff --git a/clang/test/Sema/initialize-noreturn.c b/clang/test/Sema/initialize-noreturn.c
new file mode 100644
index 0000000..5557862
--- /dev/null
+++ b/clang/test/Sema/initialize-noreturn.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+// rdar://10095762
+
+typedef void (*Fn_noret)(void) __attribute__((noreturn));
+typedef void (*Fn_ret)(void);
+
+void foo(void);
+void foo_noret(void) __attribute__((noreturn));
+
+void test() {
+ Fn_noret fn2 = &foo; // expected-warning {{incompatible pointer types initializing 'Fn_noret'}}
+ Fn_noret fn3 = &foo_noret;
+ Fn_ret fn4 = &foo_noret;
+ Fn_ret fn5 = &foo;
+}
+
diff --git a/clang/test/Sema/inline-redef.c b/clang/test/Sema/inline-redef.c
new file mode 100644
index 0000000..4a46e11
--- /dev/null
+++ b/clang/test/Sema/inline-redef.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -std=gnu89 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#if __STDC_VERSION__ >= 199901
+#define GNU_INLINE __attribute((__gnu_inline__))
+#else
+#define GNU_INLINE
+#endif
+
+// PR5253
+// rdar://9559708 (same extension in C99 mode)
+// GNU Extension: check that we can redefine an extern inline function
+GNU_INLINE extern inline int f(int a) {return a;}
+int f(int b) {return b;} // expected-note{{previous definition is here}}
+// And now check that we can't redefine a normal function
+int f(int c) {return c;} // expected-error{{redefinition of 'f'}}
+
+// Check that we can redefine an extern inline function as a static function
+GNU_INLINE extern inline int g(int a) {return a;}
+static int g(int b) {return b;}
+
+// Check that we ensure the types of the two definitions are the same
+GNU_INLINE extern inline int h(int a) {return a;} // expected-note{{previous definition is here}}
+int h(short b) {return b;} // expected-error{{conflicting types for 'h'}}
diff --git a/clang/test/Sema/inline.c b/clang/test/Sema/inline.c
new file mode 100644
index 0000000..3c99f24
--- /dev/null
+++ b/clang/test/Sema/inline.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// Check that we don't allow illegal uses of inline
+inline int a; // expected-error{{'inline' can only appear on functions}}
+typedef inline int b; // expected-error{{'inline' can only appear on functions}}
+int d(inline int a); // expected-error{{'inline' can only appear on functions}}
diff --git a/clang/test/Sema/int-arith-convert.c b/clang/test/Sema/int-arith-convert.c
new file mode 100644
index 0000000..c56ab3b
--- /dev/null
+++ b/clang/test/Sema/int-arith-convert.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple=i686-linux-gnu -fsyntax-only -verify %s
+
+// Check types are the same through redeclaration
+unsigned long x;
+__typeof(1u+1l) x;
+
+unsigned y;
+__typeof(1+1u) y;
+__typeof(1u+1) y;
+
+long long z;
+__typeof(1ll+1u) z;
diff --git a/clang/test/Sema/invalid-decl.c b/clang/test/Sema/invalid-decl.c
new file mode 100644
index 0000000..a5e7ad3
--- /dev/null
+++ b/clang/test/Sema/invalid-decl.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+void test() {
+ char = 4; // expected-error {{expected identifier}}
+}
+
+
+// PR2400
+typedef xtype (*x)(void* handle); // expected-error {{function cannot return function type}} expected-warning {{type specifier missing, defaults to 'int'}} expected-warning {{type specifier missing, defaults to 'int'}}
+
+typedef void ytype();
+
+
+typedef struct _zend_module_entry zend_module_entry;
+struct _zend_module_entry {
+ ytype globals_size; // expected-error {{field 'globals_size' declared as a function}}
+};
+
+zend_module_entry openssl_module_entry = {
+ sizeof(zend_module_entry)
+};
+
diff --git a/clang/test/Sema/invalid-init-diag.c b/clang/test/Sema/invalid-init-diag.c
new file mode 100644
index 0000000..3e4870e
--- /dev/null
+++ b/clang/test/Sema/invalid-init-diag.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+int a;
+struct {int x;} x = a; // expected-error {{with an expression of incompatible type 'int'}}
diff --git a/clang/test/Sema/invalid-struct-init.c b/clang/test/Sema/invalid-struct-init.c
new file mode 100644
index 0000000..000d3ab
--- /dev/null
+++ b/clang/test/Sema/invalid-struct-init.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+typedef struct _zend_module_entry zend_module_entry;
+struct _zend_module_entry {
+ _efree((p)); // expected-error{{type name requires a specifier or qualifier}} \
+ expected-warning {{type specifier missing, defaults to 'int'}}
+
+};
+typedef struct _zend_function_entry { } zend_function_entry;
+typedef struct _zend_pcre_globals { } zend_pcre_globals;
+zend_pcre_globals pcre_globals;
+
+static void zm_globals_ctor_pcre(zend_pcre_globals *pcre_globals ) { }
+static void zm_globals_dtor_pcre(zend_pcre_globals *pcre_globals ) { }
+static void zm_info_pcre(zend_module_entry *zend_module ) { }
+static int zm_startup_pcre(int type, int module_number ) { }
+
+static int zm_shutdown_pcre(int type, int module_number ) {
+ zend_function_entry pcre_functions[] = {{ }; // expected-error{{expected '}'}} expected-note {{to match this '{'}}
+ zend_module_entry pcre_module_entry = {
+ sizeof(zend_module_entry), 20071006, 0, 0, ((void *)0), ((void *)0),
+ "pcre", pcre_functions, zm_startup_pcre, zm_shutdown_pcre, ((void *)0),
+ ((void *)0), zm_info_pcre, ((void *)0), sizeof(zend_pcre_globals), &pcre_globals,
+ ((void (*)(void* ))(zm_globals_ctor_pcre)), ((void (*)(void* ))(zm_globals_dtor_pcre)),
+ ((void *)0), 0, 0, ((void *)0), 0
+ };
+}
diff --git a/clang/test/Sema/knr-def-call.c b/clang/test/Sema/knr-def-call.c
new file mode 100644
index 0000000..f41275d
--- /dev/null
+++ b/clang/test/Sema/knr-def-call.c
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -Wconversion -Wliteral-conversion -fsyntax-only -verify %s
+
+// C DR #316, PR 3626.
+void f0(a, b, c, d) int a,b,c,d; {}
+void t0(void) {
+ f0(1); // expected-warning{{too few arguments}}
+}
+
+void f1(a, b) int a, b; {}
+void t1(void) {
+ f1(1, 2, 3); // expected-warning{{too many arguments}}
+}
+
+void f2(float); // expected-note{{previous declaration is here}}
+void f2(x) float x; { } // expected-warning{{promoted type 'double' of K&R function parameter is not compatible with the parameter type 'float' declared in a previous prototype}}
+
+typedef void (*f3)(void);
+f3 t3(int b) { return b? f0 : f1; } // okay
+
+// <rdar://problem/8193107>
+void f4() {
+ char *rindex();
+}
+
+char *rindex(s, c)
+ register char *s, c; // expected-warning{{promoted type 'char *' of K&R function parameter is not compatible with the parameter type 'const char *' declared in a previous prototype}}
+{
+ return 0;
+}
+
+// PR8314
+void proto(int);
+void proto(x)
+ int x;
+{
+}
+
+void use_proto() {
+ proto(42.1); // expected-warning{{implicit conversion turns literal floating-point number into integer}}
+ (&proto)(42.1); // expected-warning{{implicit conversion turns literal floating-point number into integer}}
+}
diff --git a/clang/test/Sema/knr-variadic-def.c b/clang/test/Sema/knr-variadic-def.c
new file mode 100644
index 0000000..6d5d632
--- /dev/null
+++ b/clang/test/Sema/knr-variadic-def.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
+// PR4287
+
+#include <stdarg.h>
+char *foo = "test";
+int test(char*,...);
+
+int test(fmt)
+ char*fmt;
+{
+ va_list ap;
+ char*a;
+ int x;
+
+ va_start(ap,fmt);
+ a=va_arg(ap,char*);
+ x=(a!=foo);
+ va_end(ap);
+ return x;
+}
+
+void exit();
+
+int main(argc,argv)
+ int argc;char**argv;
+{
+ exit(test("",foo));
+}
+
diff --git a/clang/test/Sema/many-logical-ops.c b/clang/test/Sema/many-logical-ops.c
new file mode 100644
index 0000000..09a7684
--- /dev/null
+++ b/clang/test/Sema/many-logical-ops.c
@@ -0,0 +1,2010 @@
+// RUN: %clang_cc1 -fsyntax-only -Wconstant-conversion -verify %s
+
+// rdar://10913206&10941790
+// Check that we don't get stack overflow trying to evaluate a huge number of
+// logical operators.
+
+int foo(int x) {
+ return
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x &&
+ x;
+}
diff --git a/clang/test/Sema/many-parameters.c b/clang/test/Sema/many-parameters.c
new file mode 100644
index 0000000..1473c94
--- /dev/null
+++ b/clang/test/Sema/many-parameters.c
@@ -0,0 +1,310 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c99 %s
+
+// This test simply tests that the compiler does not crash. An optimization
+// in ParmVarDecls means that functions with fewer than 256 parameters use a fast path,
+// while those with >= 256 parameters use a slow path.
+//
+// Crash was reported in PR 10538.
+
+void foo(
+int x0,
+int x1,
+int x2,
+int x3,
+int x4,
+int x5,
+int x6,
+int x7,
+int x8,
+int x9,
+int x10,
+int x11,
+int x12,
+int x13,
+int x14,
+int x15,
+int x16,
+int x17,
+int x18,
+int x19,
+int x20,
+int x21,
+int x22,
+int x23,
+int x24,
+int x25,
+int x26,
+int x27,
+int x28,
+int x29,
+int x30,
+int x31,
+int x32,
+int x33,
+int x34,
+int x35,
+int x36,
+int x37,
+int x38,
+int x39,
+int x40,
+int x41,
+int x42,
+int x43,
+int x44,
+int x45,
+int x46,
+int x47,
+int x48,
+int x49,
+int x50,
+int x51,
+int x52,
+int x53,
+int x54,
+int x55,
+int x56,
+int x57,
+int x58,
+int x59,
+int x60,
+int x61,
+int x62,
+int x63,
+int x64,
+int x65,
+int x66,
+int x67,
+int x68,
+int x69,
+int x70,
+int x71,
+int x72,
+int x73,
+int x74,
+int x75,
+int x76,
+int x77,
+int x78,
+int x79,
+int x80,
+int x81,
+int x82,
+int x83,
+int x84,
+int x85,
+int x86,
+int x87,
+int x88,
+int x89,
+int x90,
+int x91,
+int x92,
+int x93,
+int x94,
+int x95,
+int x96,
+int x97,
+int x98,
+int x99,
+int x100,
+int x101,
+int x102,
+int x103,
+int x104,
+int x105,
+int x106,
+int x107,
+int x108,
+int x109,
+int x110,
+int x111,
+int x112,
+int x113,
+int x114,
+int x115,
+int x116,
+int x117,
+int x118,
+int x119,
+int x120,
+int x121,
+int x122,
+int x123,
+int x124,
+int x125,
+int x126,
+int x127,
+int x128,
+int x129,
+int x130,
+int x131,
+int x132,
+int x133,
+int x134,
+int x135,
+int x136,
+int x137,
+int x138,
+int x139,
+int x140,
+int x141,
+int x142,
+int x143,
+int x144,
+int x145,
+int x146,
+int x147,
+int x148,
+int x149,
+int x150,
+int x151,
+int x152,
+int x153,
+int x154,
+int x155,
+int x156,
+int x157,
+int x158,
+int x159,
+int x160,
+int x161,
+int x162,
+int x163,
+int x164,
+int x165,
+int x166,
+int x167,
+int x168,
+int x169,
+int x170,
+int x171,
+int x172,
+int x173,
+int x174,
+int x175,
+int x176,
+int x177,
+int x178,
+int x179,
+int x180,
+int x181,
+int x182,
+int x183,
+int x184,
+int x185,
+int x186,
+int x187,
+int x188,
+int x189,
+int x190,
+int x191,
+int x192,
+int x193,
+int x194,
+int x195,
+int x196,
+int x197,
+int x198,
+int x199,
+int x200,
+int x201,
+int x202,
+int x203,
+int x204,
+int x205,
+int x206,
+int x207,
+int x208,
+int x209,
+int x210,
+int x211,
+int x212,
+int x213,
+int x214,
+int x215,
+int x216,
+int x217,
+int x218,
+int x219,
+int x220,
+int x221,
+int x222,
+int x223,
+int x224,
+int x225,
+int x226,
+int x227,
+int x228,
+int x229,
+int x230,
+int x231,
+int x232,
+int x233,
+int x234,
+int x235,
+int x236,
+int x237,
+int x238,
+int x239,
+int x240,
+int x241,
+int x242,
+int x243,
+int x244,
+int x245,
+int x246,
+int x247,
+int x248,
+int x249,
+int x250,
+int x251,
+int x252,
+int x253,
+int x254,
+int x255,
+int x256,
+int x257,
+int x258,
+int x259,
+int x260,
+int x261,
+int x262,
+int x263,
+int x264,
+int x265,
+int x266,
+int x267,
+int x268,
+int x269,
+int x270,
+int x271,
+int x272,
+int x273,
+int x274,
+int x275,
+int x276,
+int x277,
+int x278,
+int x279,
+int x280,
+int x281,
+int x282,
+int x283,
+int x284,
+int x285,
+int x286,
+int x287,
+int x288,
+int x289,
+int x290,
+int x291,
+int x292,
+int x293,
+int x294,
+int x295,
+int x296,
+int x297,
+int x298,
+int x299
+);
diff --git a/clang/test/Sema/member-reference.c b/clang/test/Sema/member-reference.c
new file mode 100644
index 0000000..7bda143
--- /dev/null
+++ b/clang/test/Sema/member-reference.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+struct simple { int i; };
+
+void f(void) {
+ struct simple s[1];
+ s->i = 1;
+}
+
+typedef int x;
+struct S {
+ int x;
+ x z;
+};
+
+void g(void) {
+ struct S s[1];
+ s->x = 1;
+ s->z = 2;
+}
diff --git a/clang/test/Sema/memset-invalid.c b/clang/test/Sema/memset-invalid.c
new file mode 100644
index 0000000..c763858
--- /dev/null
+++ b/clang/test/Sema/memset-invalid.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+
+char memset(); // expected-warning {{incompatible redeclaration of library function 'memset'}} expected-note{{'memset' is a builtin with type}}
+char test() {
+ return memset();
+}
diff --git a/clang/test/Sema/merge-decls.c b/clang/test/Sema/merge-decls.c
new file mode 100644
index 0000000..1a84d33
--- /dev/null
+++ b/clang/test/Sema/merge-decls.c
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+void foo(void);
+void foo(void) {}
+void foo(void);
+void foo(void); // expected-note {{previous declaration is here}}
+
+void foo(int); // expected-error {{conflicting types for 'foo'}}
+
+int funcdef()
+{
+ return 0;
+}
+
+int funcdef();
+
+int funcdef2() { return 0; } // expected-note {{previous definition is here}}
+int funcdef2() { return 0; } // expected-error {{redefinition of 'funcdef2'}}
+
+// PR2502
+void (*f)(void);
+void (*f)() = 0;
+
+typedef __attribute__(( ext_vector_type(2) )) int Vi2;
+typedef __attribute__(( ext_vector_type(2) )) float Vf2;
+
+Vf2 g0; // expected-note {{previous definition is here}}
+Vi2 g0; // expected-error {{redefinition of 'g0'}}
+
+_Complex int g1; // expected-note {{previous definition is here}}
+_Complex float g1; // expected-error {{redefinition of 'g1'}}
+
+// rdar://6096412
+extern char i6096412[10];
+extern char i6096412[];
+void foo6096412(void) {
+ int x = sizeof(i6096412);
+}
+
diff --git a/clang/test/Sema/missing-field-initializers.c b/clang/test/Sema/missing-field-initializers.c
new file mode 100644
index 0000000..90e0e2a
--- /dev/null
+++ b/clang/test/Sema/missing-field-initializers.c
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wmissing-field-initializers %s
+
+// This was PR4808.
+
+struct Foo { int a, b; };
+
+struct Foo foo0 = { 1 }; // expected-warning {{missing field 'b' initializer}}
+struct Foo foo1 = { .a = 1 }; // designator avoids MFI warning
+struct Foo foo2 = { .b = 1 }; // designator avoids MFI warning
+
+struct Foo bar0[] = {
+ { 1,2 },
+ { 1 }, // expected-warning {{missing field 'b' initializer}}
+ { 1,2 }
+};
+
+struct Foo bar1[] = {
+ 1, 2,
+ 1, 2,
+ 1
+}; // expected-warning {{missing field 'b' initializer}}
+
+struct Foo bar2[] = { {}, {}, {} };
+
+struct One { int a; int b; };
+struct Two { float c; float d; float e; };
+
+struct Three {
+ union {
+ struct One one;
+ struct Two two;
+ } both;
+};
+
+struct Three t0 = {
+ { .one = { 1, 2 } }
+};
+struct Three t1 = {
+ { .two = { 1.0f, 2.0f, 3.0f } }
+};
+
+struct Three data[] = {
+ { { .one = { 1, 2 } } },
+ { { .one = { 1 } } }, // expected-warning {{missing field 'b' initializer}}
+ { { .two = { 1.0f, 2.0f, 3.0f } } },
+ { { .two = { 1.0f, 2.0f } } } // expected-warning {{missing field 'e' initializer}}
+};
+
+struct { int:5; int a; int:5; int b; int:5; } noNamedImplicit[] = {
+ { 1, 2 },
+ { 1 } // expected-warning {{missing field 'b' initializer}}
+};
diff --git a/clang/test/Sema/ms_class_layout.cpp b/clang/test/Sema/ms_class_layout.cpp
new file mode 100644
index 0000000..ea3f899
--- /dev/null
+++ b/clang/test/Sema/ms_class_layout.cpp
@@ -0,0 +1,335 @@
+// RUN: %clang_cc1 -emit-llvm-only -triple i686-pc-win32 -fdump-record-layouts -cxx-abi microsoft %s 2>&1 \
+// RUN: | FileCheck %s
+
+#pragma pack(push, 8)
+
+class B {
+public:
+ virtual void b(){}
+ int b_field;
+protected:
+private:
+};
+
+class A : public B {
+public:
+ int a_field;
+ virtual void a(){}
+ char one;
+protected:
+private:
+};
+
+class D {
+public:
+ virtual void b(){}
+ double a;
+};
+
+class C : public virtual A,
+ public D, public B {
+public:
+ double c1_field;
+ int c2_field;
+ double c3_field;
+ int c4_field;
+ virtual void foo(){}
+ virtual void bar(){}
+protected:
+private:
+};
+
+struct BaseStruct
+{
+ BaseStruct(){}
+ double v0;
+ float v1;
+ C fg;
+};
+
+struct DerivedStruct : public BaseStruct {
+ int x;
+};
+
+struct G
+{
+ int g_field;
+};
+
+struct H : public G,
+ public virtual D
+{
+};
+
+struct I : public virtual D
+{
+ virtual ~I(){}
+ double q;
+};
+
+struct K
+{
+ int k;
+};
+
+struct L
+{
+ int l;
+};
+
+struct M : public virtual K
+{
+ int m;
+};
+
+struct N : public L, public M
+{
+ virtual void f(){}
+};
+
+struct O : public H, public G {
+ virtual void fo(){}
+};
+
+struct P : public M, public virtual L {
+ int p;
+};
+
+struct R {};
+
+#pragma pack(pop)
+
+// This needs only for building layouts.
+// Without this clang doesn`t dump record layouts.
+int main() {
+ // This avoid "Can't yet mangle constructors!" for MS ABI.
+ C* c;
+ c->foo();
+ DerivedStruct* v;
+ H* g;
+ BaseStruct* u;
+ I* i;
+ N* n;
+ O* o;
+ P* p;
+ R* r;
+ return 0;
+}
+
+// CHECK: 0 | class D
+// CHECK-NEXT: 0 | (D vftable pointer)
+// CHECK-NEXT: 8 | double a
+
+// CHECK-NEXT: sizeof=16, dsize=16, align=8
+// CHECK-NEXT: nvsize=16, nvalign=8
+
+// CHECK: %class.D = type { i32 (...)**, double }
+
+// CHECK: 0 | class B
+// CHECK-NEXT: 0 | (B vftable pointer)
+// CHECK-NEXT: 4 | int b_field
+
+// CHECK-NEXT: sizeof=8, dsize=8, align=4
+// CHECK-NEXT: nvsize=8, nvalign=4
+
+// CHECK: %class.B = type { i32 (...)**, i32 }
+
+// CHECK: 0 | class A
+// CHECK-NEXT: 0 | class B (primary base)
+// CHECK-NEXT: 0 | (B vftable pointer)
+// CHECK-NEXT: 4 | int b_field
+// CHECK-NEXT: 8 | int a_field
+// CHECK-NEXT: 12 | char one
+
+// CHECK-NEXT: sizeof=16, dsize=16, align=4
+// CHECK-NEXT: nvsize=16, nvalign=4
+
+// CHECK: 0 | class C
+// CHECK-NEXT: 0 | class D (primary base)
+// CHECK-NEXT: 0 | (D vftable pointer)
+// CHECK-NEXT: 8 | double a
+// CHECK-NEXT: 16 | class B (base)
+// CHECK-NEXT: 16 | (B vftable pointer)
+// CHECK-NEXT: 20 | int b_field
+// CHECK-NEXT: 24 | (C vbtable pointer)
+// CHECK-NEXT: 32 | double c1_field
+// CHECK-NEXT: 40 | int c2_field
+// CHECK-NEXT: 48 | double c3_field
+// CHECK-NEXT: 56 | int c4_field
+// CHECK-NEXT: 64 | class A (virtual base)
+// CHECK-NEXT: 64 | class B (primary base)
+// CHECK-NEXT: 64 | (B vftable pointer)
+// CHECK-NEXT: 68 | int b_field
+// CHECK-NEXT: 72 | int a_field
+// CHECK-NEXT: 76 | char one
+
+// CHECK-NEXT: sizeof=80, dsize=80, align=8
+// CHECK-NEXT: nvsize=64, nvalign=8
+
+// CHECK: %class.A = type { %class.B, i32, i8 }
+
+// CHECK: %class.C = type { %class.D, %class.B, i32*, double, i32, double, i32, [4 x i8], %class.A }
+// CHECK: %class.C.base = type { %class.D, %class.B, i32*, double, i32, double, i32 }
+
+// CHECK: 0 | struct BaseStruct
+// CHECK-NEXT: 0 | double v0
+// CHECK-NEXT: 8 | float v1
+// CHECK-NEXT: 16 | class C fg
+// CHECK-NEXT: 16 | class D (primary base)
+// CHECK-NEXT: 16 | (D vftable pointer)
+// CHECK-NEXT: 24 | double a
+// CHECK-NEXT: 32 | class B (base)
+// CHECK-NEXT: 32 | (B vftable pointer)
+// CHECK-NEXT: 36 | int b_field
+// CHECK-NEXT: 40 | (C vbtable pointer)
+// CHECK-NEXT: 48 | double c1_field
+// CHECK-NEXT: 56 | int c2_field
+// CHECK-NEXT: 64 | double c3_field
+// CHECK-NEXT: 72 | int c4_field
+// CHECK-NEXT: 80 | class A (virtual base)
+// CHECK-NEXT: 80 | class B (primary base)
+// CHECK-NEXT: 80 | (B vftable pointer)
+// CHECK-NEXT: 84 | int b_field
+// CHECK-NEXT: 88 | int a_field
+// CHECK-NEXT: 92 | char one
+
+// CHECK-NEXT: sizeof=80, dsize=80, align=8
+// CHECK-NEXT: nvsize=64, nvalign=8
+
+// CHECK: sizeof=96, dsize=96, align=8
+// CHECK-NEXT: nvsize=96, nvalign=8
+
+// CHECK: %struct.BaseStruct = type { double, float, %class.C }
+
+// CHECK: 0 | struct DerivedStruct
+// CHECK-NEXT: 0 | struct BaseStruct (base)
+// CHECK-NEXT: 0 | double v0
+// CHECK-NEXT: 8 | float v1
+// CHECK-NEXT: 16 | class C fg
+// CHECK-NEXT: 16 | class D (primary base)
+// CHECK-NEXT: 16 | (D vftable pointer)
+// CHECK-NEXT: 24 | double a
+// CHECK-NEXT: 32 | class B (base)
+// CHECK-NEXT: 32 | (B vftable pointer)
+// CHECK-NEXT: 36 | int b_field
+// CHECK-NEXT: 40 | (C vbtable pointer)
+// CHECK-NEXT: 48 | double c1_field
+// CHECK-NEXT: 56 | int c2_field
+// CHECK-NEXT: 64 | double c3_field
+// CHECK-NEXT: 72 | int c4_field
+// CHECK-NEXT: 80 | class A (virtual base)
+// CHECK-NEXT: 80 | class B (primary base)
+// CHECK-NEXT: 80 | (B vftable pointer)
+// CHECK-NEXT: 84 | int b_field
+// CHECK-NEXT: 88 | int a_field
+// CHECK-NEXT: 92 | char one
+// CHECK-NEXT: sizeof=80, dsize=80, align=8
+// CHECK-NEXT: nvsize=64, nvalign=8
+
+// CHECK: 96 | int x
+// CHECK-NEXT: sizeof=104, dsize=104, align=8
+// CHECK-NEXT: nvsize=104, nvalign=8
+
+// CHECK: %struct.DerivedStruct = type { %struct.BaseStruct, i32 }
+
+// CHECK: 0 | struct G
+// CHECK-NEXT: 0 | int g_field
+// CHECK-NEXT: sizeof=4, dsize=4, align=4
+// CHECK-NEXT: nvsize=4, nvalign=4
+
+// CHECK: 0 | struct H
+// CHECK-NEXT: 0 | struct G (base)
+// CHECK-NEXT: 0 | int g_field
+// CHECK-NEXT: 4 | (H vbtable pointer)
+// CHECK-NEXT: 8 | class D (virtual base)
+// CHECK-NEXT: 8 | (D vftable pointer)
+// CHECK-NEXT: 16 | double a
+// CHECK-NEXT: sizeof=24, dsize=24, align=8
+// CHECK-NEXT: nvsize=8, nvalign=4
+
+// CHECK: %struct.H = type { %struct.G, i32*, %class.D }
+
+// CHECK: 0 | struct I
+// CHECK-NEXT: 0 | (I vftable pointer)
+// CHECK-NEXT: 8 | (I vbtable pointer)
+// CHECK-NEXT: 16 | double q
+// CHECK-NEXT: 24 | class D (virtual base)
+// CHECK-NEXT: 24 | (D vftable pointer)
+// CHECK-NEXT: 32 | double a
+// CHECK-NEXT: sizeof=40, dsize=40, align=8
+// CHECK-NEXT: nvsize=24, nvalign=8
+
+// CHECK: %struct.I = type { i32 (...)**, [4 x i8], i32*, double, %class.D }
+// CHECK: %struct.I.base = type { i32 (...)**, [4 x i8], i32*, double }
+
+// CHECK: 0 | struct L
+// CHECK-NEXT: 0 | int l
+// CHECK-NEXT: sizeof=4, dsize=4, align=4
+// CHECK-NEXT: nvsize=4, nvalign=4
+
+// CHECK: 0 | struct K
+// CHECK-NEXT: 0 | int k
+// CHECK-NEXT: sizeof=4, dsize=4, align=4
+// CHECK-NEXT: nvsize=4, nvalign=4
+
+// CHECK: 0 | struct M
+// CHECK-NEXT: 0 | (M vbtable pointer)
+// CHECK-NEXT: 4 | int m
+// CHECK-NEXT: 8 | struct K (virtual base)
+// CHECK-NEXT: 8 | int k
+// CHECK-NEXT: sizeof=12, dsize=12, align=4
+
+//CHECK: %struct.M = type { i32*, i32, %struct.K }
+//CHECK: %struct.M.base = type { i32*, i32 }
+
+// CHECK: 0 | struct N
+// CHECK-NEXT: 4 | struct L (base)
+// CHECK-NEXT: 4 | int l
+// CHECK-NEXT: 8 | struct M (base)
+// CHECK-NEXT: 8 | (M vbtable pointer)
+// CHECK-NEXT: 12 | int m
+// CHECK-NEXT: 0 | (N vftable pointer)
+// CHECK-NEXT: 16 | struct K (virtual base)
+// CHECK-NEXT: 16 | int k
+// CHECK-NEXT: sizeof=20, dsize=20, align=4
+// CHECK-NEXT: nvsize=16, nvalign=4
+
+//CHECK: %struct.N = type { i32 (...)**, %struct.L, %struct.M.base, %struct.K }
+
+// FIXME: MSVC place struct H at offset 8.
+// CHECK: 0 | struct O
+// CHECK-NEXT: 4 | struct H (base)
+// CHECK-NEXT: 4 | struct G (base)
+// CHECK-NEXT: 4 | int g_field
+// CHECK-NEXT: 8 | (H vbtable pointer)
+// CHECK-NEXT: 12 | struct G (base)
+// CHECK-NEXT: 12 | int g_field
+// CHECK-NEXT: 0 | (O vftable pointer)
+// CHECK-NEXT: 16 | class D (virtual base)
+// CHECK-NEXT: 16 | (D vftable pointer)
+// CHECK-NEXT: 24 | double a
+// CHECK-NEXT: sizeof=32, dsize=32, align=8
+// CHECK-NEXT: nvsize=16, nvalign=4
+
+//CHECK: %struct.O = type { i32 (...)**, %struct.H.base, %struct.G, %class.D }
+//CHECK: %struct.O.base = type { i32 (...)**, %struct.H.base, %struct.G }
+
+// CHECK: 0 | struct P
+// CHECK-NEXT: 0 | struct M (base)
+// CHECK-NEXT: 0 | (M vbtable pointer)
+// CHECK-NEXT: 4 | int m
+// CHECK-NEXT: 8 | int p
+// CHECK-NEXT: 12 | struct K (virtual base)
+// CHECK-NEXT: 12 | int k
+// CHECK-NEXT: 16 | struct L (virtual base)
+// CHECK-NEXT: 16 | int l
+// CHECK-NEXT: sizeof=20, dsize=20, align=4
+// CHECK-NEXT: nvsize=12, nvalign=4
+
+//CHECK: %struct.P = type { %struct.M.base, i32, %struct.K, %struct.L }
+
+// CHECK: 0 | struct R (empty)
+// CHECK-NEXT: sizeof=1, dsize=0, align=1
+// CHECK-NEXT: nvsize=0, nvalign=1
+
+//CHECK: %struct.R = type { i8 }
diff --git a/clang/test/Sema/neon-vector-types.c b/clang/test/Sema/neon-vector-types.c
new file mode 100644
index 0000000..cbf0133
--- /dev/null
+++ b/clang/test/Sema/neon-vector-types.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+typedef float float32_t;
+typedef signed char poly8_t;
+typedef short poly16_t;
+typedef unsigned long long uint64_t;
+
+// Define some valid Neon types.
+typedef __attribute__((neon_vector_type(2))) int int32x2_t;
+typedef __attribute__((neon_vector_type(4))) int int32x4_t;
+typedef __attribute__((neon_vector_type(1))) uint64_t uint64x1_t;
+typedef __attribute__((neon_vector_type(2))) uint64_t uint64x2_t;
+typedef __attribute__((neon_vector_type(2))) float32_t float32x2_t;
+typedef __attribute__((neon_vector_type(4))) float32_t float32x4_t;
+typedef __attribute__((neon_polyvector_type(16))) poly8_t poly8x16_t;
+typedef __attribute__((neon_polyvector_type(8))) poly16_t poly16x8_t;
+
+// The attributes must have a single argument.
+typedef __attribute__((neon_vector_type(2, 4))) int only_one_arg; // expected-error{{attribute takes one argument}}
+
+// The number of elements must be an ICE.
+typedef __attribute__((neon_vector_type(2.0))) int non_int_width; // expected-error{{attribute requires integer constant}}
+
+// Only certain element types are allowed.
+typedef __attribute__((neon_vector_type(2))) double double_elt; // expected-error{{invalid vector element type}}
+typedef __attribute__((neon_vector_type(4))) void* ptr_elt; // expected-error{{invalid vector element type}}
+typedef __attribute__((neon_polyvector_type(4))) float32_t bad_poly_elt; // expected-error{{invalid vector element type}}
+struct aggr { signed char c; };
+typedef __attribute__((neon_vector_type(8))) struct aggr aggregate_elt; // expected-error{{invalid vector element type}}
+
+// The total vector size must be 64 or 128 bits.
+typedef __attribute__((neon_vector_type(1))) int int32x1_t; // expected-error{{Neon vector size must be 64 or 128 bits}}
+typedef __attribute__((neon_vector_type(3))) int int32x3_t; // expected-error{{Neon vector size must be 64 or 128 bits}}
diff --git a/clang/test/Sema/nested-redef.c b/clang/test/Sema/nested-redef.c
new file mode 100644
index 0000000..bbc4859
--- /dev/null
+++ b/clang/test/Sema/nested-redef.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+struct X { // expected-note{{previous definition is here}}
+ struct X { } x; // expected-error{{nested redefinition of 'X'}}
+};
+
+struct Y { };
+void f(void) {
+ struct Y { }; // okay: this is a different Y
+}
+
+struct T;
+struct Z {
+ struct T { int x; } t;
+ struct U { int x; } u;
+};
+
+void f2(void) {
+ struct T t;
+ struct U u;
+}
+
+
diff --git a/clang/test/Sema/no-format-y2k-turnsoff-format.c b/clang/test/Sema/no-format-y2k-turnsoff-format.c
new file mode 100644
index 0000000..b206ecd
--- /dev/null
+++ b/clang/test/Sema/no-format-y2k-turnsoff-format.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -Wformat -Wno-format-y2k
+// rdar://9504680
+
+void foo(const char *, ...) __attribute__((__format__ (__printf__, 1, 2)));
+
+void bar(unsigned int a) {
+ foo("%s", a); // expected-warning {{format specifies type 'char *' but the argument has type 'unsigned int'}}
+}
+
diff --git a/clang/test/Sema/nonnull.c b/clang/test/Sema/nonnull.c
new file mode 100644
index 0000000..cea8e3d
--- /dev/null
+++ b/clang/test/Sema/nonnull.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only %s
+// rdar://9584012
+
+typedef struct {
+ char *str;
+} Class;
+
+typedef union {
+ Class *object;
+} Instance __attribute__((transparent_union));
+
+__attribute__((nonnull(1))) void Class_init(Instance this, char *str) {
+ this.object->str = str;
+}
+
+int main(void) {
+ Class *obj;
+ Class_init(0, "Hello World"); // expected-warning {{null passed to a callee which requires a non-null argument}}
+ Class_init(obj, "Hello World");
+}
+
diff --git a/clang/test/Sema/offsetof.c b/clang/test/Sema/offsetof.c
new file mode 100644
index 0000000..46fb515
--- /dev/null
+++ b/clang/test/Sema/offsetof.c
@@ -0,0 +1,71 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
+
+typedef struct P { int i; float f; } PT;
+struct external_sun3_core
+{
+ unsigned c_regs;
+
+ PT X[100];
+
+};
+
+void swap()
+{
+ int x;
+ x = offsetof(struct external_sun3_core, c_regs);
+ x = __builtin_offsetof(struct external_sun3_core, X[42].f);
+
+ x = __builtin_offsetof(struct external_sun3_core, X[42].f2); // expected-error {{no member named 'f2'}}
+ x = __builtin_offsetof(int, X[42].f2); // expected-error {{offsetof requires struct}}
+
+ int a[__builtin_offsetof(struct external_sun3_core, X) == 4 ? 1 : -1];
+ int b[__builtin_offsetof(struct external_sun3_core, X[42]) == 340 ? 1 : -1];
+ int c[__builtin_offsetof(struct external_sun3_core, X[42].f2) == 344 ? 1 : -1]; // expected-error {{no member named 'f2'}}
+}
+
+extern int f();
+
+struct s1 { int a; };
+int v1 = offsetof (struct s1, a) == 0 ? 0 : f();
+
+struct s2 { int a; };
+int v2 = (int)(&((struct s2 *) 0)->a) == 0 ? 0 : f();
+
+struct s3 { int a; };
+int v3 = __builtin_offsetof(struct s3, a) == 0 ? 0 : f();
+
+// PR3396
+struct sockaddr_un {
+ unsigned char sun_len;
+ char sun_path[104];
+};
+int a(int len) {
+int a[__builtin_offsetof(struct sockaddr_un, sun_path[len+1])];
+}
+
+// PR4079
+union x {struct {int x;};};
+int x[__builtin_offsetof(union x, x)];
+
+// rdar://problem/7222956
+struct incomplete; // expected-note 2 {{forward declaration of 'struct incomplete'}}
+int test1[__builtin_offsetof(struct incomplete, foo)]; // expected-error {{offsetof of incomplete type 'struct incomplete'}}
+
+int test2[__builtin_offsetof(struct incomplete[10], [4].foo)]; // expected-error {{array has incomplete element type 'struct incomplete'}}
+
+// Bitfields
+struct has_bitfields {
+ int i : 7;
+ int j : 12; // expected-note{{bit-field is declared here}}
+};
+
+int test3 = __builtin_offsetof(struct has_bitfields, j); // expected-error{{cannot compute offset of bit-field 'j'}}
+
+typedef struct Array { int array[1]; } Array;
+int test4 = __builtin_offsetof(Array, array);
+
+int test5() {
+ return __builtin_offsetof(Array, array[*(int*)0]); // expected-warning{{indirection of non-volatile null pointer}} expected-note{{__builtin_trap}}
+}
diff --git a/clang/test/Sema/overloadable-complex.c b/clang/test/Sema/overloadable-complex.c
new file mode 100644
index 0000000..efdeb8f
--- /dev/null
+++ b/clang/test/Sema/overloadable-complex.c
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+char *foo(float) __attribute__((__overloadable__));
+
+void test_foo_1(float fv, double dv, float _Complex fc, double _Complex dc) {
+ char *cp1 = foo(fv);
+ char *cp2 = foo(dv);
+ // Note: GCC and EDG reject these two, but they are valid C99 conversions
+ char *cp3 = foo(fc);
+ char *cp4 = foo(dc);
+}
+
+int *foo(float _Complex) __attribute__((__overloadable__));
+
+void test_foo_2(float fv, double dv, float _Complex fc, double _Complex dc) {
+ char *cp1 = foo(fv);
+ char *cp2 = foo(dv);
+ int *ip = foo(fc);
+ int *lp = foo(dc);
+}
+
+long *foo(double _Complex) __attribute__((__overloadable__));
+
+void test_foo_3(float fv, double dv, float _Complex fc, double _Complex dc) {
+ char *cp1 = foo(fv);
+ char *cp2 = foo(dv);
+ int *ip = foo(fc);
+ long *lp = foo(dc);
+}
+
+char *promote_or_convert(double _Complex) __attribute__((__overloadable__)); // expected-note 2 {{candidate function}}
+int *promote_or_convert(long double _Complex) __attribute__((__overloadable__)); // expected-note 2 {{candidate function}}
+
+void test_promote_or_convert(float f, float _Complex fc) {
+ char *cp = promote_or_convert(fc); // expected-error{{call to 'promote_or_convert' is ambiguous}}
+ int *ip2 = promote_or_convert(f); // expected-error{{call to 'promote_or_convert' is ambiguous}}
+}
+
+char *promote_or_convert2(float) __attribute__((__overloadable__));
+int *promote_or_convert2(double _Complex) __attribute__((__overloadable__));
+
+void test_promote_or_convert2(float _Complex fc) {
+ int *cp = promote_or_convert2(fc);
+}
+
+char *promote_or_convert3(int _Complex) __attribute__((__overloadable__));
+int *promote_or_convert3(long _Complex) __attribute__((__overloadable__));
+
+void test_promote_or_convert3(short _Complex sc) {
+ char *cp = promote_or_convert3(sc);
+}
diff --git a/clang/test/Sema/overloadable.c b/clang/test/Sema/overloadable.c
new file mode 100644
index 0000000..5d39f15
--- /dev/null
+++ b/clang/test/Sema/overloadable.c
@@ -0,0 +1,71 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int var __attribute__((overloadable)); // expected-error{{'overloadable' attribute can only be applied to a function}}
+
+int *f(int) __attribute__((overloadable)); // expected-note 2{{previous overload of function is here}}
+float *f(float); // expected-error{{overloaded function 'f' must have the 'overloadable' attribute}}
+int *f(int); // expected-error{{redeclaration of 'f' must have the 'overloadable' attribute}} \
+ // expected-note{{previous declaration is here}}
+double *f(double) __attribute__((overloadable)); // okay, new
+
+void test_f(int iv, float fv, double dv) {
+ int *ip = f(iv);
+ float *fp = f(fv);
+ double *dp = f(dv);
+}
+
+int *accept_funcptr(int (*)()) __attribute__((overloadable)); // \
+ // expected-note{{candidate function}}
+float *accept_funcptr(int (*)(int, double)) __attribute__((overloadable)); // \
+ // expected-note{{candidate function}}
+
+void test_funcptr(int (*f1)(int, double),
+ int (*f2)(int, float)) {
+ float *fp = accept_funcptr(f1);
+ accept_funcptr(f2); // expected-error{{no matching function for call to 'accept_funcptr'}}
+}
+
+struct X { int x; float y; };
+struct Y { int x; float y; };
+int* accept_struct(struct X x) __attribute__((__overloadable__));
+float* accept_struct(struct Y y) __attribute__((overloadable));
+
+void test_struct(struct X x, struct Y y) {
+ int *ip = accept_struct(x);
+ float *fp = accept_struct(y);
+}
+
+double *f(int) __attribute__((overloadable)); // expected-error{{conflicting types for 'f'}}
+
+double promote(float) __attribute__((__overloadable__)); // expected-note {{candidate}}
+double promote(double) __attribute__((__overloadable__)); // expected-note {{candidate}}
+long double promote(long double) __attribute__((__overloadable__)); // expected-note {{candidate}}
+
+void promote(...) __attribute__((__overloadable__, __unavailable__)); // \
+ // expected-note{{candidate function}}
+
+void test_promote(short* sp) {
+ promote(1.0);
+ promote(sp); // expected-error{{call to unavailable function 'promote'}}
+}
+
+// PR6600
+typedef double Double;
+typedef Double DoubleVec __attribute__((vector_size(16)));
+typedef int Int;
+typedef Int IntVec __attribute__((vector_size(16)));
+double magnitude(DoubleVec) __attribute__((__overloadable__));
+double magnitude(IntVec) __attribute__((__overloadable__));
+double test_p6600(DoubleVec d) {
+ return magnitude(d) * magnitude(d);
+}
+
+// PR7738
+extern int __attribute__((overloadable)) f0(); // expected-error{{'overloadable' function 'f0' must have a prototype}}
+typedef int f1_type();
+f1_type __attribute__((overloadable)) f1; // expected-error{{'overloadable' function 'f1' must have a prototype}}
+
+void test() {
+ f0();
+ f1();
+}
diff --git a/clang/test/Sema/overloaded-func-transparent-union.c b/clang/test/Sema/overloaded-func-transparent-union.c
new file mode 100644
index 0000000..fa0314e
--- /dev/null
+++ b/clang/test/Sema/overloaded-func-transparent-union.c
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+// rdar:// 9129552
+// PR9406
+
+typedef struct {
+ char *str;
+ char *str2;
+} Class;
+
+typedef union {
+ Class *object;
+} Instance __attribute__((transparent_union));
+
+__attribute__((overloadable)) void Class_Init(Instance this, char *str, void *str2) {
+ this.object->str = str;
+ this.object->str2 = str2;
+}
+
+__attribute__((overloadable)) void Class_Init(Instance this, char *str) {
+ this.object->str = str;
+ this.object->str2 = str;
+}
+
+int main(void) {
+ Class obj;
+ Class_Init(&obj, "Hello ", " World");
+}
+
diff --git a/clang/test/Sema/parentheses.c b/clang/test/Sema/parentheses.c
new file mode 100644
index 0000000..9751336
--- /dev/null
+++ b/clang/test/Sema/parentheses.c
@@ -0,0 +1,73 @@
+// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wparentheses -fixit %s -o - | %clang_cc1 -Wparentheses -Werror -
+
+// Test the various warnings under -Wparentheses
+void if_assign(void) {
+ int i;
+ if (i = 4) {} // expected-warning {{assignment as a condition}} \
+ // expected-note{{use '==' to turn this assignment into an equality comparison}} \
+ // expected-note{{place parentheses around the assignment to silence this warning}}
+ if ((i = 4)) {}
+}
+
+void bitwise_rel(unsigned i) {
+ (void)(i & 0x2 == 0); // expected-warning {{& has lower precedence than ==}} \
+ // expected-note{{place parentheses around the & expression to evaluate it first}} \
+ // expected-note{{place parentheses around the == expression to silence this warning}}
+ (void)(0 == i & 0x2); // expected-warning {{& has lower precedence than ==}} \
+ // expected-note{{place parentheses around the & expression to evaluate it first}} \
+ // expected-note{{place parentheses around the == expression to silence this warning}}
+ (void)(i & 0xff < 30); // expected-warning {{& has lower precedence than <}} \
+ // expected-note{{place parentheses around the & expression to evaluate it first}} \
+ // expected-note{{place parentheses around the < expression to silence this warning}}
+ (void)((i & 0x2) == 0);
+ (void)(i & (0x2 == 0));
+ // Eager logical op
+ (void)(i == 1 | i == 2 | i == 3);
+ (void)(i != 1 & i != 2 & i != 3);
+
+ (void)(i & i | i); // expected-warning {{'&' within '|'}} \
+ // expected-note {{place parentheses around the '&' expression to silence this warning}}
+
+ (void)(i | i & i); // expected-warning {{'&' within '|'}} \
+ // expected-note {{place parentheses around the '&' expression to silence this warning}}
+
+ (void)(i ||
+ i && i); // expected-warning {{'&&' within '||'}} \
+ // expected-note {{place parentheses around the '&&' expression to silence this warning}}
+ (void)(i || i && "w00t"); // no warning.
+ (void)("w00t" && i || i); // no warning.
+ (void)(i || i && "w00t" || i); // expected-warning {{'&&' within '||'}} \
+ // expected-note {{place parentheses around the '&&' expression to silence this warning}}
+ (void)(i || "w00t" && i || i); // expected-warning {{'&&' within '||'}} \
+ // expected-note {{place parentheses around the '&&' expression to silence this warning}}
+ (void)(i && i || 0); // no warning.
+ (void)(0 || i && i); // no warning.
+}
+
+_Bool someConditionFunc();
+
+void conditional_op(int x, int y, _Bool b) {
+ (void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} \
+ // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
+ // expected-note {{place parentheses around the '+' expression to silence this warning}}
+
+ (void)((x + someConditionFunc()) ? 1 : 2); // no warning
+
+ (void)(x - b ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '-'}} \
+ // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
+ // expected-note {{place parentheses around the '-' expression to silence this warning}}
+
+ (void)(x * (x == y) ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '*'}} \
+ // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
+ // expected-note {{place parentheses around the '*' expression to silence this warning}}
+
+ (void)(x / !x ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '/'}} \
+ // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
+ // expected-note {{place parentheses around the '/' expression to silence this warning}}
+
+ (void)(x % 2 ? 1 : 2); // no warning
+}
+
+// RUN: %clang_cc1 -fsyntax-only -Wparentheses -Werror -fdiagnostics-show-option %s 2>&1 | FileCheck %s
+// CHECK: error: using the result of an assignment as a condition without parentheses [-Werror,-Wparentheses]
diff --git a/clang/test/Sema/parentheses.cpp b/clang/test/Sema/parentheses.cpp
new file mode 100644
index 0000000..7674166
--- /dev/null
+++ b/clang/test/Sema/parentheses.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wparentheses -fixit %s -o - | %clang_cc1 -Wparentheses -Werror -
+
+bool someConditionFunc();
+
+void conditional_op(int x, int y, bool b) {
+ (void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} \
+ // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
+ // expected-note {{place parentheses around the '+' expression to silence this warning}}
+
+ (void)(x - b ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '-'}} \
+ // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
+ // expected-note {{place parentheses around the '-' expression to silence this warning}}
+
+ (void)(x * (x == y) ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '*'}} \
+ // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
+ // expected-note {{place parentheses around the '*' expression to silence this warning}}
+}
+
+class Stream {
+public:
+ operator int();
+ Stream &operator<<(int);
+ Stream &operator<<(const char*);
+};
+
+void f(Stream& s, bool b) {
+ (void)(s << b ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '<<'}} \
+ // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
+ // expected-note {{place parentheses around the '<<' expression to silence this warning}}
+}
+
+struct S {
+ operator int() { return 42; }
+ friend S operator+(const S &lhs, bool) { return S(); }
+};
+
+void test(S *s, bool (S::*m_ptr)()) {
+ (void)(*s + true ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '+'}} \
+ // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
+ // expected-note {{place parentheses around the '+' expression to silence this warning}}
+
+ (void)((*s + true) ? "foo" : "bar"); // No warning.
+
+ // Don't crash on unusual member call expressions.
+ (void)((s->*m_ptr)() ? "foo" : "bar");
+}
diff --git a/clang/test/Sema/pointer-addition.c b/clang/test/Sema/pointer-addition.c
new file mode 100644
index 0000000..21ce63b
--- /dev/null
+++ b/clang/test/Sema/pointer-addition.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
+
+typedef struct S S; // expected-note 3 {{forward declaration of 'struct S'}}
+void a(S* b, void* c) {
+ void (*fp)(int) = 0;
+ b++; // expected-error {{arithmetic on a pointer to an incomplete type}}
+ b += 1; // expected-error {{arithmetic on a pointer to an incomplete type}}
+ c++; // expected-warning {{arithmetic on a pointer to void is a GNU extension}}
+ c += 1; // expected-warning {{arithmetic on a pointer to void is a GNU extension}}
+ c--; // expected-warning {{arithmetic on a pointer to void is a GNU extension}}
+ c -= 1; // expected-warning {{arithmetic on a pointer to void is a GNU extension}}
+ (void) c[1]; // expected-warning {{subscript of a pointer to void is a GNU extension}}
+ b = 1+b; // expected-error {{arithmetic on a pointer to an incomplete type}}
+ /* The next couple tests are only pedantic warnings in gcc */
+ void (*d)(S*,void*) = a;
+ d += 1; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}}
+ d++; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}}
+ d--; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}}
+ d -= 1; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}}
+ (void)(1 + d); // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}}
+}
diff --git a/clang/test/Sema/pointer-conversion.c b/clang/test/Sema/pointer-conversion.c
new file mode 100644
index 0000000..2d755ae
--- /dev/null
+++ b/clang/test/Sema/pointer-conversion.c
@@ -0,0 +1,10 @@
+//RUN: %clang_cc1 -fsyntax-only -verify %s
+
+char * c;
+char const ** c2 = &c; // expected-warning {{discards qualifiers in nested pointer types}}
+
+typedef char dchar;
+dchar *** c3 = &c2; // expected-warning {{discards qualifiers in nested pointer types}}
+
+volatile char * c4;
+char ** c5 = &c4; // expected-warning {{discards qualifiers in nested pointer types}}
diff --git a/clang/test/Sema/pointer-subtract-compat.c b/clang/test/Sema/pointer-subtract-compat.c
new file mode 100644
index 0000000..b801f81
--- /dev/null
+++ b/clang/test/Sema/pointer-subtract-compat.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
+
+typedef const char rchar;
+int a(char* a, rchar* b) {
+ return a-b;
+}
+
+// <rdar://problem/6520707>
+void f0(void (*fp)(void)) {
+ int x = fp - fp; // expected-warning{{arithmetic on pointers to the function type 'void (void)' is a GNU extension}}
+}
diff --git a/clang/test/Sema/pragma-align-mac68k-unsupported.c b/clang/test/Sema/pragma-align-mac68k-unsupported.c
new file mode 100644
index 0000000..c23c01b
--- /dev/null
+++ b/clang/test/Sema/pragma-align-mac68k-unsupported.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple i386-pc-linux-gnu -fsyntax-only -verify %s
+
+/* expected-error {{mac68k alignment pragma is not supported}} */ #pragma options align=mac68k
diff --git a/clang/test/Sema/pragma-align-mac68k.c b/clang/test/Sema/pragma-align-mac68k.c
new file mode 100644
index 0000000..fb8da51
--- /dev/null
+++ b/clang/test/Sema/pragma-align-mac68k.c
@@ -0,0 +1,98 @@
+// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s
+
+#include <stddef.h>
+
+#pragma options align=mac68k
+
+typedef float __attribute__((vector_size (8))) v2f_t;
+typedef float __attribute__((vector_size (16))) v4f_t;
+
+extern int a0_0[__alignof(v2f_t) == 8 ? 1 : -1];
+extern int a0_1[__alignof(v4f_t) == 16 ? 1 : -1];
+
+struct s1 {
+ char f0;
+ int f1;
+};
+extern int a1_0[offsetof(struct s1, f0) == 0 ? 1 : -1];
+extern int a1_1[offsetof(struct s1, f1) == 2 ? 1 : -1];
+extern int a1_2[sizeof(struct s1) == 6 ? 1 : -1];
+extern int a1_3[__alignof(struct s1) == 2 ? 1 : -1];
+
+struct s2 {
+ char f0;
+ double f1;
+};
+extern int a2_0[offsetof(struct s2, f0) == 0 ? 1 : -1];
+extern int a2_1[offsetof(struct s2, f1) == 2 ? 1 : -1];
+extern int a2_2[sizeof(struct s2) == 10 ? 1 : -1];
+extern int a2_3[__alignof(struct s2) == 2 ? 1 : -1];
+
+struct s3 {
+ char f0;
+ v4f_t f1;
+};
+extern int a3_0[offsetof(struct s3, f0) == 0 ? 1 : -1];
+extern int a3_1[offsetof(struct s3, f1) == 2 ? 1 : -1];
+extern int a3_2[sizeof(struct s3) == 18 ? 1 : -1];
+extern int a3_3[__alignof(struct s3) == 2 ? 1 : -1];
+
+struct s4 {
+ char f0;
+ char f1;
+};
+extern int a4_0[offsetof(struct s4, f0) == 0 ? 1 : -1];
+extern int a4_1[offsetof(struct s4, f1) == 1 ? 1 : -1];
+extern int a4_2[sizeof(struct s4) == 2 ? 1 : -1];
+extern int a4_3[__alignof(struct s4) == 2 ? 1 : -1];
+
+struct s5 {
+ unsigned f0 : 9;
+ unsigned f1 : 9;
+};
+extern int a5_0[sizeof(struct s5) == 4 ? 1 : -1];
+extern int a5_1[__alignof(struct s5) == 2 ? 1 : -1];
+
+struct s6 {
+ unsigned : 0;
+ unsigned : 0;
+};
+extern int a6_0[sizeof(struct s6) == 0 ? 1 : -1];
+extern int a6_1[__alignof(struct s6) == 2 ? 1 : -1];
+
+struct s7 {
+ char : 1;
+ unsigned : 1;
+};
+extern int a7_0[sizeof(struct s7) == 2 ? 1 : -1];
+extern int a7_1[__alignof(struct s7) == 2 ? 1 : -1];
+
+struct s8 {
+ char f0;
+ unsigned : 1;
+};
+extern int a8_0[sizeof(struct s8) == 2 ? 1 : -1];
+extern int a8_1[__alignof(struct s8) == 2 ? 1 : -1];
+
+struct s9 {
+ char f0[3];
+ unsigned : 0;
+ char f1;
+};
+extern int a9_0[sizeof(struct s9) == 6 ? 1 : -1];
+extern int a9_1[__alignof(struct s9) == 2 ? 1 : -1];
+
+struct s10 {
+ char f0;
+};
+extern int a10_0[sizeof(struct s10) == 2 ? 1 : -1];
+extern int a10_1[__alignof(struct s10) == 2 ? 1 : -1];
+
+struct s11 {
+ char f0;
+ v2f_t f1;
+};
+extern int a11_0[offsetof(struct s11, f0) == 0 ? 1 : -1];
+extern int a11_1[offsetof(struct s11, f1) == 2 ? 1 : -1];
+extern int a11_2[sizeof(struct s11) == 10 ? 1 : -1];
+extern int a11_3[__alignof(struct s11) == 2 ? 1 : -1];
diff --git a/clang/test/Sema/pragma-align-packed.c b/clang/test/Sema/pragma-align-packed.c
new file mode 100644
index 0000000..74fbd13
--- /dev/null
+++ b/clang/test/Sema/pragma-align-packed.c
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s
+
+#pragma pack(push, 1)
+struct s0 {
+ char f0;
+ int f1 __attribute__((aligned(4)));
+};
+extern int a[sizeof(struct s0) == 5 ? 1 : -1];
+#pragma pack(pop)
+
+struct __attribute__((packed)) s1 {
+ char f0;
+ int f1 __attribute__((aligned(4)));
+};
+extern int a[sizeof(struct s1) == 8 ? 1 : -1];
+
+#pragma options align=packed
+struct s2 {
+ char f0;
+ int f1 __attribute__((aligned(4)));
+};
+extern int a[sizeof(struct s2) == 5 ? 1 : -1];
+#pragma options align=reset
+
+#pragma pack(1)
+struct s3_0 { unsigned char f0; unsigned int f1; };
+int t3_0[sizeof(struct s3_0) == 5 ? 1 : -1];
+#pragma options align=reset
+struct s3_1 { unsigned char f0; unsigned int f1; };
+int t3_1[sizeof(struct s3_1) == 8 ? 1 : -1];
diff --git a/clang/test/Sema/pragma-arc-cf-code-audited.c b/clang/test/Sema/pragma-arc-cf-code-audited.c
new file mode 100644
index 0000000..b646e89
--- /dev/null
+++ b/clang/test/Sema/pragma-arc-cf-code-audited.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#pragma clang arc_cf_code_audited foo // expected-error {{expected 'begin' or 'end'}}
+
+#pragma clang arc_cf_code_audited begin foo // expected-warning {{extra tokens at end of #pragma directive}}
+
+#pragma clang arc_cf_code_audited end
+#pragma clang arc_cf_code_audited end // expected-error {{not currently inside '#pragma clang arc_cf_code_audited'}}
+
+#pragma clang arc_cf_code_audited begin // expected-note {{#pragma entered here}}
+#pragma clang arc_cf_code_audited begin // expected-error {{already inside '#pragma clang arc_cf_code_audited'}} expected-note {{#pragma entered here}}
+
+#include "Inputs/pragma-arc-cf-code-audited.h" // expected-error {{cannot #include files inside '#pragma clang arc_cf_code_audited'}}
+
+// This is actually on the #pragma line in the header.
+// expected-error {{'#pragma clang arc_cf_code_audited' was not ended within this file}}
+
+#pragma clang arc_cf_code_audited begin // expected-error {{'#pragma clang arc_cf_code_audited' was not ended within this file}}
diff --git a/clang/test/Sema/pragma-ms_struct.c b/clang/test/Sema/pragma-ms_struct.c
new file mode 100644
index 0000000..d76ee8b
--- /dev/null
+++ b/clang/test/Sema/pragma-ms_struct.c
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin9 %s
+
+#pragma ms_struct on
+
+#pragma ms_struct off
+
+#pragma ms_struct reset
+
+#pragma ms_struct // expected-warning {{incorrect use of '#pragma ms_struct on|off' - ignored}}
+
+#pragma ms_struct on top of spaghetti // expected-warning {{extra tokens at end of '#pragma ms_struct' - ignored}}
+
+struct foo
+{
+ int a;
+ int b;
+ char c;
+};
+
+
+struct {
+ unsigned long bf_1 : 12;
+ unsigned long : 0;
+ unsigned long bf_2 : 12;
+} __attribute__((__ms_struct__)) t1;
+
+struct S {
+ double __attribute__((ms_struct)) d; // expected-warning {{'ms_struct' attribute ignored}}
+ unsigned long bf_1 : 12;
+ unsigned long : 0;
+ unsigned long bf_2 : 12;
+} __attribute__((ms_struct)) t2;
+
+
+// rdar://10513599
+#pragma ms_struct on
+
+typedef struct
+{
+void *pv;
+int l;
+} Foo;
+
+typedef struct
+{
+void *pv1;
+Foo foo;
+unsigned short fInited : 1;
+void *pv2;
+} PackOddity;
+
+#pragma ms_struct off
+
+static int arr[sizeof(PackOddity) == 40 ? 1 : -1];
+
diff --git a/clang/test/Sema/pragma-pack-2.c b/clang/test/Sema/pragma-pack-2.c
new file mode 100644
index 0000000..4a4c202
--- /dev/null
+++ b/clang/test/Sema/pragma-pack-2.c
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -triple i686-apple-darwin9 %s -fsyntax-only -verify
+
+#include <stddef.h>
+
+#pragma pack(4)
+
+// Baseline
+struct s0 {
+ char f0;
+ int f1;
+};
+extern int a0[offsetof(struct s0, f1) == 4 ? 1 : -1];
+
+#pragma pack(push, 2)
+struct s1 {
+ char f0;
+ int f1;
+};
+extern int a1[offsetof(struct s1, f1) == 2 ? 1 : -1];
+#pragma pack(pop)
+
+#pragma pack(1)
+struct s3_0 {
+ char f0;
+ int f1;
+};
+#pragma pack()
+struct s3_1 {
+ char f0;
+ int f1;
+};
+extern int a3_0[offsetof(struct s3_0, f1) == 1 ? 1 : -1];
+extern int a3_1[offsetof(struct s3_1, f1) == 4 ? 1 : -1];
+
+// pack(0) is like pack()
+#pragma pack(1)
+struct s4_0 {
+ char f0;
+ int f1;
+};
+#pragma pack(0)
+struct s4_1 {
+ char f0;
+ int f1;
+};
+extern int a4_0[offsetof(struct s4_0, f1) == 1 ? 1 : -1];
+extern int a4_1[offsetof(struct s4_1, f1) == 4 ? 1 : -1];
+
+void f() {
+ #pragma pack(push, 2)
+ struct s5_0 {
+ char f0;
+ struct s2_4_0 {
+ int f0;
+ } f1;
+ };
+ #pragma pack(pop)
+ extern int s5_0[offsetof(struct s5_0, f1) == 2 ? 1 : -1];
+}
diff --git a/clang/test/Sema/pragma-pack-3.c b/clang/test/Sema/pragma-pack-3.c
new file mode 100644
index 0000000..d97359e
--- /dev/null
+++ b/clang/test/Sema/pragma-pack-3.c
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple i686-apple-darwin9 %s -fsyntax-only -verify
+
+// Stack: [], Alignment: 8
+
+#pragma pack(push, 1)
+// Stack: [8], Alignment: 1
+
+#pragma pack(push, 4)
+// Stack: [8, 1], Alignment: 4
+
+// Note that this differs from gcc; pack() in gcc appears to pop the
+// top stack entry and resets the current alignment. This is both
+// inconsistent with MSVC, and the gcc documentation. In other cases,
+// for example changing this to pack(8), I don't even understand what gcc
+// is doing.
+
+#pragma pack()
+// Stack: [8, 1], Alignment: 8
+
+#pragma pack(pop)
+// Stack: [8], Alignment: 1
+struct s0 {
+ char f0;
+ short f1;
+};
+int a[sizeof(struct s0) == 3 ? 1 : -1];
+
+#pragma pack(pop)
+// Stack: [], Alignment: 8
+struct s1 {
+ char f0;
+ short f1;
+};
+int b[sizeof(struct s1) == 4 ? 1 : -1];
diff --git a/clang/test/Sema/pragma-pack-4.c b/clang/test/Sema/pragma-pack-4.c
new file mode 100644
index 0000000..b06fc0e
--- /dev/null
+++ b/clang/test/Sema/pragma-pack-4.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple i686-apple-darwin9 %s -fsyntax-only -verify
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -fsyntax-only -verify
+
+// rdar://problem/7095436
+#pragma pack(4)
+
+struct s0 {
+ long long a __attribute__((aligned(8)));
+ long long b __attribute__((aligned(8)));
+ unsigned int c __attribute__((aligned(8)));
+ int d[12];
+};
+
+struct s1 {
+ int a[15];
+ struct s0 b;
+};
+
+int arr0[((sizeof(struct s1) % 64) == 0) ? 1 : -1];
diff --git a/clang/test/Sema/pragma-pack-5.c b/clang/test/Sema/pragma-pack-5.c
new file mode 100644
index 0000000..95bbe1f
--- /dev/null
+++ b/clang/test/Sema/pragma-pack-5.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -fsyntax-only -verify -ffreestanding
+// <rdar://problem/10494810> and PR9560
+// Check #pragma pack handling with bitfields.
+
+#include <stddef.h>
+#pragma pack(2)
+
+struct s0 {
+ char f1;
+ unsigned f2 : 32;
+ char f3;
+};
+extern int check[sizeof(struct s0) == 6 ? 1 : -1];
+
+struct s1 {
+ char f1;
+ unsigned : 0;
+ char f3;
+};
+extern int check[sizeof(struct s1) == 5 ? 1 : -1];
+
+struct s2 {
+ char f1;
+ unsigned : 0;
+ unsigned f3 : 8;
+ char f4;
+};
+extern int check[sizeof(struct s2) == 6 ? 1 : -1];
+
+struct s3 {
+ char f1;
+ unsigned : 0;
+ unsigned f3 : 16;
+ char f4;
+};
+extern int check[sizeof(struct s3) == 8 ? 1 : -1];
+extern int check[offsetof(struct s3, f4) == 6 ? 1 : -1];
+
+struct s4 {
+ char f1;
+ unsigned f2 : 8;
+ char f3;
+};
+extern int check[sizeof(struct s4) == 4 ? 1 : -1];
+extern int check[offsetof(struct s4, f3) == 2 ? 1 : -1];
diff --git a/clang/test/Sema/pragma-pack-and-options-align.c b/clang/test/Sema/pragma-pack-and-options-align.c
new file mode 100644
index 0000000..ebf1ade
--- /dev/null
+++ b/clang/test/Sema/pragma-pack-and-options-align.c
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple i686-apple-darwin9 %s -fsyntax-only -verify
+
+// Check that #pragma pack and #pragma options share the same stack.
+
+#pragma pack(push, 1)
+struct s0 {
+ char c;
+ int x;
+};
+extern int a[sizeof(struct s0) == 5 ? 1 : -1];
+
+#pragma options align=natural
+struct s1 {
+ char c;
+ int x;
+};
+extern int a[sizeof(struct s1) == 8 ? 1 : -1];
+
+#pragma options align=reset
+#pragma options align=native
+struct s1_1 {
+ char c;
+ int x;
+};
+extern int a[sizeof(struct s1_1) == 8 ? 1 : -1];
+
+#pragma pack(pop)
+struct s2 {
+ char c;
+ int x;
+};
+extern int a[sizeof(struct s2) == 5 ? 1 : -1];
+#pragma pack(pop)
+
+struct s3 {
+ char c;
+ int x;
+};
+extern int a[sizeof(struct s3) == 8 ? 1 : -1];
+
+/* expected-warning {{#pragma options align=reset failed: stack empty}} */ #pragma options align=reset
+/* expected-warning {{#pragma pack(pop, ...) failed: stack empty}} */ #pragma pack(pop)
diff --git a/clang/test/Sema/pragma-pack-apple.c b/clang/test/Sema/pragma-pack-apple.c
new file mode 100644
index 0000000..5b33c03
--- /dev/null
+++ b/clang/test/Sema/pragma-pack-apple.c
@@ -0,0 +1,10 @@
+// RUN: %clang -fsyntax-only %s 2>&1 | FileCheck %s
+// RUN: %clang -fsyntax-only -fapple-pragma-pack %s 2>&1 | FileCheck -check-prefix=CHECK-APPLE %s
+
+#pragma pack(push,1)
+#pragma pack(2)
+#pragma pack()
+#pragma pack(show)
+
+// CHECK: pack(show) == 8
+// CHECK-APPLE: pack(show) == 1
diff --git a/clang/test/Sema/pragma-pack.c b/clang/test/Sema/pragma-pack.c
new file mode 100644
index 0000000..e93ce42
--- /dev/null
+++ b/clang/test/Sema/pragma-pack.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -verify %s
+
+/* expected-warning {{value of #pragma pack(show) == 8}} */ #pragma pack(show)
+/* expected-warning {{expected #pragma pack parameter to be}} */ #pragma pack(3)
+/* expected-warning {{value of #pragma pack(show) == 8}} */ #pragma pack(show)
+#pragma pack(4)
+/* expected-warning {{value of #pragma pack(show) == 4}} */ #pragma pack(show)
+#pragma pack() // resets to default
+/* expected-warning {{value of #pragma pack(show) == 8}} */ #pragma pack(show)
+#pragma pack(2)
+#pragma pack(push, eek, 16) // -> (eek, 2), 16
+/* expected-warning {{value of #pragma pack(show) == 16}} */ #pragma pack(show)
+#pragma pack(push) // -> (eek, 2), (, 2), 16
+/* expected-warning {{value of #pragma pack(show) == 16}} */ #pragma pack(show)
+#pragma pack(1)
+#pragma pack(push, 8) // -> (eek, 2), (, 2), (, 1), 8
+/* expected-warning {{value of #pragma pack(show) == 8}} */ #pragma pack(show)
+#pragma pack(pop) // -> (eek, 2), (,2), 1
+/* expected-warning {{value of #pragma pack(show) == 1}} */ #pragma pack(show)
+#pragma pack(pop, eek)
+/* expected-warning {{value of #pragma pack(show) == 2}} */ #pragma pack(show)
+/* expected-warning {{pack(pop, ...) failed: stack empty}} */ #pragma pack(pop)
+
+#pragma pack(push)
+#pragma pack(pop, 16)
+/* expected-warning {{value of #pragma pack(show) == 16}} */ #pragma pack(show)
+
diff --git a/clang/test/Sema/pragma-unused.c b/clang/test/Sema/pragma-unused.c
new file mode 100644
index 0000000..aafac0d
--- /dev/null
+++ b/clang/test/Sema/pragma-unused.c
@@ -0,0 +1,65 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-parameter -Wused-but-marked-unused -Wunused -verify %s
+
+void f1(void) {
+ int x, y, z;
+ #pragma unused(x)
+ #pragma unused(y, z)
+
+ int w; // expected-warning {{unused}}
+ #pragma unused w // expected-warning{{missing '(' after '#pragma unused' - ignoring}}
+}
+
+void f2(void) {
+ int x, y; // expected-warning {{unused}} expected-warning {{unused}}
+ #pragma unused(x,) // expected-warning{{expected '#pragma unused' argument to be a variable name}}
+ #pragma unused() // expected-warning{{expected '#pragma unused' argument to be a variable name}}
+}
+
+void f3(void) {
+ #pragma unused(x) // expected-warning{{undeclared variable 'x' used as an argument for '#pragma unused'}}
+}
+
+void f4(void) {
+ int w; // expected-warning {{unused}}
+ #pragma unused((w)) // expected-warning{{expected '#pragma unused' argument to be a variable name}}
+}
+
+void f6(void) {
+ int z; // no-warning
+ {
+ #pragma unused(z) // no-warning
+ }
+}
+
+void f7() {
+ int y;
+ #pragma unused(undeclared, undefined, y) // expected-warning{{undeclared variable 'undeclared' used as an argument for '#pragma unused'}} expected-warning{{undeclared variable 'undefined' used as an argument for '#pragma unused'}}
+}
+
+int f8(int x) { // expected-warning{{unused parameter 'x'}}
+ return 0;
+}
+
+int f9(int x) {
+ return x;
+}
+
+int f10(int x) {
+ #pragma unused(x)
+ return 0;
+}
+
+int f11(int x) {
+ #pragma unused(x)
+ return x; // expected-warning{{'x' was marked unused but was used}}
+}
+
+int f12(int x) {
+ int y = x;
+ #pragma unused(x) // expected-warning{{'x' was marked unused but was used}}
+ return y;
+}
+
+// rdar://8793832
+static int glob_var = 0;
+#pragma unused(glob_var)
diff --git a/clang/test/Sema/predef.c b/clang/test/Sema/predef.c
new file mode 100644
index 0000000..95bcfb9
--- /dev/null
+++ b/clang/test/Sema/predef.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void abcdefghi12(void) {
+ const char (*ss)[12] = &__func__;
+ static int arr[sizeof(__func__)==12 ? 1 : -1];
+}
+
+char *X = __func__; // expected-warning {{predefined identifier is only valid}} \
+ expected-warning {{initializing 'char *' with an expression of type 'const char [1]' discards qualifiers}}
+
+void a() {
+ __func__[0] = 'a'; // expected-error {{variable is not assignable}}
+}
+
+// rdar://6097892 - GCC permits this insanity.
+const char *b = __func__; // expected-warning {{predefined identifier is only valid}}
+const char *c = __FUNCTION__; // expected-warning {{predefined identifier is only valid}}
+const char *d = __PRETTY_FUNCTION__; // expected-warning {{predefined identifier is only valid}}
+
diff --git a/clang/test/Sema/predefined-function.c b/clang/test/Sema/predefined-function.c
new file mode 100644
index 0000000..1c40b6e
--- /dev/null
+++ b/clang/test/Sema/predefined-function.c
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
+
+char *funk(int format);
+enum Test {A=-1};
+char *funk(enum Test x);
+
+int eli(float b); // expected-note {{previous declaration is here}} \
+// expected-note{{passing argument to parameter 'b' here}}
+int b(int c) {return 1;}
+
+int foo();
+int foo() {
+ int eli(int (int)); // expected-error {{conflicting types for 'eli'}}
+ eli(b); // expected-error{{passing 'int (int)' to parameter of incompatible type 'float'}}
+ return 0;
+}
+
+int bar();
+int bar(int i) // expected-note {{previous definition is here}}
+{
+ return 0;
+}
+int bar() // expected-error {{redefinition of 'bar'}}
+{
+ return 0;
+}
+
+int foobar(int); // note {{previous declaration is here}}
+int foobar() // error {{conflicting types for 'foobar'}}
+{
+ return 0;
+}
+
+int wibble(); // expected-note {{previous declaration is here}}
+float wibble() // expected-error {{conflicting types for 'wibble'}}
+{
+ return 0.0f;
+}
diff --git a/clang/test/Sema/private-extern.c b/clang/test/Sema/private-extern.c
new file mode 100644
index 0000000..25591dc
--- /dev/null
+++ b/clang/test/Sema/private-extern.c
@@ -0,0 +1,84 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+static int g0; // expected-note{{previous definition}}
+int g0; // expected-error{{non-static declaration of 'g0' follows static declaration}}
+
+static int g1;
+extern int g1;
+
+static int g2;
+__private_extern__ int g2;
+
+int g3; // expected-note{{previous definition}}
+static int g3; // expected-error{{static declaration of 'g3' follows non-static declaration}}
+
+extern int g4; // expected-note{{previous definition}}
+static int g4; // expected-error{{static declaration of 'g4' follows non-static declaration}}
+
+__private_extern__ int g5; // expected-note{{previous definition}}
+static int g5; // expected-error{{static declaration of 'g5' follows non-static declaration}}
+
+void f0() {
+ int g6; // expected-note {{previous}}
+ extern int g6; // expected-error {{extern declaration of 'g6' follows non-extern declaration}}
+}
+
+void f1() {
+ int g7; // expected-note {{previous}}
+ __private_extern__ int g7; // expected-error {{extern declaration of 'g7' follows non-extern declaration}}
+}
+
+void f2() {
+ extern int g8; // expected-note{{previous definition}}
+ int g8; // expected-error {{non-extern declaration of 'g8' follows extern declaration}}
+}
+
+void f3() {
+ __private_extern__ int g9; // expected-note{{previous definition}}
+ int g9; // expected-error {{non-extern declaration of 'g9' follows extern declaration}}
+}
+
+void f4() {
+ extern int g10;
+ extern int g10;
+}
+
+void f5() {
+ __private_extern__ int g11;
+ __private_extern__ int g11;
+}
+
+void f6() {
+ // FIXME: Diagnose
+ extern int g12;
+ __private_extern__ int g12;
+}
+
+void f7() {
+ // FIXME: Diagnose
+ __private_extern__ int g13;
+ extern int g13;
+}
+
+struct s0;
+void f8() {
+ extern struct s0 g14;
+ __private_extern__ struct s0 g14;
+}
+struct s0 { int x; };
+
+void f9() {
+ extern int g15 = 0; // expected-error{{'extern' variable cannot have an initializer}}
+ // FIXME: linkage specifier in warning.
+ __private_extern__ int g16 = 0; // expected-error{{'extern' variable cannot have an initializer}}
+}
+
+extern int g17;
+int g17 = 0;
+
+extern int g18 = 0; // expected-warning{{'extern' variable has an initializer}}
+
+__private_extern__ int g19;
+int g19 = 0;
+
+__private_extern__ int g20 = 0;
diff --git a/clang/test/Sema/rdr6094103-unordered-compare-promote.c b/clang/test/Sema/rdr6094103-unordered-compare-promote.c
new file mode 100644
index 0000000..7bb363e
--- /dev/null
+++ b/clang/test/Sema/rdr6094103-unordered-compare-promote.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -ast-dump %s 2>&1 | grep ImplicitCastExpr | count 4
+
+int foo (double x, long double y) {
+ // There needs to be an implicit cast on x here.
+ return __builtin_isgreater(x, y);
+}
diff --git a/clang/test/Sema/recover-goto.c b/clang/test/Sema/recover-goto.c
new file mode 100644
index 0000000..0e8f6d3
--- /dev/null
+++ b/clang/test/Sema/recover-goto.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+
+void a() { // expected-note {{to match this '{'}}
+ goto A; // expected-error {{use of undeclared label}}
+// expected-error {{expected '}'}}
diff --git a/clang/test/Sema/redefinition.c b/clang/test/Sema/redefinition.c
new file mode 100644
index 0000000..1ee35f7
--- /dev/null
+++ b/clang/test/Sema/redefinition.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+int f(int a) { return 0; } // expected-note {{previous definition is here}}
+int f(int);
+int f(int a) { return 0; } // expected-error {{redefinition of 'f'}}
+
+// <rdar://problem/6097326>
+int foo(x) {
+ return 0;
+}
+int x = 1;
+
+// <rdar://problem/6880464>
+extern inline int g(void) { return 0; } // expected-note{{previous definition}}
+int g(void) { return 0; } // expected-error{{redefinition of a 'extern inline' function 'g' is not supported in C99 mode}}
diff --git a/clang/test/Sema/return-noreturn.c b/clang/test/Sema/return-noreturn.c
new file mode 100644
index 0000000..448fce7
--- /dev/null
+++ b/clang/test/Sema/return-noreturn.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wmissing-noreturn -Wno-unreachable-code
+
+int j;
+void test1() { // expected-warning {{function 'test1' could be declared with attribute 'noreturn'}}
+ ^ (void) { while (1) { } }(); // expected-warning {{block could be declared with attribute 'noreturn'}}
+ ^ (void) { if (j) while (1) { } }();
+ while (1) { }
+}
+
+void test2() {
+ if (j) while (1) { }
+}
+
+__attribute__((__noreturn__))
+void test2_positive() {
+ if (j) while (1) { }
+} // expected-warning{{function declared 'noreturn' should not return}}
+
+
+// This test case illustrates that we don't warn about the missing return
+// because the function is marked noreturn and there is an infinite loop.
+extern int foo_test_3();
+__attribute__((__noreturn__)) void* test3(int arg) {
+ while (1) foo_test_3();
+}
+
+__attribute__((__noreturn__)) void* test3_positive(int arg) {
+ while (0) foo_test_3();
+} // expected-warning{{function declared 'noreturn' should not return}}
+
+
+// PR5298 - -Wmissing-noreturn shouldn't warn if the function is already
+// declared noreturn.
+void __attribute__((noreturn))
+test4() {
+ test2_positive();
+}
diff --git a/clang/test/Sema/return-silent.c b/clang/test/Sema/return-silent.c
new file mode 100644
index 0000000..eb9641b
--- /dev/null
+++ b/clang/test/Sema/return-silent.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -Wno-return-type -fsyntax-only -verify
+
+int t14() {
+ return;
+}
+
+void t15() {
+ return 1;
+}
diff --git a/clang/test/Sema/return.c b/clang/test/Sema/return.c
new file mode 100644
index 0000000..77bd3f6
--- /dev/null
+++ b/clang/test/Sema/return.c
@@ -0,0 +1,266 @@
+// RUN: %clang %s -fsyntax-only -Wignored-qualifiers -Wno-error=return-type -Xclang -verify -fblocks -Wno-unreachable-code -Wno-unused-value
+
+// clang emits the following warning by default.
+// With GCC, -pedantic, -Wreturn-type or -Wall are required to produce the
+// following warning.
+int t14() {
+ return; // expected-warning {{non-void function 't14' should return a value}}
+}
+
+void t15() {
+ return 1; // expected-warning {{void function 't15' should not return a value}}
+}
+
+int unknown();
+
+void test0() {
+}
+
+int test1() {
+} // expected-warning {{control reaches end of non-void function}}
+
+int test2() {
+ a: goto a;
+}
+
+int test3() {
+ goto a;
+ a: ;
+} // expected-warning {{control reaches end of non-void function}}
+
+
+void halt() {
+ a: goto a;
+}
+
+void halt2() __attribute__((noreturn));
+
+int test4() {
+ halt2();
+}
+
+int test5() {
+ halt2(), (void)1;
+}
+
+int test6() {
+ 1, halt2();
+}
+
+int j;
+int unknown_nohalt() {
+ return j;
+}
+
+int test7() {
+ unknown();
+} // expected-warning {{control reaches end of non-void function}}
+
+int test8() {
+ (void)(1 + unknown());
+} // expected-warning {{control reaches end of non-void function}}
+
+int halt3() __attribute__((noreturn));
+
+int test9() {
+ (void)(halt3() + unknown());
+}
+
+int test10() {
+ (void)(unknown() || halt3());
+} // expected-warning {{control may reach end of non-void function}}
+
+int test11() {
+ (void)(unknown() && halt3());
+} // expected-warning {{control may reach end of non-void function}}
+
+int test12() {
+ (void)(halt3() || unknown());
+}
+
+int test13() {
+ (void)(halt3() && unknown());
+}
+
+int test14() {
+ (void)(1 || unknown());
+} // expected-warning {{control reaches end of non-void function}}
+
+int test15() {
+ (void)(0 || unknown());
+} // expected-warning {{control reaches end of non-void function}}
+
+int test16() {
+ (void)(0 && unknown());
+} // expected-warning {{control reaches end of non-void function}}
+
+int test17() {
+ (void)(1 && unknown());
+} // expected-warning {{control reaches end of non-void function}}
+
+int test18() {
+ (void)(unknown_nohalt() && halt3());
+} // expected-warning {{control may reach end of non-void function}}
+
+int test19() {
+ (void)(unknown_nohalt() && unknown());
+} // expected-warning {{control reaches end of non-void function}}
+
+int test20() {
+ int i;
+ if (i)
+ return 0;
+ else if (0)
+ return 2;
+} // expected-warning {{control may reach end of non-void function}}
+
+int test21() {
+ int i;
+ if (i)
+ return 0;
+ else if (1)
+ return 2;
+}
+
+int test22() {
+ int i;
+ switch (i) default: ;
+} // expected-warning {{control reaches end of non-void function}}
+
+int test23() {
+ int i;
+ switch (i) {
+ case 0:
+ return 0;
+ case 2:
+ return 2;
+ }
+} // expected-warning {{control may reach end of non-void function}}
+
+int test24() {
+ int i;
+ switch (i) {
+ case 0:
+ return 0;
+ case 2:
+ return 2;
+ default:
+ return -1;
+ }
+}
+
+int test25() {
+ 1 ? halt3() : unknown();
+}
+
+int test26() {
+ 0 ? halt3() : unknown();
+} // expected-warning {{control reaches end of non-void function}}
+
+int j;
+void (*fptr)() __attribute__((noreturn));
+int test27() {
+ switch (j) {
+ case 1:
+ do { } while (1);
+ break;
+ case 2:
+ for (;;) ;
+ break;
+ case 3:
+ for (;1;) ;
+ for (;0;) {
+ goto done;
+ }
+ return 1;
+ case 4:
+ while (0) { goto done; }
+ return 1;
+ case 5:
+ while (1) { return 1; }
+ break;
+ case 6:
+ fptr();
+ break;
+ default:
+ return 1;
+ }
+ done: ;
+}
+
+// PR4624
+void test28() __attribute__((noreturn));
+void test28(x) { while (1) { } }
+
+void exit(int);
+int test29() {
+ exit(1);
+}
+
+#include <setjmp.h>
+jmp_buf test30_j;
+int test30() {
+ if (j)
+ longjmp(test30_j, 1);
+ else
+#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
+ longjmp(test30_j, 2);
+#else
+ _longjmp(test30_j, 1);
+#endif
+}
+
+typedef void test31_t(int status);
+void test31(test31_t *callback __attribute__((noreturn)));
+
+void test32() {
+ ^ (void) { while (1) { } }();
+ ^ (void) { if (j) while (1) { } }();
+ while (1) { }
+}
+
+void test33() {
+ if (j) while (1) { }
+}
+
+// Test that 'static inline' functions are only analyzed for CFG-based warnings
+// when they are used.
+static inline int si_has_missing_return() {} // expected-warning{{control reaches end of non-void function}}
+static inline int si_has_missing_return_2() {}; // expected-warning{{control reaches end of non-void function}}
+static inline int si_forward();
+static inline int si_has_missing_return_3(int x) {
+ if (x)
+ return si_has_missing_return_3(x+1);
+} // expected-warning{{control may reach end of non-void function}}
+
+int test_static_inline(int x) {
+ si_forward();
+ return x ? si_has_missing_return_2() : si_has_missing_return_3(x);
+}
+static inline int si_forward() {} // expected-warning{{control reaches end of non-void function}}
+
+// Test warnings on ignored qualifiers on return types.
+const int ignored_c_quals(); // expected-warning{{'const' type qualifier on return type has no effect}}
+const volatile int ignored_cv_quals(); // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
+char* const volatile restrict ignored_cvr_quals(); // expected-warning{{'const volatile restrict' type qualifiers on return type have no effect}}
+
+// Test that for switch(enum) that if the switch statement covers all the cases
+// that we don't consider that for -Wreturn-type.
+enum Cases { C1, C2, C3, C4 };
+int test_enum_cases(enum Cases C) {
+ switch (C) {
+ case C1: return 1;
+ case C2: return 2;
+ case C4: return 3;
+ case C3: return 4;
+ }
+} // no-warning
+
+// PR12318 - Don't give a may reach end of non-void function warning.
+int test34(int x) {
+ if (x == 1) {
+ return 3;
+ } else if ( x == 2 || 1) {
+ return 5;
+ }
+}
diff --git a/clang/test/Sema/scope-check.c b/clang/test/Sema/scope-check.c
new file mode 100644
index 0000000..a9494d3
--- /dev/null
+++ b/clang/test/Sema/scope-check.c
@@ -0,0 +1,234 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=gnu99 %s -Wno-unreachable-code
+
+int test1(int x) {
+ goto L; // expected-error{{goto into protected scope}}
+ int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
+ int b[x]; // expected-note {{jump bypasses initialization of variable length array}}
+ L:
+ return sizeof a;
+}
+
+int test2(int x) {
+ goto L; // expected-error{{goto into protected scope}}
+ typedef int a[x]; // expected-note {{jump bypasses initialization of VLA typedef}}
+ L:
+ return sizeof(a);
+}
+
+void test3clean(int*);
+
+int test3() {
+ goto L; // expected-error{{goto into protected scope}}
+int a __attribute((cleanup(test3clean))); // expected-note {{jump bypasses initialization of variable with __attribute__((cleanup))}}
+L:
+ return a;
+}
+
+int test4(int x) {
+ goto L; // expected-error{{goto into protected scope}}
+int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
+ test4(x);
+L:
+ return sizeof a;
+}
+
+int test5(int x) {
+ int a[x];
+ test5(x);
+ goto L; // Ok.
+L:
+ goto L; // Ok.
+ return sizeof a;
+}
+
+int test6() {
+ // just plain invalid.
+ goto x; // expected-error {{use of undeclared label 'x'}}
+}
+
+void test7(int x) {
+ switch (x) {
+ case 1: ;
+ int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
+ case 2: // expected-error {{switch case is in protected scope}}
+ a[1] = 2;
+ break;
+ }
+}
+
+int test8(int x) {
+ // For statement.
+ goto L2; // expected-error {{goto into protected scope}}
+ for (int arr[x]; // expected-note {{jump bypasses initialization of variable length array}}
+ ; ++x)
+ L2:;
+
+ // Statement expressions.
+ goto L3; // expected-error {{goto into protected scope}}
+ int Y = ({ int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
+ L3: 4; });
+
+ goto L4; // expected-error {{goto into protected scope}}
+ {
+ int A[x], // expected-note {{jump bypasses initialization of variable length array}}
+ B[x]; // expected-note {{jump bypasses initialization of variable length array}}
+ L4: ;
+ }
+
+ {
+ L5: ;// ok
+ int A[x], B = ({ if (x)
+ goto L5;
+ else
+ goto L6;
+ 4; });
+ L6:; // ok.
+ if (x) goto L6; // ok
+ }
+
+ {
+ L7: ;// ok
+ int A[x], B = ({ if (x)
+ goto L7;
+ else
+ goto L8; // expected-error {{goto into protected scope}}
+ 4; }),
+ C[x]; // expected-note {{jump bypasses initialization of variable length array}}
+ L8:; // bad
+ }
+
+ {
+ L9: ;// ok
+ int A[({ if (x)
+ goto L9;
+ else
+ // FIXME:
+ goto L10; // fixme-error {{goto into protected scope}}
+ 4; })];
+ L10:; // bad
+ }
+
+ {
+ // FIXME: Crashes goto checker.
+ //goto L11;// ok
+ //int A[({ L11: 4; })];
+ }
+
+ {
+ goto L12;
+
+ int y = 4; // fixme-warn: skips initializer.
+ L12:
+ ;
+ }
+
+ // Statement expressions 2.
+ goto L1; // expected-error {{goto into protected scope}}
+ return x == ({
+ int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
+ L1:
+ 42; });
+}
+
+void test9(int n, void *P) {
+ int Y;
+ int Z = 4;
+ goto *P; // expected-error {{indirect goto might cross protected scopes}}
+
+L2: ;
+ int a[n]; // expected-note {{jump bypasses initialization of variable length array}}
+
+L3: // expected-note {{possible target of indirect goto}}
+L4:
+ goto *P;
+ goto L3; // ok
+ goto L4; // ok
+
+ void *Ptrs[] = {
+ &&L2,
+ &&L3
+ };
+}
+
+void test10(int n, void *P) {
+ goto L0; // expected-error {{goto into protected scope}}
+ typedef int A[n]; // expected-note {{jump bypasses initialization of VLA typedef}}
+L0:
+
+ goto L1; // expected-error {{goto into protected scope}}
+ A b, c[10]; // expected-note 2 {{jump bypasses initialization of variable length array}}
+L1:
+ goto L2; // expected-error {{goto into protected scope}}
+ A d[n]; // expected-note {{jump bypasses initialization of variable length array}}
+L2:
+ return;
+}
+
+void test11(int n) {
+ void *P = ^{
+ switch (n) {
+ case 1:;
+ case 2:
+ case 3:;
+ int Arr[n]; // expected-note {{jump bypasses initialization of variable length array}}
+ case 4: // expected-error {{switch case is in protected scope}}
+ return;
+ }
+ };
+}
+
+
+// TODO: When and if gotos are allowed in blocks, this should work.
+void test12(int n) {
+ void *P = ^{
+ goto L1;
+ L1:
+ goto L2;
+ L2:
+ goto L3; // expected-error {{goto into protected scope}}
+ int Arr[n]; // expected-note {{jump bypasses initialization of variable length array}}
+ L3:
+ goto L4;
+ L4: return;
+ };
+}
+
+void test13(int n, void *p) {
+ int vla[n];
+ goto *p;
+ a0: ;
+ static void *ps[] = { &&a0 };
+}
+
+int test14(int n) {
+ static void *ps[] = { &&a0, &&a1 };
+ if (n < 0)
+ goto *&&a0;
+
+ if (n > 0) {
+ int vla[n];
+ a1:
+ vla[n-1] = 0;
+ }
+ a0:
+ return 0;
+}
+
+
+// PR8473: IR gen can't deal with indirect gotos past VLA
+// initialization, so that really needs to be a hard error.
+void test15(int n, void *pc) {
+ static const void *addrs[] = { &&L1, &&L2 };
+
+ goto *pc; // expected-error {{indirect goto might cross protected scope}}
+
+ L1:
+ {
+ char vla[n]; // expected-note {{jump bypasses initialization}}
+ L2: // expected-note {{possible target}}
+ vla[0] = 'a';
+ }
+}
+
+// rdar://9024687
+int test16(int [sizeof &&z]); // expected-error {{use of address-of-label extension outside of a function body}}
diff --git a/clang/test/Sema/self-comparison.c b/clang/test/Sema/self-comparison.c
new file mode 100644
index 0000000..edb3a6a
--- /dev/null
+++ b/clang/test/Sema/self-comparison.c
@@ -0,0 +1,88 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int foo(int x) {
+ return x == x; // expected-warning {{self-comparison always evaluates to true}}
+}
+
+int foo2(int x) {
+ return (x) != (((x))); // expected-warning {{self-comparison always evaluates to false}}
+}
+
+void foo3(short s, short t) {
+ if (s == s) {} // expected-warning {{self-comparison always evaluates to true}}
+ if (s == t) {} // no-warning
+}
+
+void foo4(void* v, void* w) {
+ if (v == v) {} // expected-warning {{self-comparison always evaluates to true}}
+ if (v == w) {} // no-warning
+}
+
+int qux(int x) {
+ return x < x; // expected-warning {{self-comparison}}
+}
+
+int qux2(int x) {
+ return x > x; // expected-warning {{self-comparison}}
+}
+
+int bar(float x) {
+ return x == x; // no-warning
+}
+
+int bar2(float x) {
+ return x != x; // no-warning
+}
+
+#define IS_THE_ANSWER(x) (x == 42)
+
+int macro_comparison() {
+ return IS_THE_ANSWER(42);
+}
+
+// Don't complain in unevaluated contexts.
+int compare_sizeof(int x) {
+ return sizeof(x == x); // no-warning
+}
+
+int array_comparisons() {
+ int array1[2];
+ int array2[2];
+
+ //
+ // compare same array
+ //
+ return array1 == array1; // expected-warning{{self-comparison always evaluates to true}}
+ return array1 != array1; // expected-warning{{self-comparison always evaluates to false}}
+ return array1 < array1; // expected-warning{{self-comparison always evaluates to false}}
+ return array1 <= array1; // expected-warning{{self-comparison always evaluates to true}}
+ return array1 > array1; // expected-warning{{self-comparison always evaluates to false}}
+ return array1 >= array1; // expected-warning{{self-comparison always evaluates to true}}
+
+ //
+ // compare differrent arrays
+ //
+ return array1 == array2; // expected-warning{{array comparison always evaluates to false}}
+ return array1 != array2; // expected-warning{{array comparison always evaluates to true}}
+
+ //
+ // we don't know what these are going to be
+ //
+ return array1 < array2; // expected-warning{{array comparison always evaluates to a constant}}
+ return array1 <= array2; // expected-warning{{array comparison always evaluates to a constant}}
+ return array1 > array2; // expected-warning{{array comparison always evaluates to a constant}}
+ return array1 >= array2; // expected-warning{{array comparison always evaluates to a constant}}
+
+}
+
+// Don't issue a warning when either the left or right side of the comparison
+// results from a macro expansion. <rdar://problem/8435950>
+#define R8435950_A i
+#define R8435950_B i
+
+int R8435950(int i) {
+ if (R8435950_A == R8435950_B) // no-warning
+ return 0;
+ return 1;
+}
+
diff --git a/clang/test/Sema/sentinel-attribute.c b/clang/test/Sema/sentinel-attribute.c
new file mode 100644
index 0000000..e5cbf6e
--- /dev/null
+++ b/clang/test/Sema/sentinel-attribute.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+int x __attribute__((sentinel)); //expected-warning{{'sentinel' attribute only applies to functions, methods and blocks}}
+
+void f1(int a, ...) __attribute__ ((sentinel));
+void f2(int a, ...) __attribute__ ((sentinel(1)));
+
+void f3(int a, ...) __attribute__ ((sentinel("hello"))); //expected-error{{'sentinel' attribute requires parameter 1 to be an integer constant}}
+void f4(int a, ...) __attribute__ ((sentinel(1, 2, 3))); //expected-error{{attribute takes no more than 2 arguments}}
+void f4(int a, ...) __attribute__ ((sentinel(-1))); //expected-error{{parameter 1 less than zero}}
+void f4(int a, ...) __attribute__ ((sentinel(0, 2))); // expected-error{{parameter 2 not 0 or 1}}
+
+void f5(int a) __attribute__ ((sentinel)); //expected-warning{{'sentinel' attribute only supported for variadic functions}}
+
+
+void f6() __attribute__((__sentinel__)); // expected-warning {{'sentinel' attribute requires named arguments}}
diff --git a/clang/test/Sema/shift.c b/clang/test/Sema/shift.c
new file mode 100644
index 0000000..142d83c
--- /dev/null
+++ b/clang/test/Sema/shift.c
@@ -0,0 +1,68 @@
+// RUN: %clang -Wall -Wshift-sign-overflow -ffreestanding -fsyntax-only -Xclang -verify %s
+
+#include <limits.h>
+
+#define WORD_BIT (sizeof(int) * CHAR_BIT)
+
+enum {
+ X = 1 << 0,
+ Y = 1 << 1,
+ Z = 1 << 2
+};
+
+void test() {
+ char c;
+
+ c = 0 << 0;
+ c = 0 << 1;
+ c = 1 << 0;
+ c = 1 << -0;
+ c = 1 >> -0;
+ c = 1 << -1; // expected-warning {{shift count is negative}}
+ c = 1 >> -1; // expected-warning {{shift count is negative}}
+ c = 1 << c;
+ c <<= 0;
+ c >>= 0;
+ c <<= 1;
+ c >>= 1;
+ c <<= -1; // expected-warning {{shift count is negative}}
+ c >>= -1; // expected-warning {{shift count is negative}}
+ c <<= 999999; // expected-warning {{shift count >= width of type}}
+ c >>= 999999; // expected-warning {{shift count >= width of type}}
+ c <<= CHAR_BIT; // expected-warning {{shift count >= width of type}}
+ c >>= CHAR_BIT; // expected-warning {{shift count >= width of type}}
+ c <<= CHAR_BIT+1; // expected-warning {{shift count >= width of type}}
+ c >>= CHAR_BIT+1; // expected-warning {{shift count >= width of type}}
+ (void)((long)c << CHAR_BIT);
+
+ int i;
+ i = 1 << (WORD_BIT - 2);
+ i = 2 << (WORD_BIT - 1); // expected-warning {{bits to represent, but 'int' only has}}
+ i = 1 << (WORD_BIT - 1); // expected-warning {{sets the sign bit of the shift expression}}
+ i = -1 << (WORD_BIT - 1);
+ i = 0 << (WORD_BIT - 1);
+ i = (char)1 << (WORD_BIT - 2);
+
+ unsigned u;
+ u = 1U << (WORD_BIT - 1);
+ u = 5U << (WORD_BIT - 1);
+
+ long long int lli;
+ lli = INT_MIN << 2; // expected-warning {{bits to represent, but 'int' only has}}
+ lli = 1LL << (sizeof(long long) * CHAR_BIT - 2);
+}
+
+#define a 0
+#define ashift 8
+enum { b = (a << ashift) };
+
+// Don't warn for negative shifts in code that is unreachable.
+void test_pr5544() {
+ (void) (((1) > 63 && (1) < 128 ? (((unsigned long long) 1)<<((1)-64)) : (unsigned long long) 0)); // no-warning
+}
+
+void test_shift_too_much(char x) {
+ if (0)
+ (void) (x >> 80); // no-warning
+ (void) (x >> 80); // expected-warning {{shift count >= width of type}}
+}
diff --git a/clang/test/Sema/short-enums.c b/clang/test/Sema/short-enums.c
new file mode 100644
index 0000000..6605c4e
--- /dev/null
+++ b/clang/test/Sema/short-enums.c
@@ -0,0 +1,5 @@
+// RUN: not %clang_cc1 -fsyntax-only %s -verify
+// RUN: %clang_cc1 -fshort-enums -fsyntax-only %s -verify
+
+enum x { A };
+int t0[sizeof(enum x) == 1 ? 1 : -1];
diff --git a/clang/test/Sema/sign-conversion.c b/clang/test/Sema/sign-conversion.c
new file mode 100644
index 0000000..4b1ee75
--- /dev/null
+++ b/clang/test/Sema/sign-conversion.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wsign-conversion %s
+
+// PR9345: make a subgroup of -Wconversion for signedness changes
+
+void test(int x) {
+ unsigned t0 = x; // expected-warning {{implicit conversion changes signedness}}
+ unsigned t1 = (t0 == 5 ? x : 0); // expected-warning {{operand of ? changes signedness}}
+}
diff --git a/clang/test/Sema/statements.c b/clang/test/Sema/statements.c
new file mode 100644
index 0000000..f01ee40
--- /dev/null
+++ b/clang/test/Sema/statements.c
@@ -0,0 +1,102 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+typedef unsigned __uint32_t;
+
+#define __byte_swap_int_var(x) \
+__extension__ ({ register __uint32_t __X = (x); \
+ __asm ("bswap %0" : "+r" (__X)); \
+ __X; })
+
+int test(int _x) {
+ return (__byte_swap_int_var(_x));
+}
+
+// PR2374
+int test2() { return ({L:5;}); }
+int test3() { return ({ {5;} }); } // expected-error {{returning 'void' from a function with incompatible result type 'int'}}\
+ // expected-warning {{expression result unused}}
+int test4() { return ({ ({5;}); }); }
+int test5() { return ({L1: L2: L3: 5;}); }
+int test6() { return ({5;}); }
+void test7() { ({5;}); } // expected-warning {{expression result unused}}
+
+// PR3062
+int test8[({10;})]; // expected-error {{statement expression not allowed at file scope}}
+
+// PR3912
+void test9(const void *P) {
+ __builtin_prefetch(P);
+}
+
+
+void *test10() {
+bar:
+ return &&bar; // expected-warning {{returning address of label, which is local}}
+}
+
+// PR6034
+void test11(int bit) {
+ switch (bit) // expected-warning {{switch statement has empty body}} expected-note {{put the semicolon on a separate line to silence this warning}}
+ switch (env->fpscr) // expected-error {{use of undeclared identifier 'env'}}
+ {
+ }
+}
+
+// rdar://3271964
+enum Numbers { kOne, kTwo, kThree, kFour};
+int test12(enum Numbers num) {
+ switch (num == kOne) {// expected-warning {{switch condition has boolean value}}
+ default:
+ case kThree:
+ break;
+ }
+}
+
+
+enum x { a, b, c, d, e, f, g };
+
+void foo(enum x X) {
+ switch (X) { // expected-warning {{enumeration value 'g' not handled in switch}}
+ case a:
+ case b:
+ case c:
+ case d:
+ case e:
+ case f:
+ break;
+ }
+
+ switch (X) { // expected-warning {{enumeration values 'f' and 'g' not handled in switch}}
+ case a:
+ case b:
+ case c:
+ case d:
+ case e:
+ break;
+ }
+
+ switch (X) { // expected-warning {{enumeration values 'e', 'f', and 'g' not handled in switch}}
+ case a:
+ case b:
+ case c:
+ case d:
+ break;
+ }
+
+ switch (X) { // expected-warning {{5 enumeration values not handled in switch: 'c', 'd', 'e'...}}
+ case a:
+ case b:
+ break;
+ }
+}
+
+// PR 8880
+// FIXME: Clang should reject this, since GCC does. Previously this
+// was causing a crash in the CFG builder.
+int test_pr8880() {
+ int first = 1;
+ for ( ; ({ if (first) { first = 0; continue; } 0; }); )
+ return 0;
+ return 1;
+}
+
diff --git a/clang/test/Sema/static-array.c b/clang/test/Sema/static-array.c
new file mode 100644
index 0000000..2d4b968
--- /dev/null
+++ b/clang/test/Sema/static-array.c
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void cat0(int a[static 0]) {} // expected-warning {{'static' has no effect on zero-length arrays}}
+
+void cat(int a[static 3]) {} // expected-note 2 {{callee declares array parameter as static here}}
+
+typedef int i3[static 3];
+void tcat(i3 a) {}
+
+void vat(int i, int a[static i]) {} // expected-note {{callee declares array parameter as static here}}
+
+void f(int *p) {
+ int a[2], b[3], c[4];
+
+ cat0(0);
+
+ cat(0); // expected-warning {{null passed to a callee which requires a non-null argument}}
+ cat(a); // expected-warning {{array argument is too small; contains 2 elements, callee requires at least 3}}
+ cat(b);
+ cat(c);
+ cat(p);
+
+ tcat(0); // expected-warning {{null passed to a callee which requires a non-null argument}}
+ tcat(a); // expected-warning {{array argument is too small; contains 2 elements, callee requires at least 3}}
+ tcat(b);
+ tcat(c);
+ tcat(p);
+
+ vat(1, 0); // expected-warning {{null passed to a callee which requires a non-null argument}}
+ vat(3, b);
+}
diff --git a/clang/test/Sema/static-assert.c b/clang/test/Sema/static-assert.c
new file mode 100644
index 0000000..13d7070
--- /dev/null
+++ b/clang/test/Sema/static-assert.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -std=c1x -fsyntax-only -verify %s
+
+_Static_assert("foo", "string is nonzero"); // expected-error {{static_assert expression is not an integral constant expression}}
+
+_Static_assert(1, "1 is nonzero");
+_Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}}
+
+void foo(void) {
+ _Static_assert(1, "1 is nonzero");
+ _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}}
+}
diff --git a/clang/test/Sema/static-init.c b/clang/test/Sema/static-init.c
new file mode 100644
index 0000000..bbf9038
--- /dev/null
+++ b/clang/test/Sema/static-init.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+typedef __typeof((int*) 0 - (int*) 0) intptr_t;
+
+static int f = 10;
+static int b = f; // expected-error {{initializer element is not a compile-time constant}}
+
+float r = (float) (intptr_t) &r; // expected-error {{initializer element is not a compile-time constant}}
+intptr_t s = (intptr_t) &s;
+_Bool t = &t;
+
+
+union bar {
+ int i;
+};
+
+struct foo {
+ short ptr;
+};
+
+union bar u[1];
+struct foo x = {(intptr_t) u}; // expected-error {{initializer element is not a compile-time constant}}
+struct foo y = {(char) u}; // expected-error {{initializer element is not a compile-time constant}}
+intptr_t z = (intptr_t) u; // no-error
diff --git a/clang/test/Sema/stdcall-fastcall.c b/clang/test/Sema/stdcall-fastcall.c
new file mode 100644
index 0000000..eeacf94
--- /dev/null
+++ b/clang/test/Sema/stdcall-fastcall.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-pc-linux-gnu %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-apple-darwin10 %s
+
+// CC qualifier can be applied only to functions
+int __attribute__((stdcall)) var1; // expected-warning{{'stdcall' only applies to function types; type here is 'int'}}
+int __attribute__((fastcall)) var2; // expected-warning{{'fastcall' only applies to function types; type here is 'int'}}
+
+// Different CC qualifiers are not compatible
+void __attribute__((stdcall, fastcall)) foo3(void); // expected-error{{fastcall and stdcall attributes are not compatible}}
+void __attribute__((stdcall)) foo4(); // expected-note{{previous declaration is here}}
+void __attribute__((fastcall)) foo4(void); // expected-error{{function declared 'fastcall' here was previously declared 'stdcall'}}
+
+// rdar://8876096
+void rdar8876096foo1(int i, int j) __attribute__((fastcall, cdecl)); // expected-error {{not compatible}}
+void rdar8876096foo2(int i, int j) __attribute__((fastcall, stdcall)); // expected-error {{not compatible}}
+void rdar8876096foo3(int i, int j) __attribute__((fastcall, regparm(2))); // expected-error {{not compatible}}
+void rdar8876096foo4(int i, int j) __attribute__((stdcall, cdecl)); // expected-error {{not compatible}}
+void rdar8876096foo5(int i, int j) __attribute__((stdcall, fastcall)); // expected-error {{not compatible}}
+void rdar8876096foo6(int i, int j) __attribute__((cdecl, fastcall)); // expected-error {{not compatible}}
+void rdar8876096foo7(int i, int j) __attribute__((cdecl, stdcall)); // expected-error {{not compatible}}
+void rdar8876096foo8(int i, int j) __attribute__((regparm(2), fastcall)); // expected-error {{not compatible}}
diff --git a/clang/test/Sema/struct-cast.c b/clang/test/Sema/struct-cast.c
new file mode 100644
index 0000000..30ef892
--- /dev/null
+++ b/clang/test/Sema/struct-cast.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+
+struct S {
+ int one;
+ int two;
+};
+
+struct S const foo(void);
+
+
+struct S tmp;
+
+void priv_sock_init() {
+ tmp = (struct S)foo();
+}
diff --git a/clang/test/Sema/struct-compat.c b/clang/test/Sema/struct-compat.c
new file mode 100644
index 0000000..65bef9f
--- /dev/null
+++ b/clang/test/Sema/struct-compat.c
@@ -0,0 +1,17 @@
+/* RUN: %clang_cc1 %s -fsyntax-only -pedantic -verify
+ */
+
+extern struct {int a;} x; // expected-note {{previous definition is here}}
+extern struct {int a;} x; // expected-error {{redefinition of 'x'}}
+
+struct x;
+int a(struct x* b) {
+// Per C99 6.7.2.3, since the outer and inner "struct x"es have different
+// scopes, they don't refer to the same type, and are therefore incompatible
+struct x {int a;} *c = b; // expected-warning {{incompatible pointer types}}
+}
+
+struct x {int a;} r;
+int b() {
+struct x {char x;} s = r; // expected-error {{initializing 'struct x' with an expression of incompatible type 'struct x'}}
+}
diff --git a/clang/test/Sema/struct-decl.c b/clang/test/Sema/struct-decl.c
new file mode 100644
index 0000000..6070e87
--- /dev/null
+++ b/clang/test/Sema/struct-decl.c
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// PR3459
+struct bar {
+ char n[1];
+};
+
+struct foo {
+ char name[(int)&((struct bar *)0)->n];
+ char name2[(int)&((struct bar *)0)->n - 1]; //expected-error{{'name2' declared as an array with a negative size}}
+};
+
+// PR3430
+struct s {
+ struct st {
+ int v;
+ } *ts;
+};
+
+struct st;
+
+int foo() {
+ struct st *f;
+ return f->v + f[0].v;
+}
+
+// PR3642, PR3671
+struct pppoe_tag {
+ short tag_type;
+ char tag_data[];
+};
+struct datatag {
+ struct pppoe_tag hdr; //expected-warning{{field 'hdr' with variable sized type 'struct pppoe_tag' not at the end of a struct or class is a GNU extension}}
+ char data;
+};
+
+
+// PR4092
+struct s0 {
+ char a; // expected-note {{previous declaration is here}}
+ char a; // expected-error {{duplicate member 'a'}}
+};
+
+struct s0 f0(void) {}
+
+// <rdar://problem/8177927> - This previously triggered an assertion failure.
+struct x0 {
+ unsigned int x1;
+};
+
+// rdar://problem/9150338
+static struct test1 { // expected-warning {{'static' ignored on this declaration}}
+ int x;
+};
+const struct test2 { // expected-warning {{'const' ignored on this declaration}}
+ int x;
+};
+inline struct test3 { // expected-warning {{'inline' ignored on this declaration}}
+ int x;
+};
diff --git a/clang/test/Sema/struct-packed-align.c b/clang/test/Sema/struct-packed-align.c
new file mode 100644
index 0000000..6ca6a60
--- /dev/null
+++ b/clang/test/Sema/struct-packed-align.c
@@ -0,0 +1,134 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+// Packed structs.
+struct s {
+ char a;
+ int b __attribute__((packed));
+ char c;
+ int d;
+};
+
+extern int a1[sizeof(struct s) == 12 ? 1 : -1];
+extern int a2[__alignof(struct s) == 4 ? 1 : -1];
+
+struct __attribute__((packed)) packed_s {
+ char a;
+ int b __attribute__((packed));
+ char c;
+ int d;
+};
+
+extern int b1[sizeof(struct packed_s) == 10 ? 1 : -1];
+extern int b2[__alignof(struct packed_s) == 1 ? 1 : -1];
+
+struct fas {
+ char a;
+ int b[];
+};
+
+extern int c1[sizeof(struct fas) == 4 ? 1 : -1];
+extern int c2[__alignof(struct fas) == 4 ? 1 : -1];
+
+struct __attribute__((packed)) packed_fas {
+ char a;
+ int b[];
+};
+
+extern int d1[sizeof(struct packed_fas) == 1 ? 1 : -1];
+extern int d2[__alignof(struct packed_fas) == 1 ? 1 : -1];
+
+struct packed_after_fas {
+ char a;
+ int b[];
+} __attribute__((packed));
+
+extern int d1_2[sizeof(struct packed_after_fas) == 1 ? 1 : -1];
+extern int d2_2[__alignof(struct packed_after_fas) == 1 ? 1 : -1];
+
+// Alignment
+
+struct __attribute__((aligned(8))) as1 {
+ char c;
+};
+
+extern int e1[sizeof(struct as1) == 8 ? 1 : -1];
+extern int e2[__alignof(struct as1) == 8 ? 1 : -1];
+
+// FIXME: Will need to force arch once max usable alignment isn't hard
+// coded.
+struct __attribute__((aligned)) as1_2 {
+ char c;
+};
+extern int e1_2[sizeof(struct as1_2) == 16 ? 1 : -1];
+extern int e2_2[__alignof(struct as1_2) == 16 ? 1 : -1];
+
+struct as2 {
+ char c;
+ int __attribute__((aligned(8))) a;
+};
+
+extern int f1[sizeof(struct as2) == 16 ? 1 : -1];
+extern int f2[__alignof(struct as2) == 8 ? 1 : -1];
+
+struct __attribute__((packed)) as3 {
+ char c;
+ int a;
+ int __attribute__((aligned(8))) b;
+};
+
+extern int g1[sizeof(struct as3) == 16 ? 1 : -1];
+extern int g2[__alignof(struct as3) == 8 ? 1 : -1];
+
+
+// rdar://5921025
+struct packedtest {
+ int ted_likes_cheese;
+ void *args[] __attribute__((packed));
+};
+
+// Packed union
+union __attribute__((packed)) au4 {char c; int x;};
+extern int h1[sizeof(union au4) == 4 ? 1 : -1];
+extern int h2[__alignof(union au4) == 1 ? 1 : -1];
+
+// Aligned union
+union au5 {__attribute__((aligned(4))) char c;};
+extern int h1[sizeof(union au5) == 4 ? 1 : -1];
+extern int h2[__alignof(union au5) == 4 ? 1 : -1];
+
+// Alignment+packed
+struct as6 {char c; __attribute__((packed, aligned(2))) int x;};
+extern int i1[sizeof(struct as6) == 6 ? 1 : -1];
+extern int i2[__alignof(struct as6) == 2 ? 1 : -1];
+
+union au6 {char c; __attribute__((packed, aligned(2))) int x;};
+extern int k1[sizeof(union au6) == 4 ? 1 : -1];
+extern int k2[__alignof(union au6) == 2 ? 1 : -1];
+
+// Check postfix attributes
+union au7 {char c; int x;} __attribute__((packed));
+extern int l1[sizeof(union au7) == 4 ? 1 : -1];
+extern int l2[__alignof(union au7) == 1 ? 1 : -1];
+
+struct packed_fas2 {
+ char a;
+ int b[];
+} __attribute__((packed));
+
+extern int m1[sizeof(struct packed_fas2) == 1 ? 1 : -1];
+extern int m2[__alignof(struct packed_fas2) == 1 ? 1 : -1];
+
+// Attribute aligned can round down typedefs. PR9253
+typedef long long __attribute__((aligned(1))) nt;
+
+struct nS {
+ char buf_nr;
+ nt start_lba;
+};
+
+extern int n1[sizeof(struct nS) == 9 ? 1 : -1];
+extern int n2[__alignof(struct nS) == 1 ? 1 : -1];
+
+
+
+
diff --git a/clang/test/Sema/surpress-deprecated.c b/clang/test/Sema/surpress-deprecated.c
new file mode 100644
index 0000000..dd673b9
--- /dev/null
+++ b/clang/test/Sema/surpress-deprecated.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -Wno-deprecated-declarations -verify %s
+extern void OldFunction() __attribute__((deprecated));
+
+int main (int argc, const char * argv[]) {
+ OldFunction();
+}
+
diff --git a/clang/test/Sema/switch.c b/clang/test/Sema/switch.c
new file mode 100644
index 0000000..a7a7f60
--- /dev/null
+++ b/clang/test/Sema/switch.c
@@ -0,0 +1,322 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wswitch-enum -Wcovered-switch-default %s
+void f (int z) {
+ while (z) {
+ default: z--; // expected-error {{statement not in switch}}
+ }
+}
+
+void foo(int X) {
+ switch (X) {
+ case 42: ; // expected-note {{previous case}}
+ case 5000000000LL: // expected-warning {{overflow}}
+ case 42: // expected-error {{duplicate case value}}
+ ;
+
+ case 100 ... 99: ; // expected-warning {{empty case range}}
+
+ case 43: ; // expected-note {{previous case}}
+ case 43 ... 45: ; // expected-error {{duplicate case value}}
+
+ case 100 ... 20000:; // expected-note {{previous case}}
+ case 15000 ... 40000000:; // expected-error {{duplicate case value}}
+ }
+}
+
+void test3(void) {
+ // empty switch;
+ switch (0); // expected-warning {{no case matching constant switch condition '0'}} \
+ // expected-warning {{switch statement has empty body}} \
+ // expected-note{{put the semicolon on a separate line to silence this warning}}
+}
+
+extern int g();
+
+void test4()
+{
+ int cond;
+ switch (cond) {
+ case 0 && g():
+ case 1 || g():
+ break;
+ }
+
+ switch(cond) {
+ case g(): // expected-error {{expression is not an integer constant expression}}
+ case 0 ... g(): // expected-error {{expression is not an integer constant expression}}
+ break;
+ }
+
+ switch (cond) {
+ case 0 && g() ... 1 || g():
+ break;
+ }
+
+ switch (cond) {
+ case g() // expected-error {{expression is not an integer constant expression}}
+ && 0:
+ break;
+ }
+
+ switch (cond) {
+ case 0 ...
+ g() // expected-error {{expression is not an integer constant expression}}
+ || 1:
+ break;
+ }
+}
+
+void test5(int z) {
+ switch(z) {
+ default: // expected-note {{previous case defined here}}
+ default: // expected-error {{multiple default labels in one switch}}
+ break;
+ }
+}
+
+void test6() {
+ char ch = 'a';
+ switch(ch) {
+ case 1234: // expected-warning {{overflow converting case value}}
+ break;
+ }
+}
+
+// PR5606
+int f0(int var) {
+ switch (va) { // expected-error{{use of undeclared identifier 'va'}}
+ case 1:
+ break;
+ case 2:
+ return 1;
+ }
+ return 2;
+}
+
+void test7() {
+ enum {
+ A = 1,
+ B
+ } a;
+ switch(a) { //expected-warning{{enumeration value 'B' not handled in switch}}
+ case A:
+ break;
+ }
+ switch(a) {
+ case B:
+ case A:
+ break;
+ }
+ switch(a) {
+ case A:
+ case B:
+ case 3: // expected-warning{{case value not in enumerated type 'enum <anonymous enum}}
+ break;
+ }
+ switch(a) {
+ case A:
+ case B:
+ case 3 ... //expected-warning{{case value not in enumerated type 'enum <anonymous enum}}
+ 4: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}}
+ break;
+ }
+ switch(a) {
+ case 1 ... 2:
+ break;
+ }
+ switch(a) {
+ case 0 ... 2: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}}
+ break;
+ }
+ switch(a) {
+ case 1 ... 3: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}}
+ break;
+ }
+ switch(a) {
+ case 0 ... //expected-warning{{case value not in enumerated type 'enum <anonymous enum}}
+ 3: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}}
+ break;
+ }
+
+}
+
+void test8() {
+ enum {
+ A,
+ B,
+ C = 1
+ } a;
+ switch(a) {
+ case A:
+ case B:
+ break;
+ }
+ switch(a) {
+ case A:
+ case C:
+ break;
+ }
+ switch(a) { //expected-warning{{enumeration value 'B' not handled in switch}}
+ case A:
+ break;
+ }
+}
+
+void test9() {
+ enum {
+ A = 3,
+ C = 1
+ } a;
+ switch(a) {
+ case 0: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}}
+ case 1:
+ case 2: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}}
+ case 3:
+ case 4: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}}
+ break;
+ }
+}
+
+void test10() {
+ enum {
+ A = 10,
+ C = 2,
+ B = 4,
+ D = 12
+ } a;
+ switch(a) {
+ case 0 ... //expected-warning{{case value not in enumerated type 'enum <anonymous enum}}
+ 1: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}}
+ case 2 ... 4:
+ case 5 ... //expected-warning{{case value not in enumerated type 'enum <anonymous enum}}
+ 9: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}}
+ case 10 ... 12:
+ case 13 ... //expected-warning{{case value not in enumerated type 'enum <anonymous enum}}
+ 16: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}}
+ break;
+ }
+}
+
+void test11() {
+ enum {
+ A = -1,
+ B,
+ C
+ } a;
+ switch(a) { //expected-warning{{enumeration value 'A' not handled in switch}}
+ case B:
+ case C:
+ break;
+ }
+
+ switch(a) { //expected-warning{{enumeration value 'A' not explicitly handled in switch}}
+ case B:
+ case C:
+ break;
+
+ default:
+ break;
+ }
+}
+
+void test12() {
+ enum {
+ A = -1,
+ B = 4294967286
+ } a;
+ switch(a) {
+ case A:
+ case B:
+ break;
+ }
+}
+
+// <rdar://problem/7643909>
+typedef enum {
+ val1,
+ val2,
+ val3
+} my_type_t;
+
+int test13(my_type_t t) {
+ switch(t) { // expected-warning{{enumeration value 'val3' not handled in switch}}
+ case val1:
+ return 1;
+ case val2:
+ return 2;
+ }
+ return -1;
+}
+
+// <rdar://problem/7658121>
+enum {
+ EC0 = 0xFFFF0000,
+ EC1 = 0xFFFF0001,
+};
+
+int test14(int a) {
+ switch(a) {
+ case EC0: return 0;
+ case EC1: return 1;
+ }
+ return 0;
+}
+
+void f1(unsigned x) {
+ switch (x) {
+ case -1: break;
+ default: break;
+ }
+}
+
+void test15() {
+ int i = 0;
+ switch (1) { // expected-warning {{no case matching constant switch condition '1'}}
+ case 0: i = 0; break;
+ case 2: i++; break;
+ }
+}
+
+void test16() {
+ const char c = '5';
+ switch (c) { // expected-warning {{no case matching constant switch condition '53'}}
+ case '6': return;
+ }
+}
+
+// PR7359
+void test17(int x) {
+ switch (x >= 17) { // expected-warning {{switch condition has boolean value}}
+ case 0: return;
+ }
+
+ switch ((int) (x <= 17)) {
+ case 0: return;
+ }
+}
+
+int test18() {
+ enum { A, B } a;
+ switch (a) {
+ case A: return 0;
+ case B: return 1;
+ case 7: return 1; // expected-warning {{case value not in enumerated type}}
+ default: return 2; // expected-warning {{default label in switch which covers all enumeration values}}
+ }
+}
+
+// rdar://110822110
+typedef enum {
+ kOne = 1,
+} Ints;
+
+void rdar110822110(Ints i)
+{
+ switch (i) {
+ case kOne:
+ break;
+ case 2: // expected-warning {{case value not in enumerated type 'Ints'}}
+ break;
+ default: // expected-warning {{default label in switch which covers all enumeration values}}
+ break;
+ }
+}
diff --git a/clang/test/Sema/tentative-decls.c b/clang/test/Sema/tentative-decls.c
new file mode 100644
index 0000000..b15537b
--- /dev/null
+++ b/clang/test/Sema/tentative-decls.c
@@ -0,0 +1,65 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+// PR3310
+struct a x1; // expected-note 2{{forward declaration of 'struct a'}}
+static struct a x2; // expected-warning{{tentative definition of variable with internal linkage has incomplete non-array type 'struct a'}}
+struct a x3[10]; // expected-error{{array has incomplete element type 'struct a'}}
+struct a {int x;};
+static struct a x2_okay;
+struct a x3_okay[10];
+struct b x4; // expected-error{{tentative definition has type 'struct b' that is never completed}} \
+ // expected-note{{forward declaration of 'struct b'}}
+
+const int a [1] = {1};
+extern const int a[];
+
+extern const int b[];
+const int b [1] = {1};
+
+extern const int c[] = {1}; // expected-warning{{'extern' variable has an initializer}}
+const int c[];
+
+int i1 = 1; // expected-note {{previous definition is here}}
+int i1 = 2; // expected-error {{redefinition of 'i1'}}
+int i1;
+int i1;
+extern int i5; // expected-note {{previous definition is here}}
+static int i5; // expected-error{{static declaration of 'i5' follows non-static declaration}}
+
+static int i2 = 5; // expected-note 1 {{previous definition is here}}
+int i2 = 3; // expected-error{{non-static declaration of 'i2' follows static declaration}}
+
+static int i3 = 5;
+extern int i3;
+
+__private_extern__ int pExtern;
+int pExtern = 0;
+
+int i4;
+int i4;
+extern int i4;
+
+int (*pToArray)[];
+int (*pToArray)[8];
+
+int redef[10];
+int redef[]; // expected-note {{previous definition is here}}
+int redef[11]; // expected-error{{redefinition of 'redef'}}
+
+void func() {
+ extern int i6; // expected-note {{previous definition is here}}
+ static int i6; // expected-error{{static declaration of 'i6' follows non-static declaration}}
+}
+
+void func2(void)
+{
+ extern double *p;
+ extern double *p;
+}
+
+// <rdar://problem/6808352>
+static int a0[];
+static int b0;
+
+static int a0[] = { 4 };
+static int b0 = 5;
diff --git a/clang/test/Sema/text-diag.c b/clang/test/Sema/text-diag.c
new file mode 100644
index 0000000..6dcaaa8
--- /dev/null
+++ b/clang/test/Sema/text-diag.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only %s
+unsigned char *foo = "texto\
+que continua\
+e continua";
diff --git a/clang/test/Sema/thread-specifier.c b/clang/test/Sema/thread-specifier.c
new file mode 100644
index 0000000..9ec88c5
--- /dev/null
+++ b/clang/test/Sema/thread-specifier.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -verify %s
+
+__thread int t1;
+__thread extern int t2;
+__thread static int t3;
+__thread __private_extern__ int t4;
+struct t5 { __thread int x; }; // expected-error {{type name does not allow storage class to be specified}}
+__thread int t6(); // expected-error {{'__thread' is only allowed on variable declarations}}
+int f(__thread int t7) { // expected-error {{'__thread' is only allowed on variable declarations}}
+ __thread int t8; // expected-error {{'__thread' variables must have global storage}}
+ __thread extern int t9;
+ __thread static int t10;
+ __thread __private_extern__ int t11;
+ __thread auto int t12; // expected-error {{'__thread' variables must have global storage}}
+ __thread register int t13; // expected-error {{'__thread' variables must have global storage}}
+}
+__thread typedef int t14; // expected-error {{'__thread' is only allowed on variable declarations}}
+__thread int t15; // expected-note {{previous definition is here}}
+int t15; // expected-error {{non-thread-local declaration of 't15' follows thread-local declaration}}
+int t16; // expected-note {{previous definition is here}}
+__thread int t16; // expected-error {{thread-local declaration of 't16' follows non-thread-local declaration}}
diff --git a/clang/test/Sema/transparent-union-pointer.c b/clang/test/Sema/transparent-union-pointer.c
new file mode 100644
index 0000000..31c9391
--- /dev/null
+++ b/clang/test/Sema/transparent-union-pointer.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+typedef union {
+ union wait *__uptr;
+ int *__iptr;
+} __WAIT_STATUS __attribute__ ((__transparent_union__));
+
+extern int wait (__WAIT_STATUS __stat_loc);
+
+void fastcgi_cleanup() {
+ int status = 0;
+ wait(&status);
+}
+
diff --git a/clang/test/Sema/transparent-union.c b/clang/test/Sema/transparent-union.c
new file mode 100644
index 0000000..ab1ba18
--- /dev/null
+++ b/clang/test/Sema/transparent-union.c
@@ -0,0 +1,73 @@
+// RUN: %clang -fsyntax-only -Xclang -verify %s
+typedef union {
+ int *ip;
+ float *fp;
+ long *__restrict rlp;
+ void *vpa[1];
+} TU __attribute__((transparent_union));
+
+void f(TU); // expected-note{{passing argument to parameter here}}
+
+void g(int *ip, float *fp, char *cp) {
+ f(ip);
+ f(fp);
+ f(cp); // expected-error{{incompatible type}}
+ f(0);
+
+ TU tu_ip = ip; // expected-error{{incompatible type}}
+ TU tu;
+ tu.ip = ip;
+}
+
+/* Test ability to redeclare a function taking a transparent_union arg
+ with various compatible and incompatible argument types. */
+
+void fip(TU);
+void fip(int *i) {}
+
+void ffp(TU);
+void ffp(float *f) {}
+
+void flp(TU);
+void flp(long *l) {}
+
+void fvp(TU); // expected-note{{previous declaration is here}}
+void fvp(void *p) {} // expected-error{{conflicting types}}
+
+void fsp(TU); // expected-note{{previous declaration is here}}
+void fsp(short *s) {} // expected-error{{conflicting types}}
+
+void fi(TU); // expected-note{{previous declaration is here}}
+void fi(int i) {} // expected-error{{conflicting types}}
+
+void fvpp(TU); // expected-note{{previous declaration is here}}
+void fvpp(void **v) {} // expected-error{{conflicting types}}
+
+/* FIXME: we'd like to just use an "int" here and align it differently
+ from the normal "int", but if we do so we lose the alignment
+ information from the typedef within the compiler. */
+typedef struct { int x, y; } __attribute__((aligned(8))) aligned_struct8;
+
+typedef struct { int x, y; } __attribute__((aligned(4))) aligned_struct4;
+typedef union {
+ aligned_struct4 s4; // expected-note{{alignment of first field}}
+ aligned_struct8 s8; // expected-warning{{alignment of field}}
+} TU1 __attribute__((transparent_union));
+
+typedef union {
+ char c; // expected-note{{size of first field is 8 bits}}
+ int i; // expected-warning{{size of field}}
+} TU2 __attribute__((transparent_union));
+
+typedef union {
+ float f; // expected-warning{{floating}}
+} TU3 __attribute__((transparent_union));
+
+typedef union { } TU4 __attribute__((transparent_union)); // expected-warning{{field}}
+
+typedef int int4 __attribute__((ext_vector_type(4)));
+typedef union {
+ int4 vec; // expected-warning{{first field of a transparent union cannot have vector type 'int4'; transparent_union attribute ignored}}
+} TU5 __attribute__((transparent_union));
+
+
diff --git a/clang/test/Sema/type-spec-struct-union.c b/clang/test/Sema/type-spec-struct-union.c
new file mode 100644
index 0000000..ce65095
--- /dev/null
+++ b/clang/test/Sema/type-spec-struct-union.c
@@ -0,0 +1,65 @@
+// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
+
+/* This test checks the introduction of struct and union types based
+ on a type specifier of the form "struct-or-union identifier" when they
+ type has not yet been declared. See C99 6.7.2.3p8. */
+
+typedef struct S1 {
+ union {
+ struct S2 *x;
+ struct S3 *y;
+ } u1;
+} S1;
+
+int test_struct_scope(S1 *s1, struct S2 *s2, struct S3 *s3) {
+ if (s1->u1.x == s2) return 1;
+ if (s1->u1.y == s3) return 1;
+ return 0;
+}
+
+int test_struct_scope_2(S1 *s1) {
+ struct S2 { int x; } *s2 = 0;
+ if (s1->u1.x == s2) return 1; /* expected-warning {{comparison of distinct pointer types ('struct S2 *' and 'struct S2 *')}} */
+ return 0;
+}
+
+// FIXME: We do not properly implement C99 6.2.1p4, which says that
+// the type "struct S4" declared in the function parameter list has
+// block scope within the function definition. The problem, in this
+// case, is that the code is ill-formed but we warn about the two S4's
+// being incompatible (we think they are two different types).
+int test_struct_scope_3(struct S4 * s4) { // expected-warning{{declaration of 'struct S4' will not be visible outside of this function}}
+ struct S4 { int y; } *s4_2 = 0;
+ /* if (s4 == s4_2) return 1; */
+ return 0;
+}
+
+void f(struct S5 { int y; } s5); // expected-warning{{declaration of 'struct S5' will not be visible outside of this function}}
+
+// PR clang/3312
+struct S6 {
+ enum { BAR } e;
+};
+
+void test_S6() {
+ struct S6 a;
+ a.e = BAR;
+}
+
+// <rdar://problem/6487669>
+typedef struct z_foo_s {
+ struct bar_baz *baz;
+} z_foo;
+typedef z_foo *z_foop;
+struct bar_baz {
+ enum {
+ SQUAT, FLAG, DICT4, DICT3, DICT2, DICT1, DICT0, HOP, CHECK4, CHECK3, CHECK2, CHECK1, DONE, BAD
+ } mode;
+ int nowrap;
+};
+void
+wizbiz_quxPoof(z)
+ z_foop z;
+{
+ z->baz->mode = z->baz->nowrap ? HOP : SQUAT;
+}
diff --git a/clang/test/Sema/typecheck-binop.c b/clang/test/Sema/typecheck-binop.c
new file mode 100644
index 0000000..be52d0b
--- /dev/null
+++ b/clang/test/Sema/typecheck-binop.c
@@ -0,0 +1,27 @@
+/* RUN: %clang_cc1 %s -fsyntax-only -pedantic -verify
+ */
+struct incomplete; // expected-note{{forward declaration of 'struct incomplete'}}
+
+int sub1(int *a, double *b) {
+ return a - b; /* expected-error{{not pointers to compatible types}} */
+}
+
+void *sub2(struct incomplete *P) {
+ return P-4; /* expected-error{{arithmetic on a pointer to an incomplete type 'struct incomplete'}} */
+}
+
+void *sub3(void *P) {
+ return P-4; /* expected-warning{{arithmetic on a pointer to void is a GNU extension}} */
+}
+
+int sub4(void *P, void *Q) {
+ return P-Q; /* expected-warning{{arithmetic on pointers to void is a GNU extension}} */
+}
+
+int sub5(void *P, int *Q) {
+ return P-Q; /* expected-error{{not pointers to compatible types}} */
+}
+
+int logicaland1(int a) {
+ return a && (void)a; /* expected-error{{invalid operands}} */
+}
diff --git a/clang/test/Sema/typedef-prototype.c b/clang/test/Sema/typedef-prototype.c
new file mode 100644
index 0000000..8372154
--- /dev/null
+++ b/clang/test/Sema/typedef-prototype.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+typedef int unary_int_func(int arg);
+unary_int_func add_one;
+
+int add_one(int arg) {
+ return arg + 1;
+}
diff --git a/clang/test/Sema/typedef-redef.c b/clang/test/Sema/typedef-redef.c
new file mode 100644
index 0000000..025f65c
--- /dev/null
+++ b/clang/test/Sema/typedef-redef.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+typedef const int x; // expected-note {{previous definition is here}}
+extern x a;
+typedef int x; // expected-error {{typedef redefinition with different types}}
+extern x a;
+
+// <rdar://problem/6097585>
+int y; // expected-note 2 {{previous definition is here}}
+float y; // expected-error{{redefinition of 'y' with a different type}}
+double y; // expected-error{{redefinition of 'y' with a different type}}
diff --git a/clang/test/Sema/typedef-retain.c b/clang/test/Sema/typedef-retain.c
new file mode 100644
index 0000000..a7173b7
--- /dev/null
+++ b/clang/test/Sema/typedef-retain.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -fno-lax-vector-conversions
+
+typedef float float4 __attribute__((vector_size(16)));
+typedef int int4 __attribute__((vector_size(16)));
+typedef int4* int4p;
+
+void test1(float4 a, int4 *result, int i) {
+ result[i] = a; // expected-error {{assigning to 'int4' from incompatible type 'float4'}}
+}
+
+void test2(float4 a, int4p result, int i) {
+ result[i] = a; // expected-error {{assigning to 'int4' from incompatible type 'float4'}}
+}
+
+// PR2039
+typedef int a[5];
+void test3() {
+ typedef const a b;
+ b r;
+ r[0]=10; // expected-error {{read-only variable is not assignable}}
+}
+
+int test4(const a y) {
+ y[0] = 10; // expected-error {{read-only variable is not assignable}}
+}
+
diff --git a/clang/test/Sema/typedef-variable-type.c b/clang/test/Sema/typedef-variable-type.c
new file mode 100644
index 0000000..8a7ee8b
--- /dev/null
+++ b/clang/test/Sema/typedef-variable-type.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic -Wno-typedef-redefinition -std=c99
+
+// Make sure we accept a single typedef
+typedef int (*a)[!.0]; // expected-warning{{size of static array must be an integer constant expression}}
+
+// And make sure we accept identical redefinitions in system headers
+// (The test uses -Wno-typedef-redefinition to simulate this.)
+typedef int (*a)[!.0]; // expected-warning{{size of static array must be an integer constant expression}}
diff --git a/clang/test/Sema/typeof-use-deprecated.c b/clang/test/Sema/typeof-use-deprecated.c
new file mode 100644
index 0000000..238e501
--- /dev/null
+++ b/clang/test/Sema/typeof-use-deprecated.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+struct s { int a; } __attribute__((deprecated)) x; // expected-warning {{'s' is deprecated}}
+
+typeof(x) y; // expected-warning {{'s' is deprecated}}
+
+union un{ int a; } __attribute__((deprecated)) u; // expected-warning {{'un' is deprecated}}
+
+typeof( u) z; // expected-warning {{'un' is deprecated}}
+
+enum E{ one} __attribute__((deprecated)) e; // expected-warning {{'E' is deprecated}}
+
+typeof( e) w; // expected-warning {{'E' is deprecated}}
+
+struct foo { int x; } __attribute__((deprecated));
+typedef struct foo bar __attribute__((deprecated));
+bar x1; // expected-warning {{'bar' is deprecated}}
+
+int main() { typeof(x1) y; } // expected-warning {{'foo' is deprecated}}
+
+struct gorf { int x; };
+typedef struct gorf T __attribute__((deprecated));
+T t; // expected-warning {{'T' is deprecated}}
+void wee() { typeof(t) y; }
+
+
diff --git a/clang/test/Sema/types.c b/clang/test/Sema/types.c
new file mode 100644
index 0000000..3bec83e
--- /dev/null
+++ b/clang/test/Sema/types.c
@@ -0,0 +1,66 @@
+// RUN: %clang_cc1 %s -pedantic -verify -triple=x86_64-apple-darwin9
+
+// rdar://6097662
+typedef int (*T)[2];
+restrict T x;
+
+typedef int *S[2];
+restrict S y; // expected-error {{restrict requires a pointer or reference ('S' (aka 'int *[2]') is invalid)}}
+
+
+
+// int128_t is available.
+int a() {
+ __int128_t s;
+ __uint128_t t;
+}
+// but not a keyword
+int b() {
+ int __int128_t;
+ int __uint128_t;
+}
+// __int128 is a keyword
+int c() {
+ __int128 i;
+ unsigned __int128 j;
+ long unsigned __int128 k; // expected-error {{'long __int128' is invalid}}
+ int __int128; // expected-error {{cannot combine with previous}} expected-warning {{does not declare anything}}
+}
+// __int128_t is __int128; __uint128_t is unsigned __int128.
+typedef __int128 check_int_128; // expected-note {{here}}
+typedef __int128_t check_int_128; // expected-note {{here}} expected-warning {{redefinition}}
+typedef int check_int_128; // expected-error {{different types ('int' vs '__int128_t' (aka '__int128'))}}
+
+typedef unsigned __int128 check_uint_128; // expected-note {{here}}
+typedef __uint128_t check_uint_128; // expected-note {{here}} expected-warning {{redefinition}}
+typedef int check_uint_128; // expected-error {{different types ('int' vs '__uint128_t' (aka 'unsigned __int128'))}}
+
+// Array type merging should convert array size to whatever matches the target
+// pointer size.
+// rdar://6880874
+extern int i[1LL];
+int i[(short)1];
+
+enum e { e_1 };
+extern int j[sizeof(enum e)]; // expected-note {{previous definition}}
+int j[42]; // expected-error {{redefinition of 'j' with a different type}}
+
+// rdar://6880104
+_Decimal32 x; // expected-error {{GNU decimal type extension not supported}}
+
+
+// rdar://6880951
+int __attribute__ ((vector_size (8), vector_size (8))) v; // expected-error {{invalid vector element type}}
+
+void test(int i) {
+ char c = (char __attribute__((align(8)))) i; // expected-error {{'align' attribute ignored when parsing type}}
+}
+
+// http://llvm.org/PR11082
+//
+// FIXME: This may or may not be the correct approach (no warning or error),
+// but large amounts of Linux and FreeBSD code need this attribute to not be
+// a hard error in order to work correctly.
+void test2(int i) {
+ char c = (char __attribute__((may_alias))) i;
+}
diff --git a/clang/test/Sema/ucn-cstring.c b/clang/test/Sema/ucn-cstring.c
new file mode 100644
index 0000000..5d3e85d
--- /dev/null
+++ b/clang/test/Sema/ucn-cstring.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic
+
+int printf(const char *, ...);
+
+int main(void) {
+ int a[sizeof("hello \u2192 \u2603 \u2190 world") == 24 ? 1 : -1];
+
+ printf("%s (%zd)\n", "hello \u2192 \u2603 \u2190 world", sizeof("hello \u2192 \u2603 \u2190 world"));
+ printf("%s (%zd)\n", "\U00010400\U0001D12B", sizeof("\U00010400\U0001D12B"));
+ // Some error conditions...
+ printf("%s\n", "\U"); // expected-error{{\u used with no following hex digits}}
+ printf("%s\n", "\U00"); // expected-error{{incomplete universal character name}}
+ printf("%s\n", "\U0001"); // expected-error{{incomplete universal character name}}
+ printf("%s\n", "\u0001"); // expected-error{{universal character name refers to a control character}}
+ return 0;
+}
diff --git a/clang/test/Sema/uninit-variables-vectors.c b/clang/test/Sema/uninit-variables-vectors.c
new file mode 100644
index 0000000..10a8ecc
--- /dev/null
+++ b/clang/test/Sema/uninit-variables-vectors.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fsyntax-only -Wuninitialized -fsyntax-only %s -verify
+
+typedef int __v4si __attribute__((__vector_size__(16)));
+typedef float __m128 __attribute__((__vector_size__(16)));
+__m128 _mm_xor_ps(__m128 a, __m128 b);
+__m128 _mm_loadu_ps(const float *p);
+
+void test1(float *input) {
+ __m128 x, y, z, w, X; // expected-note {{variable 'x' is declared here}} expected-note {{variable 'y' is declared here}} expected-note {{variable 'w' is declared here}} expected-note {{variable 'z' is declared here}}
+ x = _mm_xor_ps(x,x); // expected-warning {{variable 'x' is uninitialized when used here}}
+ y = _mm_xor_ps(y,y); // expected-warning {{variable 'y' is uninitialized when used here}}
+ z = _mm_xor_ps(z,z); // expected-warning {{variable 'z' is uninitialized when used here}}
+ w = _mm_xor_ps(w,w); // expected-warning {{variable 'w' is uninitialized when used here}}
+ X = _mm_loadu_ps(&input[0]);
+ X = _mm_xor_ps(X,X); // no-warning
+}
+
diff --git a/clang/test/Sema/uninit-variables.c b/clang/test/Sema/uninit-variables.c
new file mode 100644
index 0000000..d62186d
--- /dev/null
+++ b/clang/test/Sema/uninit-variables.c
@@ -0,0 +1,426 @@
+// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -Wconditional-uninitialized -fsyntax-only -fblocks %s -verify
+
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+
+int test1() {
+ int x; // expected-note{{initialize the variable 'x' to silence this warning}}
+ return x; // expected-warning{{variable 'x' is uninitialized when used here}}
+}
+
+int test2() {
+ int x = 0;
+ return x; // no-warning
+}
+
+int test3() {
+ int x;
+ x = 0;
+ return x; // no-warning
+}
+
+int test4() {
+ int x; // expected-note{{initialize the variable 'x' to silence this warning}}
+ ++x; // expected-warning{{variable 'x' is uninitialized when used here}}
+ return x;
+}
+
+int test5() {
+ int x, y; // expected-note{{initialize the variable 'y' to silence this warning}}
+ x = y; // expected-warning{{variable 'y' is uninitialized when used here}}
+ return x;
+}
+
+int test6() {
+ int x; // expected-note{{initialize the variable 'x' to silence this warning}}
+ x += 2; // expected-warning{{variable 'x' is uninitialized when used here}}
+ return x;
+}
+
+int test7(int y) {
+ int x; // expected-note{{initialize the variable 'x' to silence this warning}}
+ if (y)
+ x = 1;
+ return x; // expected-warning{{variable 'x' may be uninitialized when used here}}
+}
+
+int test7b(int y) {
+ int x = x; // expected-note{{variable 'x' is declared here}}
+ if (y)
+ x = 1;
+ // Warn with "may be uninitialized" here (not "is uninitialized"), since the
+ // self-initialization is intended to suppress a -Wuninitialized warning.
+ return x; // expected-warning{{variable 'x' may be uninitialized when used here}}
+}
+
+int test8(int y) {
+ int x;
+ if (y)
+ x = 1;
+ else
+ x = 0;
+ return x;
+}
+
+int test9(int n) {
+ int x; // expected-note{{initialize the variable 'x' to silence this warning}}
+ for (unsigned i = 0 ; i < n; ++i) {
+ if (i == n - 1)
+ break;
+ x = 1;
+ }
+ return x; // expected-warning{{variable 'x' may be uninitialized when used here}}
+}
+
+int test10(unsigned n) {
+ int x; // expected-note{{initialize the variable 'x' to silence this warning}}
+ for (unsigned i = 0 ; i < n; ++i) {
+ x = 1;
+ }
+ return x; // expected-warning{{variable 'x' may be uninitialized when used here}}
+}
+
+int test11(unsigned n) {
+ int x; // expected-note{{initialize the variable 'x' to silence this warning}}
+ for (unsigned i = 0 ; i <= n; ++i) {
+ x = 1;
+ }
+ return x; // expected-warning{{variable 'x' may be uninitialized when used here}}
+}
+
+void test12(unsigned n) {
+ for (unsigned i ; n ; ++i) ; // expected-warning{{variable 'i' is uninitialized when used here}} expected-note{{initialize the variable 'i' to silence this warning}}
+}
+
+int test13() {
+ static int i;
+ return i; // no-warning
+}
+
+// Simply don't crash on this test case.
+void test14() {
+ const char *p = 0;
+ for (;;) {}
+}
+
+void test15() {
+ int x = x; // no-warning: signals intended lack of initialization.
+}
+
+int test15b() {
+ // Warn here with the self-init, since it does result in a use of
+ // an unintialized variable and this is the root cause.
+ int x = x; // expected-warning {{variable 'x' is uninitialized when used within its own initialization}}
+ return x;
+}
+
+// Don't warn in the following example; shows dataflow confluence.
+char *test16_aux();
+void test16() {
+ char *p = test16_aux();
+ for (unsigned i = 0 ; i < 100 ; i++)
+ p[i] = 'a'; // no-warning
+}
+
+void test17() {
+ // Don't warn multiple times about the same uninitialized variable
+ // along the same path.
+ int *x; // expected-note{{initialize the variable 'x' to silence this warning}}
+ *x = 1; // expected-warning{{variable 'x' is uninitialized when used here}}
+ *x = 1; // no-warning
+}
+
+int test18(int x, int y) {
+ int z;
+ if (x && y && (z = 1)) {
+ return z; // no-warning
+ }
+ return 0;
+}
+
+int test19_aux1();
+int test19_aux2();
+int test19_aux3(int *x);
+int test19() {
+ int z;
+ if (test19_aux1() + test19_aux2() && test19_aux1() && test19_aux3(&z))
+ return z; // no-warning
+ return 0;
+}
+
+int test20() {
+ int z; // expected-note{{initialize the variable 'z' to silence this warning}}
+ if ((test19_aux1() + test19_aux2() && test19_aux1()) || test19_aux3(&z))
+ return z; // expected-warning{{variable 'z' may be uninitialized when used here}}
+ return 0;
+}
+
+int test21(int x, int y) {
+ int z; // expected-note{{initialize the variable 'z' to silence this warning}}
+ if ((x && y) || test19_aux3(&z) || test19_aux2())
+ return z; // expected-warning{{variable 'z' may be uninitialized when used here}}
+ return 0;
+}
+
+int test22() {
+ int z;
+ while (test19_aux1() + test19_aux2() && test19_aux1() && test19_aux3(&z))
+ return z; // no-warning
+ return 0;
+}
+
+int test23() {
+ int z;
+ for ( ; test19_aux1() + test19_aux2() && test19_aux1() && test19_aux3(&z) ; )
+ return z; // no-warning
+ return 0;
+}
+
+// The basic uninitialized value analysis doesn't have enough path-sensitivity
+// to catch initializations relying on control-dependencies spanning multiple
+// conditionals. This possibly can be handled by making the CFG itself
+// represent such control-dependencies, but it is a niche case.
+int test24(int flag) {
+ unsigned val; // expected-note{{initialize the variable 'val' to silence this warning}}
+ if (flag)
+ val = 1;
+ if (!flag)
+ val = 1;
+ return val; // expected-warning{{variable 'val' may be uninitialized when used here}}
+}
+
+float test25() {
+ float x; // expected-note{{initialize the variable 'x' to silence this warning}}
+ return x; // expected-warning{{variable 'x' is uninitialized when used here}}
+}
+
+typedef int MyInt;
+MyInt test26() {
+ MyInt x; // expected-note{{initialize the variable 'x' to silence this warning}}
+ return x; // expected-warning{{variable 'x' is uninitialized when used here}}
+}
+
+// Test handling of sizeof().
+int test27() {
+ struct test_27 { int x; } *y;
+ return sizeof(y->x); // no-warning
+}
+
+int test28() {
+ int len; // expected-note{{initialize the variable 'len' to silence this warning}}
+ return sizeof(int[len]); // expected-warning{{variable 'len' is uninitialized when used here}}
+}
+
+void test29() {
+ int x; // expected-note{{initialize the variable 'x' to silence this warning}}
+ (void) ^{ (void) x; }; // expected-warning{{variable 'x' is uninitialized when captured by block}}
+}
+
+void test30() {
+ static int x; // no-warning
+ (void) ^{ (void) x; };
+}
+
+void test31() {
+ __block int x; // no-warning
+ (void) ^{ (void) x; };
+}
+
+int test32_x;
+void test32() {
+ (void) ^{ (void) test32_x; }; // no-warning
+}
+
+void test_33() {
+ int x; // no-warning
+ (void) x;
+}
+
+int test_34() {
+ int x; // expected-note{{initialize the variable 'x' to silence this warning}}
+ (void) x;
+ return x; // expected-warning{{variable 'x' is uninitialized when used here}}
+}
+
+// Test that this case doesn't crash.
+void test35(int x) {
+ __block int y = 0;
+ ^{ y = (x == 0); }();
+}
+
+// Test handling of indirect goto.
+void test36()
+{
+ void **pc; // expected-note{{initialize the variable 'pc' to silence this warning}}
+ void *dummy[] = { &&L1, &&L2 };
+ L1:
+ goto *pc; // expected-warning{{variable 'pc' is uninitialized when used here}}
+ L2:
+ goto *pc;
+}
+
+// Test && nested in ||.
+int test37_a();
+int test37_b();
+int test37()
+{
+ int identifier;
+ if ((test37_a() && (identifier = 1)) ||
+ (test37_b() && (identifier = 2))) {
+ return identifier; // no-warning
+ }
+ return 0;
+}
+
+// Test merging of path-specific dataflow values (without asserting).
+int test38(int r, int x, int y)
+{
+ int z;
+ return ((r < 0) || ((r == 0) && (x < y)));
+}
+
+int test39(int x) {
+ int y; // expected-note{{initialize the variable 'y' to silence this warning}}
+ int z = x + y; // expected-warning {{variable 'y' is uninitialized when used here}}
+ return z;
+}
+
+
+int test40(int x) {
+ int y; // expected-note{{initialize the variable 'y' to silence this warning}}
+ return x ? 1 : y; // expected-warning {{variable 'y' is uninitialized when used here}}
+}
+
+int test41(int x) {
+ int y; // expected-note{{initialize the variable 'y' to silence this warning}}
+ if (x) y = 1; // no-warning
+ return y; // expected-warning {{variable 'y' may be uninitialized when used here}}
+}
+
+void test42() {
+ int a;
+ a = 30; // no-warning
+}
+
+void test43_aux(int x);
+void test43(int i) {
+ int x; // expected-note{{initialize the variable 'x' to silence this warning}}
+ for (i = 0 ; i < 10; i++)
+ test43_aux(x++); // expected-warning {{variable 'x' is uninitialized when used here}}
+}
+
+void test44(int i) {
+ int x = i;
+ int y; // expected-note{{initialize the variable 'y' to silence this warning}}
+ for (i = 0; i < 10; i++ ) {
+ test43_aux(x++); // no-warning
+ x += y; // expected-warning {{variable 'y' is uninitialized when used here}}
+ }
+}
+
+int test45(int j) {
+ int x = 1, y = x + 1;
+ if (y) // no-warning
+ return x;
+ return y;
+}
+
+void test46()
+{
+ int i; // expected-note{{initialize the variable 'i' to silence this warning}}
+ int j = i ? : 1; // expected-warning {{variable 'i' is uninitialized when used here}}
+}
+
+void *test47(int *i)
+{
+ return i ? : 0; // no-warning
+}
+
+void *test49(int *i)
+{
+ int a;
+ return &a ? : i; // no-warning
+}
+
+void test50()
+{
+ char c[1 ? : 2]; // no-warning
+}
+
+int test51(void)
+{
+ __block int a;
+ ^(void) {
+ a = 42;
+ }();
+ return a; // no-warning
+}
+
+// FIXME: This is a false positive, but it tests logical operations in switch statements.
+int test52(int a, int b) {
+ int x; // expected-note {{initialize the variable 'x' to silence this warning}}
+ switch (a || b) { // expected-warning {{switch condition has boolean value}}
+ case 0:
+ x = 1;
+ break;
+ case 1:
+ x = 2;
+ break;
+ }
+ return x; // expected-warning {{variable 'x' may be uninitialized when used here}}
+}
+
+void test53() {
+ int x; // expected-note {{initialize the variable 'x' to silence this warning}}
+ int y = (x); // expected-warning {{variable 'x' is uninitialized when used here}}
+}
+
+// This CFG caused the uninitialized values warning to inf-loop.
+extern int PR10379_g();
+void PR10379_f(int *len) {
+ int new_len; // expected-note{{initialize the variable 'new_len' to silence this warning}}
+ for (int i = 0; i < 42 && PR10379_g() == 0; i++) {
+ if (PR10379_g() == 1)
+ continue;
+ if (PR10379_g() == 2)
+ PR10379_f(&new_len);
+ else if (PR10379_g() == 3)
+ PR10379_f(&new_len);
+ *len += new_len; // expected-warning {{variable 'new_len' may be uninitialized when used here}}
+ }
+}
+
+// Test that sizeof(VLA) doesn't trigger a warning.
+void test_vla_sizeof(int x) {
+ double (*memory)[2][x] = malloc(sizeof(*memory)); // no-warning
+}
+
+// Test absurd case of deadcode + use of blocks. This previously was a false positive
+// due to an analysis bug.
+int test_block_and_dead_code() {
+ __block int x;
+ ^{ x = 1; }();
+ if (0)
+ return x;
+ return x; // no-warning
+}
+
+// This previously triggered an infinite loop in the analysis.
+void PR11069(int a, int b) {
+ unsigned long flags;
+ for (;;) {
+ if (a && !b)
+ break;
+ }
+ for (;;) {
+ // This does not trigger a warning because it isn't a real use.
+ (void)(flags); // no-warning
+ }
+}
+
+// Test uninitialized value used in loop condition.
+void rdar9432305(float *P) {
+ int i; // expected-note {{initialize the variable 'i' to silence this warning}}
+ for (; i < 10000; ++i) // expected-warning {{variable 'i' is uninitialized when used here}}
+ P[i] = 0.0f;
+}
diff --git a/clang/test/Sema/unnamed-bitfield-init.c b/clang/test/Sema/unnamed-bitfield-init.c
new file mode 100644
index 0000000..f3cc49c
--- /dev/null
+++ b/clang/test/Sema/unnamed-bitfield-init.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+typedef struct {
+ int a; int : 24; char b;
+} S;
+
+S a = { 1, 2 };
diff --git a/clang/test/Sema/unused-expr-system-header.c b/clang/test/Sema/unused-expr-system-header.c
new file mode 100644
index 0000000..dcc8918
--- /dev/null
+++ b/clang/test/Sema/unused-expr-system-header.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -isystem %S/Inputs -fsyntax-only -verify %s
+#include <unused-expr-system-header.h>
+void f(int i1, int i2) {
+ POSSIBLY_BAD_MACRO(5);
+ STATEMENT_EXPR_MACRO(5);
+ COMMA_MACRO_1(i1 == i2, f(i1, i2)); // expected-warning {{expression result unused}}
+ COMMA_MACRO_2(i1 == i2, f(i1, i2));
+ COMMA_MACRO_3(i1 == i2, f(i1, i2)); // expected-warning {{expression result unused}}
+ COMMA_MACRO_4(i1 == i2, f(i1, i2));
+}
diff --git a/clang/test/Sema/unused-expr.c b/clang/test/Sema/unused-expr.c
new file mode 100644
index 0000000..9761116
--- /dev/null
+++ b/clang/test/Sema/unused-expr.c
@@ -0,0 +1,123 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unreachable-code
+
+int foo(int X, int Y);
+
+double sqrt(double X); // implicitly const because of no -fmath-errno!
+
+void bar(volatile int *VP, int *P, int A,
+ _Complex double C, volatile _Complex double VC) {
+
+ VP < P; // expected-warning {{expression result unused}}
+ (void)A;
+ (void)foo(1,2); // no warning.
+
+ A < foo(1, 2); // expected-warning {{expression result unused}}
+
+ foo(1,2)+foo(4,3); // expected-warning {{expression result unused}}
+
+
+ *P; // expected-warning {{expression result unused}}
+ *VP; // no warning.
+ P[4]; // expected-warning {{expression result unused}}
+ VP[4]; // no warning.
+
+ __real__ C; // expected-warning {{expression result unused}}
+ __real__ VC;
+
+ // We know this can't change errno because of no -fmath-errno.
+ sqrt(A); // expected-warning {{ignoring return value of function declared with const attribute}}
+}
+
+extern void t1();
+extern void t2();
+void t3(int c) {
+ c ? t1() : t2();
+}
+
+// This shouldn't warn: the expr at the end of the stmtexpr really is used.
+int stmt_expr(int x, int y) {
+ return ({int _a = x, _b = y; _a > _b ? _a : _b; });
+}
+
+void nowarn(unsigned char* a, unsigned char* b)
+{
+ unsigned char c = 1;
+ *a |= c, *b += c;
+
+
+ // PR4633
+ int y, x;
+ ((void)0), y = x;
+}
+
+void t4(int a) {
+ int b = 0;
+
+ if (a)
+ b < 1; // expected-warning{{expression result unused}}
+ else
+ b < 2; // expected-warning{{expression result unused}}
+
+ while (1)
+ b < 3; // expected-warning{{expression result unused}}
+
+ do
+ b < 4; // expected-warning{{expression result unused}}
+ while (1);
+
+ for (;;)
+ b < 5; // expected-warning{{expression result unused}}
+
+ for (b < 1;;) {} // expected-warning{{expression result unused}}
+ for (;b < 1;) {}
+ for (;;b < 1) {} // expected-warning{{expression result unused}}
+}
+
+// rdar://7186119
+int t5f(void) __attribute__((warn_unused_result));
+void t5() {
+ t5f(); // expected-warning {{ignoring return value of function declared with warn_unused_result}}
+}
+
+
+int fn1() __attribute__ ((warn_unused_result));
+int fn2() __attribute__ ((pure));
+int fn3() __attribute__ ((const));
+// rdar://6587766
+int t6() {
+ if (fn1() < 0 || fn2(2,1) < 0 || fn3(2) < 0) // no warnings
+ return -1;
+
+ fn1(); // expected-warning {{ignoring return value of function declared with warn_unused_result attribute}}
+ fn2(92, 21); // expected-warning {{ignoring return value of function declared with pure attribute}}
+ fn3(42); // expected-warning {{ignoring return value of function declared with const attribute}}
+ __builtin_fabsf(0); // expected-warning {{ignoring return value of function declared with const attribute}}
+ return 0;
+}
+
+int t7 __attribute__ ((warn_unused_result)); // expected-warning {{'warn_unused_result' attribute only applies to functions}}
+
+// PR4010
+int (*fn4)(void) __attribute__ ((warn_unused_result));
+void t8() {
+ fn4(); // expected-warning {{ignoring return value of function declared with warn_unused_result attribute}}
+}
+
+void t9() __attribute__((warn_unused_result)); // expected-warning {{attribute 'warn_unused_result' cannot be applied to functions without return value}}
+
+// rdar://7410924
+void *some_function(void);
+void t10() {
+ (void*) some_function(); //expected-warning {{expression result unused; should this cast be to 'void'?}}
+}
+
+void f(int i, ...) {
+ __builtin_va_list ap;
+
+ __builtin_va_start(ap, i);
+ __builtin_va_arg(ap, int);
+ __builtin_va_end(ap);
+}
+
+// PR8371
+int fn5() __attribute__ ((__const));
diff --git a/clang/test/Sema/usual-float.c b/clang/test/Sema/usual-float.c
new file mode 100644
index 0000000..5a9ab34
--- /dev/null
+++ b/clang/test/Sema/usual-float.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -fsyntax-only
+
+typedef float CGFloat;
+
+extern void func(CGFloat);
+void foo(int dir, int n, int tindex) {
+ const float PI = 3.142;
+ CGFloat cgf = 3.4;
+
+ float ang = (float) tindex * (-dir*2.0f*PI/n);
+ func((CGFloat)cgf/65535.0f);
+}
diff --git a/clang/test/Sema/va_arg_x86_32.c b/clang/test/Sema/va_arg_x86_32.c
new file mode 100644
index 0000000..e49f0a4
--- /dev/null
+++ b/clang/test/Sema/va_arg_x86_32.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -triple=i686-pc-linux-gnu %s
+
+int a() {
+ __builtin_va_arg((char*)0, int); // expected-error {{expression is not assignable}}
+ __builtin_va_arg((void*){0}, int); // expected-error {{first argument to 'va_arg' is of type 'void *'}}
+}
diff --git a/clang/test/Sema/va_arg_x86_64.c b/clang/test/Sema/va_arg_x86_64.c
new file mode 100644
index 0000000..9f514c1
--- /dev/null
+++ b/clang/test/Sema/va_arg_x86_64.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -triple=x86_64-unknown-freebsd7.0 %s
+
+// PR2631
+char* foo(char *fmt, __builtin_va_list ap)
+{
+ return __builtin_va_arg((ap), char *);
+}
+
+// PR2692
+typedef __builtin_va_list va_list;
+static void 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/Sema/var-redecl.c b/clang/test/Sema/var-redecl.c
new file mode 100644
index 0000000..f7576b6
--- /dev/null
+++ b/clang/test/Sema/var-redecl.c
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int outer1; // expected-note{{previous definition is here}}
+extern int outer2; // expected-note{{previous definition is here}}
+int outer4;
+int outer4; // expected-note{{previous definition is here}}
+int outer5;
+int outer6(float); // expected-note{{previous definition is here}}
+int outer7(float);
+
+void outer_test() {
+ extern float outer1; // expected-error{{redefinition of 'outer1' with a different type}}
+ extern float outer2; // expected-error{{redefinition of 'outer2' with a different type}}
+ extern float outer3; // expected-note{{previous definition is here}}
+ double outer4;
+ extern int outer5; // expected-note{{previous definition is here}}
+ extern int outer6; // expected-error{{redefinition of 'outer6' as different kind of symbol}}
+ int outer7;
+ extern int outer8; // expected-note{{previous definition is here}}
+ extern int outer9;
+ {
+ extern int outer9; // expected-note{{previous definition is here}}
+ }
+}
+
+int outer3; // expected-error{{redefinition of 'outer3' with a different type}}
+float outer4; // expected-error{{redefinition of 'outer4' with a different type}}
+float outer5; // expected-error{{redefinition of 'outer5' with a different type}}
+int outer8(int); // expected-error{{redefinition of 'outer8' as different kind of symbol}}
+float outer9; // expected-error{{redefinition of 'outer9' with a different type}}
+
+extern int outer13; // expected-note{{previous definition is here}}
+void outer_shadowing_test() {
+ extern int outer10;
+ extern int outer11; // expected-note{{previous definition is here}}
+ extern int outer12; // expected-note{{previous definition is here}}
+ {
+ float outer10;
+ float outer11;
+ float outer12;
+ {
+ extern int outer10; // okay
+ extern float outer11; // expected-error{{redefinition of 'outer11' with a different type}}
+ static double outer12;
+ {
+ extern float outer12; // expected-error{{redefinition of 'outer12' with a different type}}
+ extern float outer13; // expected-error{{redefinition of 'outer13' with a different type}}
+ }
+ }
+ }
+}
+
+void g18(void) { // expected-note{{'g18' declared here}}
+ extern int g19;
+}
+int *p=&g19; // expected-error{{use of undeclared identifier 'g19'}} \
+ // expected-warning{{incompatible pointer types}}
+
+// PR3645
+static int a;
+extern int a; // expected-note {{previous definition is here}}
+int a; // expected-error {{non-static declaration of 'a' follows static declaration}}
diff --git a/clang/test/Sema/varargs-x86-64.c b/clang/test/Sema/varargs-x86-64.c
new file mode 100644
index 0000000..2fe9b10
--- /dev/null
+++ b/clang/test/Sema/varargs-x86-64.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-apple-darwin9
+
+// rdar://6726818
+void f1() {
+ const __builtin_va_list args2;
+ (void)__builtin_va_arg(args2, int); // expected-error {{first argument to 'va_arg' is of type 'const __builtin_va_list' and not 'va_list'}}
+}
+
diff --git a/clang/test/Sema/varargs.c b/clang/test/Sema/varargs.c
new file mode 100644
index 0000000..07081ed
--- /dev/null
+++ b/clang/test/Sema/varargs.c
@@ -0,0 +1,78 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-apple-darwin9
+
+void f1(int a)
+{
+ __builtin_va_list ap;
+
+ __builtin_va_start(ap, a, a); // expected-error {{too many arguments to function}}
+ __builtin_va_start(ap, a); // expected-error {{'va_start' used in function with fixed args}}
+}
+
+void f2(int a, int b, ...)
+{
+ __builtin_va_list ap;
+
+ __builtin_va_start(ap, 10); // expected-warning {{second parameter of 'va_start' not last named argument}}
+ __builtin_va_start(ap, a); // expected-warning {{second parameter of 'va_start' not last named argument}}
+ __builtin_va_start(ap, b);
+}
+
+void f3(float a, ...)
+{
+ __builtin_va_list ap;
+
+ __builtin_va_start(ap, a);
+ __builtin_va_start(ap, (a));
+}
+
+
+// stdarg: PR3075
+void f4(const char *msg, ...) {
+ __builtin_va_list ap;
+ __builtin_stdarg_start((ap), (msg));
+ __builtin_va_end (ap);
+}
+
+void f5() {
+ __builtin_va_list ap;
+ __builtin_va_start(ap,ap); // expected-error {{'va_start' used in function with fixed args}}
+}
+
+void f6(int a, ...) {
+ __builtin_va_list ap;
+ __builtin_va_start(ap); // expected-error {{too few arguments to function}}
+}
+
+// PR3350
+void
+foo(__builtin_va_list authors, ...) {
+ __builtin_va_start (authors, authors);
+ (void)__builtin_va_arg(authors, int);
+ __builtin_va_end (authors);
+}
+
+void f7(int a, ...) {
+ __builtin_va_list ap;
+ __builtin_va_start(ap, a);
+ // FIXME: This error message is sub-par.
+ __builtin_va_arg(ap, int) = 1; // expected-error {{expression is not assignable}}
+ int *x = &__builtin_va_arg(ap, int); // expected-error {{address expression must be an lvalue or a function designator}}
+ __builtin_va_end(ap);
+}
+
+void f8(int a, ...) {
+ __builtin_va_list ap;
+ __builtin_va_start(ap, a);
+ (void)__builtin_va_arg(ap, void); // expected-error {{second argument to 'va_arg' is of incomplete type 'void'}}
+ __builtin_va_end(ap);
+}
+
+enum E { x = -1, y = 2, z = 10000 };
+void f9(__builtin_va_list args)
+{
+ (void)__builtin_va_arg(args, float); // expected-warning {{second argument to 'va_arg' is of promotable type 'float'}}
+ (void)__builtin_va_arg(args, enum E); // Don't warn here in C
+ (void)__builtin_va_arg(args, short); // expected-warning {{second argument to 'va_arg' is of promotable type 'short'}}
+ (void)__builtin_va_arg(args, char); // expected-warning {{second argument to 'va_arg' is of promotable type 'char'}}
+}
diff --git a/clang/test/Sema/variadic-block.c b/clang/test/Sema/variadic-block.c
new file mode 100644
index 0000000..ba4bb71
--- /dev/null
+++ b/clang/test/Sema/variadic-block.c
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -fblocks
+
+#include <stdarg.h>
+
+int main(int argc, char *argv[]) {
+
+ long (^addthem)(const char *, ...) = ^long (const char *format, ...){
+ va_list argp;
+ const char *p;
+ int i;
+ char c;
+ double d;
+ long result = 0;
+ va_start(argp, format);
+ for (p = format; *p; p++) switch (*p) {
+ case 'i':
+ i = va_arg(argp, int);
+ result += i;
+ break;
+ case 'd':
+ d = va_arg(argp, double);
+ result += (int)d;
+ break;
+ case 'c':
+ c = va_arg(argp, int);
+ result += c;
+ break;
+ }
+ return result;
+ };
+ long testresult = addthem("ii", 10, 20);
+ if (testresult != 30) {
+ return 1;
+ }
+ testresult = addthem("idc", 30, 40.0, 'a');
+ if (testresult != (70+'a')) {
+ return 1;
+ }
+ return 0;
+}
+
diff --git a/clang/test/Sema/variadic-incomplete-arg-type.c b/clang/test/Sema/variadic-incomplete-arg-type.c
new file mode 100644
index 0000000..2b5dd1a
--- /dev/null
+++ b/clang/test/Sema/variadic-incomplete-arg-type.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+// rdar://10961370
+
+typedef struct __CFError * CFErrorRef; // expected-note {{forward declaration of 'struct __CFError'}}
+
+void junk(int, ...);
+
+int main()
+{
+ CFErrorRef error;
+ junk(1, *error, (void)0); // expected-error {{argument type 'struct __CFError' is incomplete}} \
+ // expected-error {{argument type 'void' is incomplete}}
+}
diff --git a/clang/test/Sema/vector-assign.c b/clang/test/Sema/vector-assign.c
new file mode 100644
index 0000000..f01eb45
--- /dev/null
+++ b/clang/test/Sema/vector-assign.c
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -Wvector-conversion
+typedef unsigned int v2u __attribute__ ((vector_size (8)));
+typedef signed int v2s __attribute__ ((vector_size (8)));
+typedef signed int v1s __attribute__ ((vector_size (4)));
+typedef float v2f __attribute__ ((vector_size(8)));
+typedef signed short v4ss __attribute__ ((vector_size (8)));
+
+void test1() {
+ v2s v1;
+ v2u v2;
+ v1s v3;
+ v2f v4;
+ v4ss v5;
+
+ v1 = v2; // expected-warning {{incompatible vector types assigning to 'v2s' from 'v2u'}}
+ v1 = v3; // expected-error {{assigning to 'v2s' from incompatible type 'v1s'}}
+ v1 = v4; // expected-warning {{incompatible vector types assigning to 'v2s' from 'v2f'}}
+ v1 = v5; // expected-warning {{incompatible vector types assigning to 'v2s' from 'v4ss'}}
+
+ v2 = v1; // expected-warning {{incompatible vector types assigning to 'v2u' from 'v2s'}}
+ v2 = v3; // expected-error {{assigning to 'v2u' from incompatible type 'v1s'}}
+ v2 = v4; // expected-warning {{incompatible vector types assigning to 'v2u' from 'v2f'}}
+ v2 = v5; // expected-warning {{incompatible vector types assigning to 'v2u' from 'v4ss'}}
+
+ v3 = v1; // expected-error {{assigning to 'v1s' from incompatible type 'v2s'}}
+ v3 = v2; // expected-error {{assigning to 'v1s' from incompatible type 'v2u'}}
+ v3 = v4; // expected-error {{assigning to 'v1s' from incompatible type 'v2f'}}
+ v3 = v5; // expected-error {{assigning to 'v1s' from incompatible type 'v4ss'}}
+
+ v4 = v1; // expected-warning {{incompatible vector types assigning to 'v2f' from 'v2s'}}
+ v4 = v2; // expected-warning {{incompatible vector types assigning to 'v2f' from 'v2u'}}
+ v4 = v3; // expected-error {{assigning to 'v2f' from incompatible type 'v1s'}}
+ v4 = v5; // expected-warning {{incompatible vector types assigning to 'v2f' from 'v4ss'}}
+
+ v5 = v1; // expected-warning {{incompatible vector types assigning to 'v4ss' from 'v2s'}}
+ v5 = v2; // expected-warning {{incompatible vector types assigning to 'v4ss' from 'v2u'}}
+ v5 = v3; // expected-error {{assigning to 'v4ss' from incompatible type 'v1s'}}
+ v5 = v4; // expected-warning {{incompatible vector types assigning to 'v4ss' from 'v2f'}}
+}
+
+// PR2263
+float test2(__attribute__((vector_size(16))) float a, int b) {
+ return a[b];
+}
+
+// PR4838
+typedef long long __attribute__((__vector_size__(2 * sizeof(long long))))
+longlongvec;
+
+void test3a(longlongvec *); // expected-note{{passing argument to parameter here}}
+void test3(const unsigned *src) {
+ test3a(src); // expected-warning {{incompatible pointer types passing 'const unsigned int *' to parameter of type 'longlongvec *'}}
+}
diff --git a/clang/test/Sema/vector-cast.c b/clang/test/Sema/vector-cast.c
new file mode 100644
index 0000000..f1cf013
--- /dev/null
+++ b/clang/test/Sema/vector-cast.c
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify -Wvector-conversion
+
+typedef long long t1 __attribute__ ((vector_size (8)));
+typedef char t2 __attribute__ ((vector_size (16)));
+typedef float t3 __attribute__ ((vector_size (16)));
+
+void f()
+{
+ t1 v1;
+ t2 v2;
+ t3 v3;
+
+ v2 = (t2)v1; // -expected-error {{invalid conversion between vector type \
+'t2' and 't1' of different size}}
+ v1 = (t1)v2; // -expected-error {{invalid conversion between vector type \
+'t1' and 't2' of different size}}
+ v3 = (t3)v2;
+
+ v1 = (t1)(char *)10; // -expected-error {{invalid conversion between vector \
+type 't1' and scalar type 'char *'}}
+ v1 = (t1)(long long)10;
+ v1 = (t1)(short)10; // -expected-error {{invalid conversion between vector \
+type 't1' and integer type 'short' of different size}}
+
+ long long r1 = (long long)v1;
+ short r2 = (short)v1; // -expected-error {{invalid conversion between vector \
+type 't1' and integer type 'short' of different size}}
+ char *r3 = (char *)v1; // -expected-error {{invalid conversion between vector\
+ type 't1' and scalar type 'char *'}}
+}
+
+
+void f2(t2 X); // expected-note{{passing argument to parameter 'X' here}}
+
+void f3(t3 Y) {
+ f2(Y); // expected-warning {{incompatible vector types passing 't3' to parameter of type 't2'}}
+}
+
diff --git a/clang/test/Sema/vector-init.c b/clang/test/Sema/vector-init.c
new file mode 100644
index 0000000..5be040a
--- /dev/null
+++ b/clang/test/Sema/vector-init.c
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+//typedef __attribute__(( ext_vector_type(4) )) float float4;
+typedef float float4 __attribute__((vector_size(16)));
+
+float4 foo = (float4){ 1.0, 2.0, 3.0, 4.0 };
+
+float4 foo2 = (float4){ 1.0, 2.0, 3.0, 4.0 , 5.0 }; // expected-warning{{excess elements in vector initializer}}
+
+float4 array[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0};
+int array_sizecheck[(sizeof(array) / sizeof(float4)) == 3 ? 1 : -1];
+
+float4 array2[2] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0,
+ 9.0 }; // expected-warning {{excess elements in array initializer}}
+
+float4 array3[2] = { {1.0, 2.0, 3.0}, 5.0, 6.0, 7.0, 8.0,
+ 9.0 }; // expected-warning {{excess elements in array initializer}}
+
+// PR5650
+__attribute__((vector_size(16))) float f1(void) {
+ __attribute__((vector_size(16))) float vec = {0.0f, 0.0f, 0.0f};
+ return(vec);
+}
+
+__attribute__((vector_size(16))) float f2(
+ __attribute__((vector_size(16))) float a1) {
+ return(a1);
+}
+
+
+
+// PR5265
+typedef float __attribute__((ext_vector_type (3))) float3;
+int test2[sizeof(float3) == sizeof(float4) ? 1 : -1];
+
+// rdar://problem/8345836
+typedef long long __attribute__((vector_size(16))) longlong2;
+typedef short __attribute__((vector_size(16))) short8;
+typedef short __attribute__((vector_size(8))) short4;
+void test3() {
+ extern short8 test3_helper(void);
+ longlong2 arr1[2] = { test3_helper(), test3_helper() };
+ short4 arr2[2] = { test3_helper(), test3_helper() }; // expected-error 2 {{initializing 'short4' with an expression of incompatible type 'short8'}}
+}
diff --git a/clang/test/Sema/vector-ops.c b/clang/test/Sema/vector-ops.c
new file mode 100644
index 0000000..3ab75d0
--- /dev/null
+++ b/clang/test/Sema/vector-ops.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -Wvector-conversion
+typedef unsigned int v2u __attribute__ ((vector_size (8)));
+typedef int v2s __attribute__ ((vector_size (8)));
+typedef float v2f __attribute__ ((vector_size(8)));
+
+void test1(v2u v2ua, v2s v2sa, v2f v2fa) {
+ // Bitwise binary operators
+ (void)(v2ua & v2ua);
+ (void)(v2fa & v2fa); // expected-error{{invalid operands to binary expression}}
+
+ // Unary operators
+ (void)(~v2ua);
+ (void)(~v2fa); // expected-error{{invalid argument type 'v2f' to unary}}
+
+ // Comparison operators
+ v2ua = (v2ua==v2sa); // expected-warning{{incompatible vector types assigning to 'v2u' from 'int __attribute__((ext_vector_type(2)))'}}
+ v2sa = (v2ua==v2sa);
+
+ // Arrays
+ int array1[v2ua]; // expected-error{{size of array has non-integer type 'v2u'}}
+ int array2[17];
+ // FIXME: error message below needs type!
+ (void)(array2[v2ua]); // expected-error{{array subscript is not an integer}}
+
+ v2u *v2u_ptr = 0;
+ v2s *v2s_ptr;
+ v2s_ptr = v2u_ptr; // expected-warning{{converts between pointers to integer types with different sign}}
+}
+
diff --git a/clang/test/Sema/vfprintf-invalid-redecl.c b/clang/test/Sema/vfprintf-invalid-redecl.c
new file mode 100644
index 0000000..cbf47a6
--- /dev/null
+++ b/clang/test/Sema/vfprintf-invalid-redecl.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+// PR4290
+
+// The following declaration is not compatible with vfprintf(), but make
+// sure this isn't an error: autoconf expects this to build.
+char vfprintf(); // expected-warning {{incompatible redeclaration of library function 'vfprintf'}} expected-note {{'vfprintf' is a builtin}}
diff --git a/clang/test/Sema/vfprintf-valid-redecl.c b/clang/test/Sema/vfprintf-valid-redecl.c
new file mode 100644
index 0000000..14fbbc4
--- /dev/null
+++ b/clang/test/Sema/vfprintf-valid-redecl.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 %s -fsyntax-only -pedantic -verify
+// PR4290
+
+// The following declaration is compatible with vfprintf, so we shouldn't
+// warn.
+int vfprintf();
diff --git a/clang/test/Sema/vla-2.c b/clang/test/Sema/vla-2.c
new file mode 100644
index 0000000..819cab9
--- /dev/null
+++ b/clang/test/Sema/vla-2.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic
+// Check that we don't crash trying to emit warnings in a potentially-evaluated
+// sizeof or typeof. (This test needs to be in a separate file because we use
+// a different codepath when we have already emitted an error.)
+
+int PotentiallyEvaluatedSizeofWarn(int n) {
+ return (int)sizeof *(0 << 32,(int(*)[n])0); // expected-warning {{expression result unused}} expected-warning {{shift count >= width of type}}
+}
+
+void PotentiallyEvaluatedTypeofWarn(int n) {
+ __typeof(*(0 << 32,(int(*)[n])0)) x; // expected-warning {{expression result unused}} expected-warning {{shift count >= width of type}}
+ (void)x;
+}
+
+void PotentiallyEvaluatedArrayBoundWarn(int n) {
+ (void)*(int(*)[(0 << 32,n)])0; // FIXME: We should warn here.
+}
diff --git a/clang/test/Sema/vla.c b/clang/test/Sema/vla.c
new file mode 100644
index 0000000..4fd6361
--- /dev/null
+++ b/clang/test/Sema/vla.c
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic
+
+int test1() {
+ typedef int x[test1()]; // vla
+ static int y = sizeof(x); // expected-error {{not a compile-time constant}}
+}
+
+// PR2347
+void f (unsigned int m)
+{
+ int e[2][m];
+
+ e[0][0] = 0;
+}
+
+// PR3048
+int x = sizeof(struct{char qq[x];}); // expected-error {{fields must have a constant size}}
+
+// PR2352
+void f2(unsigned int m)
+{
+ extern int e1[2][m]; // expected-error {{variable length array declaration can not have 'extern' linkage}}
+
+ e1[0][0] = 0;
+
+}
+
+// PR2361
+int i;
+int c[][i]; // expected-error {{variably modified type declaration not allowed at file scope}}
+int d[i]; // expected-error {{variable length array declaration not allowed at file scope}}
+
+int (*e)[i]; // expected-error {{variably modified type declaration not allowed at file scope}}
+
+void f3()
+{
+ static int a[i]; // expected-error {{variable length array declaration can not have 'static' storage duration}}
+ extern int b[i]; // expected-error {{variable length array declaration can not have 'extern' linkage}}
+
+ extern int (*c1)[i]; // expected-error {{variably modified type declaration can not have 'extern' linkage}}
+ static int (*d)[i];
+}
+
+// PR3663
+static const unsigned array[((2 * (int)((((4) / 2) + 1.0/3.0) * (4) - 1e-8)) + 1)]; // expected-warning {{variable length array folded to constant array as an extension}}
+
+int a[*]; // expected-error {{star modifier used outside of function prototype}}
+int f4(int a[*][*]);
+
+// PR2044
+int pr2044(int b) {int (*c(void))[b];**c() = 2;} // expected-error {{variably modified type}}
+int pr2044b;
+int (*pr2044c(void))[pr2044b]; // expected-error {{variably modified type}}
+
+const int f5_ci = 1;
+void f5() { char a[][f5_ci] = {""}; } // expected-warning {{variable length array folded to constant array as an extension}}
+
+// PR5185
+void pr5185(int a[*]);
+void pr5185(int a[*]) // expected-error {{variable length array must be bound in function definition}}
+{
+}
+
+// Make sure this isn't treated as an error
+int TransformBug(int a) {
+ return sizeof(*(int(*)[({ goto v; v: a;})]) 0); // expected-warning {{use of GNU statement expression extension}}
+}
diff --git a/clang/test/Sema/void_arg.c b/clang/test/Sema/void_arg.c
new file mode 100644
index 0000000..337972f
--- /dev/null
+++ b/clang/test/Sema/void_arg.c
@@ -0,0 +1,26 @@
+/* RUN: %clang_cc1 -fsyntax-only %s -verify
+ */
+
+typedef void Void;
+
+void foo() {
+ int X;
+
+ X = sizeof(int (void a)); // expected-error {{argument may not have 'void' type}}
+ X = sizeof(int (int, void)); // expected-error {{must be the first and only parameter}}
+ X = sizeof(int (void, ...)); // expected-error {{must be the first and only parameter}}
+
+ X = sizeof(int (Void a)); // expected-error {{argument may not have 'void' type}}
+ X = sizeof(int (int, Void)); // expected-error {{must be the first and only parameter}}
+ X = sizeof(int (Void, ...)); // expected-error {{must be the first and only parameter}}
+
+ // Accept these.
+ X = sizeof(int (void));
+ X = sizeof(int (Void));
+}
+
+// this is ok.
+void bar(Void) {
+}
+
+void f(const void); // expected-error {{parameter must not have type qualifiers}}
diff --git a/clang/test/Sema/warn-cast-align.c b/clang/test/Sema/warn-cast-align.c
new file mode 100644
index 0000000..9d64699
--- /dev/null
+++ b/clang/test/Sema/warn-cast-align.c
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -Wcast-align -verify %s
+
+// Simple casts.
+void test0(char *P) {
+ char *a = (char*) P;
+ short *b = (short*) P; // expected-warning {{cast from 'char *' to 'short *' increases required alignment from 1 to 2}}
+ int *c = (int*) P; // expected-warning {{cast from 'char *' to 'int *' increases required alignment from 1 to 4}}
+}
+
+// Casts from void* are a special case.
+void test1(void *P) {
+ char *a = (char*) P;
+ short *b = (short*) P;
+ int *c = (int*) P;
+
+ const volatile void *P2 = P;
+ char *d = (char*) P2;
+ short *e = (short*) P2;
+ int *f = (int*) P2;
+
+ const char *g = (const char*) P2;
+ const short *h = (const short*) P2;
+ const int *i = (const int*) P2;
+
+ const volatile char *j = (const volatile char*) P2;
+ const volatile short *k = (const volatile short*) P2;
+ const volatile int *l = (const volatile int*) P2;
+}
+
+// Aligned struct.
+struct __attribute__((aligned(16))) A {
+ char buffer[16];
+};
+void test2(char *P) {
+ struct A *a = (struct A*) P; // expected-warning {{cast from 'char *' to 'struct A *' increases required alignment from 1 to 16}}
+}
+
+// Incomplete type.
+void test3(char *P) {
+ struct B *b = (struct B*) P;
+}
diff --git a/clang/test/Sema/warn-char-subscripts.c b/clang/test/Sema/warn-char-subscripts.c
new file mode 100644
index 0000000..374a609
--- /dev/null
+++ b/clang/test/Sema/warn-char-subscripts.c
@@ -0,0 +1,64 @@
+// RUN: %clang_cc1 -Wchar-subscripts -fsyntax-only -verify %s
+
+void t1() {
+ int array[1] = { 0 };
+ char subscript = 0;
+ int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}}
+}
+
+void t2() {
+ int array[1] = { 0 };
+ char subscript = 0;
+ int val = subscript[array]; // expected-warning{{array subscript is of type 'char'}}
+}
+
+void t3() {
+ int *array = 0;
+ char subscript = 0;
+ int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}}
+}
+
+void t4() {
+ int *array = 0;
+ char subscript = 0;
+ int val = subscript[array]; // expected-warning{{array subscript is of type 'char'}}
+}
+
+char returnsChar();
+void t5() {
+ int *array = 0;
+ int val = array[returnsChar()]; // expected-warning{{array subscript is of type 'char'}}
+}
+
+void t6() {
+ int array[1] = { 0 };
+ signed char subscript = 0;
+ int val = array[subscript]; // no warning for explicit signed char
+}
+
+void t7() {
+ int array[1] = { 0 };
+ unsigned char subscript = 0;
+ int val = array[subscript]; // no warning for unsigned char
+}
+
+typedef char CharTy;
+void t8() {
+ int array[1] = { 0 };
+ CharTy subscript = 0;
+ int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}}
+}
+
+typedef signed char SignedCharTy;
+void t9() {
+ int array[1] = { 0 };
+ SignedCharTy subscript = 0;
+ int val = array[subscript]; // no warning for explicit signed char
+}
+
+typedef unsigned char UnsignedCharTy;
+void t10() {
+ int array[1] = { 0 };
+ UnsignedCharTy subscript = 0;
+ int val = array[subscript]; // no warning for unsigned char
+}
diff --git a/clang/test/Sema/warn-freestanding-complex.c b/clang/test/Sema/warn-freestanding-complex.c
new file mode 100644
index 0000000..14e063f
--- /dev/null
+++ b/clang/test/Sema/warn-freestanding-complex.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -ffreestanding -pedantic -verify %s
+
+void foo(float _Complex c) { // expected-warning{{complex numbers are an extension in a freestanding C99 implementation}}
+}
diff --git a/clang/test/Sema/warn-gnu-designators.c b/clang/test/Sema/warn-gnu-designators.c
new file mode 100644
index 0000000..bdb3374
--- /dev/null
+++ b/clang/test/Sema/warn-gnu-designators.c
@@ -0,0 +1,2 @@
+// RUN: %clang_cc1 -Wno-gnu-designator -verify %s
+struct { int x, y, z[12]; } value = { x:17, .z [3 ... 5] = 7 };
diff --git a/clang/test/Sema/warn-missing-braces.c b/clang/test/Sema/warn-missing-braces.c
new file mode 100644
index 0000000..ebfe984
--- /dev/null
+++ b/clang/test/Sema/warn-missing-braces.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -fsyntax-only -Wmissing-braces -verify %s
+
+int a[2][2] = { 0, 1, 2, 3 }; // expected-warning{{suggest braces}} expected-warning{{suggest braces}}
diff --git a/clang/test/Sema/warn-missing-prototypes.c b/clang/test/Sema/warn-missing-prototypes.c
new file mode 100644
index 0000000..bfd1459
--- /dev/null
+++ b/clang/test/Sema/warn-missing-prototypes.c
@@ -0,0 +1,37 @@
+// RUN: %clang -Wmissing-prototypes -fsyntax-only -Xclang -verify %s
+
+int f();
+
+int f(int x) { return x; } // expected-warning{{no previous prototype for function 'f'}}
+
+static int g(int x) { return x; }
+
+int h(int x) { return x; } // expected-warning{{no previous prototype for function 'h'}}
+
+static int g2();
+
+int g2(int x) { return x; }
+
+void test(void);
+
+int h3();
+int h4(int);
+int h4();
+
+void test(void) {
+ int h2(int x);
+ int h3(int x);
+ int h4();
+}
+
+int h2(int x) { return x; } // expected-warning{{no previous prototype for function 'h2'}}
+int h3(int x) { return x; } // expected-warning{{no previous prototype for function 'h3'}}
+int h4(int x) { return x; }
+
+int f2(int);
+int f2();
+
+int f2(int x) { return x; }
+
+// rdar://6759522
+int main(void) { return 0; }
diff --git a/clang/test/Sema/warn-shadow.c b/clang/test/Sema/warn-shadow.c
new file mode 100644
index 0000000..32aca8d
--- /dev/null
+++ b/clang/test/Sema/warn-shadow.c
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -fblocks -Wshadow %s
+
+int i; // expected-note 3 {{previous declaration is here}}
+
+void foo() {
+ int pass1;
+ int i; // expected-warning {{declaration shadows a variable in the global scope}} \
+ // expected-note {{previous declaration is here}}
+ {
+ int pass2;
+ int i; // expected-warning {{declaration shadows a local variable}} \
+ // expected-note {{previous declaration is here}}
+ {
+ int pass3;
+ int i; // expected-warning {{declaration shadows a local variable}}
+ }
+ }
+
+ int sin; // okay; 'sin' has not been declared, even though it's a builtin.
+}
+
+// <rdar://problem/7677531>
+void (^test1)(int) = ^(int i) { // expected-warning {{declaration shadows a variable in the global scope}} \
+ // expected-note{{previous declaration is here}}
+ {
+ int i; // expected-warning {{declaration shadows a local variable}} \
+ // expected-note{{previous declaration is here}}
+
+ (^(int i) { return i; })(i); //expected-warning {{declaration shadows a local variable}}
+ }
+};
+
+
+struct test2 {
+ int i;
+};
+
+void test3(void) {
+ struct test4 {
+ int i;
+ };
+}
+
+void test4(int i) { // expected-warning {{declaration shadows a variable in the global scope}}
+}
+
+// Don't warn about shadowing for function declarations.
+void test5(int i);
+void test6(void (*f)(int i)) {}
+void test7(void *context, void (*callback)(void *context)) {}
+
+extern int bob; // expected-note {{previous declaration is here}}
+
+// rdar://8883302
+void rdar8883302() {
+ extern int bob; // don't warn for shadowing.
+}
+
+void test8() {
+ int bob; // expected-warning {{declaration shadows a variable in the global scope}}
+}
diff --git a/clang/test/Sema/warn-sizeof-arrayarg.c b/clang/test/Sema/warn-sizeof-arrayarg.c
new file mode 100644
index 0000000..ba8a5fa
--- /dev/null
+++ b/clang/test/Sema/warn-sizeof-arrayarg.c
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+typedef int Arr[10];
+
+typedef int trungl_int;
+
+void f(int a[10], Arr arr) { // \
+// expected-note {{declared here}} \
+// expected-note {{declared here}} \
+// expected-note {{declared here}} \
+// expected-note {{declared here}}
+
+ /* Should warn. */
+ (void)sizeof(a); // \
+ // expected-warning{{sizeof on array function parameter will return size of 'int *' instead of 'int [10]'}}
+ (void)sizeof((((a)))); // \
+ // expected-warning{{sizeof on array function parameter will return size of 'int *' instead of 'int [10]'}}
+ (void)sizeof a; // \
+ // expected-warning{{sizeof on array function parameter will return size of 'int *' instead of 'int [10]'}}
+ (void)sizeof arr; // \
+ // expected-warning{{sizeof on array function parameter will return size of 'int *' instead of 'Arr' (aka 'int [10]')}}
+
+ /* Shouldn't warn. */
+ int b[10];
+ (void)sizeof b;
+ Arr brr;
+ (void)sizeof brr;
+ (void)sizeof(Arr);
+ (void)sizeof(int);
+}
diff --git a/clang/test/Sema/warn-strlcpycat-size.c b/clang/test/Sema/warn-strlcpycat-size.c
new file mode 100644
index 0000000..8babdde
--- /dev/null
+++ b/clang/test/Sema/warn-strlcpycat-size.c
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -Wstrlcpy-strlcat-size -verify -fsyntax-only %s
+
+typedef __SIZE_TYPE__ size_t;
+size_t strlcpy (char * restrict dst, const char * restrict src, size_t size);
+size_t strlcat (char * restrict dst, const char * restrict src, size_t size);
+size_t strlen (const char *s);
+
+char s1[100];
+char s2[200];
+char * s3;
+
+struct {
+ char f1[100];
+ char f2[100][3];
+} s4, **s5;
+
+int x;
+
+void f(void)
+{
+ strlcpy(s1, s2, sizeof(s1)); // no warning
+ strlcpy(s1, s2, sizeof(s2)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
+ strlcpy(s1, s3, strlen(s3)+1); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
+ strlcat(s2, s3, sizeof(s3)); // expected-warning {{size argument in 'strlcat' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
+ strlcpy(s4.f1, s2, sizeof(s2)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
+ strlcpy((*s5)->f2[x], s2, sizeof(s2)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
+ strlcpy(s1+3, s2, sizeof(s2)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}}
+}
+
+// Don't issue FIXIT for flexible arrays.
+struct S {
+ int y;
+ char x[];
+};
+
+void flexible_arrays(struct S *s) {
+ char str[] = "hi";
+ strlcpy(s->x, str, sizeof(str)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}}
+}
+
+// Don't issue FIXIT for destinations of size 1.
+void size_1() {
+ char z[1];
+ char str[] = "hi";
+
+ strlcpy(z, str, sizeof(str)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}}
+}
+
+// Support VLAs.
+void vlas(int size) {
+ char z[size];
+ char str[] = "hi";
+
+ strlcpy(z, str, sizeof(str)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
+}
diff --git a/clang/test/Sema/warn-strncat-size.c b/clang/test/Sema/warn-strncat-size.c
new file mode 100644
index 0000000..7157edf
--- /dev/null
+++ b/clang/test/Sema/warn-strncat-size.c
@@ -0,0 +1,71 @@
+// RUN: %clang_cc1 -Wstrncat-size -verify -fsyntax-only %s
+// RUN: %clang_cc1 -DUSE_BUILTINS -Wstrncat-size -verify -fsyntax-only %s
+// RUN: %clang_cc1 -fsyntax-only -Wstrncat-size -fixit -x c %s
+// RUN: %clang_cc1 -DUSE_BUILTINS -fsyntax-only -Wstrncat-size -fixit -x c %s
+
+typedef __SIZE_TYPE__ size_t;
+size_t strlen (const char *s);
+
+#ifdef USE_BUILTINS
+# define BUILTIN(f) __builtin_ ## f
+#else
+# define BUILTIN(f) f
+#endif
+
+#define strncat BUILTIN(strncat)
+char *strncat(char *restrict s1, const char *restrict s2, size_t n);
+
+struct {
+ char f1[100];
+ char f2[100][3];
+} s4, **s5;
+
+char s1[100];
+char s2[200];
+int x;
+
+void test(char *src) {
+ char dest[10];
+
+ strncat(dest, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAA", sizeof(dest) - strlen(dest) - 1); // no-warning
+ strncat(dest, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAA", sizeof(dest) - 1); // no-warning - the code might assume that dest is empty
+
+ strncat(dest, src, sizeof(src)); // expected-warning {{size argument in 'strncat' call appears to be size of the source}} expected-note {{change the argument to be the free space in the destination buffer minus the terminating null byte}}
+
+ strncat(dest, src, sizeof(src) - 1); // expected-warning {{size argument in 'strncat' call appears to be size of the source}} expected-note {{change the argument to be the free space in the destination buffer minus the terminating null byte}}
+
+ strncat(dest, "AAAAAAAAAAAAAAAAAAAAAAAAAAA", sizeof(dest)); // expected-warning{{the value of the size argument in 'strncat' is too large, might lead to a buffer overflow}} expected-note {{change the argument to be the free space in the destination buffer minus the terminating null byte}}
+
+ strncat(dest, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", sizeof(dest) - strlen(dest)); // expected-warning{{the value of the size argument in 'strncat' is too large, might lead to a buffer overflow}} expected-note {{change the argument to be the free space in the destination buffer minus the terminating null byte}}
+
+ strncat((*s5)->f2[x], s2, sizeof(s2)); // expected-warning {{size argument in 'strncat' call appears to be size of the source}} expected-note {{change the argument to be the free space in the destination buffer minus the terminating null byte}}
+ strncat(s1+3, s2, sizeof(s2)); // expected-warning {{size argument in 'strncat' call appears to be size of the source}}
+ strncat(s4.f1, s2, sizeof(s2)); // expected-warning {{size argument in 'strncat' call appears to be size of the source}} expected-note {{change the argument to be the free space in the destination buffer minus the terminating null byte}}
+}
+
+// Don't issue FIXIT for flexible arrays.
+struct S {
+ int y;
+ char x[];
+};
+
+void flexible_arrays(struct S *s) {
+ char str[] = "hi";
+ strncat(s->x, str, sizeof(str)); // expected-warning {{size argument in 'strncat' call appears to be size of the source}}
+}
+
+// Don't issue FIXIT for destinations of size 1.
+void size_1() {
+ char z[1];
+ char str[] = "hi";
+
+ strncat(z, str, sizeof(z)); // expected-warning{{the value of the size argument in 'strncat' is too large, might lead to a buffer overflow}}
+}
+
+// Support VLAs.
+void vlas(int size) {
+ char z[size];
+ char str[] = "hi";
+
+ strncat(z, str, sizeof(str)); // expected-warning {{size argument in 'strncat' call appears to be size of the source}} expected-note {{change the argument to be the free space in the destination buffer minus the terminating null byte}}
+}
diff --git a/clang/test/Sema/warn-unreachable.c b/clang/test/Sema/warn-unreachable.c
new file mode 100644
index 0000000..636513f
--- /dev/null
+++ b/clang/test/Sema/warn-unreachable.c
@@ -0,0 +1,134 @@
+// RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks -Wunreachable-code -Wno-unused-value -Wno-covered-switch-default
+
+int halt() __attribute__((noreturn));
+int live();
+int dead();
+
+void test1() {
+ goto c;
+ d:
+ goto e; // expected-warning {{will never be executed}}
+ c: ;
+ int i;
+ return;
+ goto b; // expected-warning {{will never be executed}}
+ goto a; // expected-warning {{will never be executed}}
+ b:
+ i = 1;
+ a:
+ i = 2;
+ goto f;
+ e:
+ goto d;
+ f: ;
+}
+
+void test2() {
+ int i;
+ switch (live()) {
+ case 1:
+ halt(),
+ dead(); // expected-warning {{will never be executed}}
+
+ case 2:
+ live(), halt(),
+ dead(); // expected-warning {{will never be executed}}
+
+ case 3:
+ live()
+ + // expected-warning {{will never be executed}}
+ halt();
+ dead();
+
+ case 4:
+ a4:
+ live(),
+ halt();
+ goto a4; // expected-warning {{will never be executed}}
+
+ case 5:
+ goto a5;
+ c5:
+ dead(); // expected-warning {{will never be executed}}
+ goto b5;
+ a5:
+ live(),
+ halt();
+ b5:
+ goto c5;
+
+ case 6:
+ if (live())
+ goto e6;
+ live(),
+ halt();
+ d6:
+ dead(); // expected-warning {{will never be executed}}
+ goto b6;
+ c6:
+ dead();
+ goto b6;
+ e6:
+ live(),
+ halt();
+ b6:
+ goto c6;
+ case 7:
+ halt()
+ +
+ dead(); // expected-warning {{will never be executed}}
+ - // expected-warning {{will never be executed}}
+ halt();
+ case 8:
+ i // expected-warning {{will never be executed}}
+ +=
+ halt();
+ case 9:
+ halt()
+ ? // expected-warning {{will never be executed}}
+ dead() : dead();
+ case 10:
+ ( // expected-warning {{will never be executed}}
+ float)halt();
+ case 11: {
+ int a[5];
+ live(),
+ a[halt() // expected-warning {{will never be executed}}
+ ];
+ }
+ }
+}
+
+enum Cases { C1, C2, C3 };
+int test_enum_cases(enum Cases C) {
+ switch (C) {
+ case C1:
+ case C2:
+ case C3:
+ return 1;
+ default: {
+ int i = 0; // expected-warning{{will never be executed}}
+ ++i;
+ return i;
+ }
+ }
+}
+
+// Handle unreachable code triggered by macro expansions.
+void __myassert_rtn(const char *, const char *, int, const char *) __attribute__((__noreturn__));
+
+#define myassert(e) \
+ (__builtin_expect(!(e), 0) ? __myassert_rtn(__func__, __FILE__, __LINE__, #e) : (void)0)
+
+void test_assert() {
+ myassert(0 && "unreachable");
+ return; // no-warning
+}
+
+// Test case for PR 9774. Tests that dead code in macros aren't warned about.
+#define MY_MAX(a,b) ((a) >= (b) ? (a) : (b))
+void PR9774(int *s) {
+ for (int i = 0; i < MY_MAX(2, 3); i++) // no-warning
+ s[i] = 0;
+}
+
diff --git a/clang/test/Sema/warn-unused-function.c b/clang/test/Sema/warn-unused-function.c
new file mode 100644
index 0000000..8f4cdcb
--- /dev/null
+++ b/clang/test/Sema/warn-unused-function.c
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-function -Wunneeded-internal-declaration -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wunused %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wall %s
+
+void foo() {}
+static void f2() {}
+static void f1() {f2();} // expected-warning{{unused}}
+
+static int f0() { return 17; } // expected-warning{{not needed and will not be emitted}}
+int x = sizeof(f0());
+
+static void f3();
+extern void f3() { } // expected-warning{{unused}}
+
+// FIXME: This will trigger a warning when it should not.
+// Update once PR6281 is fixed.
+//inline static void f4();
+//void f4() { }
+
+static void __attribute__((used)) f5() {}
+static void f6();
+static void __attribute__((used)) f6();
+static void f6() {};
+
+static void f7(void);
+void f8(void(*a0)(void));
+void f9(void) { f8(f7); }
+static void f7(void) {}
+
+__attribute__((unused)) static void bar(void);
+void bar(void) { }
+
+__attribute__((constructor)) static void bar2(void);
+void bar2(void) { }
+
+__attribute__((destructor)) static void bar3(void);
+void bar3(void) { }
+
+static void f10(void); // expected-warning{{unused}}
+static void f10(void);
+
+static void f11(void);
+static void f11(void) { } // expected-warning{{unused}}
+
+static void f12(void) { } // expected-warning{{unused}}
+static void f12(void);
+
+// PR7923
+static void unused(void) { unused(); } // expected-warning{{not needed and will not be emitted}}
+
+// rdar://8728293
+static void cleanupMalloc(char * const * const allocation) { }
+void f13(void) {
+ char * const __attribute__((cleanup(cleanupMalloc))) a;
+ (void)a;
+}
diff --git a/clang/test/Sema/warn-unused-label.c b/clang/test/Sema/warn-unused-label.c
new file mode 100644
index 0000000..48370a5
--- /dev/null
+++ b/clang/test/Sema/warn-unused-label.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-label -verify %s
+
+void f() {
+ a:
+ goto a;
+ b: // expected-warning{{unused}}
+ c: __attribute__((unused));
+ d: __attribute__((noreturn)); // expected-warning {{'noreturn' attribute only applies to functions}}
+ goto d;
+ return;
+}
diff --git a/clang/test/Sema/warn-unused-parameters.c b/clang/test/Sema/warn-unused-parameters.c
new file mode 100644
index 0000000..af048e7
--- /dev/null
+++ b/clang/test/Sema/warn-unused-parameters.c
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -fblocks -fsyntax-only -Wunused-parameter %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fblocks -fsyntax-only -Wunused %s 2>&1 | FileCheck -check-prefix=CHECK-unused %s
+
+int f0(int x,
+ int y,
+ int z __attribute__((unused))) {
+ return x;
+}
+
+void f1() {
+ (void)^(int x,
+ int y,
+ int z __attribute__((unused))) { return x; };
+}
+
+// Used when testing '-Wunused' to see that we only emit one diagnostic, and no
+// warnings for the above cases.
+static void achor() {};
+
+// CHECK: 5:12: warning: unused parameter 'y'
+// CHECK: 12:15: warning: unused parameter 'y'
+// CHECK-unused: 1 warning generated
+
+// RUN: %clang_cc1 -fblocks -fsyntax-only -Weverything %s 2>&1 | FileCheck -check-prefix=CHECK-everything %s
+// RUN: %clang_cc1 -fblocks -fsyntax-only -Weverything -Werror %s 2>&1 | FileCheck -check-prefix=CHECK-everything-error %s
+// RUN: %clang_cc1 -fblocks -fsyntax-only -Weverything -Wno-unused %s 2>&1 | FileCheck -check-prefix=CHECK-everything-no-unused %s
+// CHECK-everything: 6 warnings generated
+// CHECK-everything-error: 5 errors generated
+// CHECK-everything-no-unused: 5 warnings generated
+
diff --git a/clang/test/Sema/warn-unused-value.c b/clang/test/Sema/warn-unused-value.c
new file mode 100644
index 0000000..95cd8fb
--- /dev/null
+++ b/clang/test/Sema/warn-unused-value.c
@@ -0,0 +1,90 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wunused-value -Wunused-label %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wunused %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wall %s
+
+int i = 0;
+int j = 0;
+
+void foo();
+
+// PR4806
+void pr4806() {
+ 1,foo(); // expected-warning {{expression result unused}}
+
+ // other
+ foo();
+ i; // expected-warning {{expression result unused}}
+
+ i,foo(); // expected-warning {{expression result unused}}
+ foo(),i; // expected-warning {{expression result unused}}
+
+ i,j,foo(); // expected-warning {{expression result unused}} expected-warning {{expression result unused}}
+ i,foo(),j; // expected-warning {{expression result unused}} expected-warning {{expression result unused}}
+ foo(),i,j; // expected-warning {{expression result unused}} expected-warning {{expression result unused}}
+
+ i++;
+
+ i++,foo();
+ foo(),i++;
+
+ i++,j,foo(); // expected-warning {{expression result unused}}
+ i++,foo(),j; // expected-warning {{expression result unused}}
+ foo(),i++,j; // expected-warning {{expression result unused}}
+
+ i,j++,foo(); // expected-warning {{expression result unused}}
+ i,foo(),j++; // expected-warning {{expression result unused}}
+ foo(),i,j++; // expected-warning {{expression result unused}}
+
+ i++,j++,foo();
+ i++,foo(),j++;
+ foo(),i++,j++;
+
+ {};
+ ({});
+ ({}),foo();
+ foo(),({});
+
+ (int)1U; // expected-warning {{expression result unused}}
+ (void)1U;
+
+ // pointer to volatile has side effect (thus no warning)
+ int* pi = &i;
+ volatile int* pj = &j;
+ *pi; // expected-warning {{expression result unused}}
+ *pj;
+
+ foo_label: // expected-warning {{unused label}}
+ i; // expected-warning {{expression result unused}}
+}
+
+// Don't warn about unused '||', '&&' expressions that contain assignments.
+int test_logical_foo1();
+int test_logical_foo2();
+int test_logical_foo3();
+int test_logical_bar() {
+ int x = 0;
+ (x = test_logical_foo1()) || // no-warning
+ (x = test_logical_foo2()) || // no-warning
+ (x = test_logical_foo3()); // no-warning
+
+ x || test_logical_foo1(); // no-warning
+
+ return x;
+}
+
+// PR8282
+void conditional_for_control_flow(int cond, int x, int y)
+{
+ cond? y++ : x; // no-warning
+ cond? y : ++x; // no-warning
+ cond? (x |= y) : ++x; // no-warning
+ cond? y : x; // expected-warning {{expression result unused}}
+}
+
+struct s0 { int f0; };
+
+void f0(int a);
+void f1(struct s0 *a) {
+ // rdar://8139785
+ f0((int)(a->f0 + 1, 10)); // expected-warning {{expression result unused}}
+}
diff --git a/clang/test/Sema/warn-unused-variables.c b/clang/test/Sema/warn-unused-variables.c
new file mode 100644
index 0000000..58e52b1
--- /dev/null
+++ b/clang/test/Sema/warn-unused-variables.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -fblocks -verify %s
+
+struct s0 {
+ unsigned int i;
+};
+
+int proto(int a, int b);
+
+void f0(void) {
+ int a __attribute__((unused)),
+ b; // expected-warning{{unused}}
+ return;
+}
+
+void f1(void) {
+ int i;
+ (void)sizeof(i);
+ return;
+}
+
+// PR5933
+int f2() {
+ int X = 4; // Shouldn't have a bogus 'unused variable X' warning.
+ return Y + X; // expected-error {{use of undeclared identifier 'Y'}}
+}
+
+int f3() {
+ int X1 = 4;
+ (void)(Y1 + X1); // expected-error {{use of undeclared identifier 'Y1'}}
+ (void)(^() { int X = 4; }); // expected-warning{{unused}}
+ (void)(^() { int X = 4; return Y + X; }); // expected-error {{use of undeclared identifier 'Y'}}
+}
diff --git a/clang/test/Sema/warn-write-strings.c b/clang/test/Sema/warn-write-strings.c
new file mode 100644
index 0000000..dee554c
--- /dev/null
+++ b/clang/test/Sema/warn-write-strings.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -fconst-strings %s
+
+// PR4804
+char* x = "foo"; // expected-warning {{initializing 'char *' with an expression of type 'const char [4]' discards qualifiers}}
+
+// PR7192
+#include <stddef.h>
+void test(wchar_t *dst) {
+ dst[0] = 0; // Ok.
+}
diff --git a/clang/test/Sema/wchar.c b/clang/test/Sema/wchar.c
new file mode 100644
index 0000000..28ec2f1
--- /dev/null
+++ b/clang/test/Sema/wchar.c
@@ -0,0 +1,22 @@
+// RUN: %clang %s -fsyntax-only -Xclang -verify
+// RUN: %clang %s -fsyntax-only -fshort-wchar -Xclang -verify -DSHORT_WCHAR
+
+typedef __WCHAR_TYPE__ wchar_t;
+
+#if defined(_WIN32) || defined(_M_IX86) || defined(__CYGWIN__) \
+ || defined(_M_X64) || defined(SHORT_WCHAR)
+ #define WCHAR_T_TYPE unsigned short
+#elif defined(__sun) || defined(__AuroraUX__)
+ #define WCHAR_T_TYPE long
+#else /* Solaris or AuroraUX. */
+ #define WCHAR_T_TYPE int
+#endif
+
+int check_wchar_size[sizeof(*L"") == sizeof(wchar_t) ? 1 : -1];
+
+void foo() {
+ WCHAR_T_TYPE t1[] = L"x";
+ wchar_t tab[] = L"x";
+ WCHAR_T_TYPE t2[] = "x"; // expected-error {{initializer}}
+ char t3[] = L"x"; // expected-error {{initializer}}
+}
diff --git a/clang/test/Sema/weak-import-on-enum.c b/clang/test/Sema/weak-import-on-enum.c
new file mode 100644
index 0000000..3a2c0e5
--- /dev/null
+++ b/clang/test/Sema/weak-import-on-enum.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin %s
+// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s
+// rdar://10277579
+
+enum __attribute__((deprecated)) __attribute__((weak_import)) A {
+ a0
+};
+
diff --git a/clang/test/Sema/x86-attr-force-align-arg-pointer.c b/clang/test/Sema/x86-attr-force-align-arg-pointer.c
new file mode 100644
index 0000000..5d36e9a
--- /dev/null
+++ b/clang/test/Sema/x86-attr-force-align-arg-pointer.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple i386-apple-darwin10 -fsyntax-only -verify %s
+
+int a __attribute__((force_align_arg_pointer)); // expected-warning{{attribute only applies to functions}}
+
+// It doesn't matter where the attribute is located.
+void b(void) __attribute__((force_align_arg_pointer));
+void __attribute__((force_align_arg_pointer)) c(void);
+
+// Functions only have to be declared force_align_arg_pointer once.
+void b(void) {}
+
+// It doesn't matter which declaration has the attribute.
+void d(void);
+void __attribute__((force_align_arg_pointer)) d(void) {}
+
+// Attribute is ignored on function pointer types.
+void (__attribute__((force_align_arg_pointer)) *p)();
+typedef void (__attribute__((__force_align_arg_pointer__)) *p2)();
+// Attribute is also ignored on function typedefs.
+typedef void __attribute__((force_align_arg_pointer)) e(void);
+
diff --git a/clang/test/Sema/x86-builtin-palignr.c b/clang/test/Sema/x86-builtin-palignr.c
new file mode 100644
index 0000000..6f4b90d
--- /dev/null
+++ b/clang/test/Sema/x86-builtin-palignr.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -ffreestanding -fsyntax-only -target-feature +ssse3 -target-feature +mmx -verify -triple x86_64-pc-linux-gnu %s
+// RUN: %clang_cc1 -ffreestanding -fsyntax-only -target-feature +ssse3 -target-feature +mmx -verify -triple i686-apple-darwin10 %s
+
+#include <tmmintrin.h>
+
+__m64 test1(__m64 a, __m64 b, int c) {
+ // FIXME: The "incompatible result type" error is due to pr10112 and should
+ // be removed when that is fixed.
+ return _mm_alignr_pi8(a, b, c); // expected-error {{argument to '__builtin_ia32_palignr' must be a constant integer}} expected-error {{incompatible result type}}
+}
+
+int test2(int N) {
+ __m128i white2;
+ white2 = __builtin_ia32_pslldqi128(white2, N); // expected-error {{argument to '__builtin_ia32_pslldqi128' must be a constant integer}}
+ return 0;
+}
+