Skip to content

Commit

Permalink
Merge branch 'main' into selectiondag-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikHogeman authored Sep 16, 2024
2 parents 2677cef + b7e51b4 commit e632028
Show file tree
Hide file tree
Showing 699 changed files with 13,918 additions and 4,803 deletions.
9 changes: 7 additions & 2 deletions bolt/lib/Passes/ADRRelaxationPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ void ADRRelaxationPass::runOnFunction(BinaryFunction &BF) {
// Don't relax adr if it points to the same function and it is not split
// and BF initial size is < 1MB.
const unsigned OneMB = 0x100000;
if (!BF.isSplit() && BF.getSize() < OneMB) {
if (BF.getSize() < OneMB) {
BinaryFunction *TargetBF = BC.getFunctionForSymbol(Symbol);
if (TargetBF && TargetBF == &BF)
if (TargetBF == &BF && !BF.isSplit())
continue;
// No relaxation needed if ADR references a basic block in the same
// fragment.
if (BinaryBasicBlock *TargetBB = BF.getBasicBlockForLabel(Symbol))
if (BB.getFragmentNum() == TargetBB->getFragmentNum())
continue;
}

MCPhysReg Reg;
Expand Down
22 changes: 19 additions & 3 deletions clang-tools-extra/clang-tidy/cert/FloatLoopCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,38 @@
#include "FloatLoopCounter.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"

using namespace clang::ast_matchers;

namespace clang::tidy::cert {

void FloatLoopCounter::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
forStmt(hasIncrement(expr(hasType(realFloatingPointType())))).bind("for"),
forStmt(hasIncrement(forEachDescendant(
declRefExpr(hasType(realFloatingPointType()),
to(varDecl().bind("var")))
.bind("inc"))),
hasCondition(forEachDescendant(
declRefExpr(hasType(realFloatingPointType()),
to(varDecl(equalsBoundNode("var"))))
.bind("cond"))))
.bind("for"),
this);
}

void FloatLoopCounter::check(const MatchFinder::MatchResult &Result) {
const auto *FS = Result.Nodes.getNodeAs<ForStmt>("for");

diag(FS->getInc()->getExprLoc(), "loop induction expression should not have "
"floating-point type");
diag(FS->getInc()->getBeginLoc(), "loop induction expression should not have "
"floating-point type")
<< Result.Nodes.getNodeAs<DeclRefExpr>("inc")->getSourceRange()
<< Result.Nodes.getNodeAs<DeclRefExpr>("cond")->getSourceRange();

if (!FS->getInc()->getType()->isRealFloatingType())
if (const auto *V = Result.Nodes.getNodeAs<VarDecl>("var"))
diag(V->getBeginLoc(), "floating-point type loop induction variable",
DiagnosticIDs::Note);
}

} // namespace clang::tidy::cert
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static void updateAssignmentLevel(
memberExpr(hasObjectExpression(cxxThisExpr()),
member(fieldDecl(indexNotLessThan(Field->getFieldIndex()))));
auto DeclMatcher = declRefExpr(
to(varDecl(unless(parmVarDecl()), hasDeclContext(equalsNode(Ctor)))));
to(valueDecl(unless(parmVarDecl()), hasDeclContext(equalsNode(Ctor)))));
const bool HasDependence = !match(expr(anyOf(MemberMatcher, DeclMatcher,
hasDescendant(MemberMatcher),
hasDescendant(DeclMatcher))),
Expand Down
33 changes: 18 additions & 15 deletions clang-tools-extra/clang-tidy/performance/AvoidEndlCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,41 @@ void AvoidEndlCheck::check(const MatchFinder::MatchResult &Result) {
// Handle the more common streaming '... << std::endl' case
const CharSourceRange TokenRange =
CharSourceRange::getTokenRange(Expression->getSourceRange());
const StringRef SourceText = Lexer::getSourceText(
StringRef SourceText = Lexer::getSourceText(
TokenRange, *Result.SourceManager, Result.Context->getLangOpts());

if (SourceText.empty())
SourceText = "std::endl";
auto Diag = diag(Expression->getBeginLoc(),
"do not use '%0' with streams; use '\\n' instead")
<< SourceText;

Diag << FixItHint::CreateReplacement(TokenRange, "'\\n'");
if (TokenRange.isValid())
Diag << FixItHint::CreateReplacement(TokenRange, "'\\n'");
} else {
// Handle the less common function call 'std::endl(...)' case
const auto *CallExpression = llvm::cast<CallExpr>(Expression);
assert(CallExpression->getNumArgs() == 1);

const StringRef SourceText = Lexer::getSourceText(
StringRef SourceText = Lexer::getSourceText(
CharSourceRange::getTokenRange(
CallExpression->getCallee()->getSourceRange()),
*Result.SourceManager, Result.Context->getLangOpts());
if (SourceText.empty())
SourceText = "std::endl";
auto Diag = diag(CallExpression->getBeginLoc(),
"do not use '%0' with streams; use '\\n' instead")
<< SourceText;

const CharSourceRange ArgTokenRange = CharSourceRange::getTokenRange(
CallExpression->getArg(0)->getSourceRange());
const StringRef ArgSourceText = Lexer::getSourceText(
ArgTokenRange, *Result.SourceManager, Result.Context->getLangOpts());

const std::string ReplacementString =
std::string(ArgSourceText) + " << '\\n'";

diag(CallExpression->getBeginLoc(),
"do not use '%0' with streams; use '\\n' instead")
<< SourceText
<< FixItHint::CreateReplacement(
CharSourceRange::getTokenRange(CallExpression->getSourceRange()),
ReplacementString);
const CharSourceRange ReplacementRange =
CharSourceRange::getTokenRange(CallExpression->getSourceRange());
if (!ArgSourceText.empty() && ReplacementRange.isValid()) {
const std::string ReplacementString =
std::string(ArgSourceText) + " << '\\n'";
Diag << FixItHint::CreateReplacement(ReplacementRange, ReplacementString);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ TEST_F(ConfigCompileTests, DiagnosticSuppression) {
"unreachable-code", "unused-variable",
"typecheck_bool_condition",
"unexpected_friend", "warn_alloca"));
clang::DiagnosticsEngine DiagEngine(nullptr, nullptr,
clang::DiagnosticsEngine DiagEngine(new DiagnosticIDs, nullptr,
new clang::IgnoringDiagConsumer);

using Diag = clang::Diagnostic;
Expand Down
13 changes: 13 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ Changes in existing checks
<clang-tidy/checks/bugprone/casting-through-void>` check to suggest replacing
the offending code with ``reinterpret_cast``, to more clearly express intent.

- Improved :doc:`cert-flp30-c<clang-tidy/checks/cert/flp30-c>` check to
fix false positive that floating point variable is only used in increment
expression.

- Improved :doc:`cppcoreguidelines-prefer-member-initializer
<clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>` check to avoid
false positive when member initialization depends on a structured binging
variable.

- Improved :doc:`modernize-use-std-format
<clang-tidy/checks/modernize/use-std-format>` check to support replacing
member function calls too.
Expand All @@ -123,6 +132,10 @@ Changes in existing checks
<clang-tidy/checks/modernize/use-std-print>` check to support replacing
member function calls too.

- Improved :doc:`performance-avoid-endl
<clang-tidy/checks/performance/avoid-endl>` check to use ``std::endl`` as
placeholder when lexer cannot get source text.

- Improved :doc:`readability-implicit-bool-conversion
<clang-tidy/checks/readability/implicit-bool-conversion>` check
by adding the option `UseUpperCaseLiteralSuffix` to select the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ after the call. When the function returns such a parameter also as constant refe
then the returned reference can be used after the object it refers to has been
destroyed.

This issue can be resolved by declaring an overload of the problematic function
where the ``const &`` parameter is instead declared as ``&&``. The developer has
to ensure that the implementation of that function does not produce a
use-after-free, the exact error that this check is warning against.
Marking such an ``&&`` overload as ``deleted``, will silence the warning as
well. In the case of different ``const &`` parameters being returned depending
on the control flow of the function, an overload where all problematic
``const &`` parameters have been declared as ``&&`` will resolve the issue.

Example
-------

Expand Down
23 changes: 16 additions & 7 deletions clang-tools-extra/test/clang-tidy/checkers/cert/flp30-c.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
// RUN: %check_clang_tidy %s cert-flp30-c %t

float g(void);
int c(float);
float f = 1.0f;

void match(void) {

void func(void) {
for (float x = 0.1f; x <= 1.0f; x += 0.1f) {}
// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: loop induction expression should not have floating-point type [cert-flp30-c]
// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: loop induction expression should not have floating-point type [cert-flp30-c]

float f = 1.0f;
for (; f > 0; --f) {}
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: loop induction expression
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: loop induction expression should not have floating-point type [cert-flp30-c]

for (;;g()) {}
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: loop induction expression
for (float x = 0.0f; c(x); x = g()) {}
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: loop induction expression should not have floating-point type [cert-flp30-c]

for (int i = 0; i < 10; i += 1.0f) {}
for (int i=0; i < 10 && f < 2.0f; f++, i++) {}
// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: loop induction expression should not have floating-point type [cert-flp30-c]
// CHECK-MESSAGES: :5:1: note: floating-point type loop induction variable
}

void not_match(void) {
for (int i = 0; i < 10; i += 1.0f) {}
for (int i = 0; i < 10; ++i) {}
for (int i = 0; i < 10; ++i, f++) {}
for (int i = 0; f < 10.f; ++i) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -639,3 +639,14 @@ struct S3 {
T M;
};
}

namespace GH82970 {
struct InitFromBingingDecl {
int m;
InitFromBingingDecl() {
struct { int i; } a;
auto [n] = a;
m = n;
}
};
} // namespace GH82970
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,14 @@ void bad_custom_stream() {
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
// CHECK-FIXES: logger << '\n';
}

namespace gh107859 {

#define ENDL std::endl;

void bad_macro() {
std::cout << ENDL;
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
}

} // namespace gh107859
4 changes: 3 additions & 1 deletion clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ Improvements to Clang's diagnostics

- Clang now warns for u8 character literals used in C23 with ``-Wpre-c23-compat`` instead of ``-Wpre-c++17-compat``.

- Clang now diagnose when importing module implementation partition units in module interface units.

Improvements to Clang's time-trace
----------------------------------

Expand Down Expand Up @@ -499,7 +501,7 @@ AST Matchers
- Fixed an issue with the `hasName` and `hasAnyName` matcher when matching
inline namespaces with an enclosing namespace of the same name.

- Fixed an ordering issue with the `hasOperands` matcher occuring when setting a
- Fixed an ordering issue with the `hasOperands` matcher occurring when setting a
binding in the first matcher and using it in the second matcher.

clang-format
Expand Down
33 changes: 33 additions & 0 deletions clang/docs/UsersManual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2410,6 +2410,39 @@ are listed below.
link-time optimizations like whole program inter-procedural basic block
reordering.

.. option:: -fcodegen-data-generate[=<path>]

Emit the raw codegen (CG) data into custom sections in the object file.
Currently, this option also combines the raw CG data from the object files
into an indexed CG data file specified by the <path>, for LLD MachO only.
When the <path> is not specified, `default.cgdata` is created.
The CG data file combines all the outlining instances that occurred locally
in each object file.

.. code-block:: console
$ clang -fuse-ld=lld -Oz -fcodegen-data-generate code.cc
For linkers that do not yet support this feature, `llvm-cgdata` can be used
manually to merge this CG data in object files.

.. code-block:: console
$ clang -c -fuse-ld=lld -Oz -fcodegen-data-generate code.cc
$ llvm-cgdata --merge -o default.cgdata code.o
.. option:: -fcodegen-data-use[=<path>]

Read the codegen data from the specified path to more effectively outline
functions across compilation units. When the <path> is not specified,
`default.cgdata` is used. This option can create many identically outlined
functions that can be optimized by the conventional linker’s identical code
folding (ICF).

.. code-block:: console
$ clang -fuse-ld=lld -Oz -Wl,--icf=safe -fcodegen-data-use code.cc
Profile Guided Optimization
---------------------------

Expand Down
4 changes: 2 additions & 2 deletions clang/docs/analyzer/checkers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2571,8 +2571,8 @@ with the `offsetof` macro.
.. _alpha-core-StackAddressAsyncEscape:
alpha.core.StackAddressAsyncEscape (C)
""""""""""""""""""""""""""""""""""""""
alpha.core.StackAddressAsyncEscape (ObjC)
"""""""""""""""""""""""""""""""""""""""""
Check that addresses to stack memory do not escape the function that involves dispatch_after or dispatch_async.
This checker is a part of ``core.StackAddressEscape``, but is temporarily disabled until some false positives are fixed.
Expand Down
6 changes: 4 additions & 2 deletions clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,11 @@ bool RecursiveASTVisitor<Derived>::PostVisitStmt(Stmt *S) {

#undef DISPATCH_STMT

// Inlining this method can lead to large code size and compile-time increases
// without any benefit to runtime performance.
template <typename Derived>
bool RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S,
DataRecursionQueue *Queue) {
LLVM_ATTRIBUTE_NOINLINE bool
RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S, DataRecursionQueue *Queue) {
if (!S)
return true;

Expand Down
12 changes: 4 additions & 8 deletions clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,10 @@ class FunctionParmMutationAnalyzer {
static FunctionParmMutationAnalyzer *
getFunctionParmMutationAnalyzer(const FunctionDecl &Func, ASTContext &Context,
ExprMutationAnalyzer::Memoized &Memorized) {
auto it = Memorized.FuncParmAnalyzer.find(&Func);
if (it == Memorized.FuncParmAnalyzer.end())
it =
Memorized.FuncParmAnalyzer
.try_emplace(&Func, std::unique_ptr<FunctionParmMutationAnalyzer>(
new FunctionParmMutationAnalyzer(
Func, Context, Memorized)))
.first;
auto [it, Inserted] = Memorized.FuncParmAnalyzer.try_emplace(&Func);
if (Inserted)
it->second = std::unique_ptr<FunctionParmMutationAnalyzer>(
new FunctionParmMutationAnalyzer(Func, Context, Memorized));
return it->getSecond().get();
}

Expand Down
4 changes: 3 additions & 1 deletion clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -1535,8 +1535,10 @@ def PedanticMacros : DiagGroup<"pedantic-macros",
def BranchProtection : DiagGroup<"branch-protection">;

// HLSL diagnostic groups
def HLSL202y : DiagGroup<"hlsl-202y-extensions">;

// Warnings for HLSL Clang extensions
def HLSLExtension : DiagGroup<"hlsl-extensions">;
def HLSLExtension : DiagGroup<"hlsl-extensions", [HLSL202y]>;

// Warning for mix packoffset and non-packoffset.
def HLSLMixPackOffset : DiagGroup<"mix-packoffset">;
Expand Down
5 changes: 4 additions & 1 deletion clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,10 @@ def err_expected_lambda_body : Error<"expected body of lambda expression">;
def warn_cxx98_compat_lambda : Warning<
"lambda expressions are incompatible with C++98">,
InGroup<CXX98Compat>, DefaultIgnore;
def ext_lambda : ExtWarn<"lambdas are a C++11 extension">, InGroup<CXX11>;
def ext_lambda : ExtWarn<"lambdas are a %select{C++11|clang HLSL}0 extension">,
InGroup<CXX11>;
def ext_hlsl_lambda : ExtWarn<ext_lambda.Summary>,
InGroup<HLSLExtension>;
def err_lambda_decl_specifier_repeated : Error<
"%select{'mutable'|'static'|'constexpr'|'consteval'}0 cannot "
"appear multiple times in a lambda declarator">;
Expand Down
9 changes: 8 additions & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ def err_invalid_width_spec : Error<
def err_invalid_complex_spec : Error<"'_Complex %0' is invalid">;

def ext_auto_type_specifier : ExtWarn<
"'auto' type specifier is a C++11 extension">, InGroup<CXX11>;
"'auto' type specifier is a %select{C++11|HLSL 202y}0 extension">,
InGroup<CXX11>;
def ext_hlsl_auto_type_specifier : ExtWarn<
ext_auto_type_specifier.Summary>, InGroup<HLSL202y>;
def warn_auto_storage_class : Warning<
"'auto' storage class specifier is redundant and incompatible with C++11">,
InGroup<CXX11Compat>, DefaultIgnore;
Expand Down Expand Up @@ -439,6 +442,10 @@ def warn_deprecated_literal_operator_id: Warning<
"is deprecated">, InGroup<DeprecatedLiteralOperator>, DefaultIgnore;
def warn_reserved_module_name : Warning<
"%0 is a reserved name for a module">, InGroup<ReservedModuleIdentifier>;
def warn_import_implementation_partition_unit_in_interface_unit : Warning<
"importing an implementation partition unit in a module interface is not recommended. "
"Names from %0 may not be reachable">,
InGroup<DiagGroup<"import-implementation-partition-unit-in-interface-unit">>;

def warn_parameter_size: Warning<
"%0 is a large (%1 bytes) pass-by-value argument; "
Expand Down
Loading

0 comments on commit e632028

Please sign in to comment.