Skip to content

Commit 7228131

Browse files
authored
merge main into amd-staging (llvm#1148)
2 parents f93cd42 + fe134d4 commit 7228131

File tree

164 files changed

+6225
-1030
lines changed

Some content is hidden

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

164 files changed

+6225
-1030
lines changed

clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "../utils/OptionsUtils.h"
1313
#include "clang/AST/ASTContext.h"
1414
#include "clang/ASTMatchers/ASTMatchFinder.h"
15+
#include "clang/ASTMatchers/ASTMatchers.h"
1516
#include <array>
1617

1718
using namespace clang::ast_matchers;
@@ -31,6 +32,7 @@ constexpr std::array<StringRef, 2> MakeSmartPtrList{
3132
"::std::make_unique",
3233
"::std::make_shared",
3334
};
35+
constexpr StringRef MakeOptional = "::std::make_optional";
3436

3537
} // namespace
3638

@@ -83,9 +85,26 @@ void OptionalValueConversionCheck::registerMatchers(MatchFinder *Finder) {
8385
// known template methods in std
8486
callExpr(
8587
argumentCountIs(1),
86-
callee(functionDecl(
87-
matchers::matchesAnyListedName(MakeSmartPtrList),
88-
hasTemplateArgument(0, refersToType(BindOptionalType)))),
88+
anyOf(
89+
// match std::make_unique std::make_shared
90+
callee(functionDecl(
91+
matchers::matchesAnyListedName(MakeSmartPtrList),
92+
hasTemplateArgument(
93+
0, refersToType(BindOptionalType)))),
94+
// match first std::make_optional by limit argument count
95+
// (1) and template count (1).
96+
// 1. template< class T > constexpr
97+
// std::optional<decay_t<T>> make_optional(T&& value);
98+
// 2. template< class T, class... Args > constexpr
99+
// std::optional<T> make_optional(Args&&... args);
100+
callee(functionDecl(templateArgumentCountIs(1),
101+
hasName(MakeOptional),
102+
returns(BindOptionalType)))),
103+
hasArgument(0, OptionalDerefMatcher)),
104+
callExpr(
105+
106+
argumentCountIs(1),
107+
89108
hasArgument(0, OptionalDerefMatcher))),
90109
unless(anyOf(hasAncestor(typeLoc()),
91110
hasAncestor(expr(matchers::hasUnevaluatedContext())))))

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ New check aliases
112112
Changes in existing checks
113113
^^^^^^^^^^^^^^^^^^^^^^^^^^
114114

115+
- Improved :doc:`bugprone-optional-value-conversion
116+
<clang-tidy/checks/bugprone/optional-value-conversion>` check to detect
117+
conversion in argument of ``std::make_optional``.
118+
115119
- Improved :doc:`bugprone-string-constructor
116120
<clang-tidy/checks/bugprone/string-constructor>` check to find suspicious
117121
calls of ``std::string`` constructor with char pointer, start position and

clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion-construct-from-std.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,19 @@ class unique_ptr {};
2727
template <typename type>
2828
class shared_ptr {};
2929

30+
template <typename T>
31+
class initializer_list {};
32+
3033
template <class T, class... Args> unique_ptr<T> make_unique(Args &&...args);
3134
template <class T, class... Args> shared_ptr<T> make_shared(Args &&...args);
3235

36+
template <class T>
37+
constexpr std::optional<__decay(T)> make_optional(T &&value);
38+
template <class T, class... Args>
39+
constexpr std::optional<T> make_optional(Args &&...args);
40+
template <class T, class U, class... Args>
41+
constexpr std::optional<T> make_optional(std::initializer_list<U> il, Args &&...args);
42+
3343
} // namespace std
3444

