Skip to content

Commit bd7b5b4

Browse files
committed
Merge from '"main"' to '"sycl-web"' (61 commits)
CONFLICT (content): Merge conflict in llvm/CMakeLists.txt
2 parents feac4ca + 6cd382b commit bd7b5b4

File tree

276 files changed

+9986
-7485
lines changed

Some content is hidden

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

276 files changed

+9986
-7485
lines changed

clang-tools-extra/clangd/CompileCommands.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,22 +198,26 @@ CommandMangler CommandMangler::forTests() { return CommandMangler(); }
198198
void CommandMangler::adjust(std::vector<std::string> &Cmd,
199199
llvm::StringRef File) const {
200200
trace::Span S("AdjustCompileFlags");
201+
// Most of the modifications below assumes the Cmd starts with a driver name.
202+
// We might consider injecting a generic driver name like "cc" or "c++", but
203+
// a Cmd missing the driver is probably rare enough in practice and errnous.
204+
if (Cmd.empty())
205+
return;
201206
auto &OptTable = clang::driver::getDriverOptTable();
202207
// OriginalArgs needs to outlive ArgList.
203208
llvm::SmallVector<const char *, 16> OriginalArgs;
204209
OriginalArgs.reserve(Cmd.size());
205210
for (const auto &S : Cmd)
206211
OriginalArgs.push_back(S.c_str());
207-
bool IsCLMode =
208-
!OriginalArgs.empty() &&
209-
driver::IsClangCL(driver::getDriverMode(
210-
OriginalArgs[0], llvm::makeArrayRef(OriginalArgs).slice(1)));
212+
bool IsCLMode = driver::IsClangCL(driver::getDriverMode(
213+
OriginalArgs[0], llvm::makeArrayRef(OriginalArgs).slice(1)));
211214
// ParseArgs propagates missig arg/opt counts on error, but preserves
212215
// everything it could parse in ArgList. So we just ignore those counts.
213216
unsigned IgnoredCount;
214217
// Drop the executable name, as ParseArgs doesn't expect it. This means
215218
// indices are actually of by one between ArgList and OriginalArgs.
216-
auto ArgList = OptTable.ParseArgs(
219+
llvm::opt::InputArgList ArgList;
220+
ArgList = OptTable.ParseArgs(
217221
llvm::makeArrayRef(OriginalArgs).drop_front(), IgnoredCount, IgnoredCount,
218222
/*FlagsToInclude=*/
219223
IsCLMode ? (driver::options::CLOption | driver::options::CoreOption)

clang-tools-extra/clangd/Compiler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ void disableUnsupportedOptions(CompilerInvocation &CI) {
8383
std::unique_ptr<CompilerInvocation>
8484
buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
8585
std::vector<std::string> *CC1Args) {
86+
if (Inputs.CompileCommand.CommandLine.empty())
87+
return nullptr;
8688
std::vector<const char *> ArgStrs;
8789
for (const auto &S : Inputs.CompileCommand.CommandLine)
8890
ArgStrs.push_back(S.c_str());

clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,13 @@ TEST(CommandMangler, StripsMultipleArch) {
396396
llvm::count_if(Args, [](llvm::StringRef Arg) { return Arg == "-arch"; }),
397397
1);
398398
}
399+
400+
TEST(CommandMangler, EmptyArgs) {
401+
const auto Mangler = CommandMangler::forTests();
402+
std::vector<std::string> Args = {};
403+
// Make sure we don't crash.
404+
Mangler.adjust(Args, "foo.cc");
405+
}
399406
} // namespace
400407
} // namespace clangd
401408
} // namespace clang

clang-tools-extra/clangd/unittests/CompilerTests.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ TEST(BuildCompilerInvocation, DropsPlugins) {
102102
EXPECT_EQ(Opts.ProgramAction, frontend::ActionKind::ParseSyntaxOnly);
103103
EXPECT_TRUE(Opts.ActionName.empty());
104104
}
105+
106+
TEST(BuildCompilerInvocation, EmptyArgs) {
107+
MockFS FS;
108+
IgnoreDiagnostics Diags;
109+
TestTU TU;
110+
auto Inputs = TU.inputs(FS);
111+
Inputs.CompileCommand.CommandLine.clear();
112+
113+
// No crash.
114+
EXPECT_EQ(buildCompilerInvocation(Inputs, Diags), nullptr);
115+
}
105116
} // namespace
106117
} // namespace clangd
107118
} // namespace clang

