llvm-project/clang/test/Sema
Douglas Gregor b9063fc1b3 Implicitly declare certain C library functions (malloc, strcpy, memmove,
etc.) when we perform name lookup on them. This ensures that we
produce the correct signature for these functions, which has two
practical impacts:

  1) When we're supporting the "implicit function declaration" feature
  of C99, these functions will be implicitly declared with the right
  signature rather than as a function returning "int" with no
  prototype. See PR3541 for the reason why this is important (hint:
  GCC always predeclares these functions).
 
  2) If users attempt to redeclare one of these library functions with
  an incompatible signature, we produce a hard error.

This patch does a little bit of work to give reasonable error
messages. For example, when we hit case #1 we complain that we're
implicitly declaring this function with a specific signature, and then
we give a note that asks the user to include the appropriate header
(e.g., "please include <stdlib.h> or explicitly declare 'malloc'"). In
case #2, we show the type of the implicit builtin that was incorrectly
declared, so the user can see the problem. We could do better here:
for example, when displaying this latter error message we say
something like:

  'strcpy' was implicitly declared here with type 'char *(char *, char
  const *)'

but we should really print out a fake code line showing the
declaration, like this:

  'strcpy' was implicitly declared here as:

    char *strcpy(char *, char const *)

This would also be good for printing built-in candidates with C++
operator overloading.

The set of C library functions supported by this patch includes all
functions from the C99 specification's <stdlib.h> and <string.h> that
(a) are predefined by GCC and (b) have signatures that could cause
codegen issues if they are treated as functions with no prototype
returning and int. Future work could extend this set of functions to
other C library functions that we know about.

