Skip to content

Commit

Permalink
[clang] Use CPlusPlus language option instead of Bool
Browse files Browse the repository at this point in the history
As it was pointed out in llvm#80724,
we should not be checking `getLangOpts().Bool` when determining something
related to logical operators, since it only indicates that bool keyword
is present, not which semantic logical operators have.
As a side effect a missing `-Wpointer-bool-conversion` in OpenCL C was
restored since like C23, OpenCL C has bool keyword but logical operators
still return int.
  • Loading branch information
Fznamznon committed Feb 7, 2024
1 parent 5690027 commit 32b1b11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16129,10 +16129,10 @@ static void CheckConditionalOperator(Sema &S, AbstractConditionalOperator *E,
/// Check conversion of given expression to boolean.
/// Input argument E is a logical expression.
static void CheckBoolLikeConversion(Sema &S, Expr *E, SourceLocation CC) {
// While C23 does have bool as a keyword, we still need to run the bool-like
// conversion checks as bools are still not used as the return type from
// "boolean" operators or as the input type for conditional operators.
if (S.getLangOpts().Bool && !S.getLangOpts().C23)
// Run the bool-like conversion checks only for C since there bools are
// still not used as the return type from "boolean" operators or as the input
// type for conditional operators.
if (S.getLangOpts().CPlusPlus)
return;
if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
return;
Expand Down
2 changes: 1 addition & 1 deletion clang/test/SemaOpenCL/operators.cl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,6 @@ kernel void pointer_ops(){
bool b = !p;
b = p==0;
int i;
b = !&i;
b = !&i; // expected-warning {{address of 'i' will always evaluate to 'true'}}
b = &i==(int *)1;
}

0 comments on commit 32b1b11

Please sign in to comment.