clang/CODE_OWNERS.TXT

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ beautification by scripts. The fields are: name (N), email (E), web-address
88
(W), PGP key ID and fingerprint (P), description (D), and snail-mail address
99
(S).
1010

11+
N: Alexey Bader
12+
13+
D: SYCL support
14+
1115
N: Aaron Ballman
1216
1317
D: Clang attributes

clang/cmake/modules/AddClang.cmake

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ macro(add_clang_library name)
100100
# The Xcode generator doesn't handle object libraries correctly.
101101
list(APPEND LIBTYPE OBJECT)
102102
endif()
103-
set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
103+
if (NOT EXCLUDE_FROM_ALL)
104+
# Only include libraries that don't have EXCLUDE_FROM_ALL set. This
105+
# ensure that the clang static analyzer libraries are not compiled
106+
# as part of clang-shlib if CLANG_ENABLE_STATIC_ANALYZER=OFF.
107+
set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
108+
endif()
104109
endif()
105110
llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
106111

@@ -110,8 +115,11 @@ macro(add_clang_library name)
110115
endif()
111116

112117
foreach(lib ${libs})
113-
if(TARGET ${lib})
118+
if(TARGET ${lib})
114119
target_link_libraries(${lib} INTERFACE ${LLVM_COMMON_LIBS})
120+
if (EXCLUDE_FROM_ALL)
121+
continue()
122+
endif()
115123

116124
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ARG_INSTALL_WITH_TOOLCHAIN)
117125
get_target_export_arg(${name} Clang export_to_clangtargets UMBRELLA clang-libraries)

clang/docs/analyzer/checkers.rst

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,20 @@ Method calls on a moved-from object and copying a moved-from object will be repo
18381838
a.foo(); // warn: method call on a 'moved-from' object 'a'
18391839
}
18401840
1841+
.. _alpha-cplusplus-SmartPtr:
1842+
1843+
alpha.cplusplus.SmartPtr (C++)
1844+
""""""""""""""""""""""""""""""
1845+
Check for dereference of null smart pointers.
1846+
1847+
.. code-block:: cpp
1848+
1849+
void deref_smart_ptr() {
1850+
std::unique_ptr<int> P;
1851+
*P; // warn: dereference of a default constructed smart unique_ptr
1852+
}
1853+
1854+
18411855
alpha.deadcode
18421856
^^^^^^^^^^^^^^
18431857
.. _alpha-deadcode-UnreachableCode:
@@ -1872,19 +1886,6 @@ Check unreachable code.
18721886
[x retain]; // warn
18731887
}
18741888
1875-
.. _alpha-cplusplus-SmartPtr:
1876-
1877-
alpha.cplusplus.SmartPtr (C++)
1878-
""""""""""""""""""""""""""""""
1879-
Check for dereference of null smart pointers.
1880-
1881-
.. code-block:: cpp
1882-
1883-
void deref_smart_ptr() {
1884-
std::unique_ptr<int> P;
1885-
*P; // warn: dereference of a default constructed smart unique_ptr
1886-
}
1887-
18881889
alpha.fuchsia
18891890
^^^^^^^^^^^^^
18901891

