Skip to content

Commit ed2e69d

Browse files
authored
Merge branch 'main' into add-target-level-include-paths
2 parents c664b02 + 1c837ec commit ed2e69d

File tree

167 files changed

+3234
-568
lines changed

Some content is hidden

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

167 files changed

+3234
-568
lines changed

.github/workflows/release-binaries.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,6 @@ jobs:
132132
arches=arm64
133133
else
134134
arches=x86_64
135-
# Disable Flang builds on macOS x86_64. The FortranLower library takes
136-
# 2-3 hours to build on macOS, much slower than on Linux.
137-
# The long build time causes the release build to time out on x86_64,
138-
# so we need to disable flang there.
139-
target_cmake_flags="$target_cmake_flags -DLLVM_RELEASE_ENABLE_PROJECTS='clang;lld;lldb;clang-tools-extra;polly;mlir'"
140135
fi
141136
target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_BOOTSTRAP_DARWIN_osx_ARCHS=$arches -DBOOTSTRAP_BOOTSTRAP_DARWIN_osx_BUILTIN_ARCHS=$arches"
142137
fi

clang/cmake/caches/Release.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@ endfunction()
3030
#
3131
# cmake -D LLVM_RELEASE_ENABLE_PGO=ON -C Release.cmake
3232

33-
set (DEFAULT_PROJECTS "clang;lld;lldb;clang-tools-extra;polly;mlir;flang")
33+
set (DEFAULT_PROJECTS "clang;lld;lldb;clang-tools-extra;polly;mlir")
3434
# bolt only supports ELF, so only enable it for Linux.
3535
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
3636
list(APPEND DEFAULT_PROJECTS "bolt")
3737
endif()
3838

39+
# Don't build flang on Darwin due to:
40+
# https://github.com/llvm/llvm-project/issues/160546
41+
if (NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
42+
list(APPEND DEFAULT_PROJECTS "flang")
43+
endif()
44+
3945
set (DEFAULT_RUNTIMES "compiler-rt;libcxx")
4046
if (NOT WIN32)
4147
list(APPEND DEFAULT_RUNTIMES "libcxxabi" "libunwind")

clang/include/clang/Basic/BuiltinsARM.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ BUILTIN(__builtin_arm_cls, "UiZUi", "nc")
125125
BUILTIN(__builtin_arm_cls64, "UiWUi", "nc")
126126

127127
// Store and load exclusive
128-
BUILTIN(__builtin_arm_ldrexd, "LLUiv*", "")
129-
BUILTIN(__builtin_arm_strexd, "iLLUiv*", "")
128+
BUILTIN(__builtin_arm_ldrexd, "v.", "t")
129+
BUILTIN(__builtin_arm_strexd, "i.", "t")
130130

131131
BUILTIN(__builtin_arm_ldrex, "v.", "t")
132132
BUILTIN(__builtin_arm_ldaex, "v.", "t")

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ def warn_drv_unsupported_option_for_offload_arch_req_feature : Warning<
133133
def warn_drv_unsupported_option_for_target : Warning<
134134
"ignoring '%0' option as it is not currently supported for target '%1'">,
135135
InGroup<OptionIgnored>;
136+
def warn_drv_invalid_argument_for_flang : Warning<
137+
"'%0' is not valid for Fortran">,
138+
InGroup<OptionIgnored>;
136139
def warn_drv_unsupported_option_for_flang : Warning<
137140
"the argument '%0' is not supported for option '%1'. Mapping to '%1%2'">,
138141
InGroup<OptionIgnored>;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9405,7 +9405,7 @@ def err_atomic_exclusive_builtin_pointer_size : Error<
94059405
"%select{|,| or }7%select{|8}8"
94069406
" byte type (%0 invalid)">;
94079407
def err_atomic_exclusive_builtin_pointer_size_none : Error<
9408-
"load and store exclusive builtins are not available on this architecture">;
9408+
"%select{|eight-byte }0load and store exclusive builtins are not available on this architecture">;
94099409
def err_atomic_builtin_ext_int_size : Error<
94109410
"atomic memory operand must have a power-of-two size">;
94119411
def err_atomic_builtin_bit_int_prohibit : Error<

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ defm borland_extensions : BoolFOption<"borland-extensions",
19551955
"Accept non-standard constructs supported by the Borland compiler">,
19561956
NegFlag<SetFalse>>;
19571957
def fbuiltin : Flag<["-"], "fbuiltin">, Group<f_Group>,
1958-
Visibility<[ClangOption, CLOption, DXCOption]>;
1958+
Visibility<[ClangOption, CLOption, DXCOption, FlangOption, FC1Option]>;
19591959
def fbuiltin_module_map : Flag <["-"], "fbuiltin-module-map">, Group<f_Group>,
19601960
Flags<[]>, HelpText<"Load the clang builtins module map file.">;
19611961
defm caret_diagnostics : BoolFOption<"caret-diagnostics",
@@ -3563,7 +3563,7 @@ def fno_assume_sane_operator_new : Flag<["-"], "fno-assume-sane-operator-new">,
35633563
Visibility<[ClangOption, CC1Option]>,
35643564
MarshallingInfoNegativeFlag<CodeGenOpts<"AssumeSaneOperatorNew">>;
35653565
def fno_builtin : Flag<["-"], "fno-builtin">, Group<f_Group>,
3566-
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
3566+
Visibility<[ClangOption, CC1Option, CLOption, DXCOption, FlangOption, FC1Option]>,
35673567
HelpText<"Disable implicit builtin knowledge of functions">;
35683568
def fno_builtin_ : Joined<["-"], "fno-builtin-">, Group<f_Group>,
35693569
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,

clang/lib/AST/ByteCode/Interp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2283,7 +2283,7 @@ std::optional<Pointer> OffsetHelper(InterpState &S, CodePtr OpPC,
22832283
}
22842284
}
22852285

