r360626 - [OpenMP][Clang][BugFix] Split declares and math functions inclusion.

Gheorghe-Teodor Bercea via cfe-commits cfe-commits at lists.llvm.org
Mon May 13 15:11:44 PDT 2019


Author: gbercea
Date: Mon May 13 15:11:44 2019
New Revision: 360626

URL: http://llvm.org/viewvc/llvm-project?rev=360626&view=rev
Log:
[OpenMP][Clang][BugFix] Split declares and math functions inclusion.

Summary: This patches fixes an issue in which the __clang_cuda_cmath.h header is being included even when cmath or math.h headers are not included.

Reviewers: jdoerfert, ABataev, hfinkel, caomhin, tra

Reviewed By: tra

Subscribers: tra, mgorny, guansong, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D61765

Added:
    cfe/trunk/lib/Headers/openmp_wrappers/__clang_openmp_math_declares.h
    cfe/trunk/test/Headers/Inputs/include/cstdlib
Modified:
    cfe/trunk/lib/Driver/ToolChains/Clang.cpp
    cfe/trunk/lib/Headers/CMakeLists.txt
    cfe/trunk/lib/Headers/__clang_cuda_cmath.h
    cfe/trunk/lib/Headers/__clang_cuda_device_functions.h
    cfe/trunk/lib/Headers/__clang_cuda_math_forward_declares.h
    cfe/trunk/lib/Headers/openmp_wrappers/__clang_openmp_math.h
    cfe/trunk/lib/Headers/openmp_wrappers/cmath
    cfe/trunk/lib/Headers/openmp_wrappers/math.h
    cfe/trunk/test/Headers/nvptx_device_cmath_functions.c
    cfe/trunk/test/Headers/nvptx_device_cmath_functions.cpp
    cfe/trunk/test/Headers/nvptx_device_math_functions.c
    cfe/trunk/test/Headers/nvptx_device_math_functions.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=360626&r1=360625&r2=360626&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon May 13 15:11:44 2019
@@ -1166,7 +1166,7 @@ void Clang::AddPreprocessingOptions(Comp
     }
 
     CmdArgs.push_back("-include");
-    CmdArgs.push_back("__clang_openmp_math.h");
+    CmdArgs.push_back("__clang_openmp_math_declares.h");
   }
 
   // Add -i* options, and automatically translate to

Modified: cfe/trunk/lib/Headers/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/CMakeLists.txt?rev=360626&r1=360625&r2=360626&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/CMakeLists.txt (original)
+++ cfe/trunk/lib/Headers/CMakeLists.txt Mon May 13 15:11:44 2019
@@ -132,6 +132,7 @@ set(openmp_wrapper_files
   openmp_wrappers/math.h
   openmp_wrappers/cmath
   openmp_wrappers/__clang_openmp_math.h
+  openmp_wrappers/__clang_openmp_math_declares.h
 )
 
 set(output_dir ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}/include)

Modified: cfe/trunk/lib/Headers/__clang_cuda_cmath.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/__clang_cuda_cmath.h?rev=360626&r1=360625&r2=360626&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/__clang_cuda_cmath.h (original)
+++ cfe/trunk/lib/Headers/__clang_cuda_cmath.h Mon May 13 15:11:44 2019
@@ -36,8 +36,10 @@
 #define __DEVICE__ static __device__ __inline__ __attribute__((always_inline))
 #endif
 
+#if !(defined(_OPENMP) && defined(__cplusplus))
 __DEVICE__ long long abs(long long __n) { return ::llabs(__n); }
 __DEVICE__ long abs(long __n) { return ::labs(__n); }
+#endif
 __DEVICE__ float abs(float __x) { return ::fabsf(__x); }
 __DEVICE__ double abs(double __x) { return ::fabs(__x); }
 __DEVICE__ float acos(float __x) { return ::acosf(__x); }

