Skip to content

Commit

Permalink
Merged master:c8f1d442d085 into amd-gfx:f962ee3d4a2c
Browse files Browse the repository at this point in the history
Local branch amd-gfx f962ee3 Merged master:ce6153a5282c into amd-gfx:1f4ea6f8b241
Remote branch master c8f1d44 split darwin-version-min-load-command.s into Arm64 subtest to avoid failures
  • Loading branch information
Sw authored and Sw committed Jun 30, 2020
2 parents f962ee3 + c8f1d44 commit 0a66eff
Show file tree
Hide file tree
Showing 195 changed files with 2,983 additions and 1,560 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static const char BreakStr[] = "break";
static const char ThrowStr[] = "throw";
static const char WarningMessage[] = "do not use 'else' after '%0'";
static const char WarnOnUnfixableStr[] = "WarnOnUnfixable";
static const char WarnOnConditionVariablesStr[] = "WarnOnConditionVariables";

const DeclRefExpr *findUsage(const Stmt *Node, int64_t DeclIdentifier) {
if (!Node)
Expand Down Expand Up @@ -138,10 +139,13 @@ void removeElseAndBrackets(DiagnosticBuilder &Diag, ASTContext &Context,
ElseAfterReturnCheck::ElseAfterReturnCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
WarnOnUnfixable(Options.get(WarnOnUnfixableStr, true)) {}
WarnOnUnfixable(Options.get(WarnOnUnfixableStr, true)),
WarnOnConditionVariables(Options.get(WarnOnConditionVariablesStr, true)) {
}

void ElseAfterReturnCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, WarnOnUnfixableStr, WarnOnUnfixable);
Options.store(Opts, WarnOnConditionVariablesStr, WarnOnConditionVariables);
}

void ElseAfterReturnCheck::registerMatchers(MatchFinder *Finder) {
Expand Down Expand Up @@ -186,6 +190,8 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult &Result) {
}

if (checkConditionVarUsageInElse(If) != nullptr) {
if (!WarnOnConditionVariables)
return;
if (IsLastInScope) {
// If the if statement is the last statement its enclosing statements
// scope, we can pull the decl out of the if statement.
Expand Down Expand Up @@ -219,6 +225,8 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult &Result) {
}

if (checkInitDeclUsageInElse(If) != nullptr) {
if (!WarnOnConditionVariables)
return;
if (IsLastInScope) {
// If the if statement is the last statement its enclosing statements
// scope, we can pull the decl out of the if statement.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ElseAfterReturnCheck : public ClangTidyCheck {

private:
const bool WarnOnUnfixable;
const bool WarnOnConditionVariables;
};

} // namespace readability
Expand Down
5 changes: 5 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ Changes in existing checks

Now checks ``std::basic_string_view`` by default.

- Improved :doc:`readability-else-after-return
<clang-tidy/checks/readability-else-after-return>` check now supports a
`WarnOnConditionVariables` option to control whether to refactor condition
variables where possible.

- Improved :doc:`readability-identifier-naming
<clang-tidy/checks/readability-identifier-naming>` check.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ Would be transformed into:
}
}

Options
-------

.. option:: WarnOnUnfixable

When `true`, emit a warning for cases where the check can't output a
Fix-It. These can occur with declarations inside the ``else`` branch that
would have an extended lifetime if the ``else`` branch was removed.
Default value is `true`.

.. option:: WarnOnConditionVariables

When `true`, the check will attempt to refactor a variable defined inside
the condition of the ``if`` statement that is used in the ``else`` branch
defining them just before the ``if`` statement. This can only be done if
the ``if`` statement is the last statement in its parents scope.
Default value is `true`.

This check helps to enforce this `LLVM Coding Standards recommendation
<https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return>`_.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// RUN: %check_clang_tidy %s readability-else-after-return %t -- \
// RUN: -config='{CheckOptions: [ \
// RUN: {key: readability-else-after-return.WarnOnConditionVariables, value: false}, \
// RUN: ]}'