2286-
if (Invalid && S.getLangOpts().CPlusPlus)
2286+
if (Invalid && (S.getLangOpts().CPlusPlus || Ptr.inArray()))
22872287
return std::nullopt;
22882288

22892289
// Offset is valid - compute it on unsigned.

clang/lib/Analysis/FlowSensitive/Models/UncheckedStatusOrAccessModel.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,41 @@ static auto isPointerComparisonOperatorCall(std::string operator_name) {
177177
pointee(anyOf(statusOrType(), statusType())))))));
178178
}
179179

180+
// The nullPointerConstant in the two matchers below is to support
181+
// absl::StatusOr<void*> X = nullptr.
182+
// nullptr does not match the bound type.
183+
// TODO: be less restrictive around convertible types in general.
184+
static auto isStatusOrValueAssignmentCall() {
185+
using namespace ::clang::ast_matchers; // NOLINT: Too many names
186+
return cxxOperatorCallExpr(
187+
hasOverloadedOperatorName("="),
188+
callee(cxxMethodDecl(ofClass(statusOrClass()))),
189+
hasArgument(1, anyOf(hasType(hasUnqualifiedDesugaredType(
190+
type(equalsBoundNode("T")))),
191+
nullPointerConstant())));
192+
}
193+
194+
static auto isStatusOrValueConstructor() {
195+
using namespace ::clang::ast_matchers; // NOLINT: Too many names
196+
return cxxConstructExpr(
197+
hasType(statusOrType()),
198+
hasArgument(0,
199+
anyOf(hasType(hasCanonicalType(type(equalsBoundNode("T")))),
200+
nullPointerConstant(),
201+
hasType(namedDecl(hasAnyName("absl::in_place_t",
202+
"std::in_place_t"))))));
203+
}
204+
205+
static auto isStatusOrConstructor() {
206+
using namespace ::clang::ast_matchers; // NOLINT: Too many names
207+
return cxxConstructExpr(hasType(statusOrType()));
208+
}
209+
210+
static auto isStatusConstructor() {
211+
using namespace ::clang::ast_matchers; // NOLINT: Too many names
212+
return cxxConstructExpr(hasType(statusType()));
213+
}
214+
180215
static auto
181216
buildDiagnoseMatchSwitch(const UncheckedStatusOrAccessModelOptions &Options) {
182217
return CFGMatchSwitchBuilder<const Environment,
@@ -528,6 +563,46 @@ static void transferEmplaceCall(const CXXMemberCallExpr *Expr,
528563
State.Env.assume(OkVal.formula());
529564
}
530565

566+
static void transferValueAssignmentCall(const CXXOperatorCallExpr *Expr,
567+
const MatchFinder::MatchResult &,
568+
LatticeTransferState &State) {
569+
assert(Expr->getNumArgs() > 1);
570+
571+
auto *StatusOrLoc = State.Env.get<RecordStorageLocation>(*Expr->getArg(0));
572+
if (StatusOrLoc == nullptr)
573+
return;
574+
575+
auto &OkVal = initializeStatusOr(*StatusOrLoc, State.Env);
576+
State.Env.assume(OkVal.formula());
577+
}
578+
579+
static void transferValueConstructor(const CXXConstructExpr *Expr,
580+
const MatchFinder::MatchResult &,
581+
LatticeTransferState &State) {
582+
auto &OkVal =
583+
initializeStatusOr(State.Env.getResultObjectLocation(*Expr), State.Env);
584+
State.Env.assume(OkVal.formula());
585+
}
586+
587+
static void transferStatusOrConstructor(const CXXConstructExpr *Expr,
588+
const MatchFinder::MatchResult &,
589+
LatticeTransferState &State) {
590+
RecordStorageLocation &StatusOrLoc = State.Env.getResultObjectLocation(*Expr);
591+
RecordStorageLocation &StatusLoc = locForStatus(StatusOrLoc);
592+
593+
if (State.Env.getValue(locForOk(StatusLoc)) == nullptr)
594+
initializeStatusOr(StatusOrLoc, State.Env);
595+
}
596+
597+
static void transferStatusConstructor(const CXXConstructExpr *Expr,
598+
const MatchFinder::MatchResult &,
599+
LatticeTransferState &State) {
600+
RecordStorageLocation &StatusLoc = State.Env.getResultObjectLocation(*Expr);
601+
602+
if (State.Env.getValue(locForOk(StatusLoc)) == nullptr)
603+
initializeStatus(StatusLoc, State.Env);
604+
}
605+
531606
CFGMatchSwitch<LatticeTransferState>
532607
buildTransferMatchSwitch(ASTContext &Ctx,
533608
CFGMatchSwitchBuilder<LatticeTransferState> Builder) {
@@ -573,6 +648,20 @@ buildTransferMatchSwitch(ASTContext &Ctx,
573648
.CaseOfCFGStmt<CallExpr>(isNotOkStatusCall(), transferNotOkStatusCall)
574649
.CaseOfCFGStmt<CXXMemberCallExpr>(isStatusOrMemberCallWithName("emplace"),
575650
transferEmplaceCall)
651+
.CaseOfCFGStmt<CXXOperatorCallExpr>(isStatusOrValueAssignmentCall(),
652+
transferValueAssignmentCall)
653+
.CaseOfCFGStmt<CXXConstructExpr>(isStatusOrValueConstructor(),
654+
transferValueConstructor)
655+
// N.B. These need to come after all other CXXConstructExpr.
656+
// These are there to make sure that every Status and StatusOr object
657+
// have their ok boolean initialized when constructed. If we were to
658+
// lazily initialize them when we first access them, we can produce
659+
// false positives if that first access is in a control flow statement.
660+
// You can comment out these two constructors and see tests fail.
661+
.CaseOfCFGStmt<CXXConstructExpr>(isStatusOrConstructor(),
662+
transferStatusOrConstructor)
663+
.CaseOfCFGStmt<CXXConstructExpr>(isStatusConstructor(),
664+
transferStatusConstructor)
576665
.Build();
577666
}
578667

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,14 +713,16 @@ static void addSanitizers(const Triple &TargetTriple,
713713
ThinOrFullLTOPhase) {
714714
if (CodeGenOpts.hasSanitizeCoverage()) {
715715
auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts);
716-
MPM.addPass(SanitizerCoveragePass(
717-
SancovOpts, CodeGenOpts.SanitizeCoverageAllowlistFiles,
718-
CodeGenOpts.SanitizeCoverageIgnorelistFiles));
716+
MPM.addPass(
717+
SanitizerCoveragePass(SancovOpts, PB.getVirtualFileSystemPtr(),
718+
CodeGenOpts.SanitizeCoverageAllowlistFiles,
719+
CodeGenOpts.SanitizeCoverageIgnorelistFiles));
719720
}
720721

721722
if (CodeGenOpts.hasSanitizeBinaryMetadata()) {
722723
MPM.addPass(SanitizerBinaryMetadataPass(
723724
getSanitizerBinaryMetadataOptions(CodeGenOpts),
725+
PB.getVirtualFileSystemPtr(),
724726
CodeGenOpts.SanitizeMetadataIgnorelistFiles));
725727
}
726728

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,13 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
945945
assert(false && "Unexpected action class for Flang tool.");
946946
}
947947

948+
// We support some options that are invalid for Fortran and have no effect.
949+
// These are solely for compatibility with other compilers. Emit a warning if
950+
// any such options are provided, then proceed normally.
951+
for (options::ID Opt : {options::OPT_fbuiltin, options::OPT_fno_builtin})
952+
if (const Arg *A = Args.getLastArg(Opt))
953+
D.Diag(diag::warn_drv_invalid_argument_for_flang) << A->getSpelling();
954+
948955
const InputInfo &Input = Inputs[0];
949956
types::ID InputType = Input.getType();
950957

0 commit comments

Comments
 (0)