Add atan, atan2, exp, and log to the builtin math library functions.

With -fno-math-errno (the default for Darwin) or -ffast-math these library 
function can be marked readnone enabling more opportunities for CSE and other
optimizations.
rdar://11251464


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155498 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/Builtins.def b/include/clang/Basic/Builtins.def
index 29c29bf..3bd8f24 100644
--- a/include/clang/Basic/Builtins.def
+++ b/include/clang/Basic/Builtins.def
@@ -804,14 +804,30 @@
 LIBBUILTIN(NSLogv, "vGa", "fP:0:", "Foundation/NSObjCRuntime.h", OBJC_LANG)
 
 // Builtin math library functions
+LIBBUILTIN(atan, "dd", "fe", "math.h", ALL_LANGUAGES)
+LIBBUILTIN(atanl, "LdLd", "fe", "math.h", ALL_LANGUAGES)
+LIBBUILTIN(atanf, "ff", "fe", "math.h", ALL_LANGUAGES)
+
+LIBBUILTIN(atan2, "ddd", "fe", "math.h", ALL_LANGUAGES)
+LIBBUILTIN(atan2l, "LdLdLd", "fe", "math.h", ALL_LANGUAGES)
+LIBBUILTIN(atan2f, "fff", "fe", "math.h", ALL_LANGUAGES)
+
 LIBBUILTIN(cos, "dd", "fe", "math.h", ALL_LANGUAGES)
 LIBBUILTIN(cosl, "LdLd", "fe", "math.h", ALL_LANGUAGES)
 LIBBUILTIN(cosf, "ff", "fe", "math.h", ALL_LANGUAGES)
 
+LIBBUILTIN(exp, "dd", "fe", "math.h", ALL_LANGUAGES)
+LIBBUILTIN(expl, "LdLd", "fe", "math.h", ALL_LANGUAGES)
+LIBBUILTIN(expf, "ff", "fe", "math.h", ALL_LANGUAGES)
+
 LIBBUILTIN(fma, "dddd", "fc", "math.h", ALL_LANGUAGES)
 LIBBUILTIN(fmal, "LdLdLdLd", "fc", "math.h", ALL_LANGUAGES)
 LIBBUILTIN(fmaf, "ffff", "fc", "math.h", ALL_LANGUAGES)
 
+LIBBUILTIN(log, "dd", "fe", "math.h", ALL_LANGUAGES)
+LIBBUILTIN(logl, "LdLd", "fe", "math.h", ALL_LANGUAGES)
+LIBBUILTIN(logf, "ff", "fe", "math.h", ALL_LANGUAGES)
+
 LIBBUILTIN(pow, "ddd", "fe", "math.h", ALL_LANGUAGES)
 LIBBUILTIN(powl, "LdLdLd", "fe", "math.h", ALL_LANGUAGES)
 LIBBUILTIN(powf, "fff", "fe", "math.h", ALL_LANGUAGES)
diff --git a/test/Analysis/self-init.m b/test/Analysis/self-init.m
index d515173..365096e 100644
--- a/test/Analysis/self-init.m
+++ b/test/Analysis/self-init.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=osx.cocoa.SelfInit -fobjc-default-synthesize-properties %s -verify
+// RUN: %clang_cc1 -analyze -analyzer-checker=osx.cocoa.SelfInit -fobjc-default-synthesize-properties -fno-builtin %s -verify
 
 @class NSZone, NSCoder;
 @protocol NSObject- (id)self;
diff --git a/test/CodeGen/libcalls.c b/test/CodeGen/libcalls.c
index 458c591..ec895ac 100644
--- a/test/CodeGen/libcalls.c
+++ b/test/CodeGen/libcalls.c
@@ -73,3 +73,48 @@
 // CHECK-NO: declare float @llvm.fma.f32(float, float, float) nounwind readnone
 // CHECK-NO: declare double @llvm.fma.f64(double, double, double) nounwind readnone
 // CHECK-NO: declare x86_fp80 @llvm.fma.f80(x86_fp80, x86_fp80, x86_fp80) nounwind readnone
+
+// Just checking to make sure these library functions are marked readnone
+void test_builtins(double d, float f, long double ld) {
+// CHEC-NO: @test_builtins
+// CHEC-YES: @test_builtins
+  double atan_ = atan(d);
+  long double atanl_ = atanl(ld);
+  float atanf_ = atanf(f);
+// CHECK-NO: declare double @atan(double) nounwind readnone
+// CHECK-NO: declare x86_fp80 @atanl(x86_fp80) nounwind readnone
+// CHECK-NO: declare float @atanf(float) nounwind readnone
+// CHECK-YES-NOT: declare double @atan(double) nounwind readnone
+// CHECK-YES-NOT: declare x86_fp80 @atanl(x86_fp80) nounwind readnone
+// CHECK-YES-NOT: declare float @atanf(float) nounwind readnone
+
+  double atan2_ = atan2(d, 2);
+  long double atan2l_ = atan2l(ld, ld);
+  float atan2f_ = atan2f(f, f);
+// CHECK-NO: declare double @atan2(double, double) nounwind readnone
+// CHECK-NO: declare x86_fp80 @atan2l(x86_fp80, x86_fp80) nounwind readnone
+// CHECK-NO: declare float @atan2f(float, float) nounwind readnone
+// CHECK-YES-NOT: declare double @atan2(double, double) nounwind readnone
+// CHECK-YES-NOT: declare x86_fp80 @atan2l(x86_fp80, x86_fp80) nounwind readnone
+// CHECK-YES-NOT: declare float @atan2f(float, float) nounwind readnone
+
+  double exp_ = exp(d);
+  long double expl_ = expl(ld);
+  float expf_ = expf(f);
+// CHECK-NO: declare double @exp(double) nounwind readnone
+// CHECK-NO: declare x86_fp80 @expl(x86_fp80) nounwind readnone
+// CHECK-NO: declare float @expf(float) nounwind readnone
+// CHECK-YES-NOT: declare double @exp(double) nounwind readnone
+// CHECK-YES-NOT: declare x86_fp80 @expl(x86_fp80) nounwind readnone
+// CHECK-YES-NOT: declare float @expf(float) nounwind readnone
+
+  double log_ = log(d);
+  long double logl_ = logl(ld);
+  float logf_ = logf(f);
+// CHECK-NO: declare double @log(double) nounwind readnone
+// CHECK-NO: declare x86_fp80 @logl(x86_fp80) nounwind readnone
+// CHECK-NO: declare float @logf(float) nounwind readnone
+// CHECK-YES-NOT: declare double @log(double) nounwind readnone
+// CHECK-YES-NOT: declare x86_fp80 @logl(x86_fp80) nounwind readnone
+// CHECK-YES-NOT: declare float @logf(float) nounwind readnone
+}