Skip to content

Commit

Permalink
merge master into amd-stg-open
Browse files Browse the repository at this point in the history
Change-Id: I051cd8b5ebeff6219d9abd9477466101e2be9548
  • Loading branch information
ssahasra committed Feb 20, 2020
2 parents e585a28 + d6d640e commit 54cdcbb
Show file tree
Hide file tree
Showing 964 changed files with 34,680 additions and 12,483 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <algorithm>
#include <cctype>

// FixItHint

using namespace clang::ast_matchers;

namespace clang {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ void UnconventionalAssignOperatorCheck::registerMatchers(
anyOf(unaryOperator(hasOperatorName("*"), hasUnaryOperand(cxxThisExpr())),
cxxOperatorCallExpr(argumentCountIs(1),
callee(unresolvedLookupExpr()),
hasArgument(0, cxxThisExpr())))))));
hasArgument(0, cxxThisExpr())),
cxxOperatorCallExpr(
hasOverloadedOperatorName("="),
hasArgument(
0, unaryOperator(hasOperatorName("*"),
hasUnaryOperand(cxxThisExpr())))))))));
const auto IsGoodAssign = cxxMethodDecl(IsAssign, HasGoodReturnType);

Finder->addMatcher(returnStmt(IsBadReturnStatement, forFunction(IsGoodAssign))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#define DEBUG_TYPE "clang-tidy"

// FixItHint

using namespace clang::ast_matchers;

namespace clang {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,55 @@ formatDereference(const ast_matchers::MatchFinder::MatchResult &Result,
return (llvm::Twine("*") + Text).str();
}

// Trying to get CallExpr in which CxxConstructExpr is called.
static const clang::CallExpr *
tryGetCallExprAncestorForCxxConstructExpr(const Expr *TheExpr,
ASTContext &Context) {
// We skip nodes such as CXXBindTemporaryExpr, MaterializeTemporaryExpr.
for (ast_type_traits::DynTypedNode DynParent : Context.getParents(*TheExpr)) {
if (const auto *Parent = DynParent.get<Expr>()) {
if (const auto *TheCallExpr = dyn_cast<CallExpr>(Parent))
return TheCallExpr;

if (const clang::CallExpr *TheCallExpr =
tryGetCallExprAncestorForCxxConstructExpr(Parent, Context))
return TheCallExpr;
}
}

return nullptr;
}

// Check that ParamDecl of CallExprDecl has rvalue type.
static bool checkParamDeclOfAncestorCallExprHasRValueRefType(
const Expr *TheCxxConstructExpr, ASTContext &Context) {
if (const clang::CallExpr *TheCallExpr =
tryGetCallExprAncestorForCxxConstructExpr(TheCxxConstructExpr,
Context)) {
for (unsigned i = 0; i < TheCallExpr->getNumArgs(); ++i) {
const Expr *Arg = TheCallExpr->getArg(i);
if (Arg->getSourceRange() == TheCxxConstructExpr->getSourceRange()) {
if (const auto *TheCallExprFuncProto =
TheCallExpr->getCallee()
->getType()
->getPointeeType()
->getAs<FunctionProtoType>()) {
if (TheCallExprFuncProto->getParamType(i)->isRValueReferenceType())
return true;
}
}
}
}

return false;
}

AST_MATCHER(CXXConstructExpr,
matchedParamDeclOfAncestorCallExprHasRValueRefType) {
return checkParamDeclOfAncestorCallExprHasRValueRefType(
&Node, Finder->getASTContext());
}

} // end namespace

void RedundantStringCStrCheck::registerMatchers(
Expand Down Expand Up @@ -95,9 +144,13 @@ void RedundantStringCStrCheck::registerMatchers(
.bind("call");

// Detect redundant 'c_str()' calls through a string constructor.
Finder->addMatcher(cxxConstructExpr(StringConstructorExpr,
hasArgument(0, StringCStrCallExpr)),
this);
// If CxxConstructExpr is the part of some CallExpr we need to
// check that matched ParamDecl of the ancestor CallExpr is not rvalue.
Finder->addMatcher(
cxxConstructExpr(
StringConstructorExpr, hasArgument(0, StringCStrCallExpr),
unless(matchedParamDeclOfAncestorCallExprHasRValueRefType())),
this);

// Detect: 's == str.c_str()' -> 's == str'
Finder->addMatcher(
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/ClangdLSPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
{"codeActionProvider", std::move(CodeActionProvider)},
{"completionProvider",
llvm::json::Object{
{"allCommitCharacters", " \t()[]{}<>:;,+-/*%^&#?.=\"'|"},
{"resolveProvider", false},
// We do extra checks for '>' and ':' in completion to only
// trigger on '->' and '::'.
Expand Down
2 changes: 2 additions & 0 deletions clang-tools-extra/clangd/Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,8 @@ struct CompletionItem {
/// the client side.
float score = 0.f;

// TODO: Add custom commitCharacters for some of the completion items. For
// example, it makes sense to use () only for the functions.
// TODO(krasimir): The following optional fields defined by the language
// server protocol are unsupported:
//
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/test/initialize-params.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# CHECK-NEXT: "capabilities": {
# CHECK-NEXT: "codeActionProvider": true,
# CHECK-NEXT: "completionProvider": {
# CHECK-NEXT: "allCommitCharacters": " \t()[]{}<>:;,+-/*%^&#?.=\"'|",
# CHECK-NEXT: "resolveProvider": false,
# CHECK-NEXT: "triggerCharacters": [
# CHECK-NEXT: ".",
Expand Down
5 changes: 4 additions & 1 deletion clang-tools-extra/docs/clang-tidy/checks/list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Clang-Tidy Checks
`bugprone-not-null-terminated-result <bugprone-not-null-terminated-result.html>`_, "Yes"
`bugprone-parent-virtual-call <bugprone-parent-virtual-call.html>`_, "Yes"
`bugprone-posix-return <bugprone-posix-return.html>`_, "Yes"
`bugprone-reserved-identifier <bugprone-reserved-identifier.html>`_, "Yes"
`bugprone-signed-char-misuse <bugprone-signed-char-misuse.html>`_,
`bugprone-sizeof-container <bugprone-sizeof-container.html>`_,
`bugprone-sizeof-expression <bugprone-sizeof-expression.html>`_,
Expand Down Expand Up @@ -189,7 +190,7 @@ Clang-Tidy Checks
`misc-definitions-in-headers <misc-definitions-in-headers.html>`_, "Yes"
`misc-misplaced-const <misc-misplaced-const.html>`_,
`misc-new-delete-overloads <misc-new-delete-overloads.html>`_,
`misc-no-recursion <misc-no-recursion>`_,
`misc-no-recursion <misc-no-recursion.html>`_,
`misc-non-copyable-objects <misc-non-copyable-objects.html>`_,
`misc-non-private-member-variables-in-classes <misc-non-private-member-variables-in-classes.html>`_,
`misc-redundant-expression <misc-redundant-expression.html>`_, "Yes"
Expand Down Expand Up @@ -299,6 +300,8 @@ Clang-Tidy Checks

`cert-dcl03-c <cert-dcl03-c.html>`_, `misc-static-assert <misc-static-assert.html>`_, "Yes"
`cert-dcl16-c <cert-dcl16-c.html>`_, `readability-uppercase-literal-suffix <readability-uppercase-literal-suffix.html>`_, "Yes"
`cert-dcl37-c <cert-dcl37-c.html>`_, `bugprone-reserved-identifier <bugprone-reserved-identifier.html>`_, "Yes"
`cert-dcl51-cpp <cert-dcl51-cpp.html>`_, `bugprone-reserved-identifier <bugprone-reserved-identifier.html>`_, "Yes"
`cert-dcl54-cpp <cert-dcl54-cpp.html>`_, `misc-new-delete-overloads <misc-new-delete-overloads.html>`_,
`cert-dcl59-cpp <cert-dcl59-cpp.html>`_, `google-build-namespaces <google-build-namespaces.html>`_,
`cert-err09-cpp <cert-err09-cpp.html>`_, `misc-throw-by-value-catch-by-reference <misc-throw-by-value-catch-by-reference.html>`_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,21 @@ struct Template {

Template<int> TemplateInt;
}

struct AssignmentCallAtReturn {
AssignmentCallAtReturn &returnThis() {
return *this;
}
AssignmentCallAtReturn &operator=(int rhs) {
return *this;
}
AssignmentCallAtReturn &operator=(char rhs) {
// Allow call to assignment from other type.
return (*this = static_cast<int>(rhs));
}
AssignmentCallAtReturn &operator=(float rhs) {
// Do not allow calls to other functions.
return returnThis();
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: operator=() should always return '*this'
}
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %check_clang_tidy -std=c++11,c++14,c++17 %s modernize-use-default-member-init %t
// RUN: %check_clang_tidy -std=c++11,c++14,c++17 %s modernize-use-default-member-init %t -- -- -fexceptions
// FIXME: Fix the checker to work in C++2a mode.

struct S {
Expand Down Expand Up @@ -418,3 +418,17 @@ NegativeTemplateExisting<double> nted(0);
};

MACRO();


class FunctionTryBlock {
public:
FunctionTryBlock() try : i(5), k(8) {}
// CHECK-FIXES: FunctionTryBlock() try {}
catch (...) {}

private:
int i, k;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'i' [modernize-use-default-member-init]
// CHECK-MESSAGES: :[[@LINE-2]]:10: warning: use default member initializer for 'k' [modernize-use-default-member-init]
// CHECK-FIXES: int i{5}, k{8};
};
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,18 @@ void dummy(const char*) {}
void invalid(const NotAString &s) {
dummy(s.c_str());
}

// Test for rvalue std::string.
void m1(std::string&&) {
std::string s;

m1(s.c_str());

void (*m1p1)(std::string&&);
m1p1 = m1;
m1p1(s.c_str());

using m1tp = void (*)(std::string &&);
m1tp m1p2 = m1;
m1p2(s.c_str());
}
2 changes: 1 addition & 1 deletion clang/docs/LanguageExtensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ of ``cxx_rvalue_references``.
``__has_cpp_attribute``
-----------------------

This function-like macro is available in C++2a by default, and is provided as an
This function-like macro is available in C++20 by default, and is provided as an
extension in earlier language standards. It takes a single argument that is the
name of a double-square-bracket-style attribute. The argument can either be a
single identifier or a scoped identifier. If the attribute is supported, a
Expand Down
48 changes: 3 additions & 45 deletions clang/docs/UsersManual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1190,50 +1190,8 @@ installed.
Controlling Floating Point Behavior
-----------------------------------

Clang provides a number of ways to control floating point behavior, including
with command line options and source pragmas. This section
describes the various floating point semantic modes and the corresponding options.

.. csv-table:: Floating Point Semantic Modes
:header: "Mode", "Values"
:widths: 15, 30, 30

"except_behavior", "{ignore, strict, may_trap}", "ffp-exception-behavior"
"fenv_access", "{off, on}", "(none)"
"rounding_mode", "{dynamic, tonearest, downward, upward, towardzero}", "frounding-math"
"contract", "{on, off, fast}", "ffp-contract"
"denormal_fp_math", "{IEEE, PreserveSign, PositiveZero}", "fdenormal-fp-math"
"denormal_fp32_math", "{IEEE, PreserveSign, PositiveZero}", "fdenormal-fp-math-fp32"
"support_math_errno", "{on, off}", "fmath-errno"
"no_honor_nans", "{on, off}", "fhonor-nans"
"no_honor_infinities", "{on, off}", "fhonor-infinities"
"no_signed_zeros", "{on, off}", "fsigned-zeros"
"allow_reciprocal", "{on, off}", "freciprocal-math"
"allow_approximate_fns", "{on, off}", "(none)"
"allow_reassociation", "{on, off}", "fassociative-math"


This table describes the option settings that correspond to the three
floating point semantic models: precise (the default), strict, and fast.


.. csv-table:: Floating Point Models
:header: "Mode", "Precise", "Strict", "Fast"
:widths: 25, 15, 15, 15

"except_behavior", "ignore", "strict", "ignore"
"fenv_access", "off", "on", "off"
"rounding_mode", "tonearest", "dynamic", "tonearest"
"contract", "on", "off", "fast"
"denormal_fp_math", "IEEE", "IEEE", "PreserveSign"
"denormal_fp32_math", "IEEE","IEEE", "PreserveSign"
"support_math_errno", "on", "on", "off"
"no_honor_nans", "off", "off", "on"
"no_honor_infinities", "off", "off", "on"
"no_signed_zeros", "off", "off", "on"
"allow_reciprocal", "off", "off", "on"
"allow_approximate_fns", "off", "off", "on"
"allow_reassociation", "off", "off", "on"
Clang provides a number of ways to control floating point behavior. The options
are listed below.

.. option:: -ffast-math

Expand Down Expand Up @@ -1427,7 +1385,7 @@ Note that floating-point operations performed as part of constant initialization
and ``fast``.
Details:

* ``precise`` Disables optimizations that are not value-safe on floating-point data, although FP contraction (FMA) is enabled (``-ffp-contract=on``). This is the default behavior.
* ``precise`` Disables optimizations that are not value-safe on floating-point data, although FP contraction (FMA) is enabled (``-ffp-contract=fast``). This is the default behavior.
* ``strict`` Enables ``-frounding-math`` and ``-ffp-exception-behavior=strict``, and disables contractions (FMA). All of the ``-ffast-math`` enablements are disabled.
* ``fast`` Behaves identically to specifying both ``-ffast-math`` and ``ffp-contract=fast``

Expand Down
32 changes: 32 additions & 0 deletions clang/docs/analyzer/checkers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1929,6 +1929,38 @@ Warns against using one vs. many plural pattern in code when generating localize
alpha.security
^^^^^^^^^^^^^^
alpha.security.cert
^^^^^^^^^^^^^^^^^^^
SEI CERT checkers which tries to find errors based on their `C coding rules<https://wiki.sei.cmu.edu/confluence/display/c/2+Rules>`_.
.. _alpha-security-cert-pos-checkers:
alpha.security.cert.pos
^^^^^^^^^^^^^^^^^^^^^^^
SEI CERT checkers of POSIX `C coding rules<https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152405>`_.
.. _alpha-security-cert-pos-34c:
alpha.security.cert.pos.34c
"""""""""""""""""""""""""""
Finds calls to the ``putenv`` function which pass a pointer to an automatic variable as the argument.
.. code-block:: c
int func(const char *var) {
char env[1024];
int retval = snprintf(env, sizeof(env),"TEST=%s", var);
if (retval < 0 || (size_t)retval >= sizeof(env)) {
/* Handle error */
}
return putenv(env); // putenv function should not be called with auto variables
}
.. _alpha-security-ArrayBound:
alpha.security.ArrayBound (C)
Expand Down
2 changes: 1 addition & 1 deletion clang/examples/clang-interpreter/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SimpleJIT {
std::unique_ptr<TargetMachine> TM;
const DataLayout DL;
MangleAndInterner Mangle{ES, DL};
JITDylib &MainJD{ES.createJITDylib("<main>")};
JITDylib &MainJD{ES.createBareJITDylib("<main>")};
RTDyldObjectLinkingLayer ObjectLayer{ES, createMemMgr};
IRCompileLayer CompileLayer{ES, ObjectLayer,
std::make_unique<SimpleCompiler>(*TM)};
Expand Down
20 changes: 13 additions & 7 deletions clang/include/clang-c/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@

LLVM_CLANG_C_EXTERN_C_BEGIN

/* MSVC DLL import/export. */
#ifdef _MSC_VER
#ifdef _CINDEX_LIB_
#define CINDEX_LINKAGE __declspec(dllexport)
#else
#define CINDEX_LINKAGE __declspec(dllimport)
/* Windows DLL import/export. */
#ifdef _WIN32
#ifdef CINDEX_EXPORTS
#ifdef _CINDEX_LIB_
#define CINDEX_LINKAGE __declspec(dllexport)
#else
#define CINDEX_LINKAGE __declspec(dllimport)
#endif
#endif
#else
#elif defined(CINDEX_EXPORTS)
#define CINDEX_LINKAGE __attribute__((visibility("default")))
#endif

#ifndef CINDEX_LINKAGE
#define CINDEX_LINKAGE
#endif

Expand Down
16 changes: 8 additions & 8 deletions clang/include/clang/Basic/BuiltinsHexagon.def
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ TARGET_BUILTIN(__builtin_HEXAGON_S2_storerd_pcr, "vv*iLLivC*", "", V5)
TARGET_BUILTIN(__builtin_HEXAGON_prefetch,"vv*","", V5)
TARGET_BUILTIN(__builtin_HEXAGON_A6_vminub_RdP,"LLiLLiLLi","", V62)

TARGET_BUILTIN(__builtin_HEXAGON_V6_vmaskedstoreq,"vV16iv*V16i","", HVXV60)
TARGET_BUILTIN(__builtin_HEXAGON_V6_vmaskedstorenq,"vV16iv*V16i","", HVXV60)
TARGET_BUILTIN(__builtin_HEXAGON_V6_vmaskedstorentq,"vV16iv*V16i","", HVXV60)
TARGET_BUILTIN(__builtin_HEXAGON_V6_vmaskedstorentnq,"vV16iv*V16i","", HVXV60)
TARGET_BUILTIN(__builtin_HEXAGON_V6_vmaskedstoreq_128B,"vV32iv*V32i","", HVXV60)
TARGET_BUILTIN(__builtin_HEXAGON_V6_vmaskedstorenq_128B,"vV32iv*V32i","", HVXV60)
TARGET_BUILTIN(__builtin_HEXAGON_V6_vmaskedstorentq_128B,"vV32iv*V32i","", HVXV60)
TARGET_BUILTIN(__builtin_HEXAGON_V6_vmaskedstorentnq_128B,"vV32iv*V32i","", HVXV60)
TARGET_BUILTIN(__builtin_HEXAGON_V6_vmaskedstoreq,"vV64bv*V16i","", HVXV60)
TARGET_BUILTIN(__builtin_HEXAGON_V6_vmaskedstorenq,"vV64bv*V16i","", HVXV60)
TARGET_BUILTIN(__builtin_HEXAGON_V6_vmaskedstorentq,"vV64bv*V16i","", HVXV60)
TARGET_BUILTIN(__builtin_HEXAGON_V6_vmaskedstorentnq,"vV64bv*V16i","", HVXV60)
TARGET_BUILTIN(__builtin_HEXAGON_V6_vmaskedstoreq_128B,"vV128bv*V32i","", HVXV60)
TARGET_BUILTIN(__builtin_HEXAGON_V6_vmaskedstorenq_128B,"vV128bv*V32i","", HVXV60)
TARGET_BUILTIN(__builtin_HEXAGON_V6_vmaskedstorentq_128B,"vV128bv*V32i","", HVXV60)
TARGET_BUILTIN(__builtin_HEXAGON_V6_vmaskedstorentnq_128B,"vV128bv*V32i","", HVXV60)


// These are only valid on v65
Expand Down
Loading

0 comments on commit 54cdcbb

Please sign in to comment.