forked from rust-lang/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang][sema] Generate builtin operator overloads for (volatile) _Ato…
…mic types We observed a failed assert in overloaded compound-assignment operator resolution: ``` Assertion failed: (Result.isInvalid() && "C++ binary operator overloading is missing candidates!"), function CreateOverloadedBinOp, file SemaOverload.cpp, line 13944. ... frame rust-lang#4: clang` clang::Sema::CreateOverloadedBinOp(..., Opc=BO_OrAssign, ..., PerformADL=true, AllowRewrittenCandidates=false, ...) at SemaOverload.cpp:13943 frame rust-lang#5: clang` BuildOverloadedBinOp(..., Opc=BO_OrAssign, ...) at SemaExpr.cpp:15228 frame rust-lang#6: clang` clang::Sema::BuildBinOp(..., Opc=BO_OrAssign, ...) at SemaExpr.cpp:15330 frame rust-lang#7: clang` clang::Sema::ActOnBinOp(..., Kind=pipeequal, ...) at SemaExpr.cpp:15187 frame rust-lang#8: clang` clang::Parser::ParseRHSOfBinaryExpression(..., MinPrec=Assignment) at ParseExpr.cpp:629 frame rust-lang#9: clang` clang::Parser::ParseAssignmentExpression(..., isTypeCast=NotTypeCast) at ParseExpr.cpp:176 frame rust-lang#10: clang` clang::Parser::ParseExpression(... isTypeCast=NotTypeCast) at ParseExpr.cpp:124 frame rust-lang#11: clang` clang::Parser::ParseExprStatement(...) at ParseStmt.cpp:464 ``` A simple reproducer is: ``` _Atomic unsigned an_atomic_uint; enum { an_enum_value = 1 }; void enum1() { an_atomic_uint += an_enum_value; } ``` This patch fixes the issue by generating builtin operator overloads for (volatile) _Atomic types. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D125349
- Loading branch information
1 parent
f125518
commit b02d970
Showing
4 changed files
with
191 additions
and
25 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
55 changes: 55 additions & 0 deletions
55
clang/test/CodeGenCXX/atomic-builtin-compound-assignment-overload.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,55 @@ | ||
// RUN: %clang_cc1 -std=gnu++11 -emit-llvm -triple=x86_64-linux-gnu -o - %s | FileCheck %s | ||
|
||
_Atomic unsigned an_atomic_uint; | ||
|
||
enum { an_enum_value = 1 }; | ||
|
||
// CHECK-LABEL: define {{.*}}void @_Z5enum1v() | ||
void enum1() { | ||
an_atomic_uint += an_enum_value; | ||
// CHECK: atomicrmw add ptr | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}void @_Z5enum2v() | ||
void enum2() { | ||
an_atomic_uint |= an_enum_value; | ||
// CHECK: atomicrmw or ptr | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}void @_Z5enum3RU7_Atomicj({{.*}}) | ||
void enum3(_Atomic unsigned &an_atomic_uint_param) { | ||
an_atomic_uint_param += an_enum_value; | ||
// CHECK: atomicrmw add ptr | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}void @_Z5enum4RU7_Atomicj({{.*}}) | ||
void enum4(_Atomic unsigned &an_atomic_uint_param) { | ||
an_atomic_uint_param |= an_enum_value; | ||
// CHECK: atomicrmw or ptr | ||
} | ||
|
||
volatile _Atomic unsigned an_volatile_atomic_uint; | ||
|
||
// CHECK-LABEL: define {{.*}}void @_Z5enum5v() | ||
void enum5() { | ||
an_volatile_atomic_uint += an_enum_value; | ||
// CHECK: atomicrmw add ptr | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}void @_Z5enum6v() | ||
void enum6() { | ||
an_volatile_atomic_uint |= an_enum_value; | ||
// CHECK: atomicrmw or ptr | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}void @_Z5enum7RVU7_Atomicj({{.*}}) | ||
void enum7(volatile _Atomic unsigned &an_volatile_atomic_uint_param) { | ||
an_volatile_atomic_uint_param += an_enum_value; | ||
// CHECK: atomicrmw add ptr | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}void @_Z5enum8RVU7_Atomicj({{.*}}) | ||
void enum8(volatile _Atomic unsigned &an_volatile_atomic_uint_param) { | ||
an_volatile_atomic_uint_param |= an_enum_value; | ||
// CHECK: atomicrmw or ptr | ||
} |
16 changes: 16 additions & 0 deletions
16
clang/test/SemaCXX/atomic-builtin-compound-assignment-overload.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,16 @@ | ||
// RUN: %clang_cc1 -std=gnu++98 -fsyntax-only -verify %s | ||
// expected-no-diagnostics | ||
|
||
_Atomic unsigned an_atomic_uint; | ||
|
||
enum { an_enum_value = 1 }; | ||
|
||
void enum1() { an_atomic_uint += an_enum_value; } | ||
|
||
void enum2() { an_atomic_uint |= an_enum_value; } | ||
|
||
volatile _Atomic unsigned an_volatile_atomic_uint; | ||
|
||
void enum3() { an_volatile_atomic_uint += an_enum_value; } | ||
|
||
void enum4() { an_volatile_atomic_uint |= an_enum_value; } |