3545
struct A {
@@ -45,9 +55,12 @@ void invalid() {
4555
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: conversion from 'std::optional<int>' into 'int' and back into 'std::optional<int>', remove potentially error-prone optional dereference [bugprone-optional-value-conversion]
4656
std::make_shared<std::optional<int>>(opt.value());
4757
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: conversion from 'std::optional<int>' into 'int' and back into 'std::optional<int>', remove potentially error-prone optional dereference [bugprone-optional-value-conversion]
58+
std::make_optional(opt.value());
59+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: conversion from 'std::optional<int>' into 'int' and back into 'std::optional<int>', remove potentially error-prone optional dereference [bugprone-optional-value-conversion]
4860
}
4961

5062
void valid() {
5163
std::make_unique<A>(opt.value());
5264
std::make_shared<A>(opt.value());
65+
std::make_optional<int>(opt.value());
5366
}

clang/docs/LanguageExtensions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ of different sizes and signs is forbidden in binary and ternary builtins.
786786
T __builtin_elementwise_bitreverse(T x) return the integer represented after reversing the bits of x integer types
787787
T __builtin_elementwise_exp(T x) returns the base-e exponential, e^x, of the specified value floating point types
788788
T __builtin_elementwise_exp2(T x) returns the base-2 exponential, 2^x, of the specified value floating point types
789+
T __builtin_elementwise_exp10(T x) returns the base-10 exponential, 10^x, of the specified value floating point types
789790

790791
T __builtin_elementwise_sqrt(T x) return the square root of a floating-point number floating point types
791792
T __builtin_elementwise_roundeven(T x) round x to the nearest integer value in floating point format, floating point types

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ Non-comprehensive list of changes in this release
128128
-------------------------------------------------
129129

130130
- Support parsing the `cc` operand modifier and alias it to the `c` modifier (#GH127719).
131+
- Added `__builtin_elementwise_exp10`.
131132

132133
New Compiler Flags
133134
------------------
@@ -308,11 +309,13 @@ Bug Fixes to C++ Support
308309
- Correctly diagnoses template template paramters which have a pack parameter
309310
not in the last position.
310311
- Clang now correctly parses ``if constexpr`` expressions in immediate function context. (#GH123524)
312+
- Fixed an assertion failure affecting code that uses C++23 "deducing this". (#GH130272)
311313

312314
Bug Fixes to AST Handling
313315
^^^^^^^^^^^^^^^^^^^^^^^^^
314316
- Fixed type checking when a statement expression ends in an l-value of atomic type. (#GH106576)
315317
- Fixed uninitialized use check in a lambda within CXXOperatorCallExpr. (#GH129198)
318+
- Fixed a malformed printout of ``CXXParenListInitExpr`` in certain contexts.
316319

317320
Miscellaneous Bug Fixes
318321
^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/Expr.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,18 +3005,6 @@ class CallExpr : public Expr {
30053005
FPOptionsOverride FPFeatures, unsigned MinNumArgs = 0,
30063006
ADLCallKind UsesADL = NotADL);
30073007

3008-
/// Create a temporary call expression with no arguments in the memory
3009-
/// pointed to by Mem. Mem must points to at least sizeof(CallExpr)
3010-
/// + sizeof(Stmt *) bytes of storage, aligned to alignof(CallExpr):
3011-
///
3012-
/// \code{.cpp}
3013-
/// alignas(CallExpr) char Buffer[sizeof(CallExpr) + sizeof(Stmt *)];
3014-
/// CallExpr *TheCall = CallExpr::CreateTemporary(Buffer, etc);
3015-
/// \endcode
3016-
static CallExpr *CreateTemporary(void *Mem, Expr *Fn, QualType Ty,
3017-
ExprValueKind VK, SourceLocation RParenLoc,
3018-
ADLCallKind UsesADL = NotADL);
3019-
30203008
/// Create an empty call expression, for deserialization.
30213009
static CallExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
30223010
bool HasFPFeatures, EmptyShell Empty);

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,12 @@ def ElementwiseExp2 : Builtin {
13401340
let Prototype = "void(...)";
13411341
}
13421342

1343+
def ElementwiseExp10 : Builtin {
1344+
let Spellings = ["__builtin_elementwise_exp10"];
1345+
let Attributes = [NoThrow, Const, CustomTypeChecking];
1346+
let Prototype = "void(...)";
1347+
}
1348+
13431349
def ElementwiseFloor : Builtin {
13441350
let Spellings = ["__builtin_elementwise_floor"];
13451351
let Attributes = [NoThrow, Const, CustomTypeChecking];
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
add_subdirectory(IR)
2+
3+
set(LLVM_TARGET_DEFINITIONS Passes.td)
4+
mlir_tablegen(Passes.h.inc -gen-pass-decls -name CIR)
5+
mlir_tablegen(Passes.capi.h.inc -gen-pass-capi-header --prefix CIR)
6+
mlir_tablegen(Passes.capi.cpp.inc -gen-pass-capi-impl --prefix CIR)
7+
add_public_tablegen_target(MLIRCIRPassIncGen)

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,46 @@ def ScopeOp : CIR_Op<"scope", [
428428
];
429429
}
430430

431+
//===----------------------------------------------------------------------===//
432+
// BrOp
433+
//===----------------------------------------------------------------------===//
434+
435+
def BrOp : CIR_Op<"br",
436+
[DeclareOpInterfaceMethods<BranchOpInterface, ["getSuccessorForOperands"]>,
437+
Pure, Terminator]> {
438+
let summary = "Unconditional branch";
439+
let description = [{
440+
The `cir.br` branches unconditionally to a block. Used to represent C/C++
441+
goto's and general block branching.
442+
443+
Note that for source level `goto`'s crossing scope boundaries, those are
444+
usually represented with the "symbolic" `cir.goto` operation.
445+
446+
Example:
447+
448+
```mlir
449+
...
450+
cir.br ^bb3
451+
^bb3:
452+
cir.return
453+
```
454+
}];
455+
456+
let builders = [
457+
OpBuilder<(ins "mlir::Block *":$dest,
458+
CArg<"mlir::ValueRange", "{}">:$destOperands), [{
459+
$_state.addSuccessors(dest);
460+
$_state.addOperands(destOperands);
461+
}]>
462+
];
463+
464+
let arguments = (ins Variadic<CIR_AnyType>:$destOperands);
465+
let successors = (successor AnySuccessor:$dest);
466+
let assemblyFormat = [{
467+
$dest (`(` $destOperands^ `:` type($destOperands) `)`)? attr-dict
468+
}];
469+
}
470+
431471
//===----------------------------------------------------------------------===//
432472
// GlobalOp
433473
//===----------------------------------------------------------------------===//
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===- Passes.h - CIR pass entry points -------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This header file defines prototypes that expose pass constructors.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef CLANG_CIR_DIALECT_PASSES_H
14+
#define CLANG_CIR_DIALECT_PASSES_H
15+
16+
#include "mlir/Pass/Pass.h"
17+
18+
namespace clang {
19+
class ASTContext;
20+
}
21+
namespace mlir {
22+
23+
std::unique_ptr<Pass> createCIRFlattenCFGPass();
24+
25+
void populateCIRPreLoweringPasses(mlir::OpPassManager &pm);
26+
27+
//===----------------------------------------------------------------------===//
28+
// Registration
29+
//===----------------------------------------------------------------------===//
30+
31+
void registerCIRDialectTranslation(mlir::MLIRContext &context);
32+
33+
/// Generate the code for registering passes.
34+
#define GEN_PASS_REGISTRATION
35+
#include "clang/CIR/Dialect/Passes.h.inc"
36+
37+
} // namespace mlir
38+
39+
#endif // CLANG_CIR_DIALECT_PASSES_H

0 commit comments

Comments
 (0)