Skip to content

Commit 8cfdd37

Browse files
authored
[clang] Fixes compile error that double colon operator cannot resolve macro with parentheses. (#68618)
Error message: ``` In file included from ../src/amd/addrlib/src/core/addrobject.h:21: ../src/amd/addrlib/src/core/addrcommon.h:343:13: error: expected unqualified-id out = ::_tzcnt_u32(mask); ^ /usr/lib/llvm-15/lib/clang/15.0.6/include/bmiintrin.h:74:27: note: expanded from macro '_tzcnt_u32' #define _tzcnt_u32(a) (__tzcnt_u32((a))) ``` This is because both GCC/Clang doesn't support compiling the following code: ``` #ifdef _MSC_VER #include <intrin.h> #else #include <x86intrin.h> #endif int f(int a) { return ::(_tzcnt_u32)(a); } ``` This is because the return statement expects an expression or braced init list: http://eel.is/c++draft/stmt.jump#general-1 but we really only need to care about the expression form (there's no braces in sight). Grammatically, the leading :: will parse as a qualified-id because it matches the production for nested-name-specifier: http://eel.is/c++draft/expr.prim.id.qual#nt:qualified-id That needs to be followed by an unqualified-id (http://eel.is/c++draft/expr.prim.id.unqual#nt:unqualified-id), but the open paren does not match any of the grammar productions, so this is a syntax error. Closes: #64467 Signed-off-by: Yonggang Luo <[email protected]>
1 parent 543589a commit 8cfdd37

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,8 @@ Bug Fixes in This Version
651651
- Fixed false positive error emitted by clang when performing qualified name
652652
lookup and the current class instantiation has dependent bases.
653653
Fixes (`#13826 <https://github.com/llvm/llvm-project/issues/13826>`_)
654+
- Fixes compile error that double colon operator cannot resolve macro with parentheses.
655+
Fixes (`#64467 <https://github.com/llvm/llvm-project/issues/64467>`_)- Clang now properly diagnoses use of stand-alone OpenMP directives after a
654656
- Clang's ``-Wchar-subscripts`` no longer warns on chars whose values are known non-negative constants.
655657
Fixes (`#18763 <https://github.com/llvm/llvm-project/issues/18763>`_)
656658

clang/lib/Headers/bmiintrin.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
to use it as a potentially faster version of BSF. */
2020
#define __RELAXED_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
2121

22-
#define _tzcnt_u16(a) (__tzcnt_u16((a)))
22+
#define _tzcnt_u16 __tzcnt_u16
2323

2424
/// Counts the number of trailing zero bits in the operand.
2525
///
@@ -71,7 +71,7 @@ _mm_tzcnt_32(unsigned int __X)
7171
return (int)__builtin_ia32_tzcnt_u32(__X);
7272
}
7373

74-
#define _tzcnt_u32(a) (__tzcnt_u32((a)))
74+
#define _tzcnt_u32 __tzcnt_u32
7575

7676
#ifdef __x86_64__
7777

@@ -109,7 +109,7 @@ _mm_tzcnt_64(unsigned long long __X)
109109
return (long long)__builtin_ia32_tzcnt_u64(__X);
110110
}
111111

112-
#define _tzcnt_u64(a) (__tzcnt_u64((a)))
112+
#define _tzcnt_u64 __tzcnt_u64
113113

114114
#endif /* __x86_64__ */
115115

@@ -121,14 +121,14 @@ _mm_tzcnt_64(unsigned long long __X)
121121
/* Define the default attributes for the functions in this file. */
122122
#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("bmi")))
123123

124-
#define _andn_u32(a, b) (__andn_u32((a), (b)))
124+
#define _andn_u32 __andn_u32
125125

126126
/* _bextr_u32 != __bextr_u32 */
127-
#define _blsi_u32(a) (__blsi_u32((a)))
127+
#define _blsi_u32 __blsi_u32
128128

129-
#define _blsmsk_u32(a) (__blsmsk_u32((a)))
129+
#define _blsmsk_u32 __blsmsk_u32
130130

131-
#define _blsr_u32(a) (__blsr_u32((a)))
131+
#define _blsr_u32 __blsr_u32
132132

133133
/// Performs a bitwise AND of the second operand with the one's
134134
/// complement of the first operand.
@@ -272,14 +272,14 @@ __blsr_u32(unsigned int __X)
272272

273273
#ifdef __x86_64__
274274

275-
#define _andn_u64(a, b) (__andn_u64((a), (b)))
275+
#define _andn_u64 __andn_u64
276276

277277
/* _bextr_u64 != __bextr_u64 */
278-
#define _blsi_u64(a) (__blsi_u64((a)))
278+
#define _blsi_u64 __blsi_u64
279279

280-
#define _blsmsk_u64(a) (__blsmsk_u64((a)))
280+
#define _blsmsk_u64 __blsmsk_u64
281281

282-
#define _blsr_u64(a) (__blsr_u64((a)))
282+
#define _blsr_u64 __blsr_u64
283283

284284
/// Performs a bitwise AND of the second operand with the one's
285285
/// complement of the first operand.

0 commit comments

Comments
 (0)