[clang] f64903f - Add -Wno-error=unknown flag to clang-format.

2020-09-19 Thread Joachim Meyer via cfe-commits

Author: Joachim Meyer
Date: 2020-09-19T10:17:57+02:00
New Revision: f64903fd81764f1fde7aeb00eea5e1d488458f63

URL: 
https://github.com/llvm/llvm-project/commit/f64903fd81764f1fde7aeb00eea5e1d488458f63
DIFF: 
https://github.com/llvm/llvm-project/commit/f64903fd81764f1fde7aeb00eea5e1d488458f63.diff

LOG: Add -Wno-error=unknown flag to clang-format.

Currently newer clang-format options cannot be included in .clang-format files, 
if not all users can be forced to use an updated version.
This patch tries to solve this by adding an option to clang-format, enabling to 
ignore unknown (newer) options.

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

Added: 


Modified: 
clang/docs/ClangFormat.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/tools/clang-format/ClangFormat.cpp
clang/unittests/Format/FormatTest.cpp
llvm/include/llvm/Support/YAMLParser.h
llvm/include/llvm/Support/YAMLTraits.h
llvm/lib/Support/YAMLParser.cpp
llvm/lib/Support/YAMLTraits.cpp
llvm/unittests/ObjectYAML/YAMLTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index b09f48b0027b..d396667ce10c 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -31,6 +31,12 @@ to format C/C++/Java/JavaScript/Objective-C/Protobuf/C# code.
   Clang-format options:
 
 --Werror   - If set, changes formatting warnings to errors
+--Wno-error=unknown- If set, unknown format options are only 
warned about.
+ This can be used to enable formatting, even 
if the
+ configuration contains unknown (newer) 
options.
+ Use with caution, as this might lead to 
dramatically
+ 
diff ering format depending on an option being
+ supported or not.
 --assume-filename= - Override filename used to determine the 
language.
  When reading from stdin, clang-format assumes 
this
  filename to determine the language.

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 2840a6846018..40d5184f4d0d 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2523,7 +2523,8 @@ struct FormatStyle {
 private:
   FormatStyleSet StyleSet;
 
-  friend std::error_code parseConfiguration(StringRef Text, FormatStyle 
*Style);
+  friend std::error_code parseConfiguration(StringRef Text, FormatStyle *Style,
+bool AllowUnknownOptions);
 };
 
 /// Returns a format style complying with the LLVM coding standards:
@@ -2578,7 +2579,11 @@ bool getPredefinedStyle(StringRef Name, 
FormatStyle::LanguageKind Language,
 ///
 /// When ``BasedOnStyle`` is not present, options not present in the YAML
 /// document, are retained in \p Style.
-std::error_code parseConfiguration(StringRef Text, FormatStyle *Style);
+///
+/// If AllowUnknownOptions is true, no errors are emitted if unknown
+/// format options are occured.
+std::error_code parseConfiguration(StringRef Text, FormatStyle *Style,
+   bool AllowUnknownOptions = false);
 
 /// Gets configuration in a YAML string.
 std::string configurationAsText(const FormatStyle &Style);
@@ -2715,6 +2720,9 @@ extern const char *DefaultFallbackStyle;
 /// language if the filename isn't sufficient.
 /// \param[in] FS The underlying file system, in which the file resides. By
 /// default, the file system is the real file system.
+/// \param[in] AllowUnknownOptions If true, unknown format options only
+/// emit a warning. If false, errors are emitted on unknown format
+/// options.
 ///
 /// \returns FormatStyle as specified by ``StyleName``. If ``StyleName`` is
 /// "file" and no file is found, returns ``FallbackStyle``. If no style could 
be
@@ -2722,7 +2730,8 @@ extern const char *DefaultFallbackStyle;
 llvm::Expected getStyle(StringRef StyleName, StringRef FileName,
  StringRef FallbackStyle,
  StringRef Code = "",
- llvm::vfs::FileSystem *FS = nullptr);
+ llvm::vfs::FileSystem *FS = nullptr,
+ bool AllowUnknownOptions = false);
 
 // Guesses the language from the ``FileName`` and ``Code`` to be formatted.
 // Defaults to FormatStyle::LK_Cpp.

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 03188b46099d..8e4f65ace3f0 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1301,7 +1301,8 @@ bool getPredefinedStyle(StringRef Name, 
FormatStyle::LanguageKind Language,
   return true;
 }
 
