143 changes: 52 additions & 91 deletions clang/include/clang/Basic/Diagnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -1043,35 +1043,6 @@ class DiagnosticErrorTrap {
}
};

/// The streaming interface shared between DiagnosticBuilder and
/// PartialDiagnostic.
///
/// Any new type of argument accepted by DiagnosticBuilder and PartialDiagnostic
/// should be implemented as a '<<' operator of StreamableDiagnosticBase, e.g.
///
/// const StreamableDiagnosticBase&
/// operator<<(const StreamableDiagnosticBase&, NewArgType);
///
class StreamableDiagnosticBase {
public:
virtual void AddString(StringRef S) const = 0;
virtual void AddTaggedVal(intptr_t V,
DiagnosticsEngine::ArgumentKind Kind) const = 0;
virtual void AddSourceRange(const CharSourceRange &R) const = 0;
virtual void AddFixItHint(const FixItHint &Hint) const = 0;

/// Conversion of StreamableDiagnosticBase to bool always returns \c true.
///
/// This allows is to be used in boolean error contexts (where \c true is
/// used to indicate that an error has occurred), like:
/// \code
/// return Diag(...);
/// \endcode
operator bool() const { return true; }

virtual ~StreamableDiagnosticBase() {}
};

//===----------------------------------------------------------------------===//
// DiagnosticBuilder
//===----------------------------------------------------------------------===//
Expand All @@ -1088,7 +1059,7 @@ class StreamableDiagnosticBase {
/// This ensures that compilers with somewhat reasonable optimizers will promote
/// the common fields to registers, eliminating increments of the NumArgs field,
/// for example.
class DiagnosticBuilder : public StreamableDiagnosticBase {
class DiagnosticBuilder {
friend class DiagnosticsEngine;
friend class PartialDiagnostic;

Expand Down Expand Up @@ -1166,57 +1137,50 @@ class DiagnosticBuilder : public StreamableDiagnosticBase {
NumArgs = D.NumArgs;
}

template <typename T> const DiagnosticBuilder &operator<<(const T &V) const {
const StreamableDiagnosticBase &DB = *this;
DB << V;
return *this;
}

// It is necessary to limit this to rvalue reference to avoid calling this
// function with a bitfield lvalue argument since non-const reference to
// bitfield is not allowed.
template <typename T, typename = typename std::enable_if<
!std::is_lvalue_reference<T>::value>::type>
const DiagnosticBuilder &operator<<(T &&V) const {
const StreamableDiagnosticBase &DB = *this;
DB << std::move(V);
return *this;
}

DiagnosticBuilder &operator=(const DiagnosticBuilder &) = delete;

/// Emits the diagnostic.
virtual ~DiagnosticBuilder() { Emit(); }
~DiagnosticBuilder() {
Emit();
}

/// Forces the diagnostic to be emitted.
const DiagnosticBuilder &setForceEmit() const {
IsForceEmit = true;
return *this;
}

void AddString(StringRef S) const override {
/// Conversion of DiagnosticBuilder to bool always returns \c true.
///
/// This allows is to be used in boolean error contexts (where \c true is
/// used to indicate that an error has occurred), like:
/// \code
/// return Diag(...);
/// \endcode
operator bool() const { return true; }

void AddString(StringRef S) const {
assert(isActive() && "Clients must not add to cleared diagnostic!");
assert(NumArgs < DiagnosticsEngine::MaxArguments &&
"Too many arguments to diagnostic!");
DiagObj->DiagArgumentsKind[NumArgs] = DiagnosticsEngine::ak_std_string;
DiagObj->DiagArgumentsStr[NumArgs++] = std::string(S);
}

void AddTaggedVal(intptr_t V,
DiagnosticsEngine::ArgumentKind Kind) const override {
void AddTaggedVal(intptr_t V, DiagnosticsEngine::ArgumentKind Kind) const {
assert(isActive() && "Clients must not add to cleared diagnostic!");
assert(NumArgs < DiagnosticsEngine::MaxArguments &&
"Too many arguments to diagnostic!");
DiagObj->DiagArgumentsKind[NumArgs] = Kind;
DiagObj->DiagArgumentsVal[NumArgs++] = V;
}

void AddSourceRange(const CharSourceRange &R) const override {
void AddSourceRange(const CharSourceRange &R) const {
assert(isActive() && "Clients must not add to cleared diagnostic!");
DiagObj->DiagRanges.push_back(R);
}

void AddFixItHint(const FixItHint &Hint) const override {
void AddFixItHint(const FixItHint &Hint) const {
assert(isActive() && "Clients must not add to cleared diagnostic!");
if (!Hint.isNull())
DiagObj->DiagFixItHints.push_back(Hint);
Expand All @@ -1241,49 +1205,47 @@ inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
return DB;
}

inline const StreamableDiagnosticBase &
operator<<(const StreamableDiagnosticBase &DB, StringRef S) {
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
StringRef S) {
DB.AddString(S);
return DB;
}

inline const StreamableDiagnosticBase &
operator<<(const StreamableDiagnosticBase &DB, const char *Str) {
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
const char *Str) {
DB.AddTaggedVal(reinterpret_cast<intptr_t>(Str),
DiagnosticsEngine::ak_c_string);
return DB;
}

inline const StreamableDiagnosticBase &
operator<<(const StreamableDiagnosticBase &DB, int I) {
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, int I) {
DB.AddTaggedVal(I, DiagnosticsEngine::ak_sint);
return DB;
}

// We use enable_if here to prevent that this overload is selected for
// pointers or other arguments that are implicitly convertible to bool.
template <typename T>
inline std::enable_if_t<std::is_same<T, bool>::value,
const StreamableDiagnosticBase &>
operator<<(const StreamableDiagnosticBase &DB, T I) {
inline std::enable_if_t<std::is_same<T, bool>::value, const DiagnosticBuilder &>
operator<<(const DiagnosticBuilder &DB, T I) {
DB.AddTaggedVal(I, DiagnosticsEngine::ak_sint);
return DB;
}

inline const StreamableDiagnosticBase &
operator<<(const StreamableDiagnosticBase &DB, unsigned I) {
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
unsigned I) {
DB.AddTaggedVal(I, DiagnosticsEngine::ak_uint);
return DB;
}

inline const StreamableDiagnosticBase &
operator<<(const StreamableDiagnosticBase &DB, tok::TokenKind I) {
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
tok::TokenKind I) {
DB.AddTaggedVal(static_cast<unsigned>(I), DiagnosticsEngine::ak_tokenkind);
return DB;
}

inline const StreamableDiagnosticBase &
operator<<(const StreamableDiagnosticBase &DB, const IdentifierInfo *II) {
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
const IdentifierInfo *II) {
DB.AddTaggedVal(reinterpret_cast<intptr_t>(II),
DiagnosticsEngine::ak_identifierinfo);
return DB;
Expand All @@ -1296,64 +1258,63 @@ operator<<(const StreamableDiagnosticBase &DB, const IdentifierInfo *II) {
template <typename T>
inline std::enable_if_t<
std::is_same<std::remove_const_t<T>, DeclContext>::value,
const StreamableDiagnosticBase &>
operator<<(const StreamableDiagnosticBase &DB, T *DC) {
const DiagnosticBuilder &>
operator<<(const DiagnosticBuilder &DB, T *DC) {
DB.AddTaggedVal(reinterpret_cast<intptr_t>(DC),
DiagnosticsEngine::ak_declcontext);
return DB;
}

inline const StreamableDiagnosticBase &
operator<<(const StreamableDiagnosticBase &DB, SourceRange R) {
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
SourceRange R) {
DB.AddSourceRange(CharSourceRange::getTokenRange(R));
return DB;
}

inline const StreamableDiagnosticBase &
operator<<(const StreamableDiagnosticBase &DB, ArrayRef<SourceRange> Ranges) {
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
ArrayRef<SourceRange> Ranges) {
for (SourceRange R : Ranges)
DB.AddSourceRange(CharSourceRange::getTokenRange(R));
return DB;
}

inline const StreamableDiagnosticBase &
operator<<(const StreamableDiagnosticBase &DB, const CharSourceRange &R) {
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
const CharSourceRange &R) {
DB.AddSourceRange(R);
return DB;
}

inline const StreamableDiagnosticBase &
operator<<(const StreamableDiagnosticBase &DB, const FixItHint &Hint) {
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
const FixItHint &Hint) {
DB.AddFixItHint(Hint);
return DB;
}

inline const StreamableDiagnosticBase &
operator<<(const StreamableDiagnosticBase &DB, ArrayRef<FixItHint> Hints) {
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
ArrayRef<FixItHint> Hints) {
for (const FixItHint &Hint : Hints)
DB.AddFixItHint(Hint);
return DB;
}

inline const StreamableDiagnosticBase &
operator<<(const StreamableDiagnosticBase &DB,
inline const DiagnosticBuilder &
operator<<(const DiagnosticBuilder &DB,
const llvm::Optional<SourceRange> &Opt) {
if (Opt)
DB << *Opt;
return DB;
}

inline const StreamableDiagnosticBase &
operator<<(const StreamableDiagnosticBase &DB,
inline const DiagnosticBuilder &
operator<<(const DiagnosticBuilder &DB,
const llvm::Optional<CharSourceRange> &Opt) {
if (Opt)
DB << *Opt;
return DB;
}

inline const StreamableDiagnosticBase &
operator<<(const StreamableDiagnosticBase &DB,
const llvm::Optional<FixItHint> &Opt) {
inline const DiagnosticBuilder &
operator<<(const DiagnosticBuilder &DB, const llvm::Optional<FixItHint> &Opt) {
if (Opt)
DB << *Opt;
return DB;
Expand All @@ -1363,8 +1324,8 @@ operator<<(const StreamableDiagnosticBase &DB,
/// context-sensitive keyword.
using DiagNullabilityKind = std::pair<NullabilityKind, bool>;

const StreamableDiagnosticBase &operator<<(const StreamableDiagnosticBase &DB,
DiagNullabilityKind nullability);
const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
DiagNullabilityKind nullability);

inline DiagnosticBuilder DiagnosticsEngine::Report(SourceLocation Loc,
unsigned DiagID) {
Expand All @@ -1376,8 +1337,8 @@ inline DiagnosticBuilder DiagnosticsEngine::Report(SourceLocation Loc,
return DiagnosticBuilder(this);
}

const StreamableDiagnosticBase &operator<<(const StreamableDiagnosticBase &DB,
llvm::Error &&E);
const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
llvm::Error &&E);

inline DiagnosticBuilder DiagnosticsEngine::Report(unsigned DiagID) {
return Report(SourceLocation(), DiagID);
Expand Down
10 changes: 0 additions & 10 deletions clang/include/clang/Basic/Diagnostic.td
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class TextSubstitution<string Text> {
// diagnostics
string Component = "";
string CategoryName = "";
bit Deferrable = 0;
}

// Diagnostic Categories. These can be applied to groups or individual
Expand Down Expand Up @@ -84,7 +83,6 @@ class Diagnostic<string text, DiagClass DC, Severity defaultmapping> {
bit AccessControl = 0;
bit WarningNoWerror = 0;
bit ShowInSystemHeader = 0;
bit Deferrable = 0;
Severity DefaultSeverity = defaultmapping;
DiagGroup Group;
string CategoryName = "";
Expand All @@ -108,14 +106,6 @@ class SuppressInSystemHeader {
bit ShowInSystemHeader = 0;
}

class Deferrable {
bit Deferrable = 1;
}

class NonDeferrable {
bit Deferrable = 0;
}

// FIXME: ExtWarn and Extension should also be SFINAEFailure by default.
class Error<string str> : Diagnostic<str, CLASS_ERROR, SEV_Error>, SFINAEFailure {
bit ShowInSystemHeader = 1;
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticAST.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace clang {
namespace diag {
enum {
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
SHOWINSYSHEADER, CATEGORY) \
ENUM,
#define ASTSTART
#include "clang/Basic/DiagnosticASTKinds.inc"
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace clang {
namespace diag {
enum {
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
SHOWINSYSHEADER, CATEGORY) \
ENUM,
#define ANALYSISSTART
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticComment.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace clang {
namespace diag {
enum {
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
SHOWINSYSHEADER, CATEGORY) \
ENUM,
#define COMMENTSTART
#include "clang/Basic/DiagnosticCommentKinds.inc"
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticCrossTU.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace clang {
namespace diag {
enum {
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
SHOWINSYSHEADER, CATEGORY) \
ENUM,
#define CROSSTUSTART
#include "clang/Basic/DiagnosticCrossTUKinds.inc"
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace clang {
namespace diag {
enum {
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
SHOWINSYSHEADER, CATEGORY) \
ENUM,
#define DRIVERSTART
#include "clang/Basic/DiagnosticDriverKinds.inc"
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticFrontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace clang {
namespace diag {
enum {
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
SHOWINSYSHEADER, CATEGORY) \
ENUM,
#define FRONTENDSTART
#include "clang/Basic/DiagnosticFrontendKinds.inc"
Expand Down
12 changes: 2 additions & 10 deletions clang/include/clang/Basic/DiagnosticIDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ namespace clang {

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

/// Whether the diagnostic message can be deferred.
///
/// For single source offloading languages, a diagnostic message occurred
/// in a device host function may be deferred until the function is sure
/// to be emitted.
static bool isDeferrable(unsigned DiagID);

/// Get the string of all diagnostic flags.
///
/// \returns A list of all diagnostics flags as they would be written in a
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticLex.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace clang {
namespace diag {
enum {
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
SHOWINSYSHEADER, CATEGORY) \
ENUM,
#define LEXSTART
#include "clang/Basic/DiagnosticLexKinds.inc"
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticParse.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace clang {
namespace diag {
enum {
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
SHOWINSYSHEADER, CATEGORY) \
ENUM,
#define PARSESTART
#include "clang/Basic/DiagnosticParseKinds.inc"
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticRefactoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace clang {
namespace diag {
enum {
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
SHOWINSYSHEADER, CATEGORY) \
ENUM,
#define REFACTORINGSTART
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticSema.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace clang {
namespace diag {
enum {
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
SHOWINSYSHEADER, CATEGORY) \
ENUM,
#define SEMASTART
#include "clang/Basic/DiagnosticSemaKinds.inc"
Expand Down
4 changes: 0 additions & 4 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -4100,8 +4100,6 @@ def err_ovl_static_nonstatic_member : Error<
"static and non-static member functions with the same parameter types "
"cannot be overloaded">;

let Deferrable = 1 in {

def err_ovl_no_viable_function_in_call : Error<
"no matching function for call to %0">;
def err_ovl_no_viable_member_function_in_call : Error<
Expand Down Expand Up @@ -4415,8 +4413,6 @@ def err_addr_ovl_not_func_ptrref : Error<
def err_addr_ovl_no_qualifier : Error<
"cannot form member pointer of type %0 without '&' and class name">;

} // let Deferrable

// C++11 Literal Operators
def err_ovl_no_viable_literal_operator : Error<
"no matching literal operator for call to %0"
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticSerialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace clang {
namespace diag {
enum {
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
SHOWINSYSHEADER, CATEGORY) \
ENUM,
#define SERIALIZATIONSTART
#include "clang/Basic/DiagnosticSerializationKinds.inc"
Expand Down
1 change: 0 additions & 1 deletion clang/include/clang/Basic/LangOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ LANGOPT(CUDADeviceApproxTranscendentals, 1, 0, "using approximate transcendental
LANGOPT(GPURelocatableDeviceCode, 1, 0, "generate relocatable device code")
LANGOPT(GPUAllowDeviceInit, 1, 0, "allowing device side global init functions for HIP")
LANGOPT(GPUMaxThreadsPerBlock, 32, 256, "default max threads per block for kernel launch bounds for HIP")
LANGOPT(GPUDeferDiag, 1, 0, "defer host/device related diagnostic messages for CUDA/HIP")

LANGOPT(SYCL , 1, 0, "SYCL")
LANGOPT(SYCLIsDevice , 1, 0, "Generate code for SYCL device")
Expand Down
98 changes: 73 additions & 25 deletions clang/include/clang/Basic/PartialDiagnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace clang {
class DeclContext;
class IdentifierInfo;

class PartialDiagnostic : public StreamableDiagnosticBase {
class PartialDiagnostic {
public:
enum {
// The MaxArguments and MaxFixItHints member enum values from
Expand Down Expand Up @@ -163,15 +163,14 @@ class PartialDiagnostic : public StreamableDiagnosticBase {
DiagStorage = nullptr;
}

public:
void AddSourceRange(const CharSourceRange &R) const override {
void AddSourceRange(const CharSourceRange &R) const {
if (!DiagStorage)
DiagStorage = getStorage();

DiagStorage->DiagRanges.push_back(R);
}

void AddFixItHint(const FixItHint &Hint) const override {
void AddFixItHint(const FixItHint &Hint) const {
if (Hint.isNull())
return;

Expand All @@ -181,6 +180,7 @@ class PartialDiagnostic : public StreamableDiagnosticBase {
DiagStorage->FixItHints.push_back(Hint);
}

public:
struct NullDiagnostic {};

/// Create a null partial diagnostic, which cannot carry a payload,
Expand All @@ -198,23 +198,6 @@ class PartialDiagnostic : public StreamableDiagnosticBase {
}
}

template <typename T> const PartialDiagnostic &operator<<(const T &V) const {
const StreamableDiagnosticBase &DB = *this;
DB << V;
return *this;
}

// It is necessary to limit this to rvalue reference to avoid calling this
// function with a bitfield lvalue argument since non-const reference to
// bitfield is not allowed.
template <typename T, typename = typename std::enable_if<
!std::is_lvalue_reference<T>::value>::type>
const PartialDiagnostic &operator<<(T &&V) const {
const StreamableDiagnosticBase &DB = *this;
DB << std::move(V);
return *this;
}

PartialDiagnostic(PartialDiagnostic &&Other)
: DiagID(Other.DiagID), DiagStorage(Other.DiagStorage),
Allocator(Other.Allocator) {
Expand Down Expand Up @@ -272,7 +255,9 @@ class PartialDiagnostic : public StreamableDiagnosticBase {
return *this;
}

virtual ~PartialDiagnostic() { freeStorage(); }
~PartialDiagnostic() {
freeStorage();
}

void swap(PartialDiagnostic &PD) {
std::swap(DiagID, PD.DiagID);
Expand All @@ -282,8 +267,7 @@ class PartialDiagnostic : public StreamableDiagnosticBase {

unsigned getDiagID() const { return DiagID; }

void AddTaggedVal(intptr_t V,
DiagnosticsEngine::ArgumentKind Kind) const override {
void AddTaggedVal(intptr_t V, DiagnosticsEngine::ArgumentKind Kind) const {
if (!DiagStorage)
DiagStorage = getStorage();

Expand All @@ -293,7 +277,7 @@ class PartialDiagnostic : public StreamableDiagnosticBase {
DiagStorage->DiagArgumentsVal[DiagStorage->NumDiagArgs++] = V;
}

void AddString(StringRef V) const override {
void AddString(StringRef V) const {
if (!DiagStorage)
DiagStorage = getStorage();

Expand Down Expand Up @@ -356,6 +340,70 @@ class PartialDiagnostic : public StreamableDiagnosticBase {
== DiagnosticsEngine::ak_std_string && "Not a string arg");
return DiagStorage->DiagArgumentsStr[I];
}

friend const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
unsigned I) {
PD.AddTaggedVal(I, DiagnosticsEngine::ak_uint);
return PD;
}

friend const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
int I) {
PD.AddTaggedVal(I, DiagnosticsEngine::ak_sint);
return PD;
}

friend inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
const char *S) {
PD.AddTaggedVal(reinterpret_cast<intptr_t>(S),
DiagnosticsEngine::ak_c_string);
return PD;
}

friend inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
StringRef S) {

PD.AddString(S);
return PD;
}

friend inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
const IdentifierInfo *II) {
PD.AddTaggedVal(reinterpret_cast<intptr_t>(II),
DiagnosticsEngine::ak_identifierinfo);
return PD;
}

// Adds a DeclContext to the diagnostic. The enable_if template magic is here
// so that we only match those arguments that are (statically) DeclContexts;
// other arguments that derive from DeclContext (e.g., RecordDecls) will not
// match.
template <typename T>
friend inline std::enable_if_t<std::is_same<T, DeclContext>::value,
const PartialDiagnostic &>
operator<<(const PartialDiagnostic &PD, T *DC) {
PD.AddTaggedVal(reinterpret_cast<intptr_t>(DC),
DiagnosticsEngine::ak_declcontext);
return PD;
}

friend inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
SourceRange R) {
PD.AddSourceRange(CharSourceRange::getTokenRange(R));
return PD;
}

friend inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
const CharSourceRange &R) {
PD.AddSourceRange(R);
return PD;
}

friend const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
const FixItHint &Hint) {
PD.AddFixItHint(Hint);
return PD;
}
};

inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
Expand Down
3 changes: 0 additions & 3 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,6 @@ defm hip_new_launch_api : OptInFFlag<"hip-new-launch-api",
"Use", "Don't use", " new kernel launching API for HIP">;
defm gpu_allow_device_init : OptInFFlag<"gpu-allow-device-init",
"Allow", "Don't allow", " device side init function in HIP">;
defm gpu_defer_diag : OptInFFlag<"gpu-defer-diag",
"Defer", "Don't defer", " host/device related diagnostic messages"
" for CUDA/HIP">;
def gpu_max_threads_per_block_EQ : Joined<["--"], "gpu-max-threads-per-block=">,
Flags<[CC1Option]>,
HelpText<"Default max threads per block for kernel launch bounds for HIP">;
Expand Down
10 changes: 3 additions & 7 deletions clang/include/clang/Sema/Ownership.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace llvm {
namespace clang {

// Basic
class StreamableDiagnosticBase;
class DiagnosticBuilder;

// Determines whether the low bit of the result pointer for the
// given UID is always zero. If so, ActionResult will use that bit
Expand Down Expand Up @@ -280,12 +280,8 @@ namespace clang {
inline StmtResult StmtError() { return StmtResult(true); }
inline TypeResult TypeError() { return TypeResult(true); }

inline ExprResult ExprError(const StreamableDiagnosticBase &) {
return ExprError();
}
inline StmtResult StmtError(const StreamableDiagnosticBase &) {
return StmtError();
}
inline ExprResult ExprError(const DiagnosticBuilder&) { return ExprError(); }
inline StmtResult StmtError(const DiagnosticBuilder&) { return StmtError(); }

inline ExprResult ExprEmpty() { return ExprResult(false); }
inline StmtResult StmtEmpty() { return StmtResult(false); }
Expand Down
22 changes: 18 additions & 4 deletions clang/include/clang/Sema/ParsedAttr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1044,20 +1044,34 @@ enum AttributeDeclKind {
ExpectedFunctionWithProtoType,
};

inline const StreamableDiagnosticBase &
operator<<(const StreamableDiagnosticBase &DB, const ParsedAttr &At) {
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
const ParsedAttr &At) {
DB.AddTaggedVal(reinterpret_cast<intptr_t>(At.getAttrName()),
DiagnosticsEngine::ak_identifierinfo);
return DB;
}

inline const StreamableDiagnosticBase &
operator<<(const StreamableDiagnosticBase &DB, const ParsedAttr *At) {
inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
const ParsedAttr &At) {
PD.AddTaggedVal(reinterpret_cast<intptr_t>(At.getAttrName()),
DiagnosticsEngine::ak_identifierinfo);
return PD;
}

inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
const ParsedAttr *At) {
DB.AddTaggedVal(reinterpret_cast<intptr_t>(At->getAttrName()),
DiagnosticsEngine::ak_identifierinfo);
return DB;
}

inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
const ParsedAttr *At) {
PD.AddTaggedVal(reinterpret_cast<intptr_t>(At->getAttrName()),
DiagnosticsEngine::ak_identifierinfo);
return PD;
}

} // namespace clang

#endif // LLVM_CLANG_SEMA_ATTRIBUTELIST_H
278 changes: 103 additions & 175 deletions clang/include/clang/Sema/Sema.h

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11298,9 +11298,9 @@ OMPTraitInfo &ASTContext::getNewOMPTraitInfo() {
return *OMPTraitInfoVector.back();
}

const StreamableDiagnosticBase &clang::
operator<<(const StreamableDiagnosticBase &DB,
const ASTContext::SectionInfo &Section) {
const DiagnosticBuilder &
clang::operator<<(const DiagnosticBuilder &DB,
const ASTContext::SectionInfo &Section) {
if (Section.Decl)
return DB << Section.Decl;
return DB << "a prior #pragma section";
Expand Down
9 changes: 7 additions & 2 deletions clang/lib/AST/DeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3333,7 +3333,12 @@ static const char *getAccessName(AccessSpecifier AS) {
llvm_unreachable("Invalid access specifier!");
}

const StreamableDiagnosticBase &clang::
operator<<(const StreamableDiagnosticBase &DB, AccessSpecifier AS) {
const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB,
AccessSpecifier AS) {
return DB << getAccessName(AS);
}

const PartialDiagnostic &clang::operator<<(const PartialDiagnostic &DB,
AccessSpecifier AS) {
return DB << getAccessName(AS);
}
9 changes: 2 additions & 7 deletions clang/lib/AST/TemplateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ SourceRange TemplateArgumentLoc::getSourceRange() const {
llvm_unreachable("Invalid TemplateArgument Kind!");
}

template <typename T>
static const T &DiagTemplateArg(const T &DB, const TemplateArgument &Arg) {
const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB,
const TemplateArgument &Arg) {
switch (Arg.getKind()) {
case TemplateArgument::Null:
// This is bad, but not as bad as crashing because of argument
Expand Down Expand Up @@ -502,11 +502,6 @@ static const T &DiagTemplateArg(const T &DB, const TemplateArgument &Arg) {
llvm_unreachable("Invalid TemplateArgument Kind!");
}

const StreamableDiagnosticBase &clang::
operator<<(const StreamableDiagnosticBase &DB, const TemplateArgument &Arg) {
return DiagTemplateArg(DB, Arg);
}

clang::TemplateArgumentLocInfo::TemplateArgumentLocInfo(
ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc,
SourceLocation TemplateNameLoc, SourceLocation EllipsisLoc) {
Expand Down
18 changes: 16 additions & 2 deletions clang/lib/AST/TemplateName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ TemplateName::print(raw_ostream &OS, const PrintingPolicy &Policy,
}
}

const StreamableDiagnosticBase &clang::
operator<<(const StreamableDiagnosticBase &DB, TemplateName N) {
const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB,
TemplateName N) {
std::string NameStr;
llvm::raw_string_ostream OS(NameStr);
LangOptions LO;
Expand All @@ -268,6 +268,20 @@ operator<<(const StreamableDiagnosticBase &DB, TemplateName N) {
return DB << NameStr;
}

const PartialDiagnostic&clang::operator<<(const PartialDiagnostic &PD,
TemplateName N) {
std::string NameStr;
llvm::raw_string_ostream OS(NameStr);
LangOptions LO;
LO.CPlusPlus = true;
LO.Bool = true;
OS << '\'';
N.print(OS, PrintingPolicy(LO));
OS << '\'';
OS.flush();
return PD << NameStr;
}

void TemplateName::dump(raw_ostream &OS) const {
LangOptions LO; // FIXME!
LO.CPlusPlus = true;
Expand Down
9 changes: 4 additions & 5 deletions clang/lib/Basic/Diagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@

using namespace clang;

const StreamableDiagnosticBase &clang::
operator<<(const StreamableDiagnosticBase &DB,
DiagNullabilityKind nullability) {
const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB,
DiagNullabilityKind nullability) {
StringRef string;
switch (nullability.first) {
case NullabilityKind::NonNull:
Expand All @@ -62,8 +61,8 @@ operator<<(const StreamableDiagnosticBase &DB,
return DB;
}

const StreamableDiagnosticBase &clang::
operator<<(const StreamableDiagnosticBase &DB, llvm::Error &&E) {
const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB,
llvm::Error &&E) {
DB.AddString(toString(std::move(E)));
return DB;
}
Expand Down
22 changes: 7 additions & 15 deletions clang/lib/Basic/DiagnosticIDs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct StaticDiagInfoRec;
// platforms. See "How To Write Shared Libraries" by Ulrich Drepper.
struct StaticDiagInfoDescriptionStringTable {
#define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
SHOWINSYSHEADER, CATEGORY) \
char ENUM##_desc[sizeof(DESC)];
// clang-format off
#include "clang/Basic/DiagnosticCommonKinds.inc"
Expand All @@ -54,9 +54,9 @@ struct StaticDiagInfoDescriptionStringTable {

const StaticDiagInfoDescriptionStringTable StaticDiagInfoDescriptions = {
#define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
SHOWINSYSHEADER, CATEGORY) \
DESC,
// clang-format off
// clang-format off
#include "clang/Basic/DiagnosticCommonKinds.inc"
#include "clang/Basic/DiagnosticDriverKinds.inc"
#include "clang/Basic/DiagnosticFrontendKinds.inc"
Expand All @@ -79,9 +79,9 @@ extern const StaticDiagInfoRec StaticDiagInfo[];
// StaticDiagInfoRec would have extra padding on 64-bit platforms.
const uint32_t StaticDiagInfoDescriptionOffsets[] = {
#define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
SHOWINSYSHEADER, CATEGORY) \
offsetof(StaticDiagInfoDescriptionStringTable, ENUM##_desc),
// clang-format off
// clang-format off
#include "clang/Basic/DiagnosticCommonKinds.inc"
#include "clang/Basic/DiagnosticDriverKinds.inc"
#include "clang/Basic/DiagnosticFrontendKinds.inc"
Expand Down Expand Up @@ -114,7 +114,6 @@ struct StaticDiagInfoRec {
unsigned SFINAE : 2;
unsigned WarnNoWerror : 1;
unsigned WarnShowInSystemHeader : 1;
unsigned Deferrable : 1;
unsigned Category : 6;

uint16_t OptionGroupIndex;
Expand Down Expand Up @@ -169,19 +168,18 @@ VALIDATE_DIAG_SIZE(REFACTORING)

const StaticDiagInfoRec StaticDiagInfo[] = {
#define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, \
SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
SHOWINSYSHEADER, CATEGORY) \
{ \
diag::ENUM, \
DEFAULT_SEVERITY, \
CLASS, \
DiagnosticIDs::SFINAE, \
NOWERROR, \
SHOWINSYSHEADER, \
DEFERRABLE, \
CATEGORY, \
GROUP, \
STR_SIZE(DESC, uint16_t)},
// clang-format off
// clang-format off
#include "clang/Basic/DiagnosticCommonKinds.inc"
#include "clang/Basic/DiagnosticDriverKinds.inc"
#include "clang/Basic/DiagnosticFrontendKinds.inc"
Expand Down Expand Up @@ -336,12 +334,6 @@ DiagnosticIDs::getDiagnosticSFINAEResponse(unsigned DiagID) {
return SFINAE_Report;
}

bool DiagnosticIDs::isDeferrable(unsigned DiagID) {
if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
return Info->Deferrable;
return false;
}

/// getBuiltinDiagClass - Return the class field of the diagnostic.
///
static unsigned getBuiltinDiagClass(unsigned DiagID) {
Expand Down
4 changes: 0 additions & 4 deletions clang/lib/Driver/ToolChains/Cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,6 @@ void CudaToolChain::addClangTargetOptions(
if (DriverArgs.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
false))
CC1Args.push_back("-fgpu-rdc");

if (DriverArgs.hasFlag(options::OPT_fgpu_defer_diag,
options::OPT_fno_gpu_defer_diag, false))
CC1Args.push_back("-fgpu-defer-diag");
}

if (DriverArgs.hasArg(options::OPT_nogpulib))
Expand Down
4 changes: 0 additions & 4 deletions clang/lib/Driver/ToolChains/HIP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,6 @@ void HIPToolChain::addClangTargetOptions(
options::OPT_fno_gpu_allow_device_init, false))
CC1Args.push_back("-fgpu-allow-device-init");

if (DriverArgs.hasFlag(options::OPT_fgpu_defer_diag,
options::OPT_fno_gpu_defer_diag, false))
CC1Args.push_back("-fgpu-defer-diag");

CC1Args.push_back("-fcuda-allow-variadic-functions");

// Default to "hidden" visibility, as object level linking will not be
Expand Down
3 changes: 0 additions & 3 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2632,9 +2632,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
if (Args.hasArg(OPT_fno_cuda_host_device_constexpr))
Opts.CUDAHostDeviceConstexpr = 0;

if (Args.hasArg(OPT_fgpu_defer_diag))
Opts.GPUDeferDiag = 1;

if (Opts.CUDAIsDevice && Args.hasArg(OPT_fcuda_approx_transcendentals))
Opts.CUDADeviceApproxTranscendentals = 1;

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/AnalysisBasedWarnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2096,7 +2096,7 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,
if (cast<DeclContext>(D)->isDependentContext())
return;

if (S.hasUncompilableErrorOccurred()) {
if (Diags.hasUncompilableErrorOccurred()) {
// Flush out any possibly unreachable diagnostics.
flushDiagnostics(S, fscope);
return;
Expand Down
65 changes: 13 additions & 52 deletions clang/lib/Sema/Sema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1436,24 +1436,11 @@ void Sema::EmitCurrentDiagnostic(unsigned DiagID) {
}

Sema::SemaDiagnosticBuilder
Sema::Diag(SourceLocation Loc, const PartialDiagnostic &PD, bool DeferHint) {
return Diag(Loc, PD.getDiagID(), DeferHint) << PD;
}
Sema::Diag(SourceLocation Loc, const PartialDiagnostic& PD) {
SemaDiagnosticBuilder Builder(Diag(Loc, PD.getDiagID()));
PD.Emit(Builder);

bool Sema::hasUncompilableErrorOccurred() const {
if (getDiagnostics().hasUncompilableErrorOccurred())
return true;
auto *FD = dyn_cast<FunctionDecl>(CurContext);
if (!FD)
return false;
auto Loc = DeviceDeferredDiags.find(FD);
if (Loc == DeviceDeferredDiags.end())
return false;
for (auto PDAt : Loc->second) {
if (DiagnosticIDs::isDefaultMappingAsError(PDAt.second.getDiagID()))
return true;
}
return false;
return Builder;
}

// Print notes showing how we can reach FD starting from an a priori
Expand Down Expand Up @@ -1666,18 +1653,17 @@ void Sema::emitDeferredDiags() {
// until we discover that the function is known-emitted, at which point we take
// it out of this map and emit the diagnostic.

Sema::SemaDiagnosticBuilder::SemaDiagnosticBuilder(Kind K, SourceLocation Loc,
unsigned DiagID,
FunctionDecl *Fn, Sema &S)
Sema::DeviceDiagBuilder::DeviceDiagBuilder(Kind K, SourceLocation Loc,
unsigned DiagID, FunctionDecl *Fn,
Sema &S)
: S(S), Loc(Loc), DiagID(DiagID), Fn(Fn),
ShowCallStack(K == K_ImmediateWithCallStack || K == K_Deferred) {
switch (K) {
case K_Nop:
break;
case K_Immediate:
case K_ImmediateWithCallStack:
ImmediateDiag.emplace(
ImmediateDiagBuilder(S.Diags.Report(Loc, DiagID), S, DiagID));
ImmediateDiag.emplace(S.Diag(Loc, DiagID));
break;
case K_Deferred:
assert(Fn && "Must have a function to attach the deferred diag to.");
Expand All @@ -1688,7 +1674,7 @@ Sema::SemaDiagnosticBuilder::SemaDiagnosticBuilder(Kind K, SourceLocation Loc,
}
}

Sema::SemaDiagnosticBuilder::SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D)
Sema::DeviceDiagBuilder::DeviceDiagBuilder(DeviceDiagBuilder &&D)
: S(D.S), Loc(D.Loc), DiagID(D.DiagID), Fn(D.Fn),
ShowCallStack(D.ShowCallStack), ImmediateDiag(D.ImmediateDiag),
PartialDiagId(D.PartialDiagId) {
Expand All @@ -1698,7 +1684,7 @@ Sema::SemaDiagnosticBuilder::SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D)
D.PartialDiagId.reset();
}

Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() {
Sema::DeviceDiagBuilder::~DeviceDiagBuilder() {
if (ImmediateDiag) {
// Emit our diagnostic and, if it was a warning or error, output a callstack
// if Fn isn't a priori known-emitted.
Expand All @@ -1713,8 +1699,7 @@ Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() {
}
}

Sema::SemaDiagnosticBuilder Sema::targetDiag(SourceLocation Loc,
unsigned DiagID) {
Sema::DeviceDiagBuilder Sema::targetDiag(SourceLocation Loc, unsigned DiagID) {
if (LangOpts.OpenMP)
return LangOpts.OpenMPIsDevice ? diagIfOpenMPDeviceCode(Loc, DiagID)
: diagIfOpenMPHostCode(Loc, DiagID);
Expand All @@ -1725,32 +1710,8 @@ Sema::SemaDiagnosticBuilder Sema::targetDiag(SourceLocation Loc,
if (getLangOpts().SYCLIsDevice)
return SYCLDiagIfDeviceCode(Loc, DiagID);

return SemaDiagnosticBuilder(SemaDiagnosticBuilder::K_Immediate, Loc, DiagID,
getCurFunctionDecl(), *this);
}

Sema::SemaDiagnosticBuilder Sema::Diag(SourceLocation Loc, unsigned DiagID,
bool DeferHint) {
bool IsError = Diags.getDiagnosticIDs()->isDefaultMappingAsError(DiagID);
bool ShouldDefer = getLangOpts().CUDA && LangOpts.GPUDeferDiag &&
DiagnosticIDs::isDeferrable(DiagID) &&
(DeferHint || !IsError);
auto SetIsLastErrorImmediate = [&](bool Flag) {
if (IsError)
IsLastErrorImmediate = Flag;
};
if (!ShouldDefer) {
SetIsLastErrorImmediate(true);
return SemaDiagnosticBuilder(SemaDiagnosticBuilder::K_Immediate, Loc,
DiagID, getCurFunctionDecl(), *this);
}

SemaDiagnosticBuilder DB =
getLangOpts().CUDAIsDevice
? CUDADiagIfDeviceCode(Loc, DiagID)
: CUDADiagIfHostCode(Loc, DiagID);
SetIsLastErrorImmediate(DB.isImmediate());
return DB;
return DeviceDiagBuilder(DeviceDiagBuilder::K_Immediate, Loc, DiagID,
getCurFunctionDecl(), *this);
}

void Sema::checkDeviceDecl(const ValueDecl *D, SourceLocation Loc) {
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Sema/SemaAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ void Sema::DiagnoseUnterminatedPragmaPack() {
// The user might have already reset the alignment, so suggest replacing
// the reset with a pop.
if (IsInnermost && PackStack.CurrentValue == PackStack.DefaultValue) {
auto DB = Diag(PackStack.CurrentPragmaLocation,
diag::note_pragma_pack_pop_instead_reset);
DiagnosticBuilder DB = Diag(PackStack.CurrentPragmaLocation,
diag::note_pragma_pack_pop_instead_reset);
SourceLocation FixItLoc = Lexer::findLocationAfterToken(
PackStack.CurrentPragmaLocation, tok::l_paren, SourceMgr, LangOpts,
/*SkipTrailing=*/false);
Expand Down
90 changes: 42 additions & 48 deletions clang/lib/Sema/SemaCUDA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,63 +639,58 @@ void Sema::MaybeAddCUDAConstantAttr(VarDecl *VD) {
}
}

Sema::SemaDiagnosticBuilder Sema::CUDADiagIfDeviceCode(SourceLocation Loc,
unsigned DiagID) {
Sema::DeviceDiagBuilder Sema::CUDADiagIfDeviceCode(SourceLocation Loc,
unsigned DiagID) {
assert(getLangOpts().CUDA && "Should only be called during CUDA compilation");
SemaDiagnosticBuilder::Kind DiagKind = [&] {
if (!isa<FunctionDecl>(CurContext))
return SemaDiagnosticBuilder::K_Immediate;
DeviceDiagBuilder::Kind DiagKind = [this] {
switch (CurrentCUDATarget()) {
case CFT_Global:
case CFT_Device:
return SemaDiagnosticBuilder::K_Immediate;
return DeviceDiagBuilder::K_Immediate;
case CFT_HostDevice:
// An HD function counts as host code if we're compiling for host, and
// device code if we're compiling for device. Defer any errors in device
// mode until the function is known-emitted.
if (!getLangOpts().CUDAIsDevice)
return SemaDiagnosticBuilder::K_Nop;
if (IsLastErrorImmediate && Diags.getDiagnosticIDs()->isBuiltinNote(DiagID))
return SemaDiagnosticBuilder::K_Immediate;
return (getEmissionStatus(cast<FunctionDecl>(CurContext)) ==
FunctionEmissionStatus::Emitted)
? SemaDiagnosticBuilder::K_ImmediateWithCallStack
: SemaDiagnosticBuilder::K_Deferred;
if (getLangOpts().CUDAIsDevice) {
return (getEmissionStatus(cast<FunctionDecl>(CurContext)) ==
FunctionEmissionStatus::Emitted)
? DeviceDiagBuilder::K_ImmediateWithCallStack
: DeviceDiagBuilder::K_Deferred;
}
return DeviceDiagBuilder::K_Nop;

default:
return SemaDiagnosticBuilder::K_Nop;
return DeviceDiagBuilder::K_Nop;
}
}();
return SemaDiagnosticBuilder(DiagKind, Loc, DiagID,
dyn_cast<FunctionDecl>(CurContext), *this);
return DeviceDiagBuilder(DiagKind, Loc, DiagID,
dyn_cast<FunctionDecl>(CurContext), *this);
}

Sema::SemaDiagnosticBuilder Sema::CUDADiagIfHostCode(SourceLocation Loc,
unsigned DiagID) {
Sema::DeviceDiagBuilder Sema::CUDADiagIfHostCode(SourceLocation Loc,
unsigned DiagID) {
assert(getLangOpts().CUDA && "Should only be called during CUDA compilation");
SemaDiagnosticBuilder::Kind DiagKind = [&] {
if (!isa<FunctionDecl>(CurContext))
return SemaDiagnosticBuilder::K_Immediate;
DeviceDiagBuilder::Kind DiagKind = [this] {
switch (CurrentCUDATarget()) {
case CFT_Host:
return SemaDiagnosticBuilder::K_Immediate;
return DeviceDiagBuilder::K_Immediate;
case CFT_HostDevice:
// An HD function counts as host code if we're compiling for host, and
// device code if we're compiling for device. Defer any errors in device
// mode until the function is known-emitted.
if (getLangOpts().CUDAIsDevice)
return SemaDiagnosticBuilder::K_Nop;
if (IsLastErrorImmediate && Diags.getDiagnosticIDs()->isBuiltinNote(DiagID))
return SemaDiagnosticBuilder::K_Immediate;
return DeviceDiagBuilder::K_Nop;

return (getEmissionStatus(cast<FunctionDecl>(CurContext)) ==
FunctionEmissionStatus::Emitted)
? SemaDiagnosticBuilder::K_ImmediateWithCallStack
: SemaDiagnosticBuilder::K_Deferred;
? DeviceDiagBuilder::K_ImmediateWithCallStack
: DeviceDiagBuilder::K_Deferred;
default:
return SemaDiagnosticBuilder::K_Nop;
return DeviceDiagBuilder::K_Nop;
}
}();
return SemaDiagnosticBuilder(DiagKind, Loc, DiagID,
dyn_cast<FunctionDecl>(CurContext), *this);
return DeviceDiagBuilder(DiagKind, Loc, DiagID,
dyn_cast<FunctionDecl>(CurContext), *this);
}

bool Sema::CheckCUDACall(SourceLocation Loc, FunctionDecl *Callee) {
Expand All @@ -716,24 +711,23 @@ bool Sema::CheckCUDACall(SourceLocation Loc, FunctionDecl *Callee) {
// Otherwise, mark the call in our call graph so we can traverse it later.
bool CallerKnownEmitted =
getEmissionStatus(Caller) == FunctionEmissionStatus::Emitted;
SemaDiagnosticBuilder::Kind DiagKind = [this, Caller, Callee,
CallerKnownEmitted] {
DeviceDiagBuilder::Kind DiagKind = [this, Caller, Callee,
CallerKnownEmitted] {
switch (IdentifyCUDAPreference(Caller, Callee)) {
case CFP_Never:
case CFP_WrongSide:
assert(Caller && "Never/wrongSide calls require a non-null caller");
// If we know the caller will be emitted, we know this wrong-side call
// will be emitted, so it's an immediate error. Otherwise, defer the
// error until we know the caller is emitted.
return CallerKnownEmitted
? SemaDiagnosticBuilder::K_ImmediateWithCallStack
: SemaDiagnosticBuilder::K_Deferred;
return CallerKnownEmitted ? DeviceDiagBuilder::K_ImmediateWithCallStack
: DeviceDiagBuilder::K_Deferred;
default:
return SemaDiagnosticBuilder::K_Nop;
return DeviceDiagBuilder::K_Nop;
}
}();

if (DiagKind == SemaDiagnosticBuilder::K_Nop)
if (DiagKind == DeviceDiagBuilder::K_Nop)
return true;

// Avoid emitting this error twice for the same location. Using a hashtable
Expand All @@ -743,14 +737,14 @@ bool Sema::CheckCUDACall(SourceLocation Loc, FunctionDecl *Callee) {
if (!LocsWithCUDACallDiags.insert({Caller, Loc}).second)
return true;

SemaDiagnosticBuilder(DiagKind, Loc, diag::err_ref_bad_target, Caller, *this)
DeviceDiagBuilder(DiagKind, Loc, diag::err_ref_bad_target, Caller, *this)
<< IdentifyCUDATarget(Callee) << Callee << IdentifyCUDATarget(Caller);
if (!Callee->getBuiltinID())
SemaDiagnosticBuilder(DiagKind, Callee->getLocation(),
diag::note_previous_decl, Caller, *this)
DeviceDiagBuilder(DiagKind, Callee->getLocation(), diag::note_previous_decl,
Caller, *this)
<< Callee;
return DiagKind != SemaDiagnosticBuilder::K_Immediate &&
DiagKind != SemaDiagnosticBuilder::K_ImmediateWithCallStack;
return DiagKind != DeviceDiagBuilder::K_Immediate &&
DiagKind != DeviceDiagBuilder::K_ImmediateWithCallStack;
}

// Check the wrong-sided reference capture of lambda for CUDA/HIP.
Expand Down Expand Up @@ -787,14 +781,14 @@ void Sema::CUDACheckLambdaCapture(CXXMethodDecl *Callee,
bool ShouldCheck = CalleeIsDevice && CallerIsHost;
if (!ShouldCheck || !Capture.isReferenceCapture())
return;
auto DiagKind = SemaDiagnosticBuilder::K_Deferred;
auto DiagKind = DeviceDiagBuilder::K_Deferred;
if (Capture.isVariableCapture()) {
SemaDiagnosticBuilder(DiagKind, Capture.getLocation(),
diag::err_capture_bad_target, Callee, *this)
DeviceDiagBuilder(DiagKind, Capture.getLocation(),
diag::err_capture_bad_target, Callee, *this)
<< Capture.getVariable();
} else if (Capture.isThisCapture()) {
SemaDiagnosticBuilder(DiagKind, Capture.getLocation(),
diag::err_capture_bad_target_this_ptr, Callee, *this);
DeviceDiagBuilder(DiagKind, Capture.getLocation(),
diag::err_capture_bad_target_this_ptr, Callee, *this);
}
return;
}
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14549,11 +14549,11 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
// If any errors have occurred, clear out any temporaries that may have
// been leftover. This ensures that these temporaries won't be picked up for
// deletion in some later function.
if (hasUncompilableErrorOccurred() ||
if (getDiagnostics().hasUncompilableErrorOccurred() ||
getDiagnostics().getSuppressAllDiagnostics()) {
DiscardCleanupsInEvaluationContext();
}
if (!hasUncompilableErrorOccurred() &&
if (!getDiagnostics().hasUncompilableErrorOccurred() &&
!isa<FunctionTemplateDecl>(dcl)) {
// Since the body is valid, issue any analysis-based warnings that are
// enabled.
Expand Down Expand Up @@ -14605,7 +14605,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
// If any errors have occurred, clear out any temporaries that may have
// been leftover. This ensures that these temporaries won't be picked up for
// deletion in some later function.
if (hasUncompilableErrorOccurred()) {
if (getDiagnostics().hasUncompilableErrorOccurred()) {
DiscardCleanupsInEvaluationContext();
}

Expand Down
61 changes: 33 additions & 28 deletions clang/lib/Sema/SemaExprObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2445,8 +2445,8 @@ static void applyCocoaAPICheck(Sema &S, const ObjCMessageExpr *Msg,
SourceManager &SM = S.SourceMgr;
edit::Commit ECommit(SM, S.LangOpts);
if (refactor(Msg,*S.NSAPIObj, ECommit)) {
auto Builder = S.Diag(MsgLoc, DiagID)
<< Msg->getSelector() << Msg->getSourceRange();
DiagnosticBuilder Builder = S.Diag(MsgLoc, DiagID)
<< Msg->getSelector() << Msg->getSourceRange();
// FIXME: Don't emit diagnostic at all if fixits are non-commitable.
if (!ECommit.isCommitable())
return;
Expand Down Expand Up @@ -3139,8 +3139,9 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
if (ReceiverType->isObjCClassType() && !isImplicit &&
!(Receiver->isObjCSelfExpr() && getLangOpts().ObjCAutoRefCount)) {
{
auto Builder = Diag(Receiver->getExprLoc(),
diag::err_messaging_class_with_direct_method);
DiagnosticBuilder Builder =
Diag(Receiver->getExprLoc(),
diag::err_messaging_class_with_direct_method);
if (Receiver->isObjCSelfExpr()) {
Builder.AddFixItHint(FixItHint::CreateReplacement(
RecRange, Method->getClassInterface()->getName()));
Expand All @@ -3152,7 +3153,7 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,

if (SuperLoc.isValid()) {
{
auto Builder =
DiagnosticBuilder Builder =
Diag(SuperLoc, diag::err_messaging_super_with_direct_method);
if (ReceiverType->isObjCClassType()) {
Builder.AddFixItHint(FixItHint::CreateReplacement(
Expand Down Expand Up @@ -3735,11 +3736,15 @@ bool Sema::isKnownName(StringRef name) {
return LookupName(R, TUScope, false);
}

template <typename DiagBuilderT>
static void addFixitForObjCARCConversion(
Sema &S, DiagBuilderT &DiagB, Sema::CheckedConversionKind CCK,
SourceLocation afterLParen, QualType castType, Expr *castExpr,
Expr *realCast, const char *bridgeKeyword, const char *CFBridgeName) {
static void addFixitForObjCARCConversion(Sema &S,
DiagnosticBuilder &DiagB,
Sema::CheckedConversionKind CCK,
SourceLocation afterLParen,
QualType castType,
Expr *castExpr,
Expr *realCast,
const char *bridgeKeyword,
const char *CFBridgeName) {
// We handle C-style and implicit casts here.
switch (CCK) {
case Sema::CCK_ImplicitConversion:
Expand Down Expand Up @@ -3916,22 +3921,22 @@ diagnoseObjCARCConversion(Sema &S, SourceRange castRange,
assert(CreateRule != ACC_bottom && "This cast should already be accepted.");
if (CreateRule != ACC_plusOne)
{
auto DiagB = (CCK != Sema::CCK_OtherCast)
? S.Diag(noteLoc, diag::note_arc_bridge)
: S.Diag(noteLoc, diag::note_arc_cstyle_bridge);
DiagnosticBuilder DiagB =
(CCK != Sema::CCK_OtherCast) ? S.Diag(noteLoc, diag::note_arc_bridge)
: S.Diag(noteLoc, diag::note_arc_cstyle_bridge);

addFixitForObjCARCConversion(S, DiagB, CCK, afterLParen,
castType, castExpr, realCast, "__bridge ",
nullptr);
}
if (CreateRule != ACC_plusZero)
{
auto DiagB = (CCK == Sema::CCK_OtherCast && !br)
? S.Diag(noteLoc, diag::note_arc_cstyle_bridge_transfer)
<< castExprType
: S.Diag(br ? castExpr->getExprLoc() : noteLoc,
diag::note_arc_bridge_transfer)
<< castExprType << br;
DiagnosticBuilder DiagB =
(CCK == Sema::CCK_OtherCast && !br) ?
S.Diag(noteLoc, diag::note_arc_cstyle_bridge_transfer) << castExprType :
S.Diag(br ? castExpr->getExprLoc() : noteLoc,
diag::note_arc_bridge_transfer)
<< castExprType << br;

addFixitForObjCARCConversion(S, DiagB, CCK, afterLParen,
castType, castExpr, realCast, "__bridge_transfer ",
Expand All @@ -3957,21 +3962,21 @@ diagnoseObjCARCConversion(Sema &S, SourceRange castRange,
assert(CreateRule != ACC_bottom && "This cast should already be accepted.");
if (CreateRule != ACC_plusOne)
{
auto DiagB = (CCK != Sema::CCK_OtherCast)
? S.Diag(noteLoc, diag::note_arc_bridge)
: S.Diag(noteLoc, diag::note_arc_cstyle_bridge);
DiagnosticBuilder DiagB =
(CCK != Sema::CCK_OtherCast) ? S.Diag(noteLoc, diag::note_arc_bridge)
: S.Diag(noteLoc, diag::note_arc_cstyle_bridge);
addFixitForObjCARCConversion(S, DiagB, CCK, afterLParen,
castType, castExpr, realCast, "__bridge ",
nullptr);
}
if (CreateRule != ACC_plusZero)
{
auto DiagB = (CCK == Sema::CCK_OtherCast && !br)
? S.Diag(noteLoc, diag::note_arc_cstyle_bridge_retained)
<< castType
: S.Diag(br ? castExpr->getExprLoc() : noteLoc,
diag::note_arc_bridge_retained)
<< castType << br;
DiagnosticBuilder DiagB =
(CCK == Sema::CCK_OtherCast && !br) ?
S.Diag(noteLoc, diag::note_arc_cstyle_bridge_retained) << castType :
S.Diag(br ? castExpr->getExprLoc() : noteLoc,
diag::note_arc_bridge_retained)
<< castType << br;

addFixitForObjCARCConversion(S, DiagB, CCK, afterLParen,
castType, castExpr, realCast, "__bridge_retained ",
Expand Down
30 changes: 15 additions & 15 deletions clang/lib/Sema/SemaOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1896,58 +1896,58 @@ enum class FunctionEmissionStatus {
};
} // anonymous namespace

Sema::SemaDiagnosticBuilder Sema::diagIfOpenMPDeviceCode(SourceLocation Loc,
unsigned DiagID) {
Sema::DeviceDiagBuilder Sema::diagIfOpenMPDeviceCode(SourceLocation Loc,
unsigned DiagID) {
assert(LangOpts.OpenMP && LangOpts.OpenMPIsDevice &&
"Expected OpenMP device compilation.");

FunctionDecl *FD = getCurFunctionDecl();
SemaDiagnosticBuilder::Kind Kind = SemaDiagnosticBuilder::K_Nop;
DeviceDiagBuilder::Kind Kind = DeviceDiagBuilder::K_Nop;
if (FD) {
FunctionEmissionStatus FES = getEmissionStatus(FD);
switch (FES) {
case FunctionEmissionStatus::Emitted:
Kind = SemaDiagnosticBuilder::K_Immediate;
Kind = DeviceDiagBuilder::K_Immediate;
break;
case FunctionEmissionStatus::Unknown:
Kind = isOpenMPDeviceDelayedContext(*this)
? SemaDiagnosticBuilder::K_Deferred
: SemaDiagnosticBuilder::K_Immediate;
? DeviceDiagBuilder::K_Deferred
: DeviceDiagBuilder::K_Immediate;
break;
case FunctionEmissionStatus::TemplateDiscarded:
case FunctionEmissionStatus::OMPDiscarded:
Kind = SemaDiagnosticBuilder::K_Nop;
Kind = DeviceDiagBuilder::K_Nop;
break;
case FunctionEmissionStatus::CUDADiscarded:
llvm_unreachable("CUDADiscarded unexpected in OpenMP device compilation");
break;
}
}

return SemaDiagnosticBuilder(Kind, Loc, DiagID, getCurFunctionDecl(), *this);
return DeviceDiagBuilder(Kind, Loc, DiagID, getCurFunctionDecl(), *this);
}

Sema::SemaDiagnosticBuilder Sema::diagIfOpenMPHostCode(SourceLocation Loc,
unsigned DiagID) {
Sema::DeviceDiagBuilder Sema::diagIfOpenMPHostCode(SourceLocation Loc,
unsigned DiagID) {
assert(LangOpts.OpenMP && !LangOpts.OpenMPIsDevice &&
"Expected OpenMP host compilation.");
FunctionEmissionStatus FES = getEmissionStatus(getCurFunctionDecl());
SemaDiagnosticBuilder::Kind Kind = SemaDiagnosticBuilder::K_Nop;
DeviceDiagBuilder::Kind Kind = DeviceDiagBuilder::K_Nop;
switch (FES) {
case FunctionEmissionStatus::Emitted:
Kind = SemaDiagnosticBuilder::K_Immediate;
Kind = DeviceDiagBuilder::K_Immediate;
break;
case FunctionEmissionStatus::Unknown:
Kind = SemaDiagnosticBuilder::K_Deferred;
Kind = DeviceDiagBuilder::K_Deferred;
break;
case FunctionEmissionStatus::TemplateDiscarded:
case FunctionEmissionStatus::OMPDiscarded:
case FunctionEmissionStatus::CUDADiscarded:
Kind = SemaDiagnosticBuilder::K_Nop;
Kind = DeviceDiagBuilder::K_Nop;
break;
}

return SemaDiagnosticBuilder(Kind, Loc, DiagID, getCurFunctionDecl(), *this);
return DeviceDiagBuilder(Kind, Loc, DiagID, getCurFunctionDecl(), *this);
}

static OpenMPDefaultmapClauseKind
Expand Down
12 changes: 1 addition & 11 deletions clang/lib/Sema/SemaOverload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11522,19 +11522,9 @@ void OverloadCandidateSet::NoteCandidates(PartialDiagnosticAt PD,
StringRef Opc, SourceLocation OpLoc,
llvm::function_ref<bool(OverloadCandidate &)> Filter) {

bool DeferHint = false;
if (S.getLangOpts().CUDA && S.getLangOpts().GPUDeferDiag) {
// Defer diagnostic for CUDA/HIP if there are wrong-sided candidates.
auto WrongSidedCands =
CompleteCandidates(S, OCD_AllCandidates, Args, OpLoc, [](auto &Cand) {
return Cand.Viable == false &&
Cand.FailureKind == ovl_fail_bad_target;
});
DeferHint = WrongSidedCands.size();
}
auto Cands = CompleteCandidates(S, OCD, Args, OpLoc, Filter);

S.Diag(PD.first, PD.second, DeferHint);
S.Diag(PD.first, PD.second);

NoteCandidates(S, Args, Cands, Opc, OpLoc);

Expand Down
20 changes: 10 additions & 10 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ using namespace clang;
// SYCL device specific diagnostics implementation
// -----------------------------------------------------------------------------

Sema::SemaDiagnosticBuilder Sema::SYCLDiagIfDeviceCode(SourceLocation Loc,
unsigned DiagID) {
Sema::DeviceDiagBuilder Sema::SYCLDiagIfDeviceCode(SourceLocation Loc,
unsigned DiagID) {
assert(getLangOpts().SYCLIsDevice &&
"Should only be called during SYCL compilation");
FunctionDecl *FD = dyn_cast<FunctionDecl>(getCurLexicalContext());
SemaDiagnosticBuilder::Kind DiagKind = [this, FD] {
DeviceDiagBuilder::Kind DiagKind = [this, FD] {
if (!FD)
return SemaDiagnosticBuilder::K_Nop;
return DeviceDiagBuilder::K_Nop;
if (getEmissionStatus(FD) == Sema::FunctionEmissionStatus::Emitted)
return SemaDiagnosticBuilder::K_ImmediateWithCallStack;
return SemaDiagnosticBuilder::K_Deferred;
return DeviceDiagBuilder::K_ImmediateWithCallStack;
return DeviceDiagBuilder::K_Deferred;
}();
return SemaDiagnosticBuilder(DiagKind, Loc, DiagID, FD, *this);
return DeviceDiagBuilder(DiagKind, Loc, DiagID, FD, *this);
}

bool Sema::checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee) {
Expand All @@ -42,8 +42,8 @@ bool Sema::checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee) {
if (isUnevaluatedContext() || isConstantEvaluated())
return true;

SemaDiagnosticBuilder::Kind DiagKind = SemaDiagnosticBuilder::K_Nop;
DeviceDiagBuilder::Kind DiagKind = DeviceDiagBuilder::K_Nop;

return DiagKind != SemaDiagnosticBuilder::K_Immediate &&
DiagKind != SemaDiagnosticBuilder::K_ImmediateWithCallStack;
return DiagKind != DeviceDiagBuilder::K_Immediate &&
DiagKind != DeviceDiagBuilder::K_ImmediateWithCallStack;
}
6 changes: 3 additions & 3 deletions clang/lib/Sema/SemaStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,10 +1261,10 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch,

// Produce a nice diagnostic if multiple values aren't handled.
if (!UnhandledNames.empty()) {
auto DB = Diag(CondExpr->getExprLoc(), TheDefaultStmt
? diag::warn_def_missing_case
DiagnosticBuilder DB = Diag(CondExpr->getExprLoc(),
TheDefaultStmt ? diag::warn_def_missing_case
: diag::warn_missing_case)
<< (int)UnhandledNames.size();
<< (int)UnhandledNames.size();

for (size_t I = 0, E = std::min(UnhandledNames.size(), (size_t)3);
I != E; ++I)
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Sema/SemaStmtAsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
unsigned Size = Context.getTypeSize(Ty);
if (!Context.getTargetInfo().validateInputSize(FeatureMap,
Literal->getString(), Size))
return targetDiag(InputExpr->getBeginLoc(),
diag::err_asm_invalid_input_size)
<< Info.getConstraintStr();
return StmtResult(
targetDiag(InputExpr->getBeginLoc(), diag::err_asm_invalid_input_size)
<< Info.getConstraintStr());
}

// Check that the clobbers are valid.
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaTemplateInstantiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ Sema::InstantiatingTemplate::InstantiatingTemplate(
// error have occurred. Any diagnostics we might have raised will not be
// visible, and we do not need to construct a correct AST.
if (SemaRef.Diags.hasFatalErrorOccurred() &&
SemaRef.hasUncompilableErrorOccurred()) {
SemaRef.Diags.hasUncompilableErrorOccurred()) {
Invalid = true;
return;
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6008,7 +6008,7 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
if (!Result) {
if (isa<UsingShadowDecl>(D)) {
// UsingShadowDecls can instantiate to nothing because of using hiding.
} else if (hasUncompilableErrorOccurred()) {
} else if (Diags.hasUncompilableErrorOccurred()) {
// We've already complained about some ill-formed code, so most likely
// this declaration failed to instantiate. There's no point in
// complaining further, since this is normal in invalid code.
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Sema/SemaTemplateVariadic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ Sema::DiagnoseUnexpandedParameterPacks(SourceLocation Loc,
Locations.push_back(Unexpanded[I].second);
}

auto DB = Diag(Loc, diag::err_unexpanded_parameter_pack)
<< (int)UPPC << (int)Names.size();
DiagnosticBuilder DB = Diag(Loc, diag::err_unexpanded_parameter_pack)
<< (int)UPPC << (int)Names.size();
for (size_t I = 0, E = std::min(Names.size(), (size_t)2); I != E; ++I)
DB << Names[I];

Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4133,8 +4133,7 @@ static FileID getNullabilityCompletenessCheckFileID(Sema &S,

/// Creates a fix-it to insert a C-style nullability keyword at \p pointerLoc,
/// taking into account whitespace before and after.
template <typename DiagBuilderT>
static void fixItNullability(Sema &S, DiagBuilderT &Diag,
static void fixItNullability(Sema &S, DiagnosticBuilder &Diag,
SourceLocation PointerLoc,
NullabilityKind Nullability) {
assert(PointerLoc.isValid());
Expand Down
78 changes: 0 additions & 78 deletions clang/test/SemaCUDA/deferred-oeverload.cu

This file was deleted.

10 changes: 0 additions & 10 deletions clang/test/TableGen/DiagnosticBase.inc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class TextSubstitution<string Text> {
// diagnostics
string Component = "";
string CategoryName = "";
bit Deferrable = 0;
}

// Diagnostic Categories. These can be applied to groups or individual
Expand Down Expand Up @@ -76,7 +75,6 @@ class Diagnostic<string text, DiagClass DC, Severity defaultmapping> {
bit AccessControl = 0;
bit WarningNoWerror = 0;
bit ShowInSystemHeader = 0;
bit Deferrable = 0;
Severity DefaultSeverity = defaultmapping;
DiagGroup Group;
string CategoryName = "";
Expand All @@ -100,14 +98,6 @@ class SuppressInSystemHeader {
bit ShowInSystemHeader = 0;
}

class Deferrable {
bit Deferrable = 1;
}

class NonDeferrable {
bit Deferrable = 0;
}

// FIXME: ExtWarn and Extension should also be SFINAEFailure by default.
class Error<string str> : Diagnostic<str, CLASS_ERROR, SEV_Error>, SFINAEFailure {
bit ShowInSystemHeader = 1;
Expand Down
27 changes: 0 additions & 27 deletions clang/test/TableGen/deferred-diag.td

This file was deleted.

2 changes: 1 addition & 1 deletion clang/tools/diagtool/DiagnosticNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ llvm::ArrayRef<DiagnosticRecord> diagtool::getBuiltinDiagnosticsByName() {
// out of sync easily?
static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP, \
SFINAE,NOWERROR,SHOWINSYSHEADER,DEFER,CATEGORY) \
SFINAE,NOWERROR,SHOWINSYSHEADER,CATEGORY) \
{ #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
#include "clang/Basic/DiagnosticCommonKinds.inc"
#include "clang/Basic/DiagnosticCrossTUKinds.inc"
Expand Down
5 changes: 0 additions & 5 deletions clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1294,11 +1294,6 @@ void clang::EmitClangDiagsDefs(RecordKeeper &Records, raw_ostream &OS,
else
OS << ", false";

if (R.getValueAsBit("Deferrable"))
OS << ", true";
else
OS << ", false";

// Category number.
OS << ", " << CategoryIDs.getID(getDiagnosticCategory(&R, DGParentMap));
OS << ")\n";
Expand Down