Add the Pure attribute to C99 builtin functions from ctype.h. This is a corrected version of r266199 with test case fixes.

Patch by Taewook Oh.

llvm-svn: 268553
This commit is contained in:
Aaron Ballman 2016-05-04 21:08:13 +00:00
parent e13787ef3f
commit 781fda9387
7 changed files with 429 additions and 277 deletions

View File

@ -67,6 +67,7 @@
// Builtin::Context class. Currently we have:
// n -> nothrow
// r -> noreturn
// U -> pure
// c -> const
// t -> signature is meaningless, use custom typechecking
// F -> this is a libc/libm function with a '__builtin_' prefix added.
@ -773,6 +774,22 @@ LIBBUILTIN(sscanf, "icC*RcC*R.", "fs:1:", "stdio.h", ALL_LANGUAGES)
LIBBUILTIN(vscanf, "icC*Ra", "fS:0:", "stdio.h", ALL_LANGUAGES)
LIBBUILTIN(vfscanf, "iP*RcC*Ra", "fS:1:", "stdio.h", ALL_LANGUAGES)
LIBBUILTIN(vsscanf, "icC*RcC*Ra", "fS:1:", "stdio.h", ALL_LANGUAGES)
// C99 ctype.h
LIBBUILTIN(isalnum, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
LIBBUILTIN(isalpha, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
LIBBUILTIN(isblank, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
LIBBUILTIN(iscntrl, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
LIBBUILTIN(isdigit, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
LIBBUILTIN(isgraph, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
LIBBUILTIN(islower, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
LIBBUILTIN(isprint, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
LIBBUILTIN(ispunct, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
LIBBUILTIN(isspace, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
LIBBUILTIN(isupper, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
LIBBUILTIN(isxdigit, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
LIBBUILTIN(tolower, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
LIBBUILTIN(toupper, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
// C99
// In some systems setjmp is a macro that expands to _setjmp. We undefine
// it here to avoid having two identical LIBBUILTIN entries.

View File

@ -89,11 +89,16 @@ public:
return getRecord(ID).Type;
}
/// \brief Return true if this function is a target-specific builtin
/// \brief Return true if this function is a target-specific builtin.
bool isTSBuiltin(unsigned ID) const {
return ID >= Builtin::FirstTSBuiltin;
}
/// \brief Return true if this function has no side effects.
bool isPure(unsigned ID) const {
return strchr(getRecord(ID).Attributes, 'U') != nullptr;
}
/// \brief Return true if this function has no side effects and doesn't
/// read memory.
bool isConst(unsigned ID) const {
@ -155,7 +160,7 @@ public:
/// \brief Completely forget that the given ID was ever considered a builtin,
/// e.g., because the user provided a conflicting signature.
void forgetBuiltin(unsigned ID, IdentifierTable &Table);
/// \brief If this is a library function that comes from a specific
/// header, retrieve that header name.
const char *getHeaderName(unsigned ID) const {

File diff suppressed because it is too large Load Diff

View File

@ -113,8 +113,6 @@ void test2(Collide *a) {
@end
double *isupper(int);
@interface Sub2 : Super
- (int)method2;
@end

View File

@ -72,8 +72,8 @@ int isdigit(int c) __attribute__((overloadable)) // expected-note{{candidate fu
__attribute__((unavailable("'c' must have the value of an unsigned char or EOF")));
void test3(int c) {
isdigit(c);
isdigit(10);
isdigit(c); // expected-warning{{ignoring return value of function declared with pure attribute}}
isdigit(10); // expected-warning{{ignoring return value of function declared with pure attribute}}
#ifndef CODEGEN
isdigit(-10); // expected-error{{call to unavailable function 'isdigit': 'c' must have the value of an unsigned char or EOF}}
#endif

View File

@ -0,0 +1,65 @@
// RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu -emit-llvm < %s | FileCheck %s
int isalnum(int);
int isalpha(int);
int isblank(int);
int iscntrl(int);
int isdigit(int);
int isgraph(int);
int islower(int);
int isprint(int);
int ispunct(int);
int isspace(int);
int isupper(int);
int isxdigit(int);
int tolower(int);
int toupper(int);
void test(int x) {
// CHECK: call signext i32 @isalnum(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)isalnum(x);
// CHECK: call signext i32 @isalpha(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)isalpha(x);
// CHECK: call signext i32 @isblank(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)isblank(x);
// CHECK: call signext i32 @iscntrl(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)iscntrl(x);
// CHECK: call signext i32 @isdigit(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)isdigit(x);
// CHECK: call signext i32 @isgraph(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)isgraph(x);
// CHECK: call signext i32 @islower(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)islower(x);
// CHECK: call signext i32 @isprint(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)isprint(x);
// CHECK: call signext i32 @ispunct(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)ispunct(x);
// CHECK: call signext i32 @isspace(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)isspace(x);
// CHECK: call signext i32 @isupper(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)isupper(x);
// CHECK: call signext i32 @isxdigit(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)isxdigit(x);
// CHECK: call signext i32 @tolower(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)tolower(x);
// CHECK: call signext i32 @toupper(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)toupper(x);
}
// CHECK: declare signext i32 @isalnum(i32 signext) [[NUW_RO:#[0-9]+]]
// CHECK: declare signext i32 @isalpha(i32 signext) [[NUW_RO:#[0-9]+]]
// CHECK: declare signext i32 @isblank(i32 signext) [[NUW_RO:#[0-9]+]]
// CHECK: declare signext i32 @iscntrl(i32 signext) [[NUW_RO:#[0-9]+]]
// CHECK: declare signext i32 @isdigit(i32 signext) [[NUW_RO:#[0-9]+]]
// CHECK: declare signext i32 @isgraph(i32 signext) [[NUW_RO:#[0-9]+]]
// CHECK: declare signext i32 @islower(i32 signext) [[NUW_RO:#[0-9]+]]
// CHECK: declare signext i32 @isprint(i32 signext) [[NUW_RO:#[0-9]+]]
// CHECK: declare signext i32 @ispunct(i32 signext) [[NUW_RO:#[0-9]+]]
// CHECK: declare signext i32 @isspace(i32 signext) [[NUW_RO:#[0-9]+]]
// CHECK: declare signext i32 @isupper(i32 signext) [[NUW_RO:#[0-9]+]]
// CHECK: declare signext i32 @isxdigit(i32 signext) [[NUW_RO:#[0-9]+]]
// CHECK: declare signext i32 @tolower(i32 signext) [[NUW_RO:#[0-9]+]]
// CHECK: declare signext i32 @toupper(i32 signext) [[NUW_RO:#[0-9]+]]
// CHECK: attributes [[NUW_RO]] = { nounwind readonly{{.*}} }
// CHECK: attributes [[NUW_RO_CALL]] = { nounwind readonly }

View File

@ -0,0 +1,65 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm < %s | FileCheck %s
int isalnum(int);
int isalpha(int);
int isblank(int);
int iscntrl(int);
int isdigit(int);
int isgraph(int);
int islower(int);
int isprint(int);
int ispunct(int);
int isspace(int);
int isupper(int);
int isxdigit(int);
int tolower(int);
int toupper(int);
void test(int x) {
// CHECK: call i32 @isalnum(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)isalnum(x);
// CHECK: call i32 @isalpha(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)isalpha(x);
// CHECK: call i32 @isblank(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)isblank(x);
// CHECK: call i32 @iscntrl(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)iscntrl(x);
// CHECK: call i32 @isdigit(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)isdigit(x);
// CHECK: call i32 @isgraph(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)isgraph(x);
// CHECK: call i32 @islower(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)islower(x);
// CHECK: call i32 @isprint(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)isprint(x);
// CHECK: call i32 @ispunct(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)ispunct(x);
// CHECK: call i32 @isspace(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)isspace(x);
// CHECK: call i32 @isupper(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)isupper(x);
// CHECK: call i32 @isxdigit(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)isxdigit(x);
// CHECK: call i32 @tolower(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)tolower(x);
// CHECK: call i32 @toupper(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]]
(void)toupper(x);
}
// CHECK: declare i32 @isalnum(i32) [[NUW_RO:#[0-9]+]]
// CHECK: declare i32 @isalpha(i32) [[NUW_RO:#[0-9]+]]
// CHECK: declare i32 @isblank(i32) [[NUW_RO:#[0-9]+]]
// CHECK: declare i32 @iscntrl(i32) [[NUW_RO:#[0-9]+]]
// CHECK: declare i32 @isdigit(i32) [[NUW_RO:#[0-9]+]]
// CHECK: declare i32 @isgraph(i32) [[NUW_RO:#[0-9]+]]
// CHECK: declare i32 @islower(i32) [[NUW_RO:#[0-9]+]]
// CHECK: declare i32 @isprint(i32) [[NUW_RO:#[0-9]+]]
// CHECK: declare i32 @ispunct(i32) [[NUW_RO:#[0-9]+]]
// CHECK: declare i32 @isspace(i32) [[NUW_RO:#[0-9]+]]
// CHECK: declare i32 @isupper(i32) [[NUW_RO:#[0-9]+]]
// CHECK: declare i32 @isxdigit(i32) [[NUW_RO:#[0-9]+]]
// CHECK: declare i32 @tolower(i32) [[NUW_RO:#[0-9]+]]
// CHECK: declare i32 @toupper(i32) [[NUW_RO:#[0-9]+]]
// CHECK: attributes [[NUW_RO]] = { nounwind readonly{{.*}} }
// CHECK: attributes [[NUW_RO_CALL]] = { nounwind readonly }