-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into rsqrt-in-expand-math-expect-static-shape
- Loading branch information
Showing
606 changed files
with
94,803 additions
and
7,563 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Test bolt instrumentation won't generate a binary with any segment that | ||
// is writable and executable. Basically we want to put `.bolt.instr.counters` | ||
// section into its own segment, separated from its surrounding RX sections. | ||
|
||
// REQUIRES: system-linux | ||
|
||
void foo() {} | ||
void bar() { foo(); } | ||
|
||
// RUN: %clang %cflags -c %s -o %t.o | ||
// RUN: ld.lld -q -o %t.so %t.o -shared --init=foo --fini=foo | ||
// RUN: llvm-bolt --instrument %t.so -o %tt.so | ||
// RUN: llvm-readelf -l %tt.so | FileCheck %s | ||
// CHECK-NOT: RWE | ||
// CHECK: {{[0-9]*}} .bolt.instr.counters {{$}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
//===--- UnintendedCharOstreamOutputCheck.cpp - clang-tidy ----------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "UnintendedCharOstreamOutputCheck.h" | ||
#include "clang/AST/Type.h" | ||
#include "clang/ASTMatchers/ASTMatchFinder.h" | ||
#include "clang/ASTMatchers/ASTMatchers.h" | ||
#include "clang/Basic/Diagnostic.h" | ||
#include "clang/Tooling/FixIt.h" | ||
|
||
using namespace clang::ast_matchers; | ||
|
||
namespace clang::tidy::bugprone { | ||
|
||
namespace { | ||
|
||
// check if the type is unsigned char or signed char | ||
AST_MATCHER(Type, isNumericChar) { | ||
return Node.isSpecificBuiltinType(BuiltinType::SChar) || | ||
Node.isSpecificBuiltinType(BuiltinType::UChar); | ||
} | ||
|
||
// check if the type is char | ||
AST_MATCHER(Type, isChar) { | ||
return Node.isSpecificBuiltinType(BuiltinType::Char_S) || | ||
Node.isSpecificBuiltinType(BuiltinType::Char_U); | ||
} | ||
|
||
} // namespace | ||
|
||
UnintendedCharOstreamOutputCheck::UnintendedCharOstreamOutputCheck( | ||
StringRef Name, ClangTidyContext *Context) | ||
: ClangTidyCheck(Name, Context), CastTypeName(Options.get("CastTypeName")) { | ||
} | ||
void UnintendedCharOstreamOutputCheck::storeOptions( | ||
ClangTidyOptions::OptionMap &Opts) { | ||
if (CastTypeName.has_value()) | ||
Options.store(Opts, "CastTypeName", CastTypeName.value()); | ||
} | ||
|
||
void UnintendedCharOstreamOutputCheck::registerMatchers(MatchFinder *Finder) { | ||
auto BasicOstream = | ||
cxxRecordDecl(hasName("::std::basic_ostream"), | ||
// only basic_ostream<char, Traits> has overload operator<< | ||
// with char / unsigned char / signed char | ||
classTemplateSpecializationDecl( | ||
hasTemplateArgument(0, refersToType(isChar())))); | ||
Finder->addMatcher( | ||
cxxOperatorCallExpr( | ||
hasOverloadedOperatorName("<<"), | ||
hasLHS(hasType(hasUnqualifiedDesugaredType( | ||
recordType(hasDeclaration(cxxRecordDecl( | ||
anyOf(BasicOstream, isDerivedFrom(BasicOstream)))))))), | ||
hasRHS(hasType(hasUnqualifiedDesugaredType(isNumericChar())))) | ||
.bind("x"), | ||
this); | ||
} | ||
|
||
void UnintendedCharOstreamOutputCheck::check( | ||
const MatchFinder::MatchResult &Result) { | ||
const auto *Call = Result.Nodes.getNodeAs<CXXOperatorCallExpr>("x"); | ||
const Expr *Value = Call->getArg(1); | ||
const SourceRange SourceRange = Value->getSourceRange(); | ||
|
||
DiagnosticBuilder Builder = | ||
diag(Call->getOperatorLoc(), | ||
"%0 passed to 'operator<<' outputs as character instead of integer. " | ||
"cast to 'unsigned int' to print numeric value or cast to 'char' to " | ||
"print as character") | ||
<< Value->getType() << SourceRange; | ||
|
||
QualType T = Value->getType(); | ||
const Type *UnqualifiedDesugaredType = T->getUnqualifiedDesugaredType(); | ||
|
||
llvm::StringRef CastType = CastTypeName.value_or( | ||
UnqualifiedDesugaredType->isSpecificBuiltinType(BuiltinType::SChar) | ||
? "int" | ||
: "unsigned int"); | ||
|
||
Builder << FixItHint::CreateReplacement( | ||
SourceRange, ("static_cast<" + CastType + ">(" + | ||
tooling::fixit::getText(*Value, *Result.Context) + ")") | ||
.str()); | ||
} | ||
|
||
} // namespace clang::tidy::bugprone |
38 changes: 38 additions & 0 deletions
38
clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//===--- UnintendedCharOstreamOutputCheck.h - clang-tidy --------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNINTENDEDCHAROSTREAMOUTPUTCHECK_H | ||
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNINTENDEDCHAROSTREAMOUTPUTCHECK_H | ||
|
||
#include "../ClangTidyCheck.h" | ||
#include <optional> | ||
|
||
namespace clang::tidy::bugprone { | ||
|
||
/// Finds unintended character output from `unsigned char` and `signed char` to | ||
/// an ostream. | ||
/// | ||
/// For the user-facing documentation see: | ||
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/unintended-char-ostream-output.html | ||
class UnintendedCharOstreamOutputCheck : public ClangTidyCheck { | ||
public: | ||
UnintendedCharOstreamOutputCheck(StringRef Name, ClangTidyContext *Context); | ||
void storeOptions(ClangTidyOptions::OptionMap &Opts) override; | ||
void registerMatchers(ast_matchers::MatchFinder *Finder) override; | ||
void check(const ast_matchers::MatchFinder::MatchResult &Result) override; | ||
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { | ||
return LangOpts.CPlusPlus; | ||
} | ||
|
||
private: | ||
const std::optional<StringRef> CastTypeName; | ||
}; | ||
|
||
} // namespace clang::tidy::bugprone | ||
|
||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNINTENDEDCHAROSTREAMOUTPUTCHECK_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.