Skip to content

Commit 8b46380

Browse files

File tree

94 files changed

+2250
-283
lines changed

Some content is hidden

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

94 files changed

+2250
-283
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ def warn_drv_unsupported_option_for_offload_arch_req_feature : Warning<
136136
def warn_drv_unsupported_option_for_target : Warning<
137137
"ignoring '%0' option as it is not currently supported for target '%1'">,
138138
InGroup<OptionIgnored>;
139+
def warn_drv_invalid_argument_for_flang : Warning<
140+
"'%0' is not valid for Fortran">,
141+
InGroup<OptionIgnored>;
139142
def warn_drv_unsupported_option_for_flang : Warning<
140143
"the argument '%0' is not supported for option '%1'. Mapping to '%1%2'">,
141144
InGroup<OptionIgnored>;

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,7 @@ defm borland_extensions : BoolFOption<"borland-extensions",
19641964
"Accept non-standard constructs supported by the Borland compiler">,
19651965
NegFlag<SetFalse>>;
19661966
def fbuiltin : Flag<["-"], "fbuiltin">, Group<f_Group>,
1967-
Visibility<[ClangOption, CLOption, DXCOption]>;
1967+
Visibility<[ClangOption, CLOption, DXCOption, FlangOption, FC1Option]>;
19681968
def fbuiltin_module_map : Flag <["-"], "fbuiltin-module-map">, Group<f_Group>,
19691969
Flags<[]>, HelpText<"Load the clang builtins module map file.">;
19701970
defm caret_diagnostics : BoolFOption<"caret-diagnostics",
@@ -3572,7 +3572,7 @@ def fno_assume_sane_operator_new : Flag<["-"], "fno-assume-sane-operator-new">,
35723572
Visibility<[ClangOption, CC1Option]>,
35733573
MarshallingInfoNegativeFlag<CodeGenOpts<"AssumeSaneOperatorNew">>;
35743574
def fno_builtin : Flag<["-"], "fno-builtin">, Group<f_Group>,
3575-
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
3575+
Visibility<[ClangOption, CC1Option, CLOption, DXCOption, FlangOption, FC1Option]>,
35763576
HelpText<"Disable implicit builtin knowledge of functions">;
35773577
def fno_builtin_ : Joined<["-"], "fno-builtin-">, Group<f_Group>,
35783578
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,

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
@@ -953,6 +953,13 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
953953
assert(false && "Unexpected action class for Flang tool.");
954954
}
955955

956+
// We support some options that are invalid for Fortran and have no effect.
957+
// These are solely for compatibility with other compilers. Emit a warning if
958+
// any such options are provided, then proceed normally.
959+
for (options::ID Opt : {options::OPT_fbuiltin, options::OPT_fno_builtin})
960+
if (const Arg *A = Args.getLastArg(Opt))
961+
D.Diag(diag::warn_drv_invalid_argument_for_flang) << A->getSpelling();
962+
956963
const InputInfo &Input = Inputs[0];
957964
types::ID InputType = Input.getType();
958965

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
288288
ArrayRef<unsigned> Matches,
289289
SmallVector<WhitespaceManager::Change, 16> &Changes) {
290290
int Shift = 0;
291+
// Set when the shift is applied anywhere in the line. Cleared when the line
292+
// ends.
293+
bool LineShifted = false;
291294

292295
// ScopeStack keeps track of the current scope depth. It contains the levels
293296
// of at most 2 scopes. The first one is the one that the matched token is
@@ -339,8 +342,11 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
339342
Changes[i - 1].Tok->is(tok::string_literal);
340343
bool SkipMatchCheck = InsideNestedScope || ContinuedStringLiteral;
341344

342-
if (CurrentChange.NewlinesBefore > 0 && !SkipMatchCheck)
343-
Shift = 0;
345+
if (CurrentChange.NewlinesBefore > 0) {
346+
LineShifted = false;
347+
if (!SkipMatchCheck)
348+
Shift = 0;
349+
}
344350

345351
// If this is the first matching token to be aligned, remember by how many
346352
// spaces it has to be shifted, so the rest of the changes on the line are
@@ -349,7 +355,6 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
349355
Shift = Column - (RightJustify ? CurrentChange.TokenLength : 0) -
350356
CurrentChange.StartOfTokenColumn;
351357
ScopeStack = {CurrentChange.indentAndNestingLevel()};
352-
CurrentChange.Spaces += Shift;
353358
}
354359

355360
if (Shift == 0)
@@ -358,8 +363,10 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
358363
// This is for lines that are split across multiple lines, as mentioned in
359364
// the ScopeStack comment. The stack size being 1 means that the token is
360365
// not in a scope that should not move.
361-
if (ScopeStack.size() == 1u && CurrentChange.NewlinesBefore > 0 &&
362-
(ContinuedStringLiteral || InsideNestedScope)) {
366+
if ((!Matches.empty() && Matches[0] == i) ||
367+
(ScopeStack.size() == 1u && CurrentChange.NewlinesBefore > 0 &&
368+
(ContinuedStringLiteral || InsideNestedScope))) {
369+
LineShifted = true;
363370
CurrentChange.Spaces += Shift;
364371
}
365372

@@ -369,9 +376,11 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
369376
static_cast<int>(Changes[i].Tok->SpacesRequiredBefore) ||
370377
CurrentChange.Tok->is(tok::eof));
371378

372-
CurrentChange.StartOfTokenColumn += Shift;
373-
if (i + 1 != Changes.size())
374-
Changes[i + 1].PreviousEndOfTokenColumn += Shift;
379+
if (LineShifted) {
380+
CurrentChange.StartOfTokenColumn += Shift;
381+
if (i + 1 != Changes.size())
382+
Changes[i + 1].PreviousEndOfTokenColumn += Shift;
383+
}
375384

376385
// If PointerAlignment is PAS_Right, keep *s or &s next to the token,
377386
// except if the token is equal, then a space is needed.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Checks basic debug-info generation for property. Makes sure we
2+
// create a DIObjCProperty for the synthesized property.
3+
4+
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
5+
6+
// CHECK: !DIObjCProperty(name: "p1"
7+
// CHECK-SAME: attributes: 2316
8+
// CHECK-SAME: type: ![[P1_TYPE:[0-9]+]]
9+
//
10+
// CHECK: ![[P1_TYPE]] = !DIBasicType(name: "int"
11+
12+
@interface I1 {
13+
int p1;
14+
}
15+
@property int p1;
16+
@end
17+
18+
@implementation I1
19+
@synthesize p1;
20+
@end

clang/test/DebugInfo/ObjC/property.m

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# objective-CXX is not supported on AIX and zOS
2+
unsupported_platforms = [ "system-aix", "system-zos" ]
3+
4+
if any(up in config.available_features for up in unsupported_platforms):
5+
config.unsupported = True

0 commit comments

Comments
 (0)