From 02a65146aaa1f209013415e9247771805ca2ad5d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 25 Jul 2008 23:52:49 +0000 Subject: [PATCH] GCC supports the complex conjugate operator (an extension) on complex int as well as complex float. rdar://6097730 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54080 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 18 ++++++++---------- test/Sema/complex-int.c | 9 +++++++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 99c070990b..25a86fabdb 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -2261,16 +2261,14 @@ Action::ExprResult Sema::ActOnUnaryOp(SourceLocation OpLoc, tok::TokenKind Op, case UnaryOperator::Not: // bitwise complement UsualUnaryConversions(Input); resultType = Input->getType(); - // C99 6.5.3.3p1. We allow complex as a GCC extension. - if (!resultType->isIntegerType()) { - if (resultType->isComplexType()) - // C99 does not support '~' for complex conjugation. - Diag(OpLoc, diag::ext_integer_complement_complex, - resultType.getAsString()); - else - return Diag(OpLoc, diag::err_typecheck_unary_expr, - resultType.getAsString()); - } + // C99 6.5.3.3p1. We allow complex int and float as a GCC extension. + if (resultType->isComplexType() || resultType->isComplexIntegerType()) + // C99 does not support '~' for complex conjugation. + Diag(OpLoc, diag::ext_integer_complement_complex, + resultType.getAsString(), Input->getSourceRange()); + else if (!resultType->isIntegerType()) + return Diag(OpLoc, diag::err_typecheck_unary_expr, + resultType.getAsString(), Input->getSourceRange()); break; case UnaryOperator::LNot: // logical negation // Unlike +/-/~, integer promotions aren't done here (C99 6.5.3.3p5). diff --git a/test/Sema/complex-int.c b/test/Sema/complex-int.c index d7244d113b..1e58b5320c 100644 --- a/test/Sema/complex-int.c +++ b/test/Sema/complex-int.c @@ -41,3 +41,12 @@ TestPairs(5); TestPairs(6); TestPairs(7); TestPairs(8); } +// rdar://6097730 +void test3(_Complex int *x) { + *x = ~*x; +} + +void test4(_Complex float *x) { + *x = ~*x; +} +