clang/lib/Analysis/ThreadSafety.cpp

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,11 @@ static void findBlockLocations(CFG *CFGraph,
849849
// location.
850850
CurrBlockInfo->EntryLoc = CurrBlockInfo->ExitLoc =
851851
BlockInfo[(*CurrBlock->pred_begin())->getBlockID()].ExitLoc;
852+
} else if (CurrBlock->succ_size() == 1 && *CurrBlock->succ_begin()) {
853+
// The block is empty, and has a single successor. Use its entry
854+
// location.
855+
CurrBlockInfo->EntryLoc = CurrBlockInfo->ExitLoc =
856+
BlockInfo[(*CurrBlock->succ_begin())->getBlockID()].EntryLoc;
852857
}
853858
}
854859
}
@@ -2415,7 +2420,6 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
24152420
// union because the real error is probably that we forgot to unlock M on
24162421
// all code paths.
24172422
bool LocksetInitialized = false;
2418-
SmallVector<CFGBlock *, 8> SpecialBlocks;
24192423
for (CFGBlock::const_pred_iterator PI = CurrBlock->pred_begin(),
24202424
PE = CurrBlock->pred_end(); PI != PE; ++PI) {
24212425
// if *PI -> CurrBlock is a back edge
@@ -2432,63 +2436,28 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
24322436
// Okay, we can reach this block from the entry.
24332437
CurrBlockInfo->Reachable = true;
24342438

2435-
// If the previous block ended in a 'continue' or 'break' statement, then
2436-
// a difference in locksets is probably due to a bug in that block, rather
2437-
// than in some other predecessor. In that case, keep the other
2438-
// predecessor's lockset.
2439-
if (const Stmt *Terminator = (*PI)->getTerminatorStmt()) {
2440-
if (isa<ContinueStmt>(Terminator) || isa<BreakStmt>(Terminator)) {
2441-
SpecialBlocks.push_back(*PI);
2442-
continue;
2443-
}
2444-
}
2445-
24462439
FactSet PrevLockset;
24472440
getEdgeLockset(PrevLockset, PrevBlockInfo->ExitSet, *PI, CurrBlock);
24482441

24492442
if (!LocksetInitialized) {
24502443
CurrBlockInfo->EntrySet = PrevLockset;
24512444
LocksetInitialized = true;
24522445
} else {
2453-
intersectAndWarn(CurrBlockInfo->EntrySet, PrevLockset,
2454-
CurrBlockInfo->EntryLoc,
2455-
LEK_LockedSomePredecessors);
2446+
// Surprisingly 'continue' doesn't always produce back edges, because
2447+
// the CFG has empty "transition" blocks where they meet with the end
2448+
// of the regular loop body. We still want to diagnose them as loop.
2449+
intersectAndWarn(
2450+
CurrBlockInfo->EntrySet, PrevLockset, CurrBlockInfo->EntryLoc,
2451+
isa_and_nonnull<ContinueStmt>((*PI)->getTerminatorStmt())
2452+
? LEK_LockedSomeLoopIterations
2453+
: LEK_LockedSomePredecessors);
24562454
}
24572455
}
24582456

24592457
// Skip rest of block if it's not reachable.
24602458
if (!CurrBlockInfo->Reachable)
24612459
continue;
24622460

2463-
// Process continue and break blocks. Assume that the lockset for the
2464-
// resulting block is unaffected by any discrepancies in them.
2465-
for (const auto *PrevBlock : SpecialBlocks) {
2466-
unsigned PrevBlockID = PrevBlock->getBlockID();
2467-
CFGBlockInfo *PrevBlockInfo = &BlockInfo[PrevBlockID];
2468-
2469-
if (!LocksetInitialized) {
2470-
CurrBlockInfo->EntrySet = PrevBlockInfo->ExitSet;
2471-
LocksetInitialized = true;
2472-
} else {
2473-
// Determine whether this edge is a loop terminator for diagnostic
2474-
// purposes. FIXME: A 'break' statement might be a loop terminator, but
2475-
// it might also be part of a switch. Also, a subsequent destructor
2476-
// might add to the lockset, in which case the real issue might be a
2477-
// double lock on the other path.
2478-
const Stmt *Terminator = PrevBlock->getTerminatorStmt();
2479-
bool IsLoop = Terminator && isa<ContinueStmt>(Terminator);
2480-
2481-
FactSet PrevLockset;
2482-
getEdgeLockset(PrevLockset, PrevBlockInfo->ExitSet,
2483-
PrevBlock, CurrBlock);
2484-
2485-
// Do not update EntrySet.
2486-
intersectAndWarn(
2487-
CurrBlockInfo->EntrySet, PrevLockset, PrevBlockInfo->ExitLoc,
2488-
IsLoop ? LEK_LockedSomeLoopIterations : LEK_LockedSomePredecessors);
2489-
}
2490-
}
2491-
24922461
BuildLockset LocksetBuilder(this, *CurrBlockInfo);
24932462

24942463
// Visit all the statements in the basic block.

