summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Sema/SemaExpr.cpp8
-rw-r--r--clang/test/Sema/self-comparison.c5
-rw-r--r--clang/test/SemaCXX/self-comparison.cpp4
3 files changed, 13 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 933289360b2..e9e65fc1fc5 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9627,7 +9627,8 @@ static void diagnoseTautologicalComparison(Sema &S, SourceLocation Loc,
// result.
ValueDecl *DL = getCompareDecl(LHSStripped);
ValueDecl *DR = getCompareDecl(RHSStripped);
- if (DL && DR && DL == DR && !IsWithinTemplateSpecialization(DL)) {
+ if (DL && DR && declaresSameEntity(DL, DR) &&
+ !IsWithinTemplateSpecialization(DL)) {
StringRef Result;
switch (Opc) {
case BO_EQ: case BO_LE: case BO_GE:
@@ -9648,10 +9649,9 @@ static void diagnoseTautologicalComparison(Sema &S, SourceLocation Loc,
<< Result);
} else if (DL && DR && LHSType->isArrayType() && RHSType->isArrayType() &&
!DL->getType()->isReferenceType() &&
- !DR->getType()->isReferenceType()) {
+ !DR->getType()->isReferenceType() &&
+ !DL->isWeak() && !DR->isWeak()) {
// What is it always going to evaluate to?
- // FIXME: This is wrong if DL and DR are different Decls for the same
- // entity. It's also wrong if DL and/or DR are weak declarations.
StringRef Result;
switch(Opc) {
case BO_EQ: // e.g. array1 == array2
diff --git a/clang/test/Sema/self-comparison.c b/clang/test/Sema/self-comparison.c
index edb3a6a4c8a..bd7adcd9cda 100644
--- a/clang/test/Sema/self-comparison.c
+++ b/clang/test/Sema/self-comparison.c
@@ -86,3 +86,8 @@ int R8435950(int i) {
return 1;
}
+__attribute__((weak)) int weak_1[3];
+__attribute__((weak)) int weak_2[3];
+_Bool compare_weak() {
+ return weak_1 == weak_2;
+}
diff --git a/clang/test/SemaCXX/self-comparison.cpp b/clang/test/SemaCXX/self-comparison.cpp
index fb15ec84306..2af19abb30a 100644
--- a/clang/test/SemaCXX/self-comparison.cpp
+++ b/clang/test/SemaCXX/self-comparison.cpp
@@ -21,3 +21,7 @@ struct A {
return a == c; // expected-warning {{array comparison always evaluates to false}}
}
};
+
+namespace NA { extern "C" int x[3]; }
+namespace NB { extern "C" int x[3]; }
+bool k = NA::x == NB::x; // expected-warning {{self-comparison always evaluates to true}}
OpenPOWER on IntegriCloud