Skip to content

Commit 083445b

Browse files
committed
Merge from 'main' to 'sycl-web' (#12)
CONFLICT (content): Merge conflict in clang/lib/CodeGen/CGBuiltin.cpp
2 parents a40747d + cc94771 commit 083445b

File tree

80 files changed

+1104
-631
lines changed

Some content is hidden

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

80 files changed

+1104
-631
lines changed

clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "BufferDerefCheck.h"
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
12-
#include "clang/StaticAnalyzer/Checkers/MPIFunctionClassifier.h"
1312
#include "clang/Tooling/FixIt.h"
1413

1514
using namespace clang::ast_matchers;
@@ -23,13 +22,15 @@ void BufferDerefCheck::registerMatchers(MatchFinder *Finder) {
2322
}
2423

2524
void BufferDerefCheck::check(const MatchFinder::MatchResult &Result) {
26-
static ento::mpi::MPIFunctionClassifier FuncClassifier(*Result.Context);
2725
const auto *CE = Result.Nodes.getNodeAs<CallExpr>("CE");
2826
if (!CE->getDirectCallee())
2927
return;
3028

29+
if (!FuncClassifier)
30+
FuncClassifier.emplace(*Result.Context);
31+
3132
const IdentifierInfo *Identifier = CE->getDirectCallee()->getIdentifier();
32-
if (!Identifier || !FuncClassifier.isMPIType(Identifier))
33+
if (!Identifier || !FuncClassifier->isMPIType(Identifier))
3334
return;
3435

3536
// These containers are used, to capture the type and expression of a buffer.
@@ -60,18 +61,18 @@ void BufferDerefCheck::check(const MatchFinder::MatchResult &Result) {
6061
// Collect buffer types and argument expressions for all buffers used in the
6162
// MPI call expression. The number passed to the lambda corresponds to the
6263
// argument index of the currently verified MPI function call.
63-
if (FuncClassifier.isPointToPointType(Identifier)) {
64+
if (FuncClassifier->isPointToPointType(Identifier)) {
6465
AddBuffer(0);
65-
} else if (FuncClassifier.isCollectiveType(Identifier)) {
66-
if (FuncClassifier.isReduceType(Identifier)) {
66+
} else if (FuncClassifier->isCollectiveType(Identifier)) {
67+
if (FuncClassifier->isReduceType(Identifier)) {
6768
AddBuffer(0);
6869
AddBuffer(1);
69-
} else if (FuncClassifier.isScatterType(Identifier) ||
70-
FuncClassifier.isGatherType(Identifier) ||
71-
FuncClassifier.isAlltoallType(Identifier)) {
70+
} else if (FuncClassifier->isScatterType(Identifier) ||
71+
FuncClassifier->isGatherType(Identifier) ||
72+
FuncClassifier->isAlltoallType(Identifier)) {
7273
AddBuffer(0);
7374
AddBuffer(3);
74-
} else if (FuncClassifier.isBcastType(Identifier)) {
75+
} else if (FuncClassifier->isBcastType(Identifier)) {
7576
AddBuffer(0);
7677
}
7778
}
@@ -126,6 +127,7 @@ void BufferDerefCheck::checkBuffers(ArrayRef<const Type *> BufferTypes,
126127
}
127128
}
128129

130+
void BufferDerefCheck::onEndOfTranslationUnit() { FuncClassifier.reset(); }
129131
} // namespace mpi
130132
} // namespace tidy
131133
} // namespace clang

clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.h

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_BUFFER_DEREF_H
1111

1212
#include "../ClangTidyCheck.h"
13+
#include "clang/StaticAnalyzer/Checkers/MPIFunctionClassifier.h"
1314

1415
namespace clang {
1516
namespace tidy {
@@ -30,6 +31,7 @@ class BufferDerefCheck : public ClangTidyCheck {
3031
: ClangTidyCheck(Name, Context) {}
3132
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
3233
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
34+
void onEndOfTranslationUnit() override;
3335

3436
private:
3537
/// Checks for all buffers in an MPI call if they are sufficiently
@@ -41,6 +43,8 @@ class BufferDerefCheck : public ClangTidyCheck {
4143
ArrayRef<const Expr *> BufferExprs);
4244

4345
enum class IndirectionType : unsigned char { Pointer, Array };
46+
47+
Optional<ento::mpi::MPIFunctionClassifier> FuncClassifier;
4448
};
4549

4650
} // namespace mpi

clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "TypeMismatchCheck.h"
1010
#include "clang/Lex/Lexer.h"
11-
#include "clang/StaticAnalyzer/Checkers/MPIFunctionClassifier.h"
1211
#include "clang/Tooling/FixIt.h"
1312
#include <map>
1413
#include <unordered_set>
@@ -241,13 +240,15 @@ void TypeMismatchCheck::registerMatchers(MatchFinder *Finder) {
241240
}
242241

243242
void TypeMismatchCheck::check(const MatchFinder::MatchResult &Result) {
244-
static ento::mpi::MPIFunctionClassifier FuncClassifier(*Result.Context);
245243
const auto *const CE = Result.Nodes.getNodeAs<CallExpr>("CE");
246244
if (!CE->getDirectCallee())
247245
return;
248246

247+
if (!FuncClassifier)
248+
FuncClassifier.emplace(*Result.Context);
249+
249250
const IdentifierInfo *Identifier = CE->getDirectCallee()->getIdentifier();
250-
if (!Identifier || !FuncClassifier.isMPIType(Identifier))
251+
if (!Identifier || !FuncClassifier->isMPIType(Identifier))
251252
return;
252253

253254
// These containers are used, to capture buffer, MPI datatype pairs.
@@ -281,18 +282,18 @@ void TypeMismatchCheck::check(const MatchFinder::MatchResult &Result) {
281282
};
282283

283284
// Collect all buffer, MPI datatype pairs for the inspected call expression.
284-
if (FuncClassifier.isPointToPointType(Identifier)) {
285+
if (FuncClassifier->isPointToPointType(Identifier)) {
285286
AddPair(0, 2);
286-
} else if (FuncClassifier.isCollectiveType(Identifier)) {
287-
if (FuncClassifier.isReduceType(Identifier)) {
287+
} else if (FuncClassifier->isCollectiveType(Identifier)) {
288+
if (FuncClassifier->isReduceType(Identifier)) {
288289
AddPair(0, 3);
289290
AddPair(1, 3);
290-
} else if (FuncClassifier.isScatterType(Identifier) ||
291-
FuncClassifier.isGatherType(Identifier) ||
292-
FuncClassifier.isAlltoallType(Identifier)) {
291+
} else if (FuncClassifier->isScatterType(Identifier) ||
292+
FuncClassifier->isGatherType(Identifier) ||
293+
FuncClassifier->isAlltoallType(Identifier)) {
293294
AddPair(0, 2);
294295
AddPair(3, 5);
295-
} else if (FuncClassifier.isBcastType(Identifier)) {
296+
} else if (FuncClassifier->isBcastType(Identifier)) {
296297
AddPair(0, 2);
297298
}
298299
}
@@ -331,6 +332,7 @@ void TypeMismatchCheck::checkArguments(ArrayRef<const Type *> BufferTypes,
331332
}
332333
}
333334

335+
void TypeMismatchCheck::onEndOfTranslationUnit() { FuncClassifier.reset(); }
334336
} // namespace mpi
335337
} // namespace tidy
336338
} // namespace clang

clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.h

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "../ClangTidyCheck.h"
1313
#include "clang/ASTMatchers/ASTMatchFinder.h"
14+
#include "clang/StaticAnalyzer/Checkers/MPIFunctionClassifier.h"
1415

1516
namespace clang {
1617
namespace tidy {
@@ -31,6 +32,8 @@ class TypeMismatchCheck : public ClangTidyCheck {
3132
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
3233
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
3334

35+
void onEndOfTranslationUnit() override;
36+
3437
private:
3538
/// Check if the buffer type MPI datatype pairs match.
3639
///
@@ -41,6 +44,8 @@ class TypeMismatchCheck : public ClangTidyCheck {
4144
void checkArguments(ArrayRef<const Type *> BufferTypes,
4245
ArrayRef<const Expr *> BufferExprs,
4346
ArrayRef<StringRef> MPIDatatypes, const LangOptions &LO);
47+
48+
Optional<ento::mpi::MPIFunctionClassifier> FuncClassifier;
4449
};
4550

4651
} // namespace mpi

clang-tools-extra/clangd/ConfigCompile.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ struct FragmentCompiler {
371371
}
372372

373373
void compile(Fragment::DiagnosticsBlock &&F) {
374-
std::vector<llvm::StringRef> Normalized;
374+
std::vector<std::string> Normalized;
375375
for (const auto &Suppressed : F.Suppress) {
376376
if (*Suppressed == "*") {
377377
Out.Apply.push_back([&](const Params &, Config &C) {
@@ -380,15 +380,16 @@ struct FragmentCompiler {
380380
});
381381
return;
382382
}
383-
Normalized.push_back(normalizeSuppressedCode(*Suppressed));
383+
Normalized.push_back(normalizeSuppressedCode(*Suppressed).str());
384384
}
385385
if (!Normalized.empty())
386-
Out.Apply.push_back([Normalized](const Params &, Config &C) {
387-
if (C.Diagnostics.SuppressAll)
388-
return;
389-
for (llvm::StringRef N : Normalized)
390-
C.Diagnostics.Suppress.insert(N);
391-
});
386+
Out.Apply.push_back(
387+
[Normalized(std::move(Normalized))](const Params &, Config &C) {
388+
if (C.Diagnostics.SuppressAll)
389+
return;
390+
for (llvm::StringRef N : Normalized)
391+
C.Diagnostics.Suppress.insert(N);
392+
});
392393

393394
compile(std::move(F.ClangTidy));
394395
}

clang-tools-extra/clangd/ParsedAST.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
423423
// tokens from running the preprocessor inside the checks (only
424424
// modernize-use-trailing-return-type does that today).
425425
syntax::TokenBuffer Tokens = std::move(CollectTokens).consume();
426+
// Makes SelectionTree build much faster.
427+
Tokens.indexExpandedTokens();
426428
std::vector<Decl *> ParsedDecls = Action->takeTopLevelDecls();
427429
// AST traversals should exclude the preamble, to avoid performance cliffs.
428430
Clang->getASTContext().setTraversalScope(ParsedDecls);

clang/CMakeLists.txt

+13-2
Original file line numberDiff line numberDiff line change
@@ -867,13 +867,24 @@ if (CLANG_ENABLE_BOOTSTRAP)
867867
set(CLANG_BOOTSTRAP_TARGETS check-llvm check-clang check-all)
868868
endif()
869869
foreach(target ${CLANG_BOOTSTRAP_TARGETS})
870-
# exclude from main target
871-
set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES _EP_${target}_EXCLUDE_FROM_MAIN On)
870+
# Install targets have side effects, so we always want to execute them.
871+
# "install" is reserved by CMake and can't be used as a step name for
872+
# ExternalProject_Add_Step, so we can match against "^install-" instead of
873+
# "^install" to get a tighter match. CMake's installation scripts already
874+
# skip up-to-date files, so there's no behavior change if you install to the
875+
# same destination multiple times.
876+
if(target MATCHES "^install-")
877+
set(step_always ON)
878+
else()
879+
set(step_always OFF)
880+
endif()
872881

873882
ExternalProject_Add_Step(${NEXT_CLANG_STAGE} ${target}
874883
COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target ${target}
875884
COMMENT "Performing ${target} for '${NEXT_CLANG_STAGE}'"
876885
DEPENDEES configure
886+
ALWAYS ${step_always}
887+
EXCLUDE_FROM_MAIN ON
877888
USES_TERMINAL 1
878889
)
879890

clang/include/clang/Basic/Builtins.def

+3
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,9 @@ BUILTIN(__builtin_os_log_format, "v*v*cC*.", "p:0:nt")
16391639
// OpenMP 4.0
16401640
LANGBUILTIN(omp_is_initial_device, "i", "nc", OMP_LANG)
16411641

1642+
// CUDA/HIP
1643+
LANGBUILTIN(__builtin_get_device_side_mangled_name, "cC*.", "ncT", CUDA_LANG)
1644+
16421645
// Builtins for XRay
16431646
BUILTIN(__xray_customevent, "vcC*z", "")
16441647
BUILTIN(__xray_typedevent, "vzcC*z", "")

clang/include/clang/Basic/Builtins.h

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ enum LanguageID {
3636
OCLC20_LANG = 0x20, // builtin for OpenCL C 2.0 only.
3737
OCLC1X_LANG = 0x40, // builtin for OpenCL C 1.x only.
3838
OMP_LANG = 0x80, // builtin requires OpenMP.
39+
CUDA_LANG = 0x100, // builtin requires CUDA.
3940
ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
4041
ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG, // builtin requires GNU mode.
4142
ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG, // builtin requires MS mode.

clang/include/clang/Basic/DiagnosticSemaKinds.td

+3
Original file line numberDiff line numberDiff line change
@@ -8347,6 +8347,9 @@ def note_cuda_device_builtin_surftex_should_be_template_class : Note<
83478347
"%0 needs to be instantiated from a class template with proper "
83488348
"template arguments">;
83498349

8350+
def err_hip_invalid_args_builtin_mangled_name : Error<
8351+
"invalid argument: symbol must be a device-side function or global variable">;
8352+
83508353
def warn_non_pod_vararg_with_format_string : Warning<
83518354
"cannot pass %select{non-POD|non-trivial}0 object of type %1 to variadic "
83528355
"%select{function|block|method|constructor}2; expected type from format "

clang/include/clang/Driver/Options.td

+3-3
Original file line numberDiff line numberDiff line change
@@ -3614,8 +3614,8 @@ def pagezero__size : JoinedOrSeparate<["-"], "pagezero_size">;
36143614
def pass_exit_codes : Flag<["-", "--"], "pass-exit-codes">, Flags<[Unsupported]>;
36153615
def pedantic_errors : Flag<["-", "--"], "pedantic-errors">, Group<pedantic_Group>, Flags<[CC1Option]>,
36163616
MarshallingInfoFlag<DiagnosticOpts<"PedanticErrors">>;
3617-
def pedantic : Flag<["-", "--"], "pedantic">, Group<pedantic_Group>, Flags<[CC1Option]>,
3618-
MarshallingInfoFlag<DiagnosticOpts<"Pedantic">>;
3617+
def pedantic : Flag<["-", "--"], "pedantic">, Group<pedantic_Group>, Flags<[CC1Option,FlangOption,FC1Option]>,
3618+
HelpText<"Warn on language extensions">, MarshallingInfoFlag<DiagnosticOpts<"Pedantic">>;
36193619
def pg : Flag<["-"], "pg">, HelpText<"Enable mcount instrumentation">, Flags<[CC1Option]>,
36203620
MarshallingInfoFlag<CodeGenOpts<"InstrumentForProfiling">>;
36213621
def pipe : Flag<["-", "--"], "pipe">,
@@ -3717,7 +3717,7 @@ def static_libgcc : Flag<["-"], "static-libgcc">;
37173717
def static_libstdcxx : Flag<["-"], "static-libstdc++">;
37183718
def static : Flag<["-", "--"], "static">, Group<Link_Group>, Flags<[NoArgumentUnused]>;
37193719
def std_default_EQ : Joined<["-"], "std-default=">;
3720-
def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option]>,
3720+
def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option,FlangOption,FC1Option]>,
37213721
Group<CompileOnly_Group>, HelpText<"Language standard to compile for">,
37223722
ValuesCode<[{
37233723
const char *Values =

clang/include/clang/Tooling/Syntax/Tokens.h

+8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "clang/Basic/TokenKinds.h"
3535
#include "clang/Lex/Token.h"
3636
#include "llvm/ADT/ArrayRef.h"
37+
#include "llvm/ADT/DenseMap.h"
3738
#include "llvm/ADT/Optional.h"
3839
#include "llvm/ADT/StringRef.h"
3940
#include "llvm/Support/Compiler.h"
@@ -192,8 +193,13 @@ class TokenBuffer {
192193
return ExpandedTokens;
193194
}
194195

196+
/// Builds a cache to make future calls to expandedToken(SourceRange) faster.
197+
/// Creates an index only once. Further calls to it will be no-op.
198+
void indexExpandedTokens();
199+
195200
/// Returns the subrange of expandedTokens() corresponding to the closed
196201
/// token range R.
202+
/// Consider calling indexExpandedTokens() before for faster lookups.
197203
llvm::ArrayRef<syntax::Token> expandedTokens(SourceRange R) const;
198204

199205
/// Returns the subrange of spelled tokens corresponding to AST node spanning
@@ -366,6 +372,8 @@ class TokenBuffer {
366372
/// same stream as 'clang -E' (excluding the preprocessor directives like
367373
/// #file, etc.).
368374
std::vector<syntax::Token> ExpandedTokens;
375+
// Index of ExpandedTokens for faster lookups by SourceLocation.
376+
llvm::DenseMap<SourceLocation, unsigned> ExpandedTokIndex;
369377
llvm::DenseMap<FileID, MarkedFile> Files;
370378
// The value is never null, pointer instead of reference to avoid disabling
371379
// implicit assignment operator.

clang/lib/Basic/Builtins.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ bool Builtin::Context::builtinIsSupported(const Builtin::Info &BuiltinInfo,
7575
bool OclCUnsupported = !LangOpts.OpenCL &&
7676
(BuiltinInfo.Langs & ALL_OCLC_LANGUAGES);
7777
bool OpenMPUnsupported = !LangOpts.OpenMP && BuiltinInfo.Langs == OMP_LANG;
78+
bool CUDAUnsupported = !LangOpts.CUDA && BuiltinInfo.Langs == CUDA_LANG;
7879
bool CPlusPlusUnsupported =
7980
!LangOpts.CPlusPlus && BuiltinInfo.Langs == CXX_LANG;
8081
return !BuiltinsUnsupported && !MathBuiltinsUnsupported && !OclCUnsupported &&
8182
!OclC1Unsupported && !OclC2Unsupported && !OpenMPUnsupported &&
8283
!GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported &&
83-
!CPlusPlusUnsupported;
84+
!CPlusPlusUnsupported && !CUDAUnsupported;
8485
}
8586

8687
/// initializeBuiltins - Mark the identifiers for all the builtins with their

clang/lib/CodeGen/CGBuiltin.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "CGCUDARuntime.h"
1314
#include "CGCXXABI.h"
1415
#include "CGObjCRuntime.h"
1516
#include "CGOpenCLRuntime.h"
@@ -5064,6 +5065,17 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
50645065
return EmitIntelFPGARegBuiltin(E, ReturnValue);
50655066
case Builtin::BI__builtin_intel_fpga_mem:
50665067
return EmitIntelFPGAMemBuiltin(E);
5068+
5069+
case Builtin::BI__builtin_get_device_side_mangled_name: {
5070+
auto Name = CGM.getCUDARuntime().getDeviceSideName(
5071+
cast<DeclRefExpr>(E->getArg(0)->IgnoreImpCasts())->getDecl());
5072+
auto Str = CGM.GetAddrOfConstantCString(Name, "");
5073+
llvm::Constant *Zeros[] = {llvm::ConstantInt::get(SizeTy, 0),
5074+
llvm::ConstantInt::get(SizeTy, 0)};
5075+
auto *Ptr = llvm::ConstantExpr::getGetElementPtr(Str.getElementType(),
5076+
Str.getPointer(), Zeros);
5077+
return RValue::get(Ptr);
5078+
}
50675079
}
50685080

50695081
// If this is an alias for a lib function (e.g. __builtin_sin), emit

clang/lib/CodeGen/CGCUDANV.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "CGCUDARuntime.h"
15+
#include "CGCXXABI.h"
1516
#include "CodeGenFunction.h"
1617
#include "CodeGenModule.h"
1718
#include "clang/AST/Decl.h"
@@ -260,10 +261,15 @@ std::string CGNVCUDARuntime::getDeviceSideName(const NamedDecl *ND) {
260261
else
261262
GD = GlobalDecl(ND);
262263
std::string DeviceSideName;
263-
if (DeviceMC->shouldMangleDeclName(ND)) {
264+
MangleContext *MC;
265+
if (CGM.getLangOpts().CUDAIsDevice)
266+
MC = &CGM.getCXXABI().getMangleContext();
267+
else
268+
MC = DeviceMC.get();
269+
if (MC->shouldMangleDeclName(ND)) {
264270
SmallString<256> Buffer;
265271
llvm::raw_svector_ostream Out(Buffer);
266-
DeviceMC->mangleName(GD, Out);
272+
MC->mangleName(GD, Out);
267273
DeviceSideName = std::string(Out.str());
268274
} else
269275
DeviceSideName = std::string(ND->getIdentifier()->getName());

clang/lib/Driver/ToolChains/Flang.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ void Flang::AddPreprocessingOptions(const ArgList &Args,
4343
void Flang::AddOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
4444
Args.AddAllArgs(CmdArgs,
4545
{options::OPT_module_dir, options::OPT_fdebug_module_writer,
46-
options::OPT_fintrinsic_modules_path});
46+
options::OPT_fintrinsic_modules_path, options::OPT_pedantic,
47+
options::OPT_std_EQ});
4748
}
4849

4950
void Flang::ConstructJob(Compilation &C, const JobAction &JA,

0 commit comments

Comments
 (0)