Skip to content

Commit 8a09ec1

Browse files
Merge branch 'main' into users/mingmingl-llvm/spr/nfc
2 parents a2e3812 + 0d19efa commit 8a09ec1

File tree

116 files changed

+223244
-35482
lines changed

Some content is hidden

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

116 files changed

+223244
-35482
lines changed

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "clang/AST/ASTContext.h"
2323
#include "clang/AST/ASTDiagnostic.h"
2424
#include "clang/AST/Attr.h"
25+
#include "clang/AST/Expr.h"
2526
#include "clang/Basic/CharInfo.h"
2627
#include "clang/Basic/Diagnostic.h"
2728
#include "clang/Basic/DiagnosticOptions.h"
@@ -166,8 +167,8 @@ ClangTidyContext::ClangTidyContext(
166167
AllowEnablingAnalyzerAlphaCheckers(AllowEnablingAnalyzerAlphaCheckers),
167168
EnableModuleHeadersParsing(EnableModuleHeadersParsing) {
168169
// Before the first translation unit we can get errors related to command-line
169-
// parsing, use empty string for the file name in this case.
170-
setCurrentFile("");
170+
// parsing, use dummy string for the file name in this case.
171+
setCurrentFile("dummy");
171172
}
172173

173174
ClangTidyContext::~ClangTidyContext() = default;
@@ -528,6 +529,8 @@ void ClangTidyDiagnosticConsumer::forwardDiagnostic(const Diagnostic &Info) {
528529
case clang::DiagnosticsEngine::ak_addrspace:
529530
Builder << static_cast<LangAS>(Info.getRawArg(Index));
530531
break;
532+
case clang::DiagnosticsEngine::ak_expr:
533+
Builder << reinterpret_cast<const Expr *>(Info.getRawArg(Index));
531534
}
532535
}
533536
}

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ Improvements to Clang's diagnostics
280280
- Clang now better preserves the sugared types of pointers to member.
281281
- Clang now better preserves the presence of the template keyword with dependent
282282
prefixes.
283+
- Clang now respects the current language mode when printing expressions in
284+
diagnostics. This fixes a bunch of `bool` being printed as `_Bool`, and also
285+
a bunch of HLSL types being printed as their C++ equivalents.
283286
- When printing types for diagnostics, clang now doesn't suppress the scopes of
284287
template arguments contained within nested names.
285288
- The ``-Wshift-bool`` warning has been added to warn about shifting a boolean. (#GH28334)

clang/include/clang/AST/Decl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,6 +3048,8 @@ class FunctionDecl : public DeclaratorDecl,
30483048
static FunctionDecl *castFromDeclContext(const DeclContext *DC) {
30493049
return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
30503050
}
3051+
3052+
bool isReferenceableKernel() const;
30513053
};
30523054

30533055
/// Represents a member of a struct/union/class.

clang/include/clang/AST/Expr.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7379,6 +7379,14 @@ class RecoveryExpr final : public Expr,
73797379
friend class ASTStmtWriter;
73807380
};
73817381

7382+
/// Insertion operator for diagnostics. This allows sending
7383+
/// Expr into a diagnostic with <<.
7384+
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
7385+
const Expr *E) {
7386+
DB.AddTaggedVal(reinterpret_cast<uint64_t>(E), DiagnosticsEngine::ak_expr);
7387+
return DB;
7388+
}
7389+
73827390
} // end namespace clang
73837391

73847392
#endif // LLVM_CLANG_AST_EXPR_H

