[cfe-commits] r80610 - in /cfe/trunk: include/clang/Basic/Builtins.def include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/Sema.h lib/Sema/SemaChecking.cpp test/Sema/builtin-unary-fp.c
Eli Friedman
eli.friedman at gmail.com
Mon Aug 31 13:06:01 PDT 2009
Author: efriedma
Date: Mon Aug 31 15:06:00 2009
New Revision: 80610
URL: http://llvm.org/viewvc/llvm-project?rev=80610&view=rev
Log:
PR4836, part 1: add Sema support for __builtin_isnan and friends; they
are apparently used by Solaris libc despite the fact that clang claims
to be compatible with gcc 4.2, which doesn't support them.
Added:
cfe/trunk/test/Sema/builtin-unary-fp.c
Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaChecking.cpp
Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=80610&r1=80609&r2=80610&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Mon Aug 31 15:06:00 2009
@@ -106,6 +106,14 @@
BUILTIN(__builtin_islessgreater , "i.", "nc")
BUILTIN(__builtin_isunordered , "i.", "nc")
+// Unary FP classification
+// BUILTIN(__builtin_fpclassify, "iiiii.", "nc")
+BUILTIN(__builtin_isfinite, "i.", "nc")
+BUILTIN(__builtin_isinf, "i.", "nc")
+BUILTIN(__builtin_isinf_sign, "i.", "nc")
+BUILTIN(__builtin_isnan, "i.", "nc")
+BUILTIN(__builtin_isnormal, "i.", "nc")
+
// Builtins for arithmetic.
BUILTIN(__builtin_clz , "iUi" , "nc")
BUILTIN(__builtin_clzl , "iULi" , "nc")
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=80610&r1=80609&r2=80610&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Aug 31 15:06:00 2009
@@ -1681,6 +1681,9 @@
def err_typecheck_call_invalid_ordered_compare : Error<
"ordered compare requires two args of floating point type (%0 and %1)">;
+def err_typecheck_call_invalid_unary_fp : Error<
+ "floating point classification requires argument of floating point type "
+ "(passed in %0)">;
def err_typecheck_cond_expect_scalar : Error<
"used type %0 where arithmetic or pointer type is required">;
def ext_typecheck_cond_one_void : Extension<
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=80610&r1=80609&r2=80610&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Mon Aug 31 15:06:00 2009
@@ -3494,6 +3494,7 @@
CallExpr *TheCall);
bool SemaBuiltinVAStart(CallExpr *TheCall);
bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
+ bool SemaBuiltinUnaryFP(CallExpr *TheCall);
bool SemaBuiltinStackAddress(CallExpr *TheCall);
public:
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=80610&r1=80609&r2=80610&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Aug 31 15:06:00 2009
@@ -125,6 +125,14 @@
if (SemaBuiltinUnorderedCompare(TheCall))
return ExprError();
break;
+ case Builtin::BI__builtin_isfinite:
+ case Builtin::BI__builtin_isinf:
+ case Builtin::BI__builtin_isinf_sign:
+ case Builtin::BI__builtin_isnan:
+ case Builtin::BI__builtin_isnormal:
+ if (SemaBuiltinUnaryFP(TheCall))
+ return ExprError();
+ break;
case Builtin::BI__builtin_return_address:
case Builtin::BI__builtin_frame_address:
if (SemaBuiltinStackAddress(TheCall))
@@ -557,6 +565,33 @@
return false;
}
+/// SemaBuiltinUnorderedCompare - Handle functions like __builtin_isnan and
+/// friends. This is declared to take (...), so we have to check everything.
+bool Sema::SemaBuiltinUnaryFP(CallExpr *TheCall) {
+ if (TheCall->getNumArgs() < 1)
+ return Diag(TheCall->getLocEnd(), diag::err_typecheck_call_too_few_args)
+ << 0 /*function call*/;
+ if (TheCall->getNumArgs() > 1)
+ return Diag(TheCall->getArg(1)->getLocStart(),
+ diag::err_typecheck_call_too_many_args)
+ << 0 /*function call*/
+ << SourceRange(TheCall->getArg(1)->getLocStart(),
+ (*(TheCall->arg_end()-1))->getLocEnd());
+
+ Expr *OrigArg = TheCall->getArg(0);
+
+ if (OrigArg->isTypeDependent())
+ return false;
+
+ // This operation requires a floating-point number
+ if (!OrigArg->getType()->isRealFloatingType())
+ return Diag(OrigArg->getLocStart(),
+ diag::err_typecheck_call_invalid_unary_fp)
+ << OrigArg->getType() << OrigArg->getSourceRange();
+
+ return false;
+}
+
bool Sema::SemaBuiltinStackAddress(CallExpr *TheCall) {
// The signature for these builtins is exact; the only thing we need
// to check is that the argument is a constant.
Added: cfe/trunk/test/Sema/builtin-unary-fp.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/builtin-unary-fp.c?rev=80610&view=auto
==============================================================================
--- cfe/trunk/test/Sema/builtin-unary-fp.c (added)
+++ cfe/trunk/test/Sema/builtin-unary-fp.c Mon Aug 31 15:06:00 2009
@@ -0,0 +1,12 @@
+// RUN: clang-cc %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}}
+}
More information about the cfe-commits
mailing list