Skip to content

Commit a98a6e9

Browse files
authored
Add clarifying parenthesis around non-trivial conditions in ternary expressions. (#90391)
Fixes [#85868](#85868) Parenthesis are added as requested on ternary operators with non trivial conditions. I used this [precedence table](https://en.cppreference.com/w/cpp/language/operator_precedence) for reference, to make sure we get the expected behavior on each change.
1 parent 028f1b0 commit a98a6e9

File tree

18 files changed

+94
-96
lines changed

18 files changed

+94
-96
lines changed

clang/lib/Basic/Targets/AMDGPU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple &Triple,
232232

233233
HasLegalHalfType = true;
234234
HasFloat16 = true;
235-
WavefrontSize = GPUFeatures & llvm::AMDGPU::FEATURE_WAVE32 ? 32 : 64;
235+
WavefrontSize = (GPUFeatures & llvm::AMDGPU::FEATURE_WAVE32) ? 32 : 64;
236236
AllowAMDGPUUnsafeFPAtomics = Opts.AllowAMDGPUUnsafeFPAtomics;
237237

238238
// Set pointer width and alignment for the generic address space.

compiler-rt/lib/xray/xray_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ constexpr size_t gcd(size_t a, size_t b) {
6161
constexpr size_t lcm(size_t a, size_t b) { return a * b / gcd(a, b); }
6262

6363
constexpr size_t nearest_boundary(size_t number, size_t multiple) {
64-
return multiple * ((number / multiple) + (number % multiple ? 1 : 0));
64+
return multiple * ((number / multiple) + ((number % multiple) ? 1 : 0));
6565
}
6666

6767
constexpr size_t next_pow2_helper(size_t num, size_t acc) {

libc/src/__support/FPUtil/aarch64/FEnvImpl.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@ struct FEnv {
5353
static constexpr uint32_t ExceptionControlFlagsBitPosition = 8;
5454

5555
LIBC_INLINE static uint32_t getStatusValueForExcept(int excepts) {
56-
return (excepts & FE_INVALID ? INVALID : 0) |
57-
(excepts & FE_DIVBYZERO ? DIVBYZERO : 0) |
58-
(excepts & FE_OVERFLOW ? OVERFLOW : 0) |
59-
(excepts & FE_UNDERFLOW ? UNDERFLOW : 0) |
60-
(excepts & FE_INEXACT ? INEXACT : 0);
56+
return ((excepts & FE_INVALID) ? INVALID : 0) |
57+
((excepts & FE_DIVBYZERO) ? DIVBYZERO : 0) |
58+
((excepts & FE_OVERFLOW) ? OVERFLOW : 0) |
59+
((excepts & FE_UNDERFLOW) ? UNDERFLOW : 0) |
60+
((excepts & FE_INEXACT) ? INEXACT : 0);
6161
}
6262

6363
LIBC_INLINE static int exceptionStatusToMacro(uint32_t status) {
64-
return (status & INVALID ? FE_INVALID : 0) |
65-
(status & DIVBYZERO ? FE_DIVBYZERO : 0) |
66-
(status & OVERFLOW ? FE_OVERFLOW : 0) |
67-
(status & UNDERFLOW ? FE_UNDERFLOW : 0) |
68-
(status & INEXACT ? FE_INEXACT : 0);
64+
return ((status & INVALID) ? FE_INVALID : 0) |
65+
((status & DIVBYZERO) ? FE_DIVBYZERO : 0) |
66+
((status & OVERFLOW) ? FE_OVERFLOW : 0) |
67+
((status & UNDERFLOW) ? FE_UNDERFLOW : 0) |
68+
((status & INEXACT) ? FE_INEXACT : 0);
6969
}
7070

7171
static uint32_t getControlWord() {

libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,39 +63,39 @@ struct FEnv {
6363
// located in a different place from FE_FLUSHTOZERO status bit relative to
6464
// the other exceptions.
6565
LIBC_INLINE static uint32_t exception_value_from_status(int status) {
66-
return (status & FE_INVALID ? EX_INVALID : 0) |
67-
(status & FE_DIVBYZERO ? EX_DIVBYZERO : 0) |
68-
(status & FE_OVERFLOW ? EX_OVERFLOW : 0) |
69-
(status & FE_UNDERFLOW ? EX_UNDERFLOW : 0) |
70-
(status & FE_INEXACT ? EX_INEXACT : 0) |
71-
(status & FE_FLUSHTOZERO ? EX_FLUSHTOZERO : 0);
66+
return ((status & FE_INVALID) ? EX_INVALID : 0) |
67+
((status & FE_DIVBYZERO) ? EX_DIVBYZERO : 0) |
68+
((status & FE_OVERFLOW) ? EX_OVERFLOW : 0) |
69+
((status & FE_UNDERFLOW) ? EX_UNDERFLOW : 0) |
70+
((status & FE_INEXACT) ? EX_INEXACT : 0) |
71+
((status & FE_FLUSHTOZERO) ? EX_FLUSHTOZERO : 0);
7272
}
7373

7474
LIBC_INLINE static uint32_t exception_value_from_control(int control) {
75-
return (control & __fpcr_trap_invalid ? EX_INVALID : 0) |
76-
(control & __fpcr_trap_divbyzero ? EX_DIVBYZERO : 0) |
77-
(control & __fpcr_trap_overflow ? EX_OVERFLOW : 0) |
78-
(control & __fpcr_trap_underflow ? EX_UNDERFLOW : 0) |
79-
(control & __fpcr_trap_inexact ? EX_INEXACT : 0) |
80-
(control & __fpcr_flush_to_zero ? EX_FLUSHTOZERO : 0);
75+
return ((control & __fpcr_trap_invalid) ? EX_INVALID : 0) |
76+
((control & __fpcr_trap_divbyzero) ? EX_DIVBYZERO : 0) |
77+
((control & __fpcr_trap_overflow) ? EX_OVERFLOW : 0) |
78+
((control & __fpcr_trap_underflow) ? EX_UNDERFLOW : 0) |
79+
((control & __fpcr_trap_inexact) ? EX_INEXACT : 0) |
80+
((control & __fpcr_flush_to_zero) ? EX_FLUSHTOZERO : 0);
8181
}
8282

8383
LIBC_INLINE static int exception_value_to_status(uint32_t excepts) {
84-
return (excepts & EX_INVALID ? FE_INVALID : 0) |
85-
(excepts & EX_DIVBYZERO ? FE_DIVBYZERO : 0) |
86-
(excepts & EX_OVERFLOW ? FE_OVERFLOW : 0) |
87-
(excepts & EX_UNDERFLOW ? FE_UNDERFLOW : 0) |
88-
(excepts & EX_INEXACT ? FE_INEXACT : 0) |
89-
(excepts & EX_FLUSHTOZERO ? FE_FLUSHTOZERO : 0);
84+
return ((excepts & EX_INVALID) ? FE_INVALID : 0) |
85+
((excepts & EX_DIVBYZERO) ? FE_DIVBYZERO : 0) |
86+
((excepts & EX_OVERFLOW) ? FE_OVERFLOW : 0) |
87+
((excepts & EX_UNDERFLOW) ? FE_UNDERFLOW : 0) |
88+
((excepts & EX_INEXACT) ? FE_INEXACT : 0) |
89+
((excepts & EX_FLUSHTOZERO) ? FE_FLUSHTOZERO : 0);
9090
}
9191

9292
LIBC_INLINE static int exception_value_to_control(uint32_t excepts) {
93-
return (excepts & EX_INVALID ? __fpcr_trap_invalid : 0) |
94-
(excepts & EX_DIVBYZERO ? __fpcr_trap_divbyzero : 0) |
95-
(excepts & EX_OVERFLOW ? __fpcr_trap_overflow : 0) |
96-
(excepts & EX_UNDERFLOW ? __fpcr_trap_underflow : 0) |
97-
(excepts & EX_INEXACT ? __fpcr_trap_inexact : 0) |
98-
(excepts & EX_FLUSHTOZERO ? __fpcr_flush_to_zero : 0);
93+
return ((excepts & EX_INVALID) ? __fpcr_trap_invalid : 0) |
94+
((excepts & EX_DIVBYZERO) ? __fpcr_trap_divbyzero : 0) |
95+
((excepts & EX_OVERFLOW) ? __fpcr_trap_overflow : 0) |
96+
((excepts & EX_UNDERFLOW) ? __fpcr_trap_underflow : 0) |
97+
((excepts & EX_INEXACT) ? __fpcr_trap_inexact : 0) |
98+
((excepts & EX_FLUSHTOZERO) ? __fpcr_flush_to_zero : 0);
9999
}
100100

101101
LIBC_INLINE static uint32_t get_control_word() { return __arm_rsr("fpcr"); }

libc/src/__support/FPUtil/arm/FEnvImpl.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,35 +50,35 @@ struct FEnv {
5050
}
5151

5252
LIBC_INLINE static int exception_enable_bits_to_macro(uint32_t status) {
53-
return (status & INVALID_ENABLE ? FE_INVALID : 0) |
54-
(status & DIVBYZERO_ENABLE ? FE_DIVBYZERO : 0) |
55-
(status & OVERFLOW_ENABLE ? FE_OVERFLOW : 0) |
56-
(status & UNDERFLOW_ENABLE ? FE_UNDERFLOW : 0) |
57-
(status & INEXACT_ENABLE ? FE_INEXACT : 0);
53+
return ((status & INVALID_ENABLE) ? FE_INVALID : 0) |
54+
((status & DIVBYZERO_ENABLE) ? FE_DIVBYZERO : 0) |
55+
((status & OVERFLOW_ENABLE) ? FE_OVERFLOW : 0) |
56+
((status & UNDERFLOW_ENABLE) ? FE_UNDERFLOW : 0) |
57+
((status & INEXACT_ENABLE) ? FE_INEXACT : 0);
5858
}
5959

6060
LIBC_INLINE static uint32_t exception_macro_to_enable_bits(int except) {
61-
return (except & FE_INVALID ? INVALID_ENABLE : 0) |
62-
(except & FE_DIVBYZERO ? DIVBYZERO_ENABLE : 0) |
63-
(except & FE_OVERFLOW ? OVERFLOW_ENABLE : 0) |
64-
(except & FE_UNDERFLOW ? UNDERFLOW_ENABLE : 0) |
65-
(except & FE_INEXACT ? INEXACT_ENABLE : 0);
61+
return ((except & FE_INVALID) ? INVALID_ENABLE : 0) |
62+
((except & FE_DIVBYZERO) ? DIVBYZERO_ENABLE : 0) |
63+
((except & FE_OVERFLOW) ? OVERFLOW_ENABLE : 0) |
64+
((except & FE_UNDERFLOW) ? UNDERFLOW_ENABLE : 0) |
65+
((except & FE_INEXACT) ? INEXACT_ENABLE : 0);
6666
}
6767

6868
LIBC_INLINE static uint32_t exception_macro_to_status_bits(int except) {
69-
return (except & FE_INVALID ? INVALID_STATUS : 0) |
70-
(except & FE_DIVBYZERO ? DIVBYZERO_STATUS : 0) |
71-
(except & FE_OVERFLOW ? OVERFLOW_STATUS : 0) |
72-
(except & FE_UNDERFLOW ? UNDERFLOW_STATUS : 0) |
73-
(except & FE_INEXACT ? INEXACT_STATUS : 0);
69+
return ((except & FE_INVALID) ? INVALID_STATUS : 0) |
70+
((except & FE_DIVBYZERO) ? DIVBYZERO_STATUS : 0) |
71+
((except & FE_OVERFLOW) ? OVERFLOW_STATUS : 0) |
72+
((except & FE_UNDERFLOW) ? UNDERFLOW_STATUS : 0) |
73+
((except & FE_INEXACT) ? INEXACT_STATUS : 0);
7474
}
7575

7676
LIBC_INLINE static uint32_t exception_status_bits_to_macro(int status) {
77-
return (status & INVALID_STATUS ? FE_INVALID : 0) |
78-
(status & DIVBYZERO_STATUS ? FE_DIVBYZERO : 0) |
79-
(status & OVERFLOW_STATUS ? FE_OVERFLOW : 0) |
80-
(status & UNDERFLOW_STATUS ? FE_UNDERFLOW : 0) |
81-
(status & INEXACT_STATUS ? FE_INEXACT : 0);
77+
return ((status & INVALID_STATUS) ? FE_INVALID : 0) |
78+
((status & DIVBYZERO_STATUS) ? FE_DIVBYZERO : 0) |
79+
((status & OVERFLOW_STATUS) ? FE_OVERFLOW : 0) |
80+
((status & UNDERFLOW_STATUS) ? FE_UNDERFLOW : 0) |
81+
((status & INEXACT_STATUS) ? FE_INEXACT : 0);
8282
}
8383
};
8484

libc/src/__support/FPUtil/riscv/FEnvImpl.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ struct FEnv {
6565
}
6666

6767
LIBC_INLINE static int exception_bits_to_macro(uint32_t status) {
68-
return (status & INVALID ? FE_INVALID : 0) |
69-
(status & DIVBYZERO ? FE_DIVBYZERO : 0) |
70-
(status & OVERFLOW ? FE_OVERFLOW : 0) |
71-
(status & UNDERFLOW ? FE_UNDERFLOW : 0) |
72-
(status & INEXACT ? FE_INEXACT : 0);
68+
return ((status & INVALID) ? FE_INVALID : 0) |
69+
((status & DIVBYZERO) ? FE_DIVBYZERO : 0) |
70+
((status & OVERFLOW) ? FE_OVERFLOW : 0) |
71+
((status & UNDERFLOW) ? FE_UNDERFLOW : 0) |
72+
((status & INEXACT) ? FE_INEXACT : 0);
7373
}
7474

7575
LIBC_INLINE static uint32_t exception_macro_to_bits(int except) {
76-
return (except & FE_INVALID ? INVALID : 0) |
77-
(except & FE_DIVBYZERO ? DIVBYZERO : 0) |
78-
(except & FE_OVERFLOW ? OVERFLOW : 0) |
79-
(except & FE_UNDERFLOW ? UNDERFLOW : 0) |
80-
(except & FE_INEXACT ? INEXACT : 0);
76+
return ((except & FE_INVALID) ? INVALID : 0) |
77+
((except & FE_DIVBYZERO) ? DIVBYZERO : 0) |
78+
((except & FE_OVERFLOW) ? OVERFLOW : 0) |
79+
((except & FE_UNDERFLOW) ? UNDERFLOW : 0) |
80+
((except & FE_INEXACT) ? INEXACT : 0);
8181
}
8282
};
8383

libc/src/__support/FPUtil/x86_64/FEnvImpl.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,25 @@ static constexpr uint16_t MXCSR_EXCEPTION_CONTOL_BIT_POISTION = 7;
7272
LIBC_INLINE uint16_t get_status_value_for_except(int excepts) {
7373
// We will make use of the fact that exception control bits are single
7474
// bit flags in the control registers.
75-
return (excepts & FE_INVALID ? ExceptionFlags::INVALID_F : 0) |
75+
return ((excepts & FE_INVALID) ? ExceptionFlags::INVALID_F : 0) |
7676
#ifdef __FE_DENORM
77-
(excepts & __FE_DENORM ? ExceptionFlags::DENORMAL_F : 0) |
77+
((excepts & __FE_DENORM) ? ExceptionFlags::DENORMAL_F : 0) |
7878
#endif // __FE_DENORM
79-
(excepts & FE_DIVBYZERO ? ExceptionFlags::DIV_BY_ZERO_F : 0) |
80-
(excepts & FE_OVERFLOW ? ExceptionFlags::OVERFLOW_F : 0) |
81-
(excepts & FE_UNDERFLOW ? ExceptionFlags::UNDERFLOW_F : 0) |
82-
(excepts & FE_INEXACT ? ExceptionFlags::INEXACT_F : 0);
79+
((excepts & FE_DIVBYZERO) ? ExceptionFlags::DIV_BY_ZERO_F : 0) |
80+
((excepts & FE_OVERFLOW) ? ExceptionFlags::OVERFLOW_F : 0) |
81+
((excepts & FE_UNDERFLOW) ? ExceptionFlags::UNDERFLOW_F : 0) |
82+
((excepts & FE_INEXACT) ? ExceptionFlags::INEXACT_F : 0);
8383
}
8484

8585
LIBC_INLINE int exception_status_to_macro(uint16_t status) {
86-
return (status & ExceptionFlags::INVALID_F ? FE_INVALID : 0) |
86+
return ((status & ExceptionFlags::INVALID_F) ? FE_INVALID : 0) |
8787
#ifdef __FE_DENORM
88-
(status & ExceptionFlags::DENORMAL_F ? __FE_DENORM : 0) |
88+
((status & ExceptionFlags::DENORMAL_F) ? __FE_DENORM : 0) |
8989
#endif // __FE_DENORM
90-
(status & ExceptionFlags::DIV_BY_ZERO_F ? FE_DIVBYZERO : 0) |
91-
(status & ExceptionFlags::OVERFLOW_F ? FE_OVERFLOW : 0) |
92-
(status & ExceptionFlags::UNDERFLOW_F ? FE_UNDERFLOW : 0) |
93-
(status & ExceptionFlags::INEXACT_F ? FE_INEXACT : 0);
90+
((status & ExceptionFlags::DIV_BY_ZERO_F) ? FE_DIVBYZERO : 0) |
91+
((status & ExceptionFlags::OVERFLOW_F) ? FE_OVERFLOW : 0) |
92+
((status & ExceptionFlags::UNDERFLOW_F) ? FE_UNDERFLOW : 0) |
93+
((status & ExceptionFlags::INEXACT_F) ? FE_INEXACT : 0);
9494
}
9595

9696
struct X87StateDescriptor {

libclc/generic/lib/math/log_base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ log(double x)
289289
double ret = is_near ? ret_near : ret_far;
290290

291291
ret = isinf(x) ? as_double(PINFBITPATT_DP64) : ret;
292-
ret = isnan(x) | (x < 0.0) ? as_double(QNANBITPATT_DP64) : ret;
292+
ret = (isnan(x) | (x < 0.0)) ? as_double(QNANBITPATT_DP64) : ret;
293293
ret = x == 0.0 ? as_double(NINFBITPATT_DP64) : ret;
294294
return ret;
295295
}

libcxxabi/src/cxa_personality.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,9 +717,7 @@ static void scan_eh_tab(scan_results &results, _Unwind_Action actions,
717717
if (actionEntry == 0)
718718
{
719719
// Found a cleanup
720-
results.reason = actions & _UA_SEARCH_PHASE
721-
? _URC_CONTINUE_UNWIND
722-
: _URC_HANDLER_FOUND;
720+
results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
723721
return;
724722
}
725723
// Convert 1-based byte offset into

lld/ELF/LinkerScript.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ static OutputDesc *addInputSec(StringMap<TinyPtrVector<OutputSection *>> &map,
801801
auto *firstIsec = cast<InputSectionBase>(
802802
cast<InputSectionDescription>(sec->commands[0])->sectionBases[0]);
803803
OutputSection *firstIsecOut =
804-
firstIsec->flags & SHF_LINK_ORDER
804+
(firstIsec->flags & SHF_LINK_ORDER)
805805
? firstIsec->getLinkOrderDep()->getOutputSection()
806806
: nullptr;
807807
if (firstIsecOut != isec->getLinkOrderDep()->getOutputSection())

0 commit comments

Comments
 (0)