-std::erro

[clang] c755e41 - Fix -Wno-error= parsing in clang-format.

2020-12-17 Thread Joachim Meyer via cfe-commits

Author: Joachim Meyer
Date: 2020-12-17T22:23:42+01:00
New Revision: c755e41c336c898873db6c3c58a2819a982f60de

URL: 
https://github.com/llvm/llvm-project/commit/c755e41c336c898873db6c3c58a2819a982f60de
DIFF: 
https://github.com/llvm/llvm-project/commit/c755e41c336c898873db6c3c58a2819a982f60de.diff

LOG: Fix -Wno-error= parsing in clang-format.

As noted in https://reviews.llvm.org/D86137#2460135 parsing of
the clang-format parameter -Wno-error=unknown fails.
This currently is done by having `-Wno-error=unknown` as an option.
In this patch this is changed to make `-Wno-error=` parse an enum into a bit 
set.
This way the parsing is fixed and also we can possibly add new options easily.

Reviewed By: MyDeveloperDay

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

Added: 
clang/test/Format/error-config.cpp

Modified: 
clang/docs/ClangFormat.rst
clang/tools/clang-format/ClangFormat.cpp

Removed: 




diff  --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index b746ed3453df..d5333c0032b4 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -31,12 +31,13 @@ to format C/C++/Java/JavaScript/Objective-C/Protobuf/C# 
code.
   Clang-format options:
 
 --Werror   - If set, changes formatting warnings to errors
---Wno-error=unknown- If set, unknown format options are only 
warned about.
- This can be used to enable formatting, even 
if the
- configuration contains unknown (newer) 
options.
- Use with caution, as this might lead to 
dramatically
- 
diff ering format depending on an option being
- supported or not.
+--Wno-error=- If set don't error out on the specified 
warning type.
+  =unknown -   If set, unknown format options are only 
warned about.
+   This can be used to enable formatting, even 
if the
+   configuration contains unknown (newer) 
options.
+   Use with caution, as this might lead to 
dramatically
+   
diff ering format depending on an option being
+   supported or not.
 --assume-filename= - Override filename used to determine the 
language.
  When reading from stdin, clang-format assumes 
this
  filename to determine the language.

diff  --git a/clang/test/Format/error-config.cpp 
b/clang/test/Format/error-config.cpp
new file mode 100644
index ..7fbc869f3a3c
--- /dev/null
+++ b/clang/test/Format/error-config.cpp
@@ -0,0 +1,11 @@
+// RUN: clang-format %s --Wno-error=unknown --style="{UnknownKey: true}" 2>&1 
| FileCheck %s -check-prefix=CHECK
+// RUN: not clang-format %s --style="{UnknownKey: true}" 2>&1 | FileCheck %s 
-check-prefix=CHECK-FAIL
+
+// CHECK: YAML:1:2: warning: unknown key 'UnknownKey'
+// CHECK-NEXT: {UnknownKey: true}
+// CHECK-NEXT: ^~
+// CHECK-FAIL: YAML:1:2: error: unknown key 'UnknownKey'
+// CHECK-FAIL-NEXT: {UnknownKey: true}
+// CHECK-FAIL-NEXT: ^~
+
+int i ;

diff  --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index a1b42a6d0940..64f0e2badf33 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -104,18 +104,6 @@ static cl::opt SortIncludes(
  "SortIncludes style flag"),
 cl::cat(ClangFormatCategory));
 
-// using the full param name as Wno-error probably won't be a common use case 
in
-// clang-format
-static cl::opt AllowUnknownOptions(
-"Wno-error=unknown",
-cl::desc("If set, unknown format options are only warned about.\n"
- "This can be used to enable formatting, even if the\n"
- "configuration contains unknown (newer) options.\n"
- "Use with caution, as this might lead to dramatically\n"
- "
diff ering format depending on an option being\n"
- "supported or not."),
-cl::init(false), cl::cat(ClangFormatCategory));
-
 static cl::opt
 Verbose("verbose", cl::desc("If set, shows the list of processed files"),
 cl::cat(ClangFormatCategory));
