forked from CTSRD-CHERI/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Clang] Fix defaulted equality operator so that it does not attempt t…
…o compare unnamed bit-fields If we look at class.bit p2 it tells us that that unnamed bit-fields are not members and class.compare.default p5 tells us that we should only compare non-static data members of the class. This fixes: llvm/llvm-project#61335 and llvm/llvm-project#61417 Differential Revision: https://reviews.llvm.org/D146329
- Loading branch information
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
clang/test/CodeGenCXX/defaulted_equality_ignore_unnamed_bitfields.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux -emit-llvm -o - | FileCheck %s | ||
|
||
// GH61417 | ||
// Check that we don't attempt to compare the unnamed bitfields | ||
struct A { | ||
unsigned x : 1; | ||
unsigned : 1; | ||
|
||
friend bool operator==(A, A); | ||
}; | ||
|
||
|
||
struct B { | ||
unsigned x : 1; | ||
unsigned : 31; | ||
|
||
friend bool operator==(B, B); | ||
}; | ||
|
||
bool operator==(A, A) = default; | ||
// CHECK: define{{.*}} @_Zeq1AS_ | ||
// CHECK: %[[LHS:.+]] = alloca %struct.A, align 4 | ||
// CHECK: %[[RHS:.+]] = alloca %struct.A, align 4 | ||
// CHECK: %[[LHS_LOAD:.+]] = load i8, ptr %[[LHS]], align 4 | ||
// CHECK: %[[LHS_CLEAR:.+]] = and i8 %[[LHS_LOAD]], 1 | ||
// CHECK: %[[LHS_CAST:.+]] = zext i8 %[[LHS_CLEAR]] to i32 | ||
|
||
// CHECK: %[[RHS_LOAD:.+]] = load i8, ptr %[[RHS]] | ||
// CHECK: %[[RHS_CLEAR:.+]] = and i8 %[[RHS_LOAD]], 1 | ||
// CHECK: %[[RHS_CAST:.+]] = zext i8 %[[RHS_CLEAR]] to i32 | ||
// CHECK: %[[CMP:.*]] = icmp eq i32 %[[LHS_CAST]], %[[RHS_CAST]] | ||
// CHECK: ret i1 %[[CMP]] | ||
|
||
bool operator==(B, B) = default; | ||
// CHECK: define{{.*}} @_Zeq1BS_ | ||
// CHECK: %[[LHS_B:.+]] = alloca %struct.B, align 4 | ||
// CHECK: %[[RHS_B:.+]] = alloca %struct.B, align 4 | ||
// CHECK: %[[LHS_LOAD_B:.+]] = load i32, ptr %[[LHS_B]], align 4 | ||
// CHECK: %[[LHS_CLEAR_B:.+]] = and i32 %[[LHS_LOAD_B]], 1 | ||
|
||
// CHECK: %[[RHS_LOAD_B:.+]] = load i32, ptr %[[RHS_B]] | ||
// CHECK: %[[RHS_CLEAR_B:.+]] = and i32 %[[RHS_LOAD_B]], 1 | ||
// CHECK: %[[CMP_B:.*]] = icmp eq i32 %[[LHS_CLEAR_B]], %[[RHS_CLEAR_B]] | ||
// CHECK: ret i1 %[[CMP_B]] |