Skip to content

Commit a66defe

Browse files
authored
Merge branch 'llvm:main' into gh-101657
2 parents 22cd1da + b6c06d1 commit a66defe

File tree

162 files changed

+4456
-1376
lines changed

Some content is hidden

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

162 files changed

+4456
-1376
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,13 @@ New features
11571157
Crash and bug fixes
11581158
^^^^^^^^^^^^^^^^^^^
11591159

1160+
- In loops where the loop condition is opaque (i.e. the analyzer cannot
1161+
determine whether it's true or false), the analyzer will no longer assume
1162+
execution paths that perform more that two iterations. These unjustified
1163+
assumptions caused false positive reports (e.g. 100+ out-of-bounds reports in
1164+
the FFMPEG codebase) in loops where the programmer intended only two or three
1165+
steps but the analyzer wasn't able to understand that the loop is limited.
1166+
11601167
Improvements
11611168
^^^^^^^^^^^^
11621169

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,8 @@ def libomptarget_amdgcn_bc_path_EQ : Joined<["--"], "libomptarget-amdgcn-bc-path
14931493
HelpText<"Path to libomptarget-amdgcn bitcode library">, Alias<libomptarget_amdgpu_bc_path_EQ>;
14941494
def libomptarget_nvptx_bc_path_EQ : Joined<["--"], "libomptarget-nvptx-bc-path=">, Group<i_Group>,
14951495
HelpText<"Path to libomptarget-nvptx bitcode library">;
1496+
def libomptarget_spirv_bc_path_EQ : Joined<["--"], "libomptarget-spirv-bc-path=">, Group<i_Group>,
1497+
HelpText<"Path to libomptarget-spirv bitcode library">;
14961498
def dD : Flag<["-"], "dD">, Group<d_Group>, Visibility<[ClangOption, CC1Option]>,
14971499
HelpText<"Print macro definitions in -E mode in addition to normal output">;
14981500
def dI : Flag<["-"], "dI">, Group<d_Group>, Visibility<[ClangOption, CC1Option]>,

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -997,13 +997,15 @@ class CXX20ModulesGenerator : public PCHGenerator {
997997
virtual Module *getEmittingModule(ASTContext &Ctx) override;
998998

999999
CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
1000-
StringRef OutputFile, bool GeneratingReducedBMI);
1000+
StringRef OutputFile, bool GeneratingReducedBMI,
1001+
bool AllowASTWithErrors);
10011002

10021003
public:
10031004
CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
1004-
StringRef OutputFile)
1005+
StringRef OutputFile, bool AllowASTWithErrors = false)
10051006
: CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
1006-
/*GeneratingReducedBMI=*/false) {}
1007+
/*GeneratingReducedBMI=*/false,
1008+
AllowASTWithErrors) {}
10071009

10081010
void HandleTranslationUnit(ASTContext &Ctx) override;
10091011
};
@@ -1013,9 +1015,10 @@ class ReducedBMIGenerator : public CXX20ModulesGenerator {
10131015

10141016
public:
10151017
ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
1016-
StringRef OutputFile)
1018+
StringRef OutputFile, bool AllowASTWithErrors = false)
10171019
: CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
1018-
/*GeneratingReducedBMI=*/true) {}
1020+
/*GeneratingReducedBMI=*/true,
1021+
AllowASTWithErrors) {}
10191022
};
10201023

10211024
/// If we can elide the definition of \param D in reduced BMI.

clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ class CoreEngine {
126126
ExplodedNode *generateCallExitBeginNode(ExplodedNode *N,
127127
const ReturnStmt *RS);
128128

129+
/// Helper function called by `HandleBranch()`. If the currently handled
130+
/// branch corresponds to a loop, this returns the number of already
131+
/// completed iterations in that loop, otherwise the return value is
132+
/// `std::nullopt`. Note that this counts _all_ earlier iterations, including
133+
/// ones that were performed within an earlier iteration of an outer loop.
134+
std::optional<unsigned> getCompletedIterationCount(const CFGBlock *B,
135+
ExplodedNode *Pred) const;
136+
129137
public:
130138
/// Construct a CoreEngine object to analyze the provided CFG.
131139
CoreEngine(ExprEngine &exprengine,

clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,14 @@ class ExprEngine {
321321
NodeBuilderWithSinks &nodeBuilder,
322322
ExplodedNode *Pred);
323323

324-
/// ProcessBranch - Called by CoreEngine. Used to generate successor
325-
/// nodes by processing the 'effects' of a branch condition.
326-
void processBranch(const Stmt *Condition,
327-
NodeBuilderContext& BuilderCtx,
328-
ExplodedNode *Pred,
329-
ExplodedNodeSet &Dst,
330-
const CFGBlock *DstT,
331-
const CFGBlock *DstF);
324+
/// ProcessBranch - Called by CoreEngine. Used to generate successor nodes by
325+
/// processing the 'effects' of a branch condition. If the branch condition
326+
/// is a loop condition, IterationsCompletedInLoop is the number of completed
327+
/// iterations (otherwise it's std::nullopt).
328+
void processBranch(const Stmt *Condition, NodeBuilderContext &BuilderCtx,
329+
ExplodedNode *Pred, ExplodedNodeSet &Dst,
330+
const CFGBlock *DstT, const CFGBlock *DstF,
331+
std::optional<unsigned> IterationsCompletedInLoop);
332332

333333
/// Called by CoreEngine.
334334
/// Used to generate successor nodes for temporary destructors depending
@@ -588,6 +588,8 @@ class ExprEngine {
588588
void evalEagerlyAssumeBifurcation(ExplodedNodeSet &Dst, ExplodedNodeSet &Src,
589589
const Expr *Ex);
590590

591+
bool didEagerlyAssumeBifurcateAt(ProgramStateRef State, const Expr *Ex) const;
592+
591593
static std::pair<const ProgramPointTag *, const ProgramPointTag *>
592594
getEagerlyAssumeBifurcationTags();
593595

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1544,9 +1544,10 @@ static bool interp__builtin_constant_p(InterpState &S, CodePtr OpPC,
15441544
if (Res.isInvalid()) {
15451545
C.cleanup();
15461546
Stk.clear();
1547+
return returnInt(false);
15471548
}
15481549

1549-
if (!Res.isInvalid() && !Res.empty()) {
1550+
if (!Res.empty()) {
15501551
const APValue &LV = Res.toAPValue();
15511552
if (LV.isLValue()) {
15521553
APValue::LValueBase Base = LV.getLValueBase();

clang/lib/Driver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ add_clang_library(clangDriver
7777
ToolChains/RISCVToolchain.cpp
7878
ToolChains/Solaris.cpp
7979
ToolChains/SPIRV.cpp
80+
ToolChains/SPIRVOpenMP.cpp
8081
ToolChains/TCE.cpp
8182
ToolChains/UEFI.cpp
8283
ToolChains/VEToolchain.cpp

clang/lib/Driver/Driver.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "ToolChains/PS4CPU.h"
4444
#include "ToolChains/RISCVToolchain.h"
4545
#include "ToolChains/SPIRV.h"
46+
#include "ToolChains/SPIRVOpenMP.h"
4647
#include "ToolChains/Solaris.h"
4748
#include "ToolChains/TCE.h"
4849
#include "ToolChains/UEFI.h"
@@ -890,9 +891,9 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
890891
HostTC->getTriple());
891892

892893
// Attempt to deduce the offloading triple from the set of architectures.
893-
// We can only correctly deduce NVPTX / AMDGPU triples currently. We need
894-
// to temporarily create these toolchains so that we can access tools for
895-
// inferring architectures.
894+
// We can only correctly deduce NVPTX / AMDGPU triples currently.
895+
// We need to temporarily create these toolchains so that we can access
896+
// tools for inferring architectures.
896897
llvm::DenseSet<StringRef> Archs;
897898
if (NVPTXTriple) {
898899
auto TempTC = std::make_unique<toolchains::CudaToolChain>(
@@ -962,7 +963,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
962963
const ToolChain *TC;
963964
// Device toolchains have to be selected differently. They pair host
964965
// and device in their implementation.
965-
if (TT.isNVPTX() || TT.isAMDGCN()) {
966+
if (TT.isNVPTX() || TT.isAMDGCN() || TT.isSPIRV()) {
966967
const ToolChain *HostTC =
967968
C.getSingleOffloadToolChain<Action::OFK_Host>();
968969
assert(HostTC && "Host toolchain should be always defined.");
@@ -975,6 +976,9 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
975976
else if (TT.isAMDGCN())
976977
DeviceTC = std::make_unique<toolchains::AMDGPUOpenMPToolChain>(
977978
*this, TT, *HostTC, C.getInputArgs());
979+
else if (TT.isSPIRV())
980+
DeviceTC = std::make_unique<toolchains::SPIRVOpenMPToolChain>(
981+
*this, TT, *HostTC, C.getInputArgs());
978982
else
979983
assert(DeviceTC && "Device toolchain not defined.");
980984
}

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2839,10 +2839,13 @@ void tools::addOpenMPDeviceRTL(const Driver &D,
28392839
LibraryPaths.emplace_back(LibPath);
28402840

28412841
OptSpecifier LibomptargetBCPathOpt =
2842-
Triple.isAMDGCN() ? options::OPT_libomptarget_amdgpu_bc_path_EQ
2843-
: options::OPT_libomptarget_nvptx_bc_path_EQ;
2842+
Triple.isAMDGCN() ? options::OPT_libomptarget_amdgpu_bc_path_EQ
2843+
: Triple.isNVPTX() ? options::OPT_libomptarget_nvptx_bc_path_EQ
2844+
: options::OPT_libomptarget_spirv_bc_path_EQ;
28442845

2845-
StringRef ArchPrefix = Triple.isAMDGCN() ? "amdgpu" : "nvptx";
2846+
StringRef ArchPrefix = Triple.isAMDGCN() ? "amdgpu"
2847+
: Triple.isNVPTX() ? "nvptx"
2848+
: "spirv64";
28462849
std::string LibOmpTargetName = ("libomptarget-" + ArchPrefix + ".bc").str();
28472850

28482851
// First check whether user specifies bc library

clang/lib/Driver/ToolChains/OHOS.cpp

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include "llvm/ProfileData/InstrProf.h"
2020
#include "llvm/Support/FileSystem.h"
2121
#include "llvm/Support/Path.h"
22-
#include "llvm/Support/ScopedPrinter.h"
2322
#include "llvm/Support/VirtualFileSystem.h"
23+
#include "llvm/Support/ScopedPrinter.h"
2424

2525
using namespace clang::driver;
2626
using namespace clang::driver::toolchains;
@@ -58,9 +58,11 @@ static bool findOHOSMuslMultilibs(const Driver &D,
5858
return false;
5959
}
6060

61-
static bool findOHOSMultilibs(const Driver &D, const ToolChain &TC,
62-
const llvm::Triple &TargetTriple, StringRef Path,
63-
const ArgList &Args, DetectedMultilibs &Result) {
61+
static bool findOHOSMultilibs(const Driver &D,
62+
const ToolChain &TC,
63+
const llvm::Triple &TargetTriple,
64+
StringRef Path, const ArgList &Args,
65+
DetectedMultilibs &Result) {
6466
Multilib::flags_list Flags;
6567
bool IsA7 = false;
6668
if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
@@ -170,7 +172,8 @@ OHOS::OHOS(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
170172
Paths);
171173
}
172174

173-
ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(const ArgList &Args) const {
175+
ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(
176+
const ArgList &Args) const {
174177
if (Arg *A = Args.getLastArg(clang::driver::options::OPT_rtlib_EQ)) {
175178
StringRef Value = A->getValue();
176179
if (Value != "compiler-rt")
@@ -181,19 +184,20 @@ ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(const ArgList &Args) const {
181184
return ToolChain::RLT_CompilerRT;
182185
}
183186

184-
ToolChain::CXXStdlibType OHOS::GetCXXStdlibType(const ArgList &Args) const {
187+
ToolChain::CXXStdlibType
188+
OHOS::GetCXXStdlibType(const ArgList &Args) const {
185189
if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
186190
StringRef Value = A->getValue();
187191
if (Value != "libc++")
188192
getDriver().Diag(diag::err_drv_invalid_stdlib_name)
189-
<< A->getAsString(Args);
193+
<< A->getAsString(Args);
190194
}
191195

192196
return ToolChain::CST_Libcxx;
193197
}
194198

195199
void OHOS::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
196-
ArgStringList &CC1Args) const {
200+
ArgStringList &CC1Args) const {
197201
const Driver &D = getDriver();
198202
const llvm::Triple &Triple = getTriple();
199203
std::string SysRoot = computeSysRoot();
@@ -254,7 +258,7 @@ void OHOS::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
254258
}
255259

256260
void OHOS::AddCXXStdlibLibArgs(const ArgList &Args,
257-
ArgStringList &CmdArgs) const {
261+
ArgStringList &CmdArgs) const {
258262
switch (GetCXXStdlibType(Args)) {
259263
case ToolChain::CST_Libcxx:
260264
CmdArgs.push_back("-lc++");
@@ -287,8 +291,7 @@ ToolChain::path_list OHOS::getRuntimePaths() const {
287291

288292
// First try the triple passed to driver as --target=<triple>.
289293
P.assign(D.ResourceDir);
290-
llvm::sys::path::append(P, "lib", D.getTargetTriple(),
291-
SelectedMultilib.gccSuffix());
294+
llvm::sys::path::append(P, "lib", D.getTargetTriple(), SelectedMultilib.gccSuffix());
292295
Paths.push_back(P.c_str());
293296

294297
// Second try the normalized triple.
@@ -337,20 +340,26 @@ std::string OHOS::getDynamicLinker(const ArgList &Args) const {
337340

338341
std::string OHOS::getCompilerRT(const ArgList &Args, StringRef Component,
339342
FileType Type) const {
340-
std::string CRTBasename =
341-
buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
342-
343343
SmallString<128> Path(getDriver().ResourceDir);
344344
llvm::sys::path::append(Path, "lib", getMultiarchTriple(getTriple()),
345-
SelectedMultilib.gccSuffix(), CRTBasename);
346-
if (getVFS().exists(Path))
347-
return std::string(Path);
348-
349-
std::string NewPath = ToolChain::getCompilerRT(Args, Component, Type);
350-
if (getVFS().exists(NewPath))
351-
return NewPath;
352-
353-
return std::string(Path);
345+
SelectedMultilib.gccSuffix());
346+
const char *Prefix =
347+
Type == ToolChain::FT_Object ? "" : "lib";
348+
const char *Suffix;
349+
switch (Type) {
350+
case ToolChain::FT_Object:
351+
Suffix = ".o";
352+
break;
353+
case ToolChain::FT_Static:
354+
Suffix = ".a";
355+
break;
356+
case ToolChain::FT_Shared:
357+
Suffix = ".so";
358+
break;
359+
}
360+
llvm::sys::path::append(
361+
Path, Prefix + Twine("clang_rt.") + Component + Suffix);
362+
return static_cast<std::string>(Path.str());
354363
}
355364

356365
void OHOS::addExtraOpts(llvm::opt::ArgStringList &CmdArgs) const {
@@ -387,7 +396,7 @@ SanitizerMask OHOS::getSupportedSanitizers() const {
387396

388397
// TODO: Make a base class for Linux and OHOS and move this there.
389398
void OHOS::addProfileRTLibs(const llvm::opt::ArgList &Args,
390-
llvm::opt::ArgStringList &CmdArgs) const {
399+
llvm::opt::ArgStringList &CmdArgs) const {
391400
// Add linker option -u__llvm_profile_runtime to cause runtime
392401
// initialization module to be linked in.
393402
if (needsProfileRT(Args))
@@ -404,8 +413,7 @@ ToolChain::path_list OHOS::getArchSpecificLibPaths() const {
404413
return Paths;
405414
}
406415

407-
ToolChain::UnwindLibType
408-
OHOS::GetUnwindLibType(const llvm::opt::ArgList &Args) const {
416+
ToolChain::UnwindLibType OHOS::GetUnwindLibType(const llvm::opt::ArgList &Args) const {
409417
if (Args.getLastArg(options::OPT_unwindlib_EQ))
410418
return Generic_ELF::GetUnwindLibType(Args);
411419
return GetDefaultUnwindLibType();

0 commit comments

Comments
 (0)