Author: Arthur Eubanks Date: 2023-05-07T16:51:02-07:00 New Revision: ad5bed5372f3f73a07f0b98a05444e7acda2b9d9
URL: https://github.com/llvm/llvm-project/commit/ad5bed5372f3f73a07f0b98a05444e7acda2b9d9 DIFF: https://github.com/llvm/llvm-project/commit/ad5bed5372f3f73a07f0b98a05444e7acda2b9d9.diff LOG: Revert "[clang] Make predefined expressions string literals under -fms-extensions" This reverts commit 856f384bf94513c89e754906b7d80fbe5377ab53. Breaks bots, e.g. https://lab.llvm.org/buildbot/#/builders/123/builds/18775 Added: Modified: clang/docs/ReleaseNotes.rst clang/include/clang/AST/Expr.h clang/include/clang/AST/IgnoreExpr.h clang/include/clang/AST/Stmt.h clang/include/clang/Basic/DiagnosticGroups.td clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/AST/ASTImporter.cpp clang/lib/AST/Expr.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaInit.cpp clang/lib/Serialization/ASTReaderStmt.cpp clang/lib/Serialization/ASTWriterStmt.cpp Removed: clang/test/Modules/predefined.cpp clang/test/Sema/ms_predefined_expr.cpp ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index cd41106640f87..910a853eafc81 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -416,9 +416,6 @@ Bug Fixes to C++ Support initialization. (`#61567 <https://github.com/llvm/llvm-project/issues/61567>`_) - Fix a crash when expanding a pack as the index of a subscript expression. -- Some predefined expressions are now treated as string literals in MSVC - compatibility mode. - (`#114 <https://github.com/llvm/llvm-project/issues/114>`_) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index db4316d8faf1f..0ab778e5d8cd3 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -1992,7 +1992,7 @@ class PredefinedExpr final private: PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK, - bool IsTransparent, StringLiteral *SL); + StringLiteral *SL); explicit PredefinedExpr(EmptyShell Empty, bool HasFunctionName); @@ -2007,12 +2007,8 @@ class PredefinedExpr final public: /// Create a PredefinedExpr. - /// - /// If IsTransparent, the PredefinedExpr is transparently handled as a - /// StringLiteral. static PredefinedExpr *Create(const ASTContext &Ctx, SourceLocation L, - QualType FNTy, IdentKind IK, bool IsTransparent, - StringLiteral *SL); + QualType FNTy, IdentKind IK, StringLiteral *SL); /// Create an empty PredefinedExpr. static PredefinedExpr *CreateEmpty(const ASTContext &Ctx, @@ -2022,8 +2018,6 @@ class PredefinedExpr final return static_cast<IdentKind>(PredefinedExprBits.Kind); } - bool isTransparent() const { return PredefinedExprBits.IsTransparent; } - SourceLocation getLocation() const { return PredefinedExprBits.Loc; } void setLocation(SourceLocation L) { PredefinedExprBits.Loc = L; } diff --git a/clang/include/clang/AST/IgnoreExpr.h b/clang/include/clang/AST/IgnoreExpr.h index ce30a7fc00558..f8d2d6c7d00c0 100644 --- a/clang/include/clang/AST/IgnoreExpr.h +++ b/clang/include/clang/AST/IgnoreExpr.h @@ -166,11 +166,6 @@ inline Expr *IgnoreParensSingleStep(Expr *E) { return CE->getChosenSubExpr(); } - else if (auto *PE = dyn_cast<PredefinedExpr>(E)) { - if (PE->isTransparent()) - return PE->getFunctionName(); - } - return E; } diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h index e466aa1755daf..ea979d791ce7b 100644 --- a/clang/include/clang/AST/Stmt.h +++ b/clang/include/clang/AST/Stmt.h @@ -364,10 +364,6 @@ class alignas(void *) Stmt { /// for the predefined identifier. unsigned HasFunctionName : 1; - /// True if this PredefinedExpr should be treated as a StringLiteral (for - /// MSVC compatibility). - unsigned IsTransparent : 1; - /// The location of this PredefinedExpr. SourceLocation Loc; }; diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 2ba42f9b73763..87e72f000d494 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -1190,7 +1190,6 @@ def MicrosoftCommentPaste : DiagGroup<"microsoft-comment-paste">; def MicrosoftEndOfFile : DiagGroup<"microsoft-end-of-file">; def MicrosoftInaccessibleBase : DiagGroup<"microsoft-inaccessible-base">; def MicrosoftStaticAssert : DiagGroup<"microsoft-static-assert">; -def MicrosoftInitFromPredefined : DiagGroup<"microsoft-init-from-predefined">; // Aliases. def : DiagGroup<"msvc-include", [MicrosoftInclude]>; @@ -1208,7 +1207,7 @@ def Microsoft : DiagGroup<"microsoft", MicrosoftFlexibleArray, MicrosoftExtraQualification, MicrosoftCast, MicrosoftConstInit, MicrosoftVoidPseudoDtor, MicrosoftAnonTag, MicrosoftCommentPaste, MicrosoftEndOfFile, MicrosoftStaticAssert, - MicrosoftInitFromPredefined, MicrosoftInconsistentDllImport]>; + MicrosoftInconsistentDllImport]>; def ClangClPch : DiagGroup<"clang-cl-pch">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index ab6aaebcf0cd7..b496900fac06e 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -112,9 +112,6 @@ def err_expr_not_string_literal : Error<"expression is not a string literal">; def ext_predef_outside_function : Warning< "predefined identifier is only valid inside function">, InGroup<DiagGroup<"predefined-identifier-outside-function">>; -def ext_init_from_predefined : ExtWarn< - "initializing an array from a '%0' predefined identifier is a Microsoft extension">, - InGroup<MicrosoftInitFromPredefined>; def warn_float_overflow : Warning< "magnitude of floating-point constant too large for type %0; maximum is %1">, InGroup<LiteralRange>; diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index 6e2566b638609..44a5f77fa6c24 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -7068,8 +7068,7 @@ ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { return std::move(Err); return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, - E->getIdentKind(), E->isTransparent(), - ToFunctionName); + E->getIdentKind(), ToFunctionName); } ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 588a7ad322b9a..0ff10a511ef44 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -663,14 +663,13 @@ std::string SYCLUniqueStableNameExpr::ComputeName(ASTContext &Context, } PredefinedExpr::PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK, - bool IsTransparent, StringLiteral *SL) + StringLiteral *SL) : Expr(PredefinedExprClass, FNTy, VK_LValue, OK_Ordinary) { PredefinedExprBits.Kind = IK; assert((getIdentKind() == IK) && "IdentKind do not fit in PredefinedExprBitfields!"); bool HasFunctionName = SL != nullptr; PredefinedExprBits.HasFunctionName = HasFunctionName; - PredefinedExprBits.IsTransparent = IsTransparent; PredefinedExprBits.Loc = L; if (HasFunctionName) setFunctionName(SL); @@ -684,11 +683,11 @@ PredefinedExpr::PredefinedExpr(EmptyShell Empty, bool HasFunctionName) PredefinedExpr *PredefinedExpr::Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, IdentKind IK, - bool IsTransparent, StringLiteral *SL) { + StringLiteral *SL) { bool HasFunctionName = SL != nullptr; void *Mem = Ctx.Allocate(totalSizeToAlloc<Stmt *>(HasFunctionName), alignof(PredefinedExpr)); - return new (Mem) PredefinedExpr(L, FNTy, IK, IsTransparent, SL); + return new (Mem) PredefinedExpr(L, FNTy, IK, SL); } PredefinedExpr *PredefinedExpr::CreateEmpty(const ASTContext &Ctx, diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 29f64cd5c2d87..622b36407495b 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3581,8 +3581,7 @@ ExprResult Sema::BuildPredefinedExpr(SourceLocation Loc, } } - return PredefinedExpr::Create(Context, Loc, ResTy, IK, LangOpts.MicrosoftExt, - SL); + return PredefinedExpr::Create(Context, Loc, ResTy, IK, SL); } ExprResult Sema::BuildSYCLUniqueStableNameExpr(SourceLocation OpLoc, diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index b701b0616a03e..d27cd6b64c62a 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -174,8 +174,6 @@ static void updateStringLiteralType(Expr *E, QualType Ty) { E = GSE->getResultExpr(); } else if (ChooseExpr *CE = dyn_cast<ChooseExpr>(E)) { E = CE->getChosenSubExpr(); - } else if (PredefinedExpr *PE = dyn_cast<PredefinedExpr>(E)) { - E = PE->getFunctionName(); } else { llvm_unreachable("unexpected expr in string literal init"); } @@ -8503,15 +8501,6 @@ ExprResult InitializationSequence::Perform(Sema &S, << Init->getSourceRange(); } - if (S.getLangOpts().MicrosoftExt && Args.size() == 1 && - isa<PredefinedExpr>(Args[0]) && Entity.getType()->isArrayType()) { - // Produce a Microsoft compatibility warning when initializing from a - // predefined expression since MSVC treats predefined expressions as string - // literals. - Expr *Init = Args[0]; - S.Diag(Init->getBeginLoc(), diag::ext_init_from_predefined) << Init; - } - // OpenCL v2.0 s6.13.11.1. atomic variables can be initialized in global scope QualType ETy = Entity.getType(); bool HasGlobalAS = ETy.hasAddressSpace() && diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index a96b1a2fa4f31..cfe0dd121f5f7 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -582,7 +582,6 @@ void ASTStmtReader::VisitPredefinedExpr(PredefinedExpr *E) { bool HasFunctionName = Record.readInt(); E->PredefinedExprBits.HasFunctionName = HasFunctionName; E->PredefinedExprBits.Kind = Record.readInt(); - E->PredefinedExprBits.IsTransparent = Record.readInt(); E->setLocation(readSourceLocation()); if (HasFunctionName) E->setFunctionName(cast<StringLiteral>(Record.readSubExpr())); diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp index 90c30fce0a8e7..b3fa1cb3d5dec 100644 --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -593,7 +593,6 @@ void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) { bool HasFunctionName = E->getFunctionName() != nullptr; Record.push_back(HasFunctionName); Record.push_back(E->getIdentKind()); // FIXME: stable encoding - Record.push_back(E->isTransparent()); Record.AddSourceLocation(E->getLocation()); if (HasFunctionName) Record.AddStmt(E->getFunctionName()); diff --git a/clang/test/Modules/predefined.cpp b/clang/test/Modules/predefined.cpp deleted file mode 100644 index fbe0c4e23ca59..0000000000000 --- a/clang/test/Modules/predefined.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// RUN: rm -rf %t -// RUN: split-file %s %t -// RUN: cd %t - -// RUN: %clang_cc1 -x c++ -std=c++20 -emit-module-interface a.h -o a.pcm -fms-extensions -verify -// RUN: %clang_cc1 -std=c++20 a.cpp -fmodule-file=A=a.pcm -fms-extensions -fsyntax-only -verify - -//--- a.h - -// expected-no-diagnostics - -export module A; - -export template <typename T> -void f() { - char a[] = __func__; -} - -//--- a.cpp - -// expected-warning@a.h:8 {{initializing an array from a '__func__' predefined identifier is a Microsoft extension}} - -import A; - -void g() { - f<int>(); // expected-note {{in instantiation of function template specialization 'f<int>' requested here}} -} diff --git a/clang/test/Sema/ms_predefined_expr.cpp b/clang/test/Sema/ms_predefined_expr.cpp deleted file mode 100644 index be56c59e5a126..0000000000000 --- a/clang/test/Sema/ms_predefined_expr.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// RUN: %clang_cc1 %s -fsyntax-only -Wmicrosoft -verify -fms-extensions - -void f() { - const char a[] = __FUNCTION__; // expected-warning{{initializing an array from a '__FUNCTION__' predefined identifier is a Microsoft extension}} - const char b[] = __FUNCDNAME__; // expected-warning{{initializing an array from a '__FUNCDNAME__' predefined identifier is a Microsoft extension}} - const char c[] = __FUNCSIG__; // expected-warning{{initializing an array from a '__FUNCSIG__' predefined identifier is a Microsoft extension}} - const char d[] = __func__; // expected-warning{{initializing an array from a '__func__' predefined identifier is a Microsoft extension}} - const char e[] = __PRETTY_FUNCTION__; // expected-warning{{initializing an array from a '__PRETTY_FUNCTION__' predefined identifier is a Microsoft extension}} -} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits