Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
59ed6df
[LLVM][CodeGen][SVE] Use DUPM for constantfp splats. (#168391)
paulwalker-arm Nov 18, 2025
22a2cae
[Clang] Fix cleanup attribute by delaying type checks after the type …
to268 Nov 18, 2025
0be4218
[CMake] Declare all parts of *GenRegisterInfo.inc as outputs. (#168405)
kosarev Nov 18, 2025
3c87119
[TableGen][NFCI] Change TableGenMain() to take function_ref. (#167888)
kosarev Nov 18, 2025
4c9020d
[ORC] Fix shlibs build: add Object to libLLVMOrcDebugging (#168343)
weliveindetail Nov 18, 2025
52f4c36
[X86] combineTruncate - trunc(srl(load(p),amt)) -> load(p+amt/8) - en…
RKSimon Nov 18, 2025
3d5d32c
[CGP]: Optimize mul.overflow. (#148343)
hassnaaHamdi Nov 18, 2025
c61c5d2
[mlir][tosa] Add a pass to narrow i64 to i32 (#165581)
lhutton1 Nov 18, 2025
c771159
[RTSan] Fix tests under Internal Shell (#168470)
boomanaiden154 Nov 18, 2025
e9f74df
[BAZEL] Fix BAZEL build issue (#168539)
lialan Nov 18, 2025
38891ba
[mlir][tosa] Fix shared build
darkbuck Nov 18, 2025
65c4a53
[OpenMP] Implement omp_get_uid_from_device() / omp_get_device_from_ui…
ro-i Nov 18, 2025
6fc2bc1
[BAZEL] Fix OrcDebugging dep (#168540)
lialan Nov 18, 2025
f2b5d04
[LLVM][InstSimplify] Add folds for SVE integer reduction intrinsics. …
paulwalker-arm Nov 18, 2025
75792d6
[libc++] Fix header deprecations (#163356)
philnik777 Nov 18, 2025
9a0fd22
Revert "[OpenMP] Implement omp_get_uid_from_device() / omp_get_device…
ro-i Nov 18, 2025
2befda2
[VPlan] Populate and use VPIRFlags from initial VPInstruction. (#168450)
fhahn Nov 18, 2025
1e18b48
[DWARFCFIChecker] Remove an unused local variable (NFC) (#168487)
kazutakahirata Nov 18, 2025
4749cc4
[Bitcode] Use a range-based for loop (NFC) (#168489)
kazutakahirata Nov 18, 2025
00ef948
[AMDGPU] Remove const on a return type. (#168490)
kazutakahirata Nov 18, 2025
cc0c899
[clang][CIR] Temporarily fix CIR codegen test on call. NFC
darkbuck Nov 18, 2025
906f175
[ELF][AArch64] Fix copy/paste error in llvm_unreachable message
jrtc27 Nov 18, 2025
2ede6af
[TSan] Make tests work with internal shell
boomanaiden154 Nov 18, 2025
40645ed
[clang-tidy] Add a fully custom message to `bugprone-unsafe-functions…
Discookie Nov 18, 2025
1fcfd5c
[mlir][amdgpu] Sink op creation in scaled conversion intrinsics (NFC)…
amd-eochoalo Nov 18, 2025
ed60cd2
[HLSL] Implement ddx/ddy_coarse intrinsics (#164831)
Alexander-Johnston Nov 18, 2025
61c2cc9
[clang][clang-linker-wrapper] Use the correct triple for clang-offloa…
mgcarrasco Nov 18, 2025
4d09368
[bazel] Add MODULE.bazel (#164891)
rupprecht Nov 18, 2025
47d9d73
[MLIR][Python] Add arg_attrs and res_attrs to gpu func (#168475)
ashermancinelli Nov 18, 2025
83d27f6
[Clang][Driver] Create crash reproducers for IR inputs (#165572)
omern1 Nov 18, 2025
a1e47ce
[llvm][AddressSanitizer] option for specifying the address space of t…
etsal Nov 18, 2025
82a7832
[llvm][AddressSanitizer][BPF] add default shadow mapping offset for B…
etsal Nov 18, 2025
1347b23
[clang][BPF] Turn on AddressSanitizer pass (#167766)
etsal Nov 18, 2025
2ee4a8f
merge main into amd-staging
z1-cciauto Nov 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,20 @@ void UnsafeFunctionsCheck::check(const MatchFinder::MatchResult &Result) {
if (Custom) {
for (const auto &Entry : CustomFunctions) {
if (Entry.Pattern.match(*FuncDecl)) {
const StringRef Reason =
StringRef Reason =
Entry.Reason.empty() ? "is marked as unsafe" : Entry.Reason.c_str();

if (Entry.Replacement.empty()) {
// Omit the replacement, when a fully-custom reason is given.
if (Reason.consume_front(">")) {
diag(SourceExpr->getExprLoc(), "function %0 %1")
<< FuncDecl << Reason.trim() << SourceExpr->getSourceRange();
// Do not recommend a replacement when it is not present.
} else if (Entry.Replacement.empty()) {
diag(SourceExpr->getExprLoc(),
"function %0 %1; it should not be used")
<< FuncDecl << Reason << Entry.Replacement
<< SourceExpr->getSourceRange();
// Otherwise, emit the replacement.
} else {
diag(SourceExpr->getExprLoc(),
"function %0 %1; '%2' should be used instead")
Expand Down
12 changes: 12 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ Potentially Breaking Changes
- `CharTypdefsToIgnore` to `CharTypedefsToIgnore` in
:doc:`bugprone-signed-char-misuse
<clang-tidy/checks/bugprone/signed-char-misuse>`

- Modified the custom message format of :doc:`bugprone-unsafe-functions
<clang-tidy/checks/bugprone/unsafe-functions>` by assigning a special meaning
to the character ``>`` at the start of the value of the option
``CustomFunctions``. If the option value starts with ``>``, then the
replacement suggestion part of the message (which would be included by
default) is omitted. (This does not change the warning locations.)

- :program:`clang-tidy` now displays warnings from all non-system headers by
default. Previously, users had to explicitly opt-in to header warnings using
Expand Down Expand Up @@ -387,6 +394,11 @@ Changes in existing checks
<clang-tidy/checks/bugprone/unhandled-self-assignment>` check by adding
an additional matcher that generalizes the copy-and-swap idiom pattern
detection.

- Improved :doc:`bugprone-unsafe-functions
<clang-tidy/checks/bugprone/unsafe-functions>` check by hiding the default
suffix when the reason starts with the character `>` in the `CustomFunctions`
option.

- Improved :doc:`cppcoreguidelines-avoid-non-const-global-variables
<clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables>` check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,37 +96,62 @@ to be checked. The format is the following, without newlines:
The functions are matched using POSIX extended regular expressions.
*(Note: The regular expressions do not support negative* ``(?!)`` *matches.)*

The `reason` is optional and is used to provide additional information
about the reasoning behind the replacement. The default reason is
`is marked as unsafe`.
The ``reason`` is optional and is used to provide additional information about the
reasoning behind the replacement. The default reason is ``is marked as unsafe``.

If `replacement` is empty, the text `it should not be used` will be shown
instead of the suggestion for a replacement.
If ``replacement`` is empty, the default text ``it should not be used`` will be
shown instead of the suggestion for a replacement.

As an example, the configuration `^original$, replacement, is deprecated;`
will produce the following diagnostic message.
If the ``reason`` starts with the character ``>``, the reason becomes fully custom.
The default suffix is disabled even if a ``replacement`` is present, and only the
reason message is shown after the matched function, to allow better control over
the suggestions. (The starting ``>`` and whitespace directly after it are
trimmed from the message.)

As an example, the following configuration matches only the function ``original``
in the default namespace. A similar diagnostic can also be printed using a fully
custom reason.

.. code:: c

// bugprone-unsafe-functions.CustomFunctions:
// ^original$, replacement, is deprecated;
// Using the fully custom message syntax:
// ^suspicious$,,> should be avoided if possible.
original(); // warning: function 'original' is deprecated; 'replacement' should be used instead.
suspicious(); // warning: function 'suspicious' should be avoided if possible.
::std::original(); // no-warning
original_function(); // no-warning

If the regular expression contains the character `:`, it is matched against the
qualified name (i.e. ``std::original``), otherwise the regex is matched against the unqualified name (``original``).
If the regular expression starts with `::` (or `^::`), it is matched against the
fully qualified name (``::std::original``).
If the regular expression contains the character ``:``, it is matched against the
qualified name (i.e. ``std::original``), otherwise the regex is matched against
the unqualified name (``original``). If the regular expression starts with ``::``
(or ``^::``), it is matched against the fully qualified name
(``::std::original``).

One of the use cases for fully custom messages is suggesting compiler options
and warning flags:

.. code:: c

// bugprone-unsafe-functions.CustomFunctions:
// ^memcpy$,,>is recommended to have compiler hardening using '_FORTIFY_SOURCE';
// ^printf$,,>is recommended to have the '-Werror=format-security' compiler warning flag;

memcpy(dest, src, 999'999); // warning: function 'memcpy' is recommended to have compiler hardening using '_FORTIFY_SOURCE'
printf(raw_str); // warning: function 'printf' is recommended to have the '-Werror=format-security' compiler warning flag

.. note::

Fully qualified names can contain template parameters on certain C++ classes, but not on C++ functions.
Type aliases are resolved before matching.
Fully qualified names can contain template parameters on certain C++ classes,
but not on C++ functions. Type aliases are resolved before matching.

As an example, the member function ``open`` in the class ``std::ifstream``
has a fully qualified name of ``::std::basic_ifstream<char>::open``.

The example could also be matched with the regex ``::std::basic_ifstream<[^>]*>::open``, which matches all potential
template parameters, but does not match nested template classes.
The example could also be matched with the regex
``::std::basic_ifstream<[^>]*>::open``, which matches all potential template
parameters, but does not match nested template classes.

Options
-------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %check_clang_tidy -check-suffix=NON-STRICT-REGEX %s bugprone-unsafe-functions %t --\
// RUN: -config="{CheckOptions: {bugprone-unsafe-functions.CustomFunctions: '::name_match,replacement,is a qualname match;^::prefix_match,,is matched on qualname prefix'}}"
// RUN: -config="{CheckOptions: {bugprone-unsafe-functions.CustomFunctions: \"::name_match,,>is a qualname match, but with a fully 'custom' message;^::prefix_match,,is matched on qualname prefix\"}}"
// RUN: %check_clang_tidy -check-suffix=STRICT-REGEX %s bugprone-unsafe-functions %t --\
// RUN: -config="{CheckOptions: {bugprone-unsafe-functions.CustomFunctions: '^name_match$,replacement,is matched on function name only;^::prefix_match$,,is a full qualname match'}}"

Expand All @@ -11,14 +11,14 @@ void prefix_match_regex();

void f1() {
name_match();
// CHECK-MESSAGES-NON-STRICT-REGEX: :[[@LINE-1]]:3: warning: function 'name_match' is a qualname match; 'replacement' should be used instead
// CHECK-MESSAGES-NON-STRICT-REGEX: :[[@LINE-1]]:3: warning: function 'name_match' is a qualname match, but with a fully 'custom' message
// CHECK-MESSAGES-STRICT-REGEX: :[[@LINE-2]]:3: warning: function 'name_match' is matched on function name only; 'replacement' should be used instead
prefix_match();
// CHECK-MESSAGES-NON-STRICT-REGEX: :[[@LINE-1]]:3: warning: function 'prefix_match' is matched on qualname prefix; it should not be used
// CHECK-MESSAGES-STRICT-REGEX: :[[@LINE-2]]:3: warning: function 'prefix_match' is a full qualname match; it should not be used

name_match_regex();
// CHECK-MESSAGES-NON-STRICT-REGEX: :[[@LINE-1]]:3: warning: function 'name_match_regex' is a qualname match; 'replacement' should be used instead
// CHECK-MESSAGES-NON-STRICT-REGEX: :[[@LINE-1]]:3: warning: function 'name_match_regex' is a qualname match, but with a fully 'custom' message
// no-warning STRICT-REGEX

prefix_match_regex();
Expand Down
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ Bug Fixes to Attribute Support
- Fixes crashes or missing diagnostics with the `device_kernel` attribute. (#GH161905)
- Fix handling of parameter indexes when an attribute is applied to a C++23 explicit object member function.
- Fixed several false positives and false negatives in function effect (`nonblocking`) analysis. (#GH166078) (#GH166101) (#GH166110)
- Fix ``cleanup`` attribute by delaying type checks until after the type is deduced. (#GH129631)

Bug Fixes to C++ Support
^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
12 changes: 12 additions & 0 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,17 @@ class Attr {
// our existing general parsing we need to have a separate flag that
// opts an attribute into strict parsing of attribute parameters
bit StrictEnumParameters = 0;
// Set to true for attributes which have Sema checks which requires the type
// to be deduced.
// When `IsTypeDependent` is set to true, you should add an `ActOn*Attr`
// function to `Sema.h`. The signature of the function must be:
// `void ActOn*Attr(Decl *, const Attr *);` where the `Decl *` is the
// declaration the attribute will be attached to; its type will have already
// been deduced, and the `Attr *` is the attribute being applied to that
// declaration. This function should handle all type-sensitive semantics for
// the attribute. This function will be automatically called by
// `Sema::CheckAttributesOnDeducedType()`.
bit IsTypeDependent = 0;
// Lists language options, one of which is required to be true for the
// attribute to be applicable. If empty, no language options are required.
list<LangOpt> LangOpts = [];
Expand Down Expand Up @@ -1400,6 +1411,7 @@ def Cleanup : InheritableAttr {
let Args = [DeclArgument<Function, "FunctionDecl">];
let Subjects = SubjectList<[LocalVar]>;
let Documentation = [CleanupDocs];
let IsTypeDependent = 1;
// FIXME: DeclArgument should be reworked to also store the
// Expr instead of adding attr specific hacks like the following.
// See the discussion in https://github.com/llvm/llvm-project/pull/14023.
Expand Down
12 changes: 12 additions & 0 deletions clang/include/clang/Basic/Builtins.td
Original file line number Diff line number Diff line change
Expand Up @@ -5253,6 +5253,18 @@ def HLSLF16ToF32 : LangBuiltin<"HLSL_LANG"> {
let Prototype = "void(...)";
}

def HLSLDdxCoarse : LangBuiltin<"HLSL_LANG"> {
let Spellings = ["__builtin_hlsl_elementwise_ddx_coarse"];
let Attributes = [NoThrow, Const, CustomTypeChecking];
let Prototype = "void(...)";
}

def HLSLDdyCoarse : LangBuiltin<"HLSL_LANG"> {
let Spellings = ["__builtin_hlsl_elementwise_ddy_coarse"];
let Attributes = [NoThrow, Const, CustomTypeChecking];
let Prototype = "void(...)";
}

// Builtins for XRay.
def XRayCustomEvent : Builtin {
let Spellings = ["__xray_customevent"];
Expand Down
5 changes: 5 additions & 0 deletions clang/include/clang/Sema/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ clang_tablegen(AttrParsedAttrKinds.inc -gen-clang-attr-parsed-attr-kinds
SOURCE ../Basic/Attr.td
TARGET ClangAttrParsedAttrKinds)

clang_tablegen(AttrIsTypeDependent.inc -gen-clang-attr-is-type-dependent
-I ${CMAKE_CURRENT_SOURCE_DIR}/../../
SOURCE ../Basic/Attr.td
TARGET ClangAttrIsTypeDependent)

clang_tablegen(AttrSpellingListIndex.inc -gen-clang-attr-spelling-index
-I ${CMAKE_CURRENT_SOURCE_DIR}/../../
SOURCE ../Basic/Attr.td
Expand Down
8 changes: 8 additions & 0 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -4456,6 +4456,10 @@ class Sema final : public SemaBase {
NamedDecl *New, Decl *Old,
AvailabilityMergeKind AMK = AvailabilityMergeKind::Redeclaration);

/// CheckAttributesOnDeducedType - Calls Sema functions for attributes that
/// requires the type to be deduced.
void CheckAttributesOnDeducedType(Decl *D);

/// MergeTypedefNameDecl - We just parsed a typedef 'New' which has the
/// same name and scope as a previous declaration 'Old'. Figure out
/// how to resolve this situation, merging decls or emitting
Expand Down Expand Up @@ -4760,6 +4764,8 @@ class Sema final : public SemaBase {
// linkage or not.
static bool mightHaveNonExternalLinkage(const DeclaratorDecl *FD);

#include "clang/Sema/AttrIsTypeDependent.inc"

///@}

//
Expand Down Expand Up @@ -15469,6 +15475,8 @@ class Sema final : public SemaBase {
std::optional<FunctionEffectMode>
ActOnEffectExpression(Expr *CondExpr, StringRef AttributeName);

void ActOnCleanupAttr(Decl *D, const Attr *A);

private:
/// The implementation of RequireCompleteType
bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T,
Expand Down
18 changes: 18 additions & 0 deletions clang/lib/CodeGen/CGHLSLBuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,24 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
return EmitRuntimeCall(
Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID));
}
case Builtin::BI__builtin_hlsl_elementwise_ddx_coarse: {
Value *Op0 = EmitScalarExpr(E->getArg(0));
if (!E->getArg(0)->getType()->hasFloatingRepresentation())
llvm_unreachable("ddx_coarse operand must have a float representation");
Intrinsic::ID ID = CGM.getHLSLRuntime().getDdxCoarseIntrinsic();
return Builder.CreateIntrinsic(/*ReturnType=*/Op0->getType(), ID,
ArrayRef<Value *>{Op0}, nullptr,
"hlsl.ddx.coarse");
}
case Builtin::BI__builtin_hlsl_elementwise_ddy_coarse: {
Value *Op0 = EmitScalarExpr(E->getArg(0));
if (!E->getArg(0)->getType()->hasFloatingRepresentation())
llvm_unreachable("ddy_coarse operand must have a float representation");
Intrinsic::ID ID = CGM.getHLSLRuntime().getDdyCoarseIntrinsic();
return Builder.CreateIntrinsic(/*ReturnType=*/Op0->getType(), ID,
ArrayRef<Value *>{Op0}, nullptr,
"hlsl.ddy.coarse");
}
case Builtin::BI__builtin_get_spirv_spec_constant_bool:
case Builtin::BI__builtin_get_spirv_spec_constant_short:
case Builtin::BI__builtin_get_spirv_spec_constant_ushort:
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/CGHLSLRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ class CGHLSLRuntime {
GENERATE_HLSL_INTRINSIC_FUNCTION(GroupMemoryBarrierWithGroupSync,
group_memory_barrier_with_group_sync)
GENERATE_HLSL_INTRINSIC_FUNCTION(GetDimensionsX, resource_getdimensions_x)
GENERATE_HLSL_INTRINSIC_FUNCTION(DdxCoarse, ddx_coarse)
GENERATE_HLSL_INTRINSIC_FUNCTION(DdyCoarse, ddy_coarse)

//===----------------------------------------------------------------------===//
// End of reserved area for HLSL intrinsic getters.
Expand Down
Loading