diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2024-07-08 13:43:03 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-08 13:43:03 -0400 |
commit | c22625cb3eaf052e2377881d64640196ff5da3d1 (patch) | |
tree | 1db8b9d5e4fd3dfa24198ed8bb59c6f9597a4bfe /clang/lib | |
parent | 03d4332625d13014ac94dcd145f538fbfe4c4d0c (diff) | |
download | llvm-c22625cb3eaf052e2377881d64640196ff5da3d1.zip llvm-c22625cb3eaf052e2377881d64640196ff5da3d1.tar.gz llvm-c22625cb3eaf052e2377881d64640196ff5da3d1.tar.bz2 |
[C2y] Remove support for _Imaginary (#97436)
WG14 N3274 removed _Imaginary from Annex G. Clang has never fully
supported Annex G or _Imaginary, so removal is pretty trivial for us.
Note, we are keeping _Imaginary as a keyword so that we get better
diagnostic behavior. This is still conforming because _I makes it a
reserved identifier, so it's not available for users to use as an
identifier anyway.
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CGExprComplex.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Sema/DeclSpec.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Sema/SemaCodeComplete.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Sema/SemaLookup.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Sema/SemaType.cpp | 4 |
5 files changed, 12 insertions, 11 deletions
diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp index 84ad3b5..000d4ff 100644 --- a/clang/lib/CodeGen/CGExprComplex.cpp +++ b/clang/lib/CodeGen/CGExprComplex.cpp @@ -817,8 +817,6 @@ ComplexPairTy ComplexExprEmitter::EmitBinMul(const BinOpInfo &Op) { // // But we can fold away components which would be zero due to a real // operand according to C11 Annex G.5.1p2. - // FIXME: C11 also provides for imaginary types which would allow folding - // still more of this within the type system. CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, Op.FPFeatures); if (Op.LHS.second && Op.RHS.second) { @@ -1049,9 +1047,6 @@ ComplexPairTy ComplexExprEmitter::EmitBinDiv(const BinOpInfo &Op) { // delegate to a libcall to handle all of the complexities and minimize // underflow/overflow cases. When FastMath is allowed we construct the // divide inline using the same algorithm as for integer operands. - // - // FIXME: We would be able to avoid the libcall in many places if we - // supported imaginary types in addition to complex types. BinOpInfo LibCallOp = Op; // If LHS was a real, supply a null imaginary part. if (!LHSi) diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp index 96c90a60..9a4d52d 100644 --- a/clang/lib/Sema/DeclSpec.cpp +++ b/clang/lib/Sema/DeclSpec.cpp @@ -1146,7 +1146,7 @@ void DeclSpec::SaveWrittenBuiltinSpecs() { } /// Finish - This does final analysis of the declspec, rejecting things like -/// "_Imaginary" (lacking an FP type). After calling this method, DeclSpec is +/// "_Complex" (lacking an FP type). After calling this method, DeclSpec is /// guaranteed to be self-consistent, even if an error occurred. void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) { // Before possibly changing their values, save specs as written. @@ -1331,8 +1331,8 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) { break; } - // TODO: if the implementation does not implement _Complex or _Imaginary, - // disallow their use. Need information about the backend. + // TODO: if the implementation does not implement _Complex, disallow their + // use. Need information about the backend. if (TypeSpecComplex != TSC_unspecified) { if (TypeSpecType == TST_unspecified) { S.Diag(TSCLoc, diag::ext_plain_complex) diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 7ea760c..8fea7b0 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -1805,7 +1805,8 @@ static void AddTypeSpecifierResults(const LangOptions &LangOpts, if (LangOpts.C99) { // C99-specific Results.AddResult(Result("_Complex", CCP_Type)); - Results.AddResult(Result("_Imaginary", CCP_Type)); + if (!LangOpts.C2y) + Results.AddResult(Result("_Imaginary", CCP_Type)); Results.AddResult(Result("_Bool", CCP_Type)); Results.AddResult(Result("restrict", CCP_Type)); } diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index a4acf3b..7851c5d 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -4983,7 +4983,7 @@ static void AddKeywordsToConsumer(Sema &SemaRef, static const char *const CTypeSpecs[] = { "char", "const", "double", "enum", "float", "int", "long", "short", "signed", "struct", "union", "unsigned", "void", "volatile", - "_Complex", "_Imaginary", + "_Complex", // storage-specifiers as well "extern", "inline", "static", "typedef" }; @@ -4991,6 +4991,9 @@ static void AddKeywordsToConsumer(Sema &SemaRef, for (const auto *CTS : CTypeSpecs) Consumer.addKeywordResult(CTS); + if (SemaRef.getLangOpts().C99 && !SemaRef.getLangOpts().C2y) + Consumer.addKeywordResult("_Imaginary"); + if (SemaRef.getLangOpts().C99) Consumer.addKeywordResult("restrict"); if (SemaRef.getLangOpts().Bool || SemaRef.getLangOpts().CPlusPlus) diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 066003c..f3510a0 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1423,7 +1423,9 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) { Result = Context.getVectorType(Result, 128/typeSize, VecKind); } - // FIXME: Imaginary. + // _Imaginary was a feature of C99 through C23 but was never supported in + // Clang. The feature was removed in C2y, but we retain the unsupported + // diagnostic for an improved user experience. if (DS.getTypeSpecComplex() == DeclSpec::TSC_imaginary) S.Diag(DS.getTypeSpecComplexLoc(), diag::err_imaginary_not_supported); |