clang/lib/CodeGen/TargetInfo.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3438,17 +3438,21 @@ llvm::Type *X86_64ABIInfo::
34383438
GetSSETypeAtOffset(llvm::Type *IRType, unsigned IROffset,
34393439
QualType SourceTy, unsigned SourceOffset) const {
34403440
const llvm::DataLayout &TD = getDataLayout();
3441+
unsigned SourceSize =
3442+
(unsigned)getContext().getTypeSize(SourceTy) / 8 - SourceOffset;
34413443
llvm::Type *T0 = getFPTypeAtOffset(IRType, IROffset, TD);
34423444
if (!T0 || T0->isDoubleTy())
34433445
return llvm::Type::getDoubleTy(getVMContext());
34443446

34453447
// Get the adjacent FP type.
3446-
llvm::Type *T1 =
3447-
getFPTypeAtOffset(IRType, IROffset + TD.getTypeAllocSize(T0), TD);
3448+
llvm::Type *T1 = nullptr;
3449+
unsigned T0Size = TD.getTypeAllocSize(T0);
3450+
if (SourceSize > T0Size)
3451+
T1 = getFPTypeAtOffset(IRType, IROffset + T0Size, TD);
34483452
if (T1 == nullptr) {
34493453
// Check if IRType is a half + float. float type will be in IROffset+4 due
34503454
// to its alignment.
3451-
if (T0->isHalfTy())
3455+
if (T0->isHalfTy() && SourceSize > 4)
34523456
T1 = getFPTypeAtOffset(IRType, IROffset + 4, TD);
34533457
// If we can't get a second FP type, return a simple half or float.
34543458
// avx512fp16-abi.c:pr51813_2 shows it works to return float for
@@ -3461,7 +3465,9 @@ GetSSETypeAtOffset(llvm::Type *IRType, unsigned IROffset,
34613465
return llvm::FixedVectorType::get(T0, 2);
34623466

34633467
if (T0->isHalfTy() && T1->isHalfTy()) {
3464-
llvm::Type *T2 = getFPTypeAtOffset(IRType, IROffset + 4, TD);
3468+
llvm::Type *T2 = nullptr;
3469+
if (SourceSize > 4)
3470+
T2 = getFPTypeAtOffset(IRType, IROffset + 4, TD);
34653471
if (T2 == nullptr)
34663472
return llvm::FixedVectorType::get(T0, 2);
34673473
return llvm::FixedVectorType::get(T0, 4);

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,6 +2143,12 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
21432143
// Declare a bunch of static data sets that we'll select between below. These
21442144
// are specifically designed to always refer to string literals to avoid any
21452145
// lifetime or initialization issues.
2146+
//
2147+
// The *Triples variables hard code some triples so that, for example,
2148+
// --target=aarch64 (incomplete triple) can detect lib/aarch64-linux-gnu.
2149+
// They are not needed when the user has correct LLVM_DEFAULT_TARGET_TRIPLE
2150+
// and always uses the full --target (e.g. --target=aarch64-linux-gnu). The
2151+
// lists should shrink over time. Please don't add more elements to *Triples.
21462152
static const char *const AArch64LibDirs[] = {"/lib64", "/lib"};
21472153
static const char *const AArch64Triples[] = {
21482154
"aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-redhat-linux",
@@ -2250,9 +2256,7 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
22502256
static const char *const RISCV64LibDirs[] = {"/lib64", "/lib"};
22512257
static const char *const RISCV64Triples[] = {"riscv64-unknown-linux-gnu",
22522258
"riscv64-linux-gnu",
2253-
"riscv64-unknown-elf",
2254-
"riscv64-redhat-linux",
2255-
"riscv64-suse-linux"};
2259+
"riscv64-unknown-elf"};
22562260

22572261
static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"};
22582262
static const char *const SPARCv8Triples[] = {"sparc-linux-gnu",

clang/lib/Frontend/CreateInvocationFromCommandLine.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ std::unique_ptr<CompilerInvocation> clang::createInvocationFromCommandLine(
3030
ArrayRef<const char *> ArgList, IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
3131
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, bool ShouldRecoverOnErorrs,
3232
std::vector<std::string> *CC1Args) {
33+
assert(!ArgList.empty());
3334
if (!Diags.get()) {
3435
// No diagnostics engine was provided, so create our own diagnostics object
3536
// with the default options.

clang/lib/Headers/opencl-c-base.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,9 @@ typedef enum memory_scope {
348348
memory_scope_device = __OPENCL_MEMORY_SCOPE_DEVICE,
349349
#if defined(__opencl_c_atomic_scope_all_devices)
350350
memory_scope_all_svm_devices = __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES,
351-
#if (__OPENCL_C_VERSION__ >= CL_VERSION_3_0)
351+
#if (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 202100)
352352
memory_scope_all_devices = memory_scope_all_svm_devices,
353-
#endif // __OPENCL_C_VERSION__ >= CL_VERSION_3_0
353+
#endif // (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 202100)
354354
#endif // defined(__opencl_c_atomic_scope_all_devices)
355355
/**
356356
* Subgroups have different requirements on forward progress, so just test

0 commit comments

Comments
 (0)