forked from llvm/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.
Reapply "[Clang][Sema] Earlier type checking for builtin unary operat…
…ors (llvm#90500)"
- Loading branch information
1 parent
97e35e0
commit 365d975
Showing
15 changed files
with
402 additions
and
245 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,65 @@ | ||
// RUN: %clang_cc1 -Wno-unused -fsyntax-only %s -verify | ||
|
||
struct A { | ||
void operator*(); | ||
void operator+(); | ||
void operator-(); | ||
void operator!(); | ||
void operator~(); | ||
void operator&(); | ||
void operator++(); | ||
void operator--(); | ||
}; | ||
|
||
struct B { }; | ||
|
||
template<typename T, typename U> | ||
void dependent(T t, T* pt, T U::* mpt, T(&ft)(), T(&at)[4]) { | ||
*t; | ||
+t; | ||
-t; | ||
!t; | ||
~t; | ||
&t; | ||
++t; | ||
--t; | ||
|
||
*pt; | ||
+pt; | ||
-pt; // expected-error {{invalid argument type 'T *' to unary expression}} | ||
!pt; | ||
~pt; // expected-error {{invalid argument type 'T *' to unary expression}} | ||
&pt; | ||
++pt; | ||
--pt; | ||
|
||
*mpt; // expected-error {{indirection requires pointer operand ('T U::*' invalid)}} | ||
+mpt; // expected-error {{invalid argument type 'T U::*' to unary expression}} | ||
-mpt; // expected-error {{invalid argument type 'T U::*' to unary expression}} | ||
!mpt; | ||
~mpt; // expected-error {{invalid argument type 'T U::*' to unary expression}} | ||
&mpt; | ||
++mpt; // expected-error {{cannot increment value of type 'T U::*'}} | ||
--mpt; // expected-error {{cannot decrement value of type 'T U::*'}} | ||
|
||
*ft; | ||
+ft; | ||
-ft; // expected-error {{invalid argument type 'T (*)()' to unary expression}} | ||
!ft; | ||
~ft; // expected-error {{invalid argument type 'T (*)()' to unary expression}} | ||
&ft; | ||
++ft; // expected-error {{cannot increment value of type 'T ()'}} | ||
--ft; // expected-error {{cannot decrement value of type 'T ()'}} | ||
|
||
*at; | ||
+at; | ||
-at; // expected-error {{invalid argument type 'T *' to unary expression}} | ||
!at; | ||
~at; // expected-error {{invalid argument type 'T *' to unary expression}} | ||
&at; | ||
++at; // expected-error {{cannot increment value of type 'T[4]'}} | ||
--at; // expected-error {{cannot decrement value of type 'T[4]'}} | ||
} | ||
|
||
// Make sure we only emit diagnostics once. | ||
template void dependent(A t, A* pt, A B::* mpt, A(&ft)(), A(&at)[4]); |
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 |
---|---|---|
@@ -1,41 +1,139 @@ | ||
// RUN: %clang_cc1 -std=c++17 -ast-dump %s -ast-dump-filter Test | FileCheck %s | ||
// RUN: %clang_cc1 -std=c++17 -Wno-unused -ast-dump %s -ast-dump-filter Test | FileCheck %s | ||
|
||
struct A{}; | ||
namespace Test { | ||
template<typename T, typename U> | ||
void Unary(T t, T* pt, T U::* mpt, T(&ft)(), T(&at)[4]) { | ||
// CHECK: UnaryOperator {{.*}} '<dependent type>' lvalue prefix '*' cannot overflow | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T' lvalue ParmVar {{.*}} 't' 'T' | ||
*t; | ||
|
||
template <typename T, typename U> | ||
auto Test(T* pt, U* pu) { | ||
// CHECK: UnaryOperator {{.*}} '<dependent type>' lvalue prefix '*' | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
(void)*pt; | ||
// CHECK: UnaryOperator {{.*}} '<dependent type>' prefix '+' cannot overflow | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T' lvalue ParmVar {{.*}} 't' 'T' | ||
+t; | ||
|
||
// CHECK: UnaryOperator {{.*}} '<dependent type>' lvalue prefix '++' | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
(void)(++pt); | ||
// CHECK: UnaryOperator {{.*}} '<dependent type>' prefix '-' cannot overflow | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T' lvalue ParmVar {{.*}} 't' 'T' | ||
-t; | ||
|
||
// CHECK: UnaryOperator {{.*}} '<dependent type>' prefix '+' | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
(void)(+pt); | ||
// CHECK: UnaryOperator {{.*}} '<dependent type>' prefix '!' cannot overflow | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T' lvalue ParmVar {{.*}} 't' 'T' | ||
!t; | ||
|
||
// CHECK: BinaryOperator {{.*}} '<dependent type>' '+' | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 3 | ||
(void)(pt + 3); | ||
// CHECK: UnaryOperator {{.*}} '<dependent type>' prefix '~' cannot overflow | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T' lvalue ParmVar {{.*}} 't' 'T' | ||
~t; | ||
|
||
// CHECK: BinaryOperator {{.*}} '<dependent type>' '-' | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
(void)(pt - pt); | ||
// CHECK: UnaryOperator {{.*}} '<dependent type>' prefix '&' cannot overflow | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T' lvalue ParmVar {{.*}} 't' 'T' | ||
&t; | ||
|
||
// CHECK: BinaryOperator {{.*}} '<dependent type>' '-' | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'U *' lvalue ParmVar {{.*}} 'pu' 'U *' | ||
(void)(pt - pu); | ||
// CHECK: UnaryOperator {{.*}} '<dependent type>' lvalue prefix '++' cannot overflow | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T' lvalue ParmVar {{.*}} 't' 'T' | ||
++t; | ||
|
||
// CHECK: BinaryOperator {{.*}} '<dependent type>' '==' | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'U *' lvalue ParmVar {{.*}} 'pu' 'U *' | ||
(void)(pt == pu); | ||
// CHECK: UnaryOperator {{.*}} '<dependent type>' lvalue prefix '--' cannot overflow | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T' lvalue ParmVar {{.*}} 't' 'T' | ||
--t; | ||
|
||
} | ||
// CHECK: UnaryOperator {{.*}} 'T' lvalue prefix '*' cannot overflow | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'T *' <LValueToRValue> | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
*pt; | ||
|
||
// CHECK: UnaryOperator {{.*}} 'T *' prefix '+' cannot overflow | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'T *' <LValueToRValue> | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
+pt; | ||
|
||
// CHECK: UnaryOperator {{.*}} 'bool' prefix '!' cannot overflow | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'bool' <PointerToBoolean> | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'T *' <LValueToRValue> | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
!pt; | ||
|
||
// CHECK: UnaryOperator {{.*}} '<dependent type>' prefix '&' cannot overflow | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
&pt; | ||
|
||
// CHECK: UnaryOperator {{.*}} 'T *' lvalue prefix '++' cannot overflow | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
++pt; | ||
|
||
// CHECK: UnaryOperator {{.*}} 'T *' lvalue prefix '--' cannot overflow | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
--pt; | ||
|
||
// CHECK: UnaryOperator {{.*}} 'bool' prefix '!' cannot overflow | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'bool' <MemberPointerToBoolean> | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'T U::*' <LValueToRValue> | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T U::*' lvalue ParmVar {{.*}} 'mpt' 'T U::*' | ||
!mpt; | ||
|
||
// CHECK: UnaryOperator {{.*}} '<dependent type>' prefix '&' cannot overflow | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T U::*' lvalue ParmVar {{.*}} 'mpt' 'T U::*' | ||
&mpt; | ||
|
||
// CHECK: UnaryOperator {{.*}} 'T ()' lvalue prefix '*' cannot overflow | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'T (*)()' <FunctionToPointerDecay> | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T ()' lvalue ParmVar {{.*}} 'ft' 'T (&)()' | ||
*ft; | ||
|
||
// CHECK: UnaryOperator {{.*}} 'T (*)()' prefix '+' cannot overflow | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'T (*)()' <FunctionToPointerDecay> | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T ()' lvalue ParmVar {{.*}} 'ft' 'T (&)()' | ||
+ft; | ||
|
||
// CHECK: UnaryOperator {{.*}} 'bool' prefix '!' cannot overflow | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'bool' <PointerToBoolean> | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'T (*)()' <FunctionToPointerDecay> | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T ()' lvalue ParmVar {{.*}} 'ft' 'T (&)()' | ||
!ft; | ||
|
||
// CHECK: UnaryOperator {{.*}} '<dependent type>' prefix '&' cannot overflow | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T ()' lvalue ParmVar {{.*}} 'ft' 'T (&)()' | ||
&ft; | ||
|
||
// CHECK: UnaryOperator {{.*}} 'T' lvalue prefix '*' cannot overflow | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'T *' <ArrayToPointerDecay> | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T[4]' lvalue ParmVar {{.*}} 'at' 'T (&)[4]' | ||
*at; | ||
|
||
// CHECK: UnaryOperator {{.*}} 'T *' prefix '+' cannot overflow | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'T *' <ArrayToPointerDecay> | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T[4]' lvalue ParmVar {{.*}} 'at' 'T (&)[4]' | ||
+at; | ||
|
||
// CHECK: UnaryOperator {{.*}} 'bool' prefix '!' cannot overflow | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'bool' <PointerToBoolean> | ||
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'T *' <ArrayToPointerDecay> | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T[4]' lvalue ParmVar {{.*}} 'at' 'T (&)[4]' | ||
!at; | ||
|
||
// CHECK: UnaryOperator {{.*}} '<dependent type>' prefix '&' cannot overflow | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T[4]' lvalue ParmVar {{.*}} 'at' 'T (&)[4]' | ||
&at; | ||
} | ||
|
||
template<typename T, typename U> | ||
void Binary(T* pt, U* pu) { | ||
// CHECK: BinaryOperator {{.*}} '<dependent type>' '+' | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 3 | ||
pt + 3; | ||
|
||
// CHECK: BinaryOperator {{.*}} '<dependent type>' '-' | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
pt - pt; | ||
|
||
// CHECK: BinaryOperator {{.*}} '<dependent type>' '-' | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'U *' lvalue ParmVar {{.*}} 'pu' 'U *' | ||
pt - pu; | ||
|
||
// CHECK: BinaryOperator {{.*}} '<dependent type>' '==' | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *' | ||
// CHECK-NEXT: DeclRefExpr {{.*}} 'U *' lvalue ParmVar {{.*}} 'pu' 'U *' | ||
pt == pu; | ||
} | ||
} // namespace Test |
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
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
Oops, something went wrong.