llvm-svn: 64504
2009-02-13 23:20:09 +00:00
..
128bitint.c Initial implementation of arbitrary fixed-width integer types. 2009-02-13 02:31:07 +00:00
PR2727.c Fix isIntegerConstantExpr eval of __builtin_offsetof to return result 2008-08-28 18:42:20 +00:00
PR2728.c Fix isIntegerConstantExpr eval of __builtin_offsetof to return result 2008-08-28 18:42:20 +00:00
PR2919-builtin-types-compat-strips-crv.c add missing RUN lines 2008-11-26 15:50:12 +00:00
PR2923.c Fix missing %s in run string causing hang during tests. 2008-10-29 19:29:09 +00:00
PR2963-enum-constant.c Use VerifyIntegerConstantExpression instead of isIntegerConstantExpr. Fixes PR2963 2008-12-05 16:33:57 +00:00
address-constant.c PR1963: Address of function is a constant expression 2008-04-04 09:45:30 +00:00
address_spaces.c testcase that works now with r62061 2009-01-12 00:08:58 +00:00
annotate.c add a test case 2008-02-21 19:44:16 +00:00
anonymous-struct-union.c Implement support for anonymous structs and unions in C. Both C and 2009-01-12 22:49:06 +00:00
arg-duplicate.c reject 'typedef int y; int test(x, y)'. 2008-04-06 06:47:48 +00:00
arg-scope-c99.c Add support for C++ default arguments, and rework Parse-Sema 2008-04-08 04:40:51 +00:00
arg-scope.c Add support for C++ default arguments, and rework Parse-Sema 2008-04-08 04:40:51 +00:00
array-constraint.c GNU allows structs with flexible array members to be placed inside 2009-02-10 21:49:46 +00:00
array-declared-as-incorrect-type.c Make all the 'redefinition' diagnostics more consistent, and make the 2008-11-23 23:12:31 +00:00
array-init.c Implement semantic analysis for the GNU flexible array initialization 2009-02-04 22:46:25 +00:00
asm.c If an input constraint refers to an output constraint, it should have the same constraint info as the output constraint. Fixes PR3417 2009-01-27 20:38:24 +00:00
assign-null.c Move the null pointer constant check from Sema::CheckSingleInitializer/ActOnCallExpr/CheckMessageArgumentTypes/ActOnReturnStmt to Sema::CheckSingleAssignmentConstraints. This makes sure all null pointer assignments are considered compatible. 2007-11-27 17:58:44 +00:00
assign.c Fix <rdar://problem/5733511> clang doesn't emit error for const array. 2008-02-09 16:59:44 +00:00
ast-print.c Fix a bug handling typedefs of functions, patch by Nuno Lopes! 2007-12-06 17:20:20 +00:00
attr-cleanup.c Improve Sema of the cleanup attribute somewhat. 2009-02-07 23:16:50 +00:00
attr-deprecated.c Start warning about unknown attributes. 2009-02-13 08:22:04 +00:00
attr-mode.c Make ProcessDeclAttributes walk the declarator structure pulling 2008-06-29 00:16:31 +00:00
attr-nodebug.c Add sema support for the nodebug attribute. 2009-02-13 06:46:13 +00:00
attr-noreturn.c Improve attribute parsing & tests. 2008-10-19 02:04:16 +00:00
attr-unused.c Improve attribute parsing & tests. 2008-10-19 02:04:16 +00:00
attr-used.c Warn about attribute used ignored on "extern int a 2009-02-13 22:48:56 +00:00
bitfield-layout.c Cleanup/refactoring of Sema struct layout. This patch unifies the struct 2008-05-30 09:31:38 +00:00
bitfield.c Implement rdar://6138816 - [sema] named bitfields cannot have 0 width 2008-12-12 04:56:04 +00:00
block-args.c instead of forcing blocks on by default, make them default to off, but let 2008-12-04 23:20:07 +00:00
block-as-object.m instead of forcing blocks on by default, make them default to off, but let 2008-12-04 23:20:07 +00:00
block-byref-args.c instead of forcing blocks on by default, make them default to off, but let 2008-12-04 23:20:07 +00:00
block-call.c Fix <rdar://problem/6418623> Bogus block type compatibility warning. 2008-12-10 17:49:55 +00:00
block-explicit-return-type.c Add support for blocks with explicit return types. 2009-02-04 22:31:32 +00:00
block-literal.c instead of forcing blocks on by default, make them default to off, but let 2008-12-04 23:20:07 +00:00
block-misc.c Fixup expected errors. 2009-02-08 07:59:54 +00:00
block-return.c Add support for blocks with explicit return types. 2009-02-04 22:31:32 +00:00
block-storageclass.c instead of forcing blocks on by default, make them default to off, but let 2008-12-04 23:20:07 +00:00
block-syntax-error.c Add support for blocks with explicit return types. 2009-02-04 22:31:32 +00:00
builtin-object-size.c Append the test runs with '&&'. 2008-10-05 00:08:56 +00:00
builtin-prefetch.c Switch several more Sema Diag methods over. This simplifies the 2008-11-19 05:08:23 +00:00
builtin-stackaddress.c Fix typo in test. 2008-05-20 08:27:04 +00:00
builtins.c merge some simple call diagnostics. 2008-11-21 18:44:24 +00:00
c89-2.c -C mode doesn't return comments on "#" lines, so the diag checker doesn't pick them up. 2007-08-30 06:38:49 +00:00
c89.c Clean up the C89/C++ warnings about C99 array features to not 2008-12-18 06:50:14 +00:00
callingconv.c Add new test 2008-03-07 20:04:49 +00:00
carbon.c Re-enable PTH testing for Cocoa.h and Carbon.h (and include testing for Objective-C++). 2009-01-09 00:41:48 +00:00
cast-to-union.c add support for initializing static vars with a cast to union (gcc extension) 2009-01-15 16:44:45 +00:00
cast.c casting to void is ok for structs (C99 6.5.4p2), this fixes 2007-10-29 04:26:44 +00:00
check-increment.c Make sure Sema::CheckIncrementDecrementOperand() removes typedefs when doing it's analysis. 2007-11-11 14:15:57 +00:00
compare.c Be a bit stricter about array type compatibility. 2008-02-06 04:53:22 +00:00
complex-int.c Use VerifyIntegerConstantExpression for case values. 2008-12-01 02:13:02 +00:00
complex-promotion.c Add another complex promotion test. 2008-12-10 23:57:51 +00:00
compound-literal.c Centralize error reporting of improper uses of incomplete types in the 2009-01-19 19:26:10 +00:00
conditional-expr.c Fix <rdar://problem/5928590> clang -fsyntax-only: "incompatible operand types ('int' and 'void')" on input that 'gcc -fsyntax-only' eats 2008-05-12 21:44:38 +00:00
conditional.c fix type of ?: operator. If one of the operator is void, the type should be void as well. 2008-06-04 19:14:12 +00:00
const-eval.c Fix invalid evaluation of _Complex float (real & imaginary parts had 2009-01-24 19:08:01 +00:00
const-ptr-int-ptr-cast.c Fix for PR2720; be a little bit more permissive in initializers for 2008-08-25 20:46:57 +00:00
constant-builtins-2.c Teach tryEvaluate that fabs, copysign, and unary +/- are constants for 2008-10-16 03:51:50 +00:00
constant-builtins.c Make Sema::CheckForConstantInitializer use Expr::Evaluate. This fixes PR3130. 2008-12-05 05:09:56 +00:00
constructor-attribute.c Support __attribute__(({con,de}structor)) in Parse & Sema 2008-07-31 22:40:48 +00:00
darwin-align-cast.c Put back my temporary hack until Eli addresses this in a more complete fashion. 2008-06-03 22:06:04 +00:00
decl-invalid.c Diagnose declarations that don't declare anything, and fix PR3020. 2008-12-28 15:28:59 +00:00
decl-type-merging.c Fix for PR2100: merge types for variables. 2009-01-24 23:49:55 +00:00
declspec.c Change a whole lot of diagnostics to take QualType's directly 2008-11-24 06:25:27 +00:00
default.c rename -parse-ast-print to -ast-print 2007-10-11 00:18:28 +00:00
default1.c Add support for C++ default arguments, and rework Parse-Sema 2008-04-08 04:40:51 +00:00
deref.c Tweak fix for http://llvm.org/bugs/show_bug.cgi?id=2000 to work across typedefs. 2008-02-18 15:14:59 +00:00
designated-initializers.c Fix a bug with designated initializers where we were stepping out of a 2009-02-12 19:00:39 +00:00
dllimport-dllexport.c Fix filename typo. 2008-12-28 14:19:27 +00:00
enum.c Centralize error reporting of improper uses of incomplete types in the 2009-01-19 19:26:10 +00:00
expr-address-of.c Set register storage class correctly for function parameters. 2008-09-03 21:54:21 +00:00
expr-comma-c89.c c89 does not perform array -> pointer promotion unless the array is an lvalue. This 2008-07-25 21:33:13 +00:00
expr-comma.c c89 does not perform array -> pointer promotion unless the array is an lvalue. This 2008-07-25 21:33:13 +00:00
exprs.c If x is an invalid field decl, don't construct an expression for P->x, 2009-02-13 22:08:30 +00:00
ext_vector_components.c Update support for vector component access on ExtVectors. 2009-01-18 01:47:54 +00:00
flexible-array-init.c GNU allows structs with flexible array members to be placed inside 2009-02-10 21:49:46 +00:00
floating-point-compare.c Fixed test case to not expect a warning when one should not be emitted. 2007-11-29 01:03:21 +00:00
for.c rename -parse-ast-print to -ast-print 2007-10-11 00:18:28 +00:00
format-attribute.c Add attribute "format" support for typedefs of function pointers. 2008-05-09 17:36:24 +00:00
format-strings.c Fix test case (incomplete "expected-warning" line) 2009-01-12 23:09:55 +00:00
function-ptr.c give better diagnostics for converting between function pointer and void*. 2008-01-03 22:56:36 +00:00
function.c Note the Radar number that corresponds to PR3137 2009-02-04 19:10:27 +00:00
i-c-e.c Implement the final (hopefully) wrinkle to i-c-e + builtin_constant_p 2008-12-12 18:00:51 +00:00
if-empty-body.c improve error recovery handling broken 'then' or 'else' stmts in 2007-10-29 05:08:52 +00:00
illegal-types.c Make sure Sema::GetTypeForDeclarator() deals with abstract declarators when diagnosing incorrect code. 2008-01-14 23:33:18 +00:00
implicit-builtin-decl.c Implicitly declare certain C library functions (malloc, strcpy, memmove, 2009-02-13 23:20:09 +00:00
implicit-cast.c Fix a bug in Sema::CheckConditionalOperands(). When mixing pointers and null pointer constants, we need to promote the null pointer constant (which is an integer) to the pointer type. Test case is self explanatory. 2007-10-18 05:13:08 +00:00
implicit-decl.c Merge function-return.c into function.c 2008-12-18 02:01:17 +00:00
implicit-def.c rename -parse-ast-print to -ast-print 2007-10-11 00:18:28 +00:00
implicit-int.c Unspecified type specs default to int. This fixes a crash 2007-07-13 21:02:29 +00:00
incomplete-decl.c Make one expected-diag directive match exactly one actual diagnostic. 2009-02-07 19:52:04 +00:00
init-struct-qualified.c For struct initialization, check compatibility with the unqualified 2008-06-09 03:52:40 +00:00
init.c Use our new snazzy stdint.h to make a testcase 64-bit portable. 2009-02-07 00:23:52 +00:00
int-arith-convert.c int-arith-convert.c makes assumptions about integer sizes, so force a specific architecture 2008-12-02 16:34:01 +00:00
invalid-decl.c Fix PR3031 by silencing follow-on errors in invalid declarations. 2008-11-11 06:13:16 +00:00
invalid-struct-init.c make the 'to match this' diagnostic a note. 2008-11-23 23:17:07 +00:00
member-reference.c Unify the code for defining tags in C and C++, so that we always 2009-01-08 20:45:30 +00:00
merge-decls.c testcase for rdar://6096412 which already works. 2009-02-11 06:22:30 +00:00
ms-fuzzy-asm.c Use getLogicalLineNumber() in FuzzyParseMicrosoftAsmStatement(), it's more general and simplifies the code. 2008-02-08 18:01:27 +00:00
nested-redef.c Unify the code for defining tags in C and C++, so that we always 2009-01-08 20:45:30 +00:00
nonnull.c Tidy up sema processing of attribute "nonull": 2008-09-01 19:57:52 +00:00
offsetof.c Simplify test. 2008-12-06 22:27:22 +00:00
overloadable-complex.c Add test for overloading with _Complex in C 2009-02-12 00:57:03 +00:00
overloadable.c Tighten checking of the "overloadable" attribute. If any function by a 2009-02-13 00:26:38 +00:00
pointer-addition.c Make one expected-diag directive match exactly one actual diagnostic. 2009-02-07 19:52:04 +00:00
pointer-subtract-compat.c Allow subtraction of function pointer types in C, as a GNU extension. Fixes rdar://problem/6520707 2009-01-23 19:03:35 +00:00
pragma-pack-2.c Implement #pragma pack use in structure packing. The general approach 2008-10-16 02:34:03 +00:00
pragma-pack.c Exercise #pragma pack(pop, <width>) in test case. 2008-10-17 16:05:47 +00:00
predef.c fix rdar://6097892 - gcc incompat: clang rejects __func__, __FUNCTION__, and __PRETTY_FUNCTION__ outside func 2008-12-12 05:05:20 +00:00
predefined-function.c Make all the 'redefinition' diagnostics more consistent, and make the 2008-11-23 23:12:31 +00:00
rdar6248119.m Enter a new scope for a @try block. 2008-09-26 17:32:47 +00:00
recover-goto.c Fix a bug recovering from broken code with a goto that Eli reported. 2008-01-25 00:01:10 +00:00
redefinition.c Handle any undeclared parameters in a K&R-style function with a 2009-01-23 16:23:13 +00:00
self-comparison.c Added to test case for "self-comparison check" uses of relation operators: x < x and x > x 2007-10-29 17:02:56 +00:00
sentinel-attribute.c Add parsing of the sentinel attribute. Still need to create the attribute. 2008-10-05 18:05:59 +00:00
shift.c Don't do integer promotions of LHS for compound shift assignment. The LHS has to be a modifiable lvalue. 2007-12-13 07:28:16 +00:00
static-init.c emit diagnostic when casting a ptr to a small int when doing static initialization (addresses Eli's comments I believe) 2009-02-02 22:57:15 +00:00
stdcall-fastcall.c Complete the test after adding handling of merged attributes on decls. 2008-12-26 00:52:17 +00:00
stmt_exprs.c Correct test; sorry for any inconvenience. 2009-01-24 23:44:26 +00:00
struct-cast.c Use the unqualified type for GCCs struct/union cast extension 2009-01-13 17:00:51 +00:00
struct-compat.c Make all the 'redefinition' diagnostics more consistent, and make the 2008-11-23 23:12:31 +00:00
struct-decl.c Simplify the way in which we inject the names of tag definitions and 2009-02-03 00:34:39 +00:00
struct-packed-align.c Merge postfix attributes on record decls. 2008-10-03 17:33:35 +00:00
switch.c Use VerifyIntegerConstantExpression for case values. 2008-12-01 02:13:02 +00:00
tentative-decls.c Fix redundant errors for redefinitions with multiple existing definitions. 2009-02-08 10:49:44 +00:00
text-diag.c fix crash when printing diagnostics with tokens that span through more than one line 2008-08-05 19:40:20 +00:00
transparent-union-pointer.c An extremely hacky version of transparent_union support; it isn't 2008-09-02 05:19:23 +00:00
type-spec-struct-union.c Properly set the scope of non-fields declared within a struct, union, 2009-01-12 18:45:55 +00:00
typecheck-binop.c Change a whole lot of diagnostics to take QualType's directly 2008-11-24 06:25:27 +00:00
typedef-prototype.c implement test/Sema/typedef-prototype.c, allowing code 2007-11-14 06:34:38 +00:00
typedef-redef.c Replace DeclContext's vector of ScopedDecl pointers with a linked list 2009-01-09 19:42:16 +00:00
typedef-retain.c Fix typo noticed by Chris. 2009-01-30 23:26:40 +00:00
typedef-variable-type.c a minor grammar fix 2008-12-07 00:59:53 +00:00
types.c Testcase for something that already works. Clang agrees with Comeau, 2008-12-12 05:25:55 +00:00
unnamed-bitfield-init.c Make sure to count the struct elements correctly; here, we want the 2008-08-09 23:45:45 +00:00
unused-expr.c Make the unused expression warning a bit less aggressive (found in PHP 2008-05-19 21:24:43 +00:00
usual-float.c Fix a basic bug (having to do with typedefs) in Sema::UsualArithmeticConversions(). 2007-11-10 19:45:54 +00:00
va_arg_x86_64.c Fix a regression from my fix to PR2631. Fixes PR2692. 2008-08-20 22:17:17 +00:00
varargs.c Fix va_arg bug noticed by Eli, __builtin_va_arg is not an l-value 2009-02-12 09:21:08 +00:00
vector-assign.c Turn on -flax-vector-conversions by default, issue a warning whenever one is done. Add a -fnolax-vector-conversions option. Fixes PR2862. 2009-01-30 23:17:46 +00:00
vector-cast.c Report errors for invalid casts from/to vectors. 2007-11-27 05:51:55 +00:00
vector-init.c Upgrade the "excess elements in array initializer" warning to an 2009-01-30 22:26:29 +00:00
vla.c a minor grammar fix 2008-12-07 00:59:53 +00:00
void_arg.c Patch for PR2350; the issue was tnat we were allowing (with an error) 2008-05-22 08:54:03 +00:00
wchar_size.c Get the type right for wide string literals; it's wchar_t, not char. 2008-05-27 07:57:14 +00:00