Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 2577f0f

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:a1d31caa8c53082d12f580122dcf2b2ff8285e78 into amd-gfx:a0b628df54bb
Local branch amd-gfx a0b628d Merged main:39ac64c1c0fc61a476aa22c53e6977608ead03cf into amd-gfx:b8f516d9c3d8 Remote branch main a1d31ca [clang-tidy] fix false positive for implicit conversion of comparison result in C23 (llvm#113639)
2 parents a0b628d + a1d31ca commit 2577f0f

File tree

21 files changed

+1252
-2
lines changed

21 files changed

+1252
-2
lines changed

clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "../utils/FixItHintUtils.h"
1111
#include "clang/AST/ASTContext.h"
1212
#include "clang/ASTMatchers/ASTMatchFinder.h"
13+
#include "clang/ASTMatchers/ASTMatchers.h"
1314
#include "clang/Lex/Lexer.h"
1415
#include "clang/Tooling/FixIt.h"
1516
#include <queue>
@@ -26,6 +27,8 @@ AST_MATCHER(Stmt, isMacroExpansion) {
2627
return SM.isMacroBodyExpansion(Loc) || SM.isMacroArgExpansion(Loc);
2728
}
2829

30+
AST_MATCHER(Stmt, isC23) { return Finder->getASTContext().getLangOpts().C23; }
31+
2932
bool isNULLMacroExpansion(const Stmt *Statement, ASTContext &Context) {
3033
SourceManager &SM = Context.getSourceManager();
3134
const LangOptions &LO = Context.getLangOpts();
@@ -298,6 +301,11 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
298301
hasCastKind(CK_FloatingToBoolean),
299302
hasCastKind(CK_PointerToBoolean),
300303
hasCastKind(CK_MemberPointerToBoolean)),
304+
// Exclude cases of C23 comparison result.
305+
unless(allOf(isC23(),
306+
hasSourceExpression(ignoringParens(
307+
binaryOperator(hasAnyOperatorName(
308+
">", ">=", "==", "!=", "<", "<=")))))),
301309
// Exclude case of using if or while statements with variable
302310
// declaration, e.g.:
303311
// if (int var = functionCall()) {}

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ Changes in existing checks
249249
- Improved :doc:`readability-implicit-bool-conversion
250250
<clang-tidy/checks/readability/implicit-bool-conversion>` check
251251
by adding the option `UseUpperCaseLiteralSuffix` to select the
252-
case of the literal suffix in fixes.
252+
case of the literal suffix in fixes and fixing false positive for implicit
253+
conversion of comparison result in C23.
253254

254255
- Improved :doc:`readability-redundant-smartptr-get
255256
<clang-tidy/checks/readability/redundant-smartptr-get>` check to

clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,15 @@ void implicitConversionToBoolFromUnaryMinusAndZeroLiterals() {
304304
// CHECK-FIXES: functionTakingBool((-0.0) != 0.0);
305305
}
306306

307+
void ignoreImplicitCastToBoolForComparisonResult() {
308+
bool boolFromComparison0 = 1 != 0;
309+
bool boolFromComparison1 = 1 == 0;
310+
bool boolFromComparison2 = 1 > 0;
311+
bool boolFromComparison3 = 1 >= 0;
312+
bool boolFromComparison4 = 1 < 0;
313+
bool boolFromComparison5 = 1 <= 0;
314+
}
315+
307316
void ignoreExplicitCastsToBool() {
308317
int integer = 10;
309318
bool boolComingFromInt = (bool)integer;

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,10 @@ X86 Support
628628
* Supported MINMAX intrinsics of ``*_(mask(z)))_minmax(ne)_p[s|d|h|bh]`` and
629629
``*_(mask(z)))_minmax_s[s|d|h]``.
630630

631+
- Supported intrinsics for ``SM4 and AVX10.2``.
632+
* Supported SM4 intrinsics of ``_mm512_sm4key4_epi32`` and
633+
``_mm512_sm4rnds4_epi32``.
634+
631635
- All intrinsics in adcintrin.h can now be used in constant expressions.
632636

633637
- All intrinsics in adxintrin.h can now be used in constant expressions.

clang/include/clang/Basic/BuiltinsX86.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,6 +2179,10 @@ TARGET_BUILTIN(__builtin_ia32_vsm4key4256, "V8UiV8UiV8Ui", "nV:256:", "sm4")
21792179
TARGET_BUILTIN(__builtin_ia32_vsm4rnds4128, "V4UiV4UiV4Ui", "nV:128:", "sm4")
21802180
TARGET_BUILTIN(__builtin_ia32_vsm4rnds4256, "V8UiV8UiV8Ui", "nV:256:", "sm4")
21812181