Modified: cfe/trunk/lib/Headers/__clang_cuda_device_functions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/__clang_cuda_device_functions.h?rev=360626&r1=360625&r2=360626&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/__clang_cuda_device_functions.h (original)
+++ cfe/trunk/lib/Headers/__clang_cuda_device_functions.h Mon May 13 15:11:44 2019
@@ -1493,8 +1493,10 @@ __DEVICE__ double cbrt(double __a) { ret
 __DEVICE__ float cbrtf(float __a) { return __nv_cbrtf(__a); }
 __DEVICE__ double ceil(double __a) { return __nv_ceil(__a); }
 __DEVICE__ float ceilf(float __a) { return __nv_ceilf(__a); }
+#ifndef _OPENMP
 __DEVICE__ int clock() { return __nvvm_read_ptx_sreg_clock(); }
 __DEVICE__ long long clock64() { return __nvvm_read_ptx_sreg_clock64(); }
+#endif
 __DEVICE__ double copysign(double __a, double __b) {
   return __nv_copysign(__a, __b);
 }

Modified: cfe/trunk/lib/Headers/__clang_cuda_math_forward_declares.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/__clang_cuda_math_forward_declares.h?rev=360626&r1=360625&r2=360626&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/__clang_cuda_math_forward_declares.h (original)
+++ cfe/trunk/lib/Headers/__clang_cuda_math_forward_declares.h Mon May 13 15:11:44 2019
@@ -27,11 +27,13 @@
   static __inline__ __attribute__((always_inline)) __attribute__((device))
 #endif
 
-__DEVICE__ double abs(double);
-__DEVICE__ float abs(float);
-__DEVICE__ int abs(int);
+#if !(defined(_OPENMP) && defined(__cplusplus))
 __DEVICE__ long abs(long);
 __DEVICE__ long long abs(long long);
+#endif
+__DEVICE__ int abs(int);
+__DEVICE__ double abs(double);
+__DEVICE__ float abs(float);
 __DEVICE__ double acos(double);
 __DEVICE__ float acos(float);
 __DEVICE__ double acosh(double);

Modified: cfe/trunk/lib/Headers/openmp_wrappers/__clang_openmp_math.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/openmp_wrappers/__clang_openmp_math.h?rev=360626&r1=360625&r2=360626&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/openmp_wrappers/__clang_openmp_math.h (original)
+++ cfe/trunk/lib/Headers/openmp_wrappers/__clang_openmp_math.h Mon May 13 15:11:44 2019
@@ -23,15 +23,6 @@
 #define __CUDA__
 
 #if defined(__cplusplus)
-  #include <__clang_cuda_math_forward_declares.h>
-#endif
-
-/// Include declarations for libdevice functions.
-#include <__clang_cuda_libdevice_declares.h>
-/// Provide definitions for these functions.
-#include <__clang_cuda_device_functions.h>
-
-#if defined(__cplusplus)
   #include <__clang_cuda_cmath.h>
 #endif
 

Added: cfe/trunk/lib/Headers/openmp_wrappers/__clang_openmp_math_declares.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/openmp_wrappers/__clang_openmp_math_declares.h?rev=360626&view=auto
==============================================================================
--- cfe/trunk/lib/Headers/openmp_wrappers/__clang_openmp_math_declares.h (added)
+++ cfe/trunk/lib/Headers/openmp_wrappers/__clang_openmp_math_declares.h Mon May 13 15:11:44 2019
@@ -0,0 +1,33 @@
+/*===---- __clang_openmp_math_declares.h - OpenMP math declares ------------===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#ifndef __CLANG_OPENMP_MATH_DECLARES_H__
+#define __CLANG_OPENMP_MATH_DECLARES_H__
+
+#ifndef _OPENMP
+#error "This file is for OpenMP compilation only."
+#endif
+
+#if defined(__NVPTX__) && defined(_OPENMP)
+
+#define __CUDA__
+
+#if defined(__cplusplus)
+  #include <__clang_cuda_math_forward_declares.h>
+#endif
+
+/// Include declarations for libdevice functions.
+#include <__clang_cuda_libdevice_declares.h>
+/// Provide definitions for these functions.
+#include <__clang_cuda_device_functions.h>
+
+#undef __CUDA__
+
+#endif
+#endif

Modified: cfe/trunk/lib/Headers/openmp_wrappers/cmath
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/openmp_wrappers/cmath?rev=360626&r1=360625&r2=360626&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/openmp_wrappers/cmath (original)
+++ cfe/trunk/lib/Headers/openmp_wrappers/cmath Mon May 13 15:11:44 2019
@@ -7,9 +7,7 @@
  *===-----------------------------------------------------------------------===
  */
 
-#ifndef __cplusplus
 #include <__clang_openmp_math.h>
-#endif
 
 #ifndef __CLANG_NO_HOST_MATH__
 #include_next <cmath>

Modified: cfe/trunk/lib/Headers/openmp_wrappers/math.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/openmp_wrappers/math.h?rev=360626&r1=360625&r2=360626&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/openmp_wrappers/math.h (original)
+++ cfe/trunk/lib/Headers/openmp_wrappers/math.h Mon May 13 15:11:44 2019
@@ -7,9 +7,7 @@
  *===-----------------------------------------------------------------------===
  */
 
-#ifndef __cplusplus
 #include <__clang_openmp_math.h>
-#endif
 
 #ifndef __CLANG_NO_HOST_MATH__
 #include_next <math.h>

Added: cfe/trunk/test/Headers/Inputs/include/cstdlib
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/Inputs/include/cstdlib?rev=360626&view=auto
==============================================================================
--- cfe/trunk/test/Headers/Inputs/include/cstdlib (added)
+++ cfe/trunk/test/Headers/Inputs/include/cstdlib Mon May 13 15:11:44 2019
@@ -0,0 +1,16 @@
+#pragma once
+
+extern int abs (int __x) __attribute__ ((__const__)) ;
+extern long int labs (long int __x) __attribute__ ((__const__)) ;
+
+namespace std
+{
+
+using ::abs;
+
+inline long
+abs(long __i) { return __builtin_labs(__i); }
+
+inline long long
+abs(long long __x) { return __builtin_llabs (__x); }
+}

Modified: cfe/trunk/test/Headers/nvptx_device_cmath_functions.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/nvptx_device_cmath_functions.c?rev=360626&r1=360625&r2=360626&view=diff
==============================================================================
--- cfe/trunk/test/Headers/nvptx_device_cmath_functions.c (original)
+++ cfe/trunk/test/Headers/nvptx_device_cmath_functions.c Mon May 13 15:11:44 2019
@@ -4,7 +4,7 @@
 // REQUIRES: nvptx-registered-target
 
 // RUN: %clang_cc1 -internal-isystem %S/Inputs/include -include cmath -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
-// RUN: %clang_cc1 -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_math.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -include cmath -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefix CHECK-YES %s
+// RUN: %clang_cc1 -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_math_declares.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -include cmath -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefix CHECK-YES %s
 
 #include <cmath>
 

Modified: cfe/trunk/test/Headers/nvptx_device_cmath_functions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/nvptx_device_cmath_functions.cpp?rev=360626&r1=360625&r2=360626&view=diff
==============================================================================
--- cfe/trunk/test/Headers/nvptx_device_cmath_functions.cpp (original)
+++ cfe/trunk/test/Headers/nvptx_device_cmath_functions.cpp Mon May 13 15:11:44 2019
@@ -4,9 +4,10 @@
 // REQUIRES: nvptx-registered-target
 
 // RUN: %clang_cc1 -internal-isystem %S/Inputs/include -include cmath -x c++ -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
-// RUN: %clang_cc1 -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_math.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -include cmath -internal-isystem %S/Inputs/include -include stdlib.h -x c++ -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefix CHECK-YES %s
+// RUN: %clang_cc1 -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_math_declares.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -include cmath -internal-isystem %S/Inputs/include -include stdlib.h -x c++ -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefix CHECK-YES %s
 
 #include <cmath>
+#include <cstdlib>
 
 void test_sqrt(double a1) {
   #pragma omp target

Modified: cfe/trunk/test/Headers/nvptx_device_math_functions.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/nvptx_device_math_functions.c?rev=360626&r1=360625&r2=360626&view=diff
==============================================================================
--- cfe/trunk/test/Headers/nvptx_device_math_functions.c (original)
+++ cfe/trunk/test/Headers/nvptx_device_math_functions.c Mon May 13 15:11:44 2019
@@ -4,7 +4,7 @@
 // REQUIRES: nvptx-registered-target
 
 // RUN: %clang_cc1 -internal-isystem %S/Inputs/include -include math.h -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
-// RUN: %clang_cc1 -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_math.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -include math.h -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefix CHECK-YES %s
+// RUN: %clang_cc1 -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_math_declares.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -include math.h -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefix CHECK-YES %s
 
 #include <math.h>
 

Modified: cfe/trunk/test/Headers/nvptx_device_math_functions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/nvptx_device_math_functions.cpp?rev=360626&r1=360625&r2=360626&view=diff
==============================================================================
--- cfe/trunk/test/Headers/nvptx_device_math_functions.cpp (original)
+++ cfe/trunk/test/Headers/nvptx_device_math_functions.cpp Mon May 13 15:11:44 2019
@@ -4,8 +4,9 @@
 // REQUIRES: nvptx-registered-target
 
 // RUN: %clang_cc1 -internal-isystem %S/Inputs/include -include math.h -x c++ -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
-// RUN: %clang_cc1 -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_math.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -include math.h -internal-isystem %S/Inputs/include -include stdlib.h -include limits -x c++ -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefix CHECK-YES %s
+// RUN: %clang_cc1 -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_math_declares.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -include math.h -internal-isystem %S/Inputs/include -include stdlib.h -include limits -include cstdlib -x c++ -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefix CHECK-YES %s
 
+#include <cstdlib>
 #include <math.h>
 
 void test_sqrt(double a1) {




More information about the cfe-commits mailing list