bool foo(int Y) {
// Excess scopes are here so that the check would have to opportunity to
// refactor the variable out of the condition.

// Expect warnings here as we don't need to move declaration of 'X' out of the
// if condition as its not used in the else.
{
if (int X = Y)
return X < 0;
else
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use 'else' after 'return'
return false;
}
{
if (int X = Y; X)
return X < 0;
else
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use 'else' after 'return'
return false;
}

// Expect no warnings for these cases, as even though its safe to move
// declaration of 'X' out of the if condition, that has been disabled
// by the options.
{
if (int X = Y)
return false;
else
return X < 0;
}
{
if (int X = Y; X)
return false;
else
return X < 0;
}
}
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticLexKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ def pp_macro_not_used : Warning<"macro is not used">, DefaultIgnore,
def warn_pp_undef_identifier : Warning<
"%0 is not defined, evaluates to 0">,
InGroup<DiagGroup<"undef">>, DefaultIgnore;
def warn_pp_undef_prefix : Warning<
"%0 is not defined, evaluates to 0">,
InGroup<DiagGroup<"undef-prefix">>, DefaultIgnore;
def warn_pp_ambiguous_macro : Warning<
"ambiguous expansion of macro %0">, InGroup<AmbiguousMacro>;
def note_pp_ambiguous_macro_chosen : Note<
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/DiagnosticOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ class DiagnosticOptions : public RefCountedBase<DiagnosticOptions>{
/// prefixes removed.
std::vector<std::string> Warnings;

/// The list of prefixes from -Wundef-prefix=... used to generate warnings
/// for undefined macros.
std::vector<std::string> UndefPrefixes;

/// The list of -R... options used to alter the diagnostic mappings, with the
/// prefixes removed.
std::vector<std::string> Remarks;
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,9 @@ def Wnonportable_cfstrings : Joined<["-"], "Wnonportable-cfstrings">, Group<W_Gr
def Wp_COMMA : CommaJoined<["-"], "Wp,">,
HelpText<"Pass the comma separated arguments in <arg> to the preprocessor">,
MetaVarName<"<arg>">, Group<Preprocessor_Group>;
def Wundef_prefix_EQ : CommaJoined<["-"], "Wundef-prefix=">, Group<W_value_Group>,
Flags<[CC1Option, CoreOption, HelpHidden]>, MetaVarName<"<arg>">,
HelpText<"Enable warnings for undefined macros with a prefix in the comma separated list <arg>">;
def Wwrite_strings : Flag<["-"], "Wwrite-strings">, Group<W_Group>, Flags<[CC1Option, HelpHidden]>;
def Wno_write_strings : Flag<["-"], "Wno-write-strings">, Group<W_Group>, Flags<[CC1Option, HelpHidden]>;
def W_Joined : Joined<["-"], "W">, Group<W_Group>, Flags<[CC1Option, CoreOption]>,
Expand Down
6 changes: 5 additions & 1 deletion clang/lib/AST/ASTImporterLookupTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ struct Builder : RecursiveASTVisitor<Builder> {
LT.add(RTy->getAsCXXRecordDecl());
else if (const auto *SpecTy = dyn_cast<TemplateSpecializationType>(Ty))
LT.add(SpecTy->getAsCXXRecordDecl());
else if (isa<TypedefType>(Ty)) {
else if (const auto *SubstTy =
dyn_cast<SubstTemplateTypeParmType>(Ty)) {
if (SubstTy->getAsCXXRecordDecl())
LT.add(SubstTy->getAsCXXRecordDecl());
} else if (isa<TypedefType>(Ty)) {
// We do not put friend typedefs to the lookup table because
// ASTImporter does not organize typedefs into redecl chains.
} else {
Expand Down
27 changes: 26 additions & 1 deletion clang/lib/Basic/Targets/AArch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,22 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
Builder.defineMacro("__ARM_FEATURE_BF16", "1");
Builder.defineMacro("__ARM_FEATURE_BF16_VECTOR_ARITHMETIC", "1");
Builder.defineMacro("__ARM_BF16_FORMAT_ALTERNATIVE", "1");
Builder.defineMacro("__ARM_FEATURE_BF16_SCALAR_ARITHMETIC", "1");
}

if ((FPU & SveMode) && HasBFloat16) {
Builder.defineMacro("__ARM_FEATURE_SVE_BF16", "1");
}

if ((FPU & SveMode) && HasMatmulFP64)
Builder.defineMacro("__ARM_FEATURE_SVE_MATMUL_FP64", "1");

if ((FPU & SveMode) && HasMatmulFP32)
Builder.defineMacro("__ARM_FEATURE_SVE_MATMUL_FP32", "1");

if ((FPU & SveMode) && HasMatMul)
Builder.defineMacro("__ARM_FEATURE_SVE_MATMUL_INT8", "1");

if ((FPU & NeonMode) && HasFP16FML)
Builder.defineMacro("__ARM_FEATURE_FP16FML", "1");

Expand Down Expand Up @@ -374,7 +388,8 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const {
(Feature == "neon" && (FPU & NeonMode)) ||
((Feature == "sve" || Feature == "sve2" || Feature == "sve2-bitperm" ||
Feature == "sve2-aes" || Feature == "sve2-sha3" ||
Feature == "sve2-sm4") &&
Feature == "sve2-sm4" || Feature == "f64mm" || Feature == "f32mm" ||
Feature == "i8mm" || Feature == "bf16") &&
(FPU & SveMode));
}

Expand All @@ -396,6 +411,8 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
HasSVE2SHA3 = false;
HasSVE2SM4 = false;
HasSVE2BitPerm = false;
HasMatmulFP64 = false;
HasMatmulFP32 = false;

ArchKind = llvm::AArch64::ArchKind::ARMV8A;

Expand Down Expand Up @@ -435,6 +452,14 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
HasSVE2 = 1;
HasSVE2BitPerm = 1;
}
if (Feature == "+f32mm") {
FPU |= SveMode;
HasMatmulFP32 = true;
}
if (Feature == "+f64mm") {
FPU |= SveMode;
HasMatmulFP64 = true;
}
if (Feature == "+crc")
HasCRC = true;
if (Feature == "+crypto")
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Basic/Targets/AArch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
bool HasSVE2SHA3;
bool HasSVE2SM4;
bool HasSVE2BitPerm;
bool HasMatmulFP64;
bool HasMatmulFP32;

llvm::AArch64::ArchKind ArchKind;

Expand Down
Loading

0 comments on commit 0a66eff

Please sign in to comment.