clang/include/clang/AST/GlobalDecl.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ class GlobalDecl {
7070
GlobalDecl(const VarDecl *D) { Init(D);}
7171
GlobalDecl(const FunctionDecl *D, unsigned MVIndex = 0)
7272
: MultiVersionIndex(MVIndex) {
73-
if (!D->hasAttr<CUDAGlobalAttr>()) {
74-
Init(D);
73+
if (D->isReferenceableKernel()) {
74+
Value.setPointerAndInt(D, unsigned(getDefaultKernelReference(D)));
7575
return;
7676
}
77-
Value.setPointerAndInt(D, unsigned(getDefaultKernelReference(D)));
77+
Init(D);
7878
}
7979
GlobalDecl(const FunctionDecl *D, KernelReferenceKind Kind)
8080
: Value(D, unsigned(Kind)) {
81-
assert(D->hasAttr<CUDAGlobalAttr>() && "Decl is not a GPU kernel!");
81+
assert(D->isReferenceableKernel() && "Decl is not a GPU kernel!");
8282
}
8383
GlobalDecl(const NamedDecl *D) { Init(D); }
8484
GlobalDecl(const BlockDecl *D) { Init(D); }
@@ -131,12 +131,13 @@ class GlobalDecl {
131131

132132
KernelReferenceKind getKernelReferenceKind() const {
133133
assert(((isa<FunctionDecl>(getDecl()) &&
134-
cast<FunctionDecl>(getDecl())->hasAttr<CUDAGlobalAttr>()) ||
134+
cast<FunctionDecl>(getDecl())->isReferenceableKernel()) ||
135135
(isa<FunctionTemplateDecl>(getDecl()) &&
136136
cast<FunctionTemplateDecl>(getDecl())
137137
->getTemplatedDecl()
138138
->hasAttr<CUDAGlobalAttr>())) &&
139139
"Decl is not a GPU kernel!");
140+
140141
return static_cast<KernelReferenceKind>(Value.getInt());
141142
}
142143

@@ -160,8 +161,9 @@ class GlobalDecl {
160161
}
161162

162163
static KernelReferenceKind getDefaultKernelReference(const FunctionDecl *D) {
163-
return D->getLangOpts().CUDAIsDevice ? KernelReferenceKind::Kernel
164-
: KernelReferenceKind::Stub;
164+
return (D->hasAttr<OpenCLKernelAttr>() || D->getLangOpts().CUDAIsDevice)
165+
? KernelReferenceKind::Kernel
166+
: KernelReferenceKind::Stub;
165167
}
166168

167169
GlobalDecl getWithDecl(const Decl *D) {
@@ -197,7 +199,7 @@ class GlobalDecl {
197199

198200
GlobalDecl getWithKernelReferenceKind(KernelReferenceKind Kind) {
199201
assert(isa<FunctionDecl>(getDecl()) &&
200-
cast<FunctionDecl>(getDecl())->hasAttr<CUDAGlobalAttr>() &&
202+
cast<FunctionDecl>(getDecl())->isReferenceableKernel() &&
201203
"Decl is not a GPU kernel!");
202204
GlobalDecl Result(*this);
203205
Result.Value.setInt(unsigned(Kind));

clang/include/clang/AST/TemplateBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class TemplateArgument {
262262
/// This form of template argument only occurs in template argument
263263
/// lists used for dependent types and for expression; it will not
264264
/// occur in a non-dependent, canonical template argument list.
265-
TemplateArgument(Expr *E, bool IsDefaulted = false) {
265+
explicit TemplateArgument(Expr *E, bool IsDefaulted = false) {
266266
TypeOrValue.Kind = Expression;
267267
TypeOrValue.IsDefaulted = IsDefaulted;
268268
TypeOrValue.V = reinterpret_cast<uintptr_t>(E);

clang/include/clang/Basic/Diagnostic.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,10 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
284284
ak_qualtype_pair,
285285

286286
/// Attr *
287-
ak_attr
287+
ak_attr,
288+
289+
/// Expr *
290+
ak_expr,
288291
};
289292

290293
/// Represents on argument value, which is a union discriminated

clang/lib/AST/ASTDiagnostic.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,14 @@ void clang::FormatASTNodeDiagnosticArgument(
508508
NeedQuotes = false;
509509
break;
510510
}
511+
case DiagnosticsEngine::ak_expr: {
512+
const Expr *E = reinterpret_cast<Expr *>(Val);
513+
assert(E && "Received null Expr!");
514+
E->printPretty(OS, /*Helper=*/nullptr, Context.getPrintingPolicy());
515+
// FIXME: Include quotes when printing expressions.
516+
NeedQuotes = false;
517+
break;
518+
}
511519
}
512520

513521
if (NeedQuotes) {

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6148,7 +6148,8 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
61486148

61496149
if (!this->visit(SubExpr))
61506150
return false;
6151-
if (classifyPrim(SubExpr) == PT_Ptr && !E->getType()->isArrayType())
6151+
6152+
if (classifyPrim(SubExpr) == PT_Ptr)
61526153
return this->emitNarrowPtr(E);
61536154
return true;
61546155

@@ -6800,6 +6801,10 @@ bool Compiler<Emitter>::emitDestruction(const Descriptor *Desc,
68006801
assert(!Desc->isPrimitive());
68016802
assert(!Desc->isPrimitiveArray());
68026803

6804+
// Can happen if the decl is invalid.
6805+
if (Desc->isDummy())
6806+
return true;
6807+
68036808
// Arrays.
68046809
if (Desc->isArray()) {
68056810
const Descriptor *ElemDesc = Desc->ElemDesc;
@@ -6818,15 +6823,17 @@ bool Compiler<Emitter>::emitDestruction(const Descriptor *Desc,
68186823
return true;
68196824
}
68206825

6821-
for (ssize_t I = Desc->getNumElems() - 1; I >= 0; --I) {
6822-
if (!this->emitConstUint64(I, Loc))
6823-
return false;
6824-
if (!this->emitArrayElemPtrUint64(Loc))
6825-
return false;
6826-
if (!this->emitDestruction(ElemDesc, Loc))
6827-
return false;
6828-
if (!this->emitPopPtr(Loc))
6829-
return false;
6826+
if (size_t N = Desc->getNumElems()) {
6827+
for (ssize_t I = N - 1; I >= 0; --I) {
6828+
if (!this->emitConstUint64(I, Loc))
6829+
return false;
6830+
if (!this->emitArrayElemPtrUint64(Loc))
6831+
return false;
6832+
if (!this->emitDestruction(ElemDesc, Loc))
6833+
return false;
6834+
if (!this->emitPopPtr(Loc))
6835+
return false;
6836+
}
68306837
}
68316838
return true;
68326839
}

clang/lib/AST/ByteCode/Interp.h

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,8 +2059,11 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T &Offset,
20592059
// useful thing we can do. Any other index has been diagnosed before and
20602060
// we don't get here.
20612061
if (Result == 0 && Ptr.isOnePastEnd()) {
2062-
S.Stk.push<Pointer>(Ptr.asBlockPointer().Pointee,
2063-
Ptr.asBlockPointer().Base);
2062+
if (Ptr.getFieldDesc()->isArray())
2063+
S.Stk.push<Pointer>(Ptr.atIndex(0));
2064+
else
2065+
S.Stk.push<Pointer>(Ptr.asBlockPointer().Pointee,
2066+
Ptr.asBlockPointer().Base);
20642067
return true;
20652068
}
20662069

@@ -2677,8 +2680,16 @@ inline bool ArrayElemPtr(InterpState &S, CodePtr OpPC) {
26772680
return false;
26782681
}
26792682

2680-
if (!OffsetHelper<T, ArithOp::Add>(S, OpPC, Offset, Ptr))
2681-
return false;
2683+
if (Offset.isZero()) {
2684+
if (Ptr.getFieldDesc()->isArray() && Ptr.getIndex() == 0) {
2685+
S.Stk.push<Pointer>(Ptr.atIndex(0));
2686+
} else {
2687+
S.Stk.push<Pointer>(Ptr);
2688+
}
2689+
} else {
2690+
if (!OffsetHelper<T, ArithOp::Add>(S, OpPC, Offset, Ptr))
2691+
return false;
2692+
}
26822693

26832694
return NarrowPtr(S, OpPC);
26842695
}
@@ -2693,8 +2704,16 @@ inline bool ArrayElemPtrPop(InterpState &S, CodePtr OpPC) {
26932704
return false;
26942705
}
26952706

2696-
if (!OffsetHelper<T, ArithOp::Add>(S, OpPC, Offset, Ptr))
2697-
return false;
2707+
if (Offset.isZero()) {
2708+
if (Ptr.getFieldDesc()->isArray() && Ptr.getIndex() == 0) {
2709+
S.Stk.push<Pointer>(Ptr.atIndex(0));
2710+
} else {
2711+
S.Stk.push<Pointer>(Ptr);
2712+
}
2713+
} else {
2714+
if (!OffsetHelper<T, ArithOp::Add>(S, OpPC, Offset, Ptr))
2715+
return false;
2716+
}
26982717

26992718
return NarrowPtr(S, OpPC);
27002719
}

0 commit comments

Comments
 (0)