@@ -156,6 +144,23 @@ static cl::opt
  cl::desc("If set, changes formatting warnings to errors"),
  cl::cat(ClangFormatCategory));
 
+namespace {
+enum class WNoError { Unknown };
+}
+
+static cl::bits WNoErrorList(
+"Wno-error",
+cl::desc("If set don't error out on the specified warning type."),
+cl::values(
+clEnumValN(WNoError::Unknown, "unknown",
+   "If set, unknown format options are only warned about.\n"
+   "This can be used to enable f

[clang] eaee608 - [OpenMP] Use __OPENMP_NVPTX__ instead of _OPENMP in complex wrapper headers.

2020-10-29 Thread Joachim Meyer via cfe-commits

Author: Joachim Meyer
Date: 2020-10-29T23:24:49+01:00
New Revision: eaee608448c832e8f806faae30ae4100620c4688

URL: 
https://github.com/llvm/llvm-project/commit/eaee608448c832e8f806faae30ae4100620c4688
DIFF: 
https://github.com/llvm/llvm-project/commit/eaee608448c832e8f806faae30ae4100620c4688.diff

LOG: [OpenMP] Use __OPENMP_NVPTX__ instead of _OPENMP in complex wrapper 
headers.

This is very similar to 7f1e6fcff942, just fixing a left-over.
With this, it should be possible to use both, -x cuda and -fopenmp in the same 
invocation,
enabling to use both OpenMP, targeting CPU, and CUDA, targeting the GPU.

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/lib/Headers/__clang_cuda_complex_builtins.h
clang/lib/Headers/openmp_wrappers/complex
clang/lib/Headers/openmp_wrappers/complex.h

Removed: 




diff  --git a/clang/lib/Headers/__clang_cuda_complex_builtins.h 
b/clang/lib/Headers/__clang_cuda_complex_builtins.h
index 9b254f700b9d..2b701fef0ea2 100644
--- a/clang/lib/Headers/__clang_cuda_complex_builtins.h
+++ b/clang/lib/Headers/__clang_cuda_complex_builtins.h
@@ -16,7 +16,7 @@
 // to work with CUDA and OpenMP target offloading [in C and C++ mode].)
 
 #pragma push_macro("__DEVICE__")
-#ifdef _OPENMP
+#ifdef __OPENMP_NVPTX__
 #pragma omp declare target
 #define __DEVICE__ __attribute__((noinline, nothrow, cold, weak))
 #else
@@ -26,7 +26,7 @@
 // To make the algorithms available for C and C++ in CUDA and OpenMP we select
 // 
diff erent but equivalent function versions. TODO: For OpenMP we currently
 // select the native builtins as the overload support for templates is lacking.
-#if !defined(_OPENMP)
+#if !defined(__OPENMP_NVPTX__)
 #define _ISNANd std::isnan
 #define _ISNANf std::isnan
 #define _ISINFd std::isinf
@@ -276,7 +276,7 @@ __DEVICE__ float _Complex __divsc3(float __a, float __b, 
float __c, float __d) {
 #undef _fmaxd
 #undef _fmaxf
 
-#ifdef _OPENMP
+#ifdef __OPENMP_NVPTX__
 #pragma omp end declare target
 #endif
 

diff  --git a/clang/lib/Headers/openmp_wrappers/complex 
b/clang/lib/Headers/openmp_wrappers/complex
index 306ffe208053..142e526b81b3 100644
--- a/clang/lib/Headers/openmp_wrappers/complex
+++ b/clang/lib/Headers/openmp_wrappers/complex
@@ -18,7 +18,9 @@
 #include 
 
 #define __CUDA__
+#define __OPENMP_NVPTX__
 #include <__clang_cuda_complex_builtins.h>
+#undef __OPENMP_NVPTX__
 #endif
 
 // Grab the host header too.

diff  --git a/clang/lib/Headers/openmp_wrappers/complex.h 
b/clang/lib/Headers/openmp_wrappers/complex.h
index 829c7a785725..00d278548f82 100644
--- a/clang/lib/Headers/openmp_wrappers/complex.h
+++ b/clang/lib/Headers/openmp_wrappers/complex.h
@@ -18,7 +18,9 @@
 #include 
 
 #define __CUDA__
+#define __OPENMP_NVPTX__
 #include <__clang_cuda_complex_builtins.h>
+#undef __OPENMP_NVPTX__
 #endif
 
 // Grab the host header too.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 75e941b - [NFC][OpenMP][CUDA] Add test for using `-x cuda -fopenmp`

2021-07-02 Thread Joachim Meyer via cfe-commits

Author: Joachim Meyer
Date: 2021-07-02T19:03:15+02:00
New Revision: 75e941b05c78e19c51e5c960c925f334b08109bb

URL: 
https://github.com/llvm/llvm-project/commit/75e941b05c78e19c51e5c960c925f334b08109bb
DIFF: 
https://github.com/llvm/llvm-project/commit/75e941b05c78e19c51e5c960c925f334b08109bb.diff

LOG: [NFC][OpenMP][CUDA] Add test for using `-x cuda -fopenmp`

This adds a very basic test in `cuda_with_openmp.cu` that just checks whether 
the CUDA & OpenMP integrated headers do compile, when a CUDA file is compiled 
with OpenMP (CPU) enabled.
Thus this basically adds the missing test for https://reviews.llvm.org/D90415.

Reviewed By: jdoerfert

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

Added: 
clang/test/Headers/Inputs/include/crt/device_double_functions.hpp
clang/test/Headers/Inputs/include/crt/device_functions.hpp
clang/test/Headers/Inputs/include/crt/device_runtime.h
clang/test/Headers/Inputs/include/crt/host_runtime.h
clang/test/Headers/Inputs/include/crt/math_functions.hpp
clang/test/Headers/Inputs/include/crt/sm_70_rt.hpp
clang/test/Headers/Inputs/include/cuda.h
clang/test/Headers/Inputs/include/cuda_runtime.h
clang/test/Headers/Inputs/include/curand_mtgp32_kernel.h
clang/test/Headers/Inputs/include/device_atomic_functions.h
clang/test/Headers/Inputs/include/device_atomic_functions.hpp
clang/test/Headers/Inputs/include/device_double_functions.h
clang/test/Headers/Inputs/include/driver_types.h
clang/test/Headers/Inputs/include/host_config.h
clang/test/Headers/Inputs/include/host_defines.h
clang/test/Headers/Inputs/include/math_functions_dbl_ptx3.hpp
clang/test/Headers/Inputs/include/sm_20_atomic_functions.hpp
clang/test/Headers/Inputs/include/sm_20_intrinsics.hpp
clang/test/Headers/Inputs/include/sm_32_atomic_functions.hpp
clang/test/Headers/Inputs/include/sm_60_atomic_functions.hpp
clang/test/Headers/Inputs/include/sm_61_intrinsics.hpp
clang/test/Headers/Inputs/include/string.h
clang/test/Headers/Inputs/include/texture_indirect_functions.h
clang/test/Headers/cuda_with_openmp.cu

Modified: 
clang/test/Headers/Inputs/include/cstdlib
clang/test/Headers/Inputs/include/new

Removed: 




diff  --git a/clang/test/Headers/Inputs/include/crt/device_double_functions.hpp 
b/clang/test/Headers/Inputs/include/crt/device_double_functions.hpp
new file mode 100644
index 0..bffa775cb2822
--- /dev/null
+++ b/clang/test/Headers/Inputs/include/crt/device_double_functions.hpp
@@ -0,0 +1,2 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once

diff  --git a/clang/test/Headers/Inputs/include/crt/device_functions.hpp 
b/clang/test/Headers/Inputs/include/crt/device_functions.hpp
new file mode 100644
index 0..41dc8722fe643
--- /dev/null
+++ b/clang/test/Headers/Inputs/include/crt/device_functions.hpp
@@ -0,0 +1,3 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once
+__device__ void   __brkpt();

diff  --git a/clang/test/Headers/Inputs/include/crt/device_runtime.h 
b/clang/test/Headers/Inputs/include/crt/device_runtime.h
new file mode 100644
index 0..bffa775cb2822
--- /dev/null
+++ b/clang/test/Headers/Inputs/include/crt/device_runtime.h
@@ -0,0 +1,2 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once

diff  --git a/clang/test/Headers/Inputs/include/crt/host_runtime.h 
b/clang/test/Headers/Inputs/include/crt/host_runtime.h
new file mode 100644
index 0..bffa775cb2822
--- /dev/null
+++ b/clang/test/Headers/Inputs/include/crt/host_runtime.h
@@ -0,0 +1,2 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once

diff  --git a/clang/test/Headers/Inputs/include/crt/math_functions.hpp 
b/clang/test/Headers/Inputs/include/crt/math_functions.hpp
new file mode 100644
index 0..fbd2bb52fa842
--- /dev/null
+++ b/clang/test/Headers/Inputs/include/crt/math_functions.hpp
@@ -0,0 +1,12 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma once
+__device__ int__isinff(float);
+__device__ int__isinf(double);
+__device__ int__finitef(float);
+__device__ int__isfinited(double);
+__device__ int__isnanf(float);
+__device__ int__isnan(double);
+__device__ int__signbitf(float);
+__device__ int__signbitd(double);
+__device__ double max(double, double);
+__device__ float  max(float, float);

diff  --git a/clang/test/Headers/Inputs/include/crt/sm_70_rt.hpp 
b/clang/test/Headers/Inputs/include/crt/sm_70_rt.hpp
new file mode 100644
index 0..bffa775cb2822
--- /dev/null
+++ b/clang/test/Headers/Inputs/include/crt/sm_70_rt.hpp
@@ -0,0 +1,2 @@
+// required for __clang_cuda_runtime_wrapper.h tests
+#pragma on

[clang] 5d689cf - [NFC][CUDA] Fix order of round(f) definition in __clang_cuda_math.h for non-LP64.

2021-07-02 Thread Joachim Meyer via cfe-commits

Author: Joachim Meyer
Date: 2021-07-02T21:55:48+02:00
New Revision: 5d689cf2a667d8dc51768400455e0ecc55d19eaf

URL: 
https://github.com/llvm/llvm-project/commit/5d689cf2a667d8dc51768400455e0ecc55d19eaf
DIFF: 
https://github.com/llvm/llvm-project/commit/5d689cf2a667d8dc51768400455e0ecc55d19eaf.diff

LOG: [NFC][CUDA] Fix order of round(f) definition in __clang_cuda_math.h for 
non-LP64.

This broke ARM builds e.g.: 
https://lab.llvm.org/buildbot/#/builders/187/builds/212

Added: 


Modified: 
clang/lib/Headers/__clang_cuda_math.h

Removed: 




diff  --git a/clang/lib/Headers/__clang_cuda_math.h 
b/clang/lib/Headers/__clang_cuda_math.h
index acb26ad345d59..538556f394da4 100644
--- a/clang/lib/Headers/__clang_cuda_math.h
+++ b/clang/lib/Headers/__clang_cuda_math.h
@@ -166,6 +166,8 @@ __DEVICE__ long long llrint(double __a) { return 
__nv_llrint(__a); }
 __DEVICE__ long long llrintf(float __a) { return __nv_llrintf(__a); }
 __DEVICE__ long long llround(double __a) { return __nv_llround(__a); }
 __DEVICE__ long long llroundf(float __a) { return __nv_llroundf(__a); }
+__DEVICE__ double round(double __a) { return __nv_round(__a); }
+__DEVICE__ float roundf(float __a) { return __nv_roundf(__a); }
 __DEVICE__ double log(double __a) { return __nv_log(__a); }
 __DEVICE__ double log10(double __a) { return __nv_log10(__a); }
 __DEVICE__ float log10f(float __a) { return __nv_log10f(__a); }
@@ -270,8 +272,6 @@ __DEVICE__ float rnorm4df(float __a, float __b, float __c, 
float __d) {
 __DEVICE__ float rnormf(int __dim, const float *__t) {
   return __nv_rnormf(__dim, __t);
 }
-__DEVICE__ double round(double __a) { return __nv_round(__a); }
-__DEVICE__ float roundf(float __a) { return __nv_roundf(__a); }
 __DEVICE__ double rsqrt(double __a) { return __nv_rsqrt(__a); }
 __DEVICE__ float rsqrtf(float __a) { return __nv_rsqrtf(__a); }
 __DEVICE__ double scalbn(double __a, int __b) { return __nv_scalbn(__a, __b); }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits