From cb0b4306511810c41e00cfaea23e5f41afef9f4f Mon Sep 17 00:00:00 2001
From: Anastasia Stulova <anastasia.stulova@arm.com>
Date: Tue, 2 Feb 2016 11:29:43 +0000
Subject: [PATCH] [OpenCL] Eliminate warning when declaring OpenCL builtin
 functions.

OpenCL builtin functions are usually declared in header files.
Currently clang emits warning for OpenCL builtin functions
which have the same name as standard C library functions.

This commit eliminates such warnings by not adding the C standard
includes following the restriction from OpenCL v1.2 s6.9.f.

Patch by Liu Yaxun (Sam)!

Review: http://reviews.llvm.org/D16692



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259491 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Sema/SemaLookup.cpp    | 6 +++---
 test/SemaOpenCL/builtin.cl | 3 +++
 2 files changed, 6 insertions(+), 3 deletions(-)
 create mode 100644 test/SemaOpenCL/builtin.cl

diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp
index f28cd27e85c..93d503e20b5 100644
--- a/lib/Sema/SemaLookup.cpp
+++ b/lib/Sema/SemaLookup.cpp
@@ -684,9 +684,9 @@ static bool LookupBuiltin(Sema &S, LookupResult &R) {
 
       // If this is a builtin on this (or all) targets, create the decl.
       if (unsigned BuiltinID = II->getBuiltinID()) {
-        // In C++, we don't have any predefined library functions like
-        // 'malloc'. Instead, we'll just error.
-        if (S.getLangOpts().CPlusPlus &&
+        // In C++ and OpenCL (spec v1.2 s6.9.f), we don't have any predefined
+        // library functions like 'malloc'. Instead, we'll just error.
+        if ((S.getLangOpts().CPlusPlus || S.getLangOpts().OpenCL) &&
             S.Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
           return false;
 
diff --git a/test/SemaOpenCL/builtin.cl b/test/SemaOpenCL/builtin.cl
new file mode 100644
index 00000000000..e5f56e2577d
--- /dev/null
+++ b/test/SemaOpenCL/builtin.cl
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+float __attribute__((overloadable)) acos(float); // expected-no-diagnostics
-- 
GitLab