[clang] [clang] Use CPlusPlus language option instead of Bool (PR #80975)
Mariya Podchishchaeva via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 7 03:25:15 PST 2024
https://github.com/Fznamznon created https://github.com/llvm/llvm-project/pull/80975
As it was pointed out in https://github.com/llvm/llvm-project/pull/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.
>From 32b1b114cdf9c77af7a400b8f7705d50de2ef9de Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" <mariya.podchishchaeva at intel.com>
Date: Wed, 7 Feb 2024 03:07:47 -0800
Subject: [PATCH] [clang] Use CPlusPlus language option instead of Bool
As it was pointed out in https://github.com/llvm/llvm-project/pull/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.
---
clang/lib/Sema/SemaChecking.cpp | 8 ++++----
clang/test/SemaOpenCL/operators.cl | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index b071a02ca3713..6588aa23e1116 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -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;
diff --git a/clang/test/SemaOpenCL/operators.cl b/clang/test/SemaOpenCL/operators.cl
index cf359acd5acb9..76a7692a7105c 100644
--- a/clang/test/SemaOpenCL/operators.cl
+++ b/clang/test/SemaOpenCL/operators.cl
@@ -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;
}
More information about the cfe-commits
mailing list