2182+
// SM4_EVEX
2183+
TARGET_BUILTIN(__builtin_ia32_vsm4key4512, "V16UiV16UiV16Ui", "nV:512:", "avx10.2-512,sm4")
2184+
TARGET_BUILTIN(__builtin_ia32_vsm4rnds4512, "V16UiV16UiV16Ui", "nV:512:", "avx10.2-512,sm4")
2185+
21822186
// AVX10 MINMAX
21832187
TARGET_BUILTIN(__builtin_ia32_vminmaxnepbf16128, "V8yV8yV8yIi", "nV:128:", "avx10.2-256")
21842188
TARGET_BUILTIN(__builtin_ia32_vminmaxnepbf16256, "V16yV16yV16yIi", "nV:256:", "avx10.2-256")

clang/lib/Headers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ set(x86_files
243243
shaintrin.h
244244
sm3intrin.h
245245
sm4intrin.h
246+
sm4evexintrin.h
246247
smmintrin.h
247248
tbmintrin.h
248249
tmmintrin.h

clang/lib/Headers/immintrin.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,11 @@ _storebe_i64(void * __P, long long __D) {
677677
#include <avx10_2_512satcvtintrin.h>
678678
#endif
679679

680+
#if !defined(__SCE__) || __has_feature(modules) || \
681+
(defined(__AVX10_2_512__) && defined(__SM4__))
682+
#include <sm4evexintrin.h>
683+
#endif
684+
680685
#if !defined(__SCE__) || __has_feature(modules) || defined(__ENQCMD__)
681686
#include <enqcmdintrin.h>
682687
#endif

clang/lib/Headers/sm4evexintrin.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*===--------------- sm4evexintrin.h - SM4 EVEX intrinsics -----------------===
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+
#ifndef __IMMINTRIN_H
10+
#error "Never use <sm4evexintrin.h> directly; include <immintrin.h> instead."
11+
#endif // __IMMINTRIN_H
12+
13+
#ifndef __SM4EVEXINTRIN_H
14+
#define __SM4EVEXINTRIN_H
15+
16+
#define __DEFAULT_FN_ATTRS512 \
17+
__attribute__((__always_inline__, __nodebug__, \
18+
__target__("sm4,avx10.2-512"), __min_vector_width__(512)))
19+
20+
static __inline__ __m512i __DEFAULT_FN_ATTRS512
21+
_mm512_sm4key4_epi32(__m512i __A, __m512i __B) {
22+
return (__m512i)__builtin_ia32_vsm4key4512((__v16su)__A, (__v16su)__B);
23+
}
24+
25+
static __inline__ __m512i __DEFAULT_FN_ATTRS512
26+
_mm512_sm4rnds4_epi32(__m512i __A, __m512i __B) {
27+
return (__m512i)__builtin_ia32_vsm4rnds4512((__v16su)__A, (__v16su)__B);
28+
}
29+
30+
#undef __DEFAULT_FN_ATTRS512
31+
32+
#endif // __SM4EVEXINTRIN_H
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clang_cc1 %s -ffreestanding -triple=x86_64-- -target-feature +sm4 \
2+
// RUN: -target-feature +avx10.2-512 -emit-llvm -o - -Wall -Werror | FileCheck %s
3+
// RUN: %clang_cc1 %s -ffreestanding -triple=i386-- -target-feature +sm4 \
4+
// RUN: -target-feature +avx10.2-512 -emit-llvm -o - -Wall -Werror | FileCheck %s
5+
6+
#include <immintrin.h>
7+
#include <stddef.h>
8+
9+
__m512i test_mm512_sm4key4_epi32(__m512i __A, __m512i __B) {
10+
// CHECK-LABEL: @test_mm512_sm4key4_epi32(
11+
// CHECK: call <16 x i32> @llvm.x86.vsm4key4512(<16 x i32> %{{.*}}, <16 x i32> %{{.*}})
12+
return _mm512_sm4key4_epi32(__A, __B);
13+
}
14+
15+
__m512i test_mm512_sm4rnds4_epi32(__m512i __A, __m512i __B) {
16+
// CHECK-LABEL: @test_mm512_sm4rnds4_epi32(
17+
// CHECK: call <16 x i32> @llvm.x86.vsm4rnds4512(<16 x i32> %{{.*}}, <16 x i32> %{{.*}})
18+
return _mm512_sm4rnds4_epi32(__A, __B);
19+
}

llvm/docs/ReleaseNotes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ Changes to the X86 Backend
219219

220220
* Supported instructions of `MOVRS AND AVX10.2`
221221

222+
* Supported ISA of `SM4(EVEX)`.
223+
222224
Changes to the OCaml bindings
223225
-----------------------------
224226

0 commit comments

Comments
 (0)