Skip to content

Commit 40df06c

Browse files
committed
[CUDA][HIP] Defer overloading resolution diagnostics for host device functions
In CUDA/HIP a function may become implicit host device function by pragma or constexpr. A host device function is checked in both host and device compilation. However it may be emitted only on host or device side, therefore the diagnostics should be deferred until it is known to be emitted. Currently clang is only able to defer certain diagnostics. This causes false alarms and limits the usefulness of host device functions. This patch lets clang defer all overloading resolution diagnostics for host device functions. An option -fgpu-defer-diag is added to control this behavior. By default it is off. It is NFC for other languages. Differential Revision: https://reviews.llvm.org/D84364
1 parent d5fd3d9 commit 40df06c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+529
-256
lines changed

clang/include/clang/Basic/Diagnostic.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class TextSubstitution<string Text> {
4545
// diagnostics
4646
string Component = "";
4747
string CategoryName = "";
48+
bit Deferrable = 0;
4849
}
4950

5051
// Diagnostic Categories. These can be applied to groups or individual
@@ -83,6 +84,7 @@ class Diagnostic<string text, DiagClass DC, Severity defaultmapping> {
8384
bit AccessControl = 0;
8485
bit WarningNoWerror = 0;
8586
bit ShowInSystemHeader = 0;
87+
bit Deferrable = 0;
8688
Severity DefaultSeverity = defaultmapping;
8789
DiagGroup Group;
8890
string CategoryName = "";
@@ -106,6 +108,14 @@ class SuppressInSystemHeader {
106108
bit ShowInSystemHeader = 0;
107109
}
108110

111+
class Deferrable {
112+
bit Deferrable = 1;
113+
}
114+
115+
class NonDeferrable {
116+
bit Deferrable = 0;
117+
}
118+
109119
// FIXME: ExtWarn and Extension should also be SFINAEFailure by default.
110120
class Error<string str> : Diagnostic<str, CLASS_ERROR, SEV_Error>, SFINAEFailure {
111121
bit ShowInSystemHeader = 1;

clang/include/clang/Basic/DiagnosticAST.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace clang {
1515
namespace diag {
1616
enum {
1717
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
18-
SHOWINSYSHEADER, CATEGORY) \
18+
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
1919
ENUM,
2020
#define ASTSTART
2121
#include "clang/Basic/DiagnosticASTKinds.inc"

clang/include/clang/Basic/DiagnosticAnalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace clang {
1515
namespace diag {
1616
enum {
1717
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
18-
SHOWINSYSHEADER, CATEGORY) \
18+
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
1919
ENUM,
2020
#define ANALYSISSTART
2121
#include "clang/Basic/DiagnosticAnalysisKinds.inc"

clang/include/clang/Basic/DiagnosticComment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace clang {
1515
namespace diag {
1616
enum {
1717
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
18-
SHOWINSYSHEADER, CATEGORY) \
18+
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
1919
ENUM,
2020
#define COMMENTSTART
2121
#include "clang/Basic/DiagnosticCommentKinds.inc"

clang/include/clang/Basic/DiagnosticCrossTU.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace clang {
1515
namespace diag {
1616
enum {
1717
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
18-
SHOWINSYSHEADER, CATEGORY) \
18+
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
1919
ENUM,
2020
#define CROSSTUSTART
2121
#include "clang/Basic/DiagnosticCrossTUKinds.inc"

clang/include/clang/Basic/DiagnosticDriver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace clang {
1515
namespace diag {
1616
enum {
1717
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
18-
SHOWINSYSHEADER, CATEGORY) \
18+
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
1919
ENUM,
2020
#define DRIVERSTART
2121
#include "clang/Basic/DiagnosticDriverKinds.inc"

clang/include/clang/Basic/DiagnosticFrontend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace clang {
1515
namespace diag {
1616
enum {
1717
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
18-
SHOWINSYSHEADER, CATEGORY) \
18+
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
1919
ENUM,
2020
#define FRONTENDSTART
2121
#include "clang/Basic/DiagnosticFrontendKinds.inc"

clang/include/clang/Basic/DiagnosticIDs.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ namespace clang {
6464

6565
// Get typedefs for common diagnostics.
6666
enum {
67-
#define DIAG(ENUM,FLAGS,DEFAULT_MAPPING,DESC,GROUP,\
68-
SFINAE,CATEGORY,NOWERROR,SHOWINSYSHEADER) ENUM,
67+
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, CATEGORY, \
68+
NOWERROR, SHOWINSYSHEADER, DEFFERABLE) \
69+
ENUM,
6970
#define COMMONSTART
7071
#include "clang/Basic/DiagnosticCommonKinds.inc"
7172
NUM_BUILTIN_COMMON_DIAGNOSTICS
@@ -280,6 +281,13 @@ class DiagnosticIDs : public RefCountedBase<DiagnosticIDs> {
280281
/// are not SFINAE errors.
281282
static SFINAEResponse getDiagnosticSFINAEResponse(unsigned DiagID);
282283

284+
/// Whether the diagnostic message can be deferred.
285+
///
286+
/// For single source offloading languages, a diagnostic message occurred
287+
/// in a device host function may be deferred until the function is sure
288+
/// to be emitted.
289+
static bool isDeferrable(unsigned DiagID);
290+
283291
/// Get the string of all diagnostic flags.
284292
///
285293
/// \returns A list of all diagnostics flags as they would be written in a

clang/include/clang/Basic/DiagnosticLex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace clang {
1515
namespace diag {
1616
enum {
1717
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
18-
SHOWINSYSHEADER, CATEGORY) \
18+
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
1919
ENUM,
2020
#define LEXSTART
2121
#include "clang/Basic/DiagnosticLexKinds.inc"

clang/include/clang/Basic/DiagnosticParse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace clang {
1515
namespace diag {
1616
enum {
1717
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
18-
SHOWINSYSHEADER, CATEGORY) \
18+
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
1919
ENUM,
2020
#define PARSESTART
2121
#include "clang/Basic/DiagnosticParseKinds.inc"

clang/include/clang/Basic/DiagnosticRefactoring.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace clang {
1515
namespace diag {
1616
enum {
1717
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
18-
SHOWINSYSHEADER, CATEGORY) \
18+
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
1919
ENUM,
2020
#define REFACTORINGSTART
2121
#include "clang/Basic/DiagnosticRefactoringKinds.inc"

clang/include/clang/Basic/DiagnosticSema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace clang {
1515
namespace diag {
1616
enum {
1717
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
18-
SHOWINSYSHEADER, CATEGORY) \
18+
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
1919
ENUM,
2020
#define SEMASTART
2121
#include "clang/Basic/DiagnosticSemaKinds.inc"

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4060,6 +4060,8 @@ def err_ovl_static_nonstatic_member : Error<
40604060
"static and non-static member functions with the same parameter types "
40614061
"cannot be overloaded">;
40624062

4063+
let Deferrable = 1 in {
4064+
40634065
def err_ovl_no_viable_function_in_call : Error<
40644066
"no matching function for call to %0">;
40654067
def err_ovl_no_viable_member_function_in_call : Error<
@@ -4373,6 +4375,8 @@ def err_addr_ovl_not_func_ptrref : Error<
43734375
def err_addr_ovl_no_qualifier : Error<
43744376
"cannot form member pointer of type %0 without '&' and class name">;
43754377

4378+
} // let Deferrable
4379+
43764380
// C++11 Literal Operators
43774381
def err_ovl_no_viable_literal_operator : Error<
43784382
"no matching literal operator for call to %0"

clang/include/clang/Basic/DiagnosticSerialization.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace clang {
1515
namespace diag {
1616
enum {
1717
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
18-
SHOWINSYSHEADER, CATEGORY) \
18+
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
1919
ENUM,
2020
#define SERIALIZATIONSTART
2121
#include "clang/Basic/DiagnosticSerializationKinds.inc"

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ LANGOPT(CUDADeviceApproxTranscendentals, 1, 0, "using approximate transcendental
241241
LANGOPT(GPURelocatableDeviceCode, 1, 0, "generate relocatable device code")
242242
LANGOPT(GPUAllowDeviceInit, 1, 0, "allowing device side global init functions for HIP")
243243
LANGOPT(GPUMaxThreadsPerBlock, 32, 256, "default max threads per block for kernel launch bounds for HIP")
244+
LANGOPT(GPUDeferDiag, 1, 0, "defer host/device related diagnostic messages for CUDA/HIP")
244245

245246
LANGOPT(SYCL , 1, 0, "SYCL")
246247
LANGOPT(SYCLIsDevice , 1, 0, "Generate code for SYCL device")

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,9 @@ defm hip_new_launch_api : OptInFFlag<"hip-new-launch-api",
669669
"Use", "Don't use", " new kernel launching API for HIP">;
670670
defm gpu_allow_device_init : OptInFFlag<"gpu-allow-device-init",
671671
"Allow", "Don't allow", " device side init function in HIP">;
672+
defm gpu_defer_diag : OptInFFlag<"gpu-defer-diag",
673+
"Defer", "Don't defer", " host/device related diagnostic messages"
674+
" for CUDA/HIP">;
672675
def gpu_max_threads_per_block_EQ : Joined<["--"], "gpu-max-threads-per-block=">,
673676
Flags<[CC1Option]>,
674677
HelpText<"Default max threads per block for kernel launch bounds for HIP">;

0 commit comments

Comments
 (0)