r332384 - Fixed some rtti-options tests.
Author: ssrivastava Date: Tue May 15 11:28:42 2018 New Revision: 332384 URL: http://llvm.org/viewvc/llvm-project?rev=332384&view=rev Log: Fixed some rtti-options tests. Certain tests in rtti-options.cpp are not really testing anything because they are testing for the absence of -frtti option to the cc1 process. Since the cc1 process does not take -frtti option, these tests are passing tautologically. The RTTI mode is enabled by default in cc1, and -fno-rtti disables it. Therefore the correct way to check for enabling of RTTI is to check for the absence of -fno-rtti to cc1, and the correct way to check for disabling of RTTI is to check for the presence of -fno-rtti to cc1. This patch fixes those tests. Differential Revision: https://reviews.llvm.org/D46836 Modified: cfe/trunk/test/Driver/rtti-options.cpp Modified: cfe/trunk/test/Driver/rtti-options.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/rtti-options.cpp?rev=332384&r1=332383&r2=332384&view=diff == --- cfe/trunk/test/Driver/rtti-options.cpp (original) +++ cfe/trunk/test/Driver/rtti-options.cpp Tue May 15 11:28:42 2018 @@ -5,8 +5,8 @@ // Special cases: -fcxx-exceptions in C code should warn about unused arguments // We should also not have any rtti-related arguments -// RUN: %clang -x c -### -target x86_64-scei-ps4 -c -fcxx-exceptions %s 2>&1 | FileCheck -check-prefix=CHECK-UNUSED -check-prefix=CHECK-RTTI -check-prefix=CHECK-NO-RTTI %s -// RUN: %clang -x c -### -target x86_64-unknown-unknown -c -fcxx-exceptions %s 2>&1 | FileCheck -check-prefix=CHECK-UNUSED -check-prefix=CHECK-RTTI -check-prefix=CHECK-NO-RTTI %s +// RUN: %clang -x c -### -target x86_64-scei-ps4 -c -fcxx-exceptions %s 2>&1 | FileCheck -check-prefix=CHECK-UNUSED -check-prefix=CHECK-RTTI %s +// RUN: %clang -x c -### -target x86_64-unknown-unknown -c -fcxx-exceptions %s 2>&1 | FileCheck -check-prefix=CHECK-UNUSED -check-prefix=CHECK-RTTI %s // Make sure we keep the last -frtti/-fno-rtti argument // RUN: %clang -### -c -fno-rtti -frtti %s 2>&1 | FileCheck -check-prefix=CHECK-RTTI %s @@ -56,6 +56,6 @@ // CHECK-EXC-ERROR: invalid argument '-fno-rtti' not allowed with '-fexceptions' // CHECK-EXC-ERROR-CXX: invalid argument '-fno-rtti' not allowed with '-fcxx-exceptions' // CHECK-RTTI-NOT: "-fno-rtti" -// CHECK-NO-RTTI-NOT: "-frtti" +// CHECK-NO-RTTI: "-fno-rtti" // CHECK-OK-NOT: {{warning:|error:}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r332784 - Do not enable RTTI with -fexceptions, for PS4
Author: ssrivastava Date: Fri May 18 16:32:01 2018 New Revision: 332784 URL: http://llvm.org/viewvc/llvm-project?rev=332784&view=rev Log: Do not enable RTTI with -fexceptions, for PS4 NFC for targets other than PS4. This patch is a change in behavior for PS4, in that PS4 will no longer enable RTTI when -fexceptions is specified (RTTI and Exceptions are disabled by default on PS4). RTTI will remain disabled except for types being thrown or caught. Also, '-fexceptions -fno-rtti' (previously prohibited on PS4) is now accepted, as it is for other targets. This patch removes some PS4 specific code, making the code cleaner. Also, in the test file rtti-options.cpp, PS4 tests where the behavior is the same as the generic x86_64-linux are removed, making the test cleaner. Differential Revision: https://reviews.llvm.org/D46982 Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td cfe/trunk/include/clang/Driver/ToolChain.h cfe/trunk/lib/Driver/SanitizerArgs.cpp cfe/trunk/lib/Driver/ToolChain.cpp cfe/trunk/lib/Driver/ToolChains/Clang.cpp cfe/trunk/test/Driver/rtti-options.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=332784&r1=332783&r2=332784&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Fri May 18 16:32:01 2018 @@ -266,9 +266,6 @@ def warn_incompatible_sysroot : Warning< InGroup>; def warn_debug_compression_unavailable : Warning<"cannot compress debug sections (zlib not installed)">, InGroup>; -def warn_drv_enabling_rtti_with_exceptions : Warning< - "implicitly enabling rtti for exception handling">, - InGroup>; def warn_drv_disabling_vptr_no_rtti_default : Warning< "implicitly disabling vptr sanitizer because rtti wasn't enabled">, InGroup; Modified: cfe/trunk/include/clang/Driver/ToolChain.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=332784&r1=332783&r2=332784&view=diff == --- cfe/trunk/include/clang/Driver/ToolChain.h (original) +++ cfe/trunk/include/clang/Driver/ToolChain.h Fri May 18 16:32:01 2018 @@ -100,10 +100,8 @@ public: }; enum RTTIMode { -RM_EnabledExplicitly, -RM_EnabledImplicitly, -RM_DisabledExplicitly, -RM_DisabledImplicitly +RM_Enabled, +RM_Disabled, }; private: Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=332784&r1=332783&r2=332784&view=diff == --- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original) +++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Fri May 18 16:32:01 2018 @@ -288,19 +288,18 @@ SanitizerArgs::SanitizerArgs(const ToolC // Test for -fno-rtti + explicit -fsanitizer=vptr before expanding groups // so we don't error out if -fno-rtti and -fsanitize=undefined were // passed. - if (Add & Vptr && - (RTTIMode == ToolChain::RM_DisabledImplicitly || - RTTIMode == ToolChain::RM_DisabledExplicitly)) { -if (RTTIMode == ToolChain::RM_DisabledImplicitly) - // Warn about not having rtti enabled if the vptr sanitizer is - // explicitly enabled - D.Diag(diag::warn_drv_disabling_vptr_no_rtti_default); -else { - const llvm::opt::Arg *NoRTTIArg = TC.getRTTIArg(); - assert(NoRTTIArg && - "RTTI disabled explicitly but we have no argument!"); + if ((Add & Vptr) && (RTTIMode == ToolChain::RM_Disabled)) { +if (const llvm::opt::Arg *NoRTTIArg = TC.getRTTIArg()) { + assert(NoRTTIArg->getOption().matches(options::OPT_fno_rtti) && + "RTTI disabled without -fno-rtti option?"); + // The user explicitly passed -fno-rtti with -fsanitize=vptr, but + // the vptr sanitizer requires RTTI, so this is a user error. D.Diag(diag::err_drv_argument_not_allowed_with) << "-fsanitize=vptr" << NoRTTIArg->getAsString(Args); +} else { + // The vptr sanitizer requires RTTI, but RTTI is disabled (by + // default). Warn that the vptr sanitizer is being disabled. + D.Diag(diag::warn_drv_disabling_vptr_no_rtti_default); } // Take out the Vptr sanitizer from the enabled sanitizers @@ -372,9 +371,7 @@ SanitizerArgs::SanitizerArgs(const ToolC // We disable the vptr sanitizer if it was enabled by group expansion but RTTI // is disabled. - if ((Kinds & Vptr) && - (RTTIMode == ToolChain::RM_DisabledImplicitly || - RTTIMode == ToolChain::RM_DisabledExplicitly)) { + if ((Kinds & Vptr) && (RTTIMode == ToolC
r305862 - Prevent devirtualization of calls to un-instantiated functions.
Author: ssrivastava Date: Tue Jun 20 17:08:44 2017 New Revision: 305862 URL: http://llvm.org/viewvc/llvm-project?rev=305862&view=rev Log: Prevent devirtualization of calls to un-instantiated functions. PR 27895 Differential Revision: https://reviews.llvm.org/D22057 Added: cfe/trunk/test/CodeGen/no-devirt.cpp Modified: cfe/trunk/include/clang/AST/Decl.h cfe/trunk/lib/CodeGen/CGClass.cpp cfe/trunk/lib/Sema/Sema.cpp cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Modified: cfe/trunk/include/clang/AST/Decl.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=305862&r1=305861&r2=305862&view=diff == --- cfe/trunk/include/clang/AST/Decl.h (original) +++ cfe/trunk/include/clang/AST/Decl.h Tue Jun 20 17:08:44 2017 @@ -1656,6 +1656,7 @@ private: unsigned HasImplicitReturnZero : 1; unsigned IsLateTemplateParsed : 1; unsigned IsConstexpr : 1; + unsigned InstantiationIsPending:1; /// \brief Indicates if the function uses __try. unsigned UsesSEHTry : 1; @@ -1751,6 +1752,7 @@ protected: IsDeleted(false), IsTrivial(false), IsDefaulted(false), IsExplicitlyDefaulted(false), HasImplicitReturnZero(false), IsLateTemplateParsed(false), IsConstexpr(isConstexprSpecified), +InstantiationIsPending(false), UsesSEHTry(false), HasSkippedBody(false), WillHaveBody(false), EndRangeLoc(NameInfo.getEndLoc()), TemplateOrSpecialization(), DNLoc(NameInfo.getInfo()) {} @@ -1943,6 +1945,15 @@ public: bool isConstexpr() const { return IsConstexpr; } void setConstexpr(bool IC) { IsConstexpr = IC; } + /// \brief Whether the instantiation of this function is pending. + /// This bit is set when the decision to instantiate this function is made + /// and unset if and when the function body is created. That leaves out + /// cases where instantiation did not happen because the template definition + /// was not seen in this TU. This bit remains set in those cases, under the + /// assumption that the instantiation will happen in some other TU. + bool instantiationIsPending() const { return InstantiationIsPending; } + void setInstantiationIsPending(bool IC) { InstantiationIsPending = IC; } + /// \brief Indicates the function uses __try. bool usesSEHTry() const { return UsesSEHTry; } void setUsesSEHTry(bool UST) { UsesSEHTry = UST; } Modified: cfe/trunk/lib/CodeGen/CGClass.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=305862&r1=305861&r2=305862&view=diff == --- cfe/trunk/lib/CodeGen/CGClass.cpp (original) +++ cfe/trunk/lib/CodeGen/CGClass.cpp Tue Jun 20 17:08:44 2017 @@ -2770,10 +2770,19 @@ CodeGenFunction::CanDevirtualizeMemberFu // We can devirtualize calls on an object accessed by a class member access // expression, since by C++11 [basic.life]p6 we know that it can't refer to - // a derived class object constructed in the same location. + // a derived class object constructed in the same location. However, we avoid + // devirtualizing a call to a template function that we could instantiate + // implicitly, but have not decided to do so. This is needed because if this + // function does not get instantiated, the devirtualization will create a + // direct call to a function whose body may not exist. In contrast, calls to + // template functions that are not defined in this TU are allowed to be + // devirtualized under assumption that it is user responsibility to + // instantiate them in some other TU. if (const MemberExpr *ME = dyn_cast(Base)) if (const ValueDecl *VD = dyn_cast(ME->getMemberDecl())) - return VD->getType()->isRecordType(); + return VD->getType()->isRecordType() && + (MD->instantiationIsPending() || MD->isDefined() || + !MD->isImplicitlyInstantiable()); // Likewise for calls on an object accessed by a (non-reference) pointer to // member access. Modified: cfe/trunk/lib/Sema/Sema.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=305862&r1=305861&r2=305862&view=diff == --- cfe/trunk/lib/Sema/Sema.cpp (original) +++ cfe/trunk/lib/Sema/Sema.cpp Tue Jun 20 17:08:44 2017 @@ -740,6 +740,9 @@ void Sema::ActOnEndOfTranslationUnit() { // Load pending instantiations from the external source. SmallVector Pending; ExternalSource->ReadPendingInstantiations(Pending); + for (auto PII : Pending) +if (auto Func = dyn_cast(PII.first)) + Func->setInstantiationIsPending(true); PendingInstantiations.insert(PendingInstantiations.begin(), Pending.begin(), Pending.end()); } Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL
r334153 - Change the wording of RTTI errors to make them more generic.
Author: ssrivastava Date: Wed Jun 6 17:42:59 2018 New Revision: 334153 URL: http://llvm.org/viewvc/llvm-project?rev=334153&view=rev Log: Change the wording of RTTI errors to make them more generic. An attempt to use dynamic_cast while rtti is disabled, used to emit the error: cannot use dynamic_cast with -fno-rtti and a similar one for typeid. This patch changes that to: use of dynamic_cast requires -frtti Differential Revision: https://reviews.llvm.org/D47291 Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/test/SemaCXX/no-rtti.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=334153&r1=334152&r2=334153&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jun 6 17:42:59 2018 @@ -6607,9 +6607,9 @@ def err_not_tag_in_scope : Error< "no %select{struct|interface|union|class|enum}0 named %1 in %2">; def err_no_typeid_with_fno_rtti : Error< - "cannot use typeid with -fno-rtti">; + "use of typeid requires -frtti">; def err_no_dynamic_cast_with_fno_rtti : Error< - "cannot use dynamic_cast with -fno-rtti">; + "use of dynamic_cast requires -frtti">; def err_cannot_form_pointer_to_member_of_reference_type : Error< "cannot form a pointer-to-member to member %0 of reference type %1">; Modified: cfe/trunk/test/SemaCXX/no-rtti.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/no-rtti.cpp?rev=334153&r1=334152&r2=334153&view=diff == --- cfe/trunk/test/SemaCXX/no-rtti.cpp (original) +++ cfe/trunk/test/SemaCXX/no-rtti.cpp Wed Jun 6 17:42:59 2018 @@ -6,7 +6,7 @@ namespace std { void f() { - (void)typeid(int); // expected-error {{cannot use typeid with -fno-rtti}} + (void)typeid(int); // expected-error {{use of typeid requires -frtti}} } namespace { @@ -20,7 +20,7 @@ struct B : public A { } bool isa_B(A *a) { - return dynamic_cast(a) != 0; // expected-error {{cannot use dynamic_cast with -fno-rtti}} + return dynamic_cast(a) != 0; // expected-error {{use of dynamic_cast requires -frtti}} } void* getMostDerived(A* a) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r366368 - Renamed and changed the wording of warn_cconv_ignored
Author: ssrivastava Date: Wed Jul 17 13:41:26 2019 New Revision: 366368 URL: http://llvm.org/viewvc/llvm-project?rev=366368&view=rev Log: Renamed and changed the wording of warn_cconv_ignored As discussed in D64780 the wording of this warning message is being changed to say 'is not supported' instead of 'ignored', and the diag ID itself is being changed to warn_cconv_not_supported. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/lib/Sema/SemaDeclAttr.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/CodeGen/aarch64-vpcs.c cfe/trunk/test/Frontend/macro_defined_type.cpp cfe/trunk/test/Sema/callingconv-iamcu.c cfe/trunk/test/Sema/callingconv.c cfe/trunk/test/Sema/mrtd.c cfe/trunk/test/Sema/pr25786.c cfe/trunk/test/Sema/stdcall-fastcall-x64.c cfe/trunk/test/SemaCUDA/cuda-inherits-calling-conv.cu cfe/trunk/test/SemaCXX/borland-extensions.cpp cfe/trunk/test/SemaCXX/cxx11-gnu-attrs.cpp cfe/trunk/test/SemaCXX/decl-microsoft-call-conv.cpp cfe/trunk/test/SemaCXX/virtual-override-x64.cpp cfe/trunk/test/SemaTemplate/instantiate-function-params.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=366368&r1=366367&r2=366368&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jul 17 13:41:26 2019 @@ -2957,8 +2957,8 @@ def err_attribute_vecreturn_only_pod_rec def err_cconv_change : Error< "function declared '%0' here was previously declared " "%select{'%2'|without calling convention}1">; -def warn_cconv_ignored : Warning< - "%0 calling convention ignored %select{" +def warn_cconv_unsupported : Warning< + "%0 calling convention is not supported %select{" // Use CallingConventionIgnoredReason Enum to specify these. "for this target" "|on variadic function" Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=366368&r1=366367&r2=366368&view=diff == --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Jul 17 13:41:26 2019 @@ -3165,7 +3165,7 @@ bool Sema::MergeFunctionDecl(FunctionDec // Calling Conventions on a Builtin aren't really useful and setting a // default calling convention and cdecl'ing some builtin redeclarations is // common, so warn and ignore the calling convention on the redeclaration. - Diag(New->getLocation(), diag::warn_cconv_ignored) + Diag(New->getLocation(), diag::warn_cconv_unsupported) << FunctionType::getNameForCallConv(NewTypeInfo.getCC()) << (int)CallingConventionIgnoredReason::BuiltinFunction; NewTypeInfo = NewTypeInfo.withCallingConv(OldTypeInfo.getCC()); Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=366368&r1=366367&r2=366368&view=diff == --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Jul 17 13:41:26 2019 @@ -4669,7 +4669,7 @@ bool Sema::CheckCallingConvAttr(const Pa break; case TargetInfo::CCCR_Warning: { -Diag(Attrs.getLoc(), diag::warn_cconv_ignored) +Diag(Attrs.getLoc(), diag::warn_cconv_unsupported) << Attrs << (int)CallingConventionIgnoredReason::ForThisTarget; // This convention is not valid for the target. Use the default function or Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=366368&r1=366367&r2=366368&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Wed Jul 17 13:41:26 2019 @@ -7038,7 +7038,7 @@ static bool handleFunctionTypeAttr(TypeP // stdcall and fastcall are ignored with a warning for GCC and MS // compatibility. if (CC == CC_X86StdCall || CC == CC_X86FastCall) -return S.Diag(attr.getLoc(), diag::warn_cconv_ignored) +return S.Diag(attr.getLoc(), diag::warn_cconv_unsupported) << FunctionType::getNameForCallConv(CC) << (int)Sema::CallingConventionIgnoredReason::VariadicFunction; @@ -7103,7 +7103,7 @@ void Sema::adjustMemberFunctionCC(QualTy // Issue a warning on ignored calling convention -- except of __stdcall. // Again, this is what MS compiler does. if (CurCC != CC_X86StdCall) - Diag(Loc, diag::warn_cconv_ignored) + Diag(Loc, diag::warn_cconv_unsupported) << FunctionType::getNameForCallCon
r366617 - Disallow most calling convention attributes on PS4
Author: ssrivastava Date: Fri Jul 19 14:38:34 2019 New Revision: 366617 URL: http://llvm.org/viewvc/llvm-project?rev=366617&view=rev Log: Disallow most calling convention attributes on PS4 PS4 now only allows "cdecl", and its equivalent on PS4, "sysv_abi". Differential Revision: https://reviews.llvm.org/D64780 Added: cfe/trunk/test/Sema/no_callconv.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/include/clang/Basic/TargetInfo.h cfe/trunk/lib/Basic/Targets/OSTargets.h cfe/trunk/lib/Sema/SemaDeclAttr.cpp cfe/trunk/unittests/Tooling/RecursiveASTVisitorTests/LambdaExpr.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=366617&r1=366616&r2=366617&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jul 19 14:38:34 2019 @@ -2966,6 +2966,7 @@ def warn_cconv_unsupported : Warning< "|on builtin function" "}1">, InGroup; +def error_cconv_unsupported : Error; def err_cconv_knr : Error< "function with no prototype cannot use the %0 calling convention">; def warn_cconv_knr : Warning< Modified: cfe/trunk/include/clang/Basic/TargetInfo.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=366617&r1=366616&r2=366617&view=diff == --- cfe/trunk/include/clang/Basic/TargetInfo.h (original) +++ cfe/trunk/include/clang/Basic/TargetInfo.h Fri Jul 19 14:38:34 2019 @@ -1268,6 +1268,7 @@ public: CCCR_OK, CCCR_Warning, CCCR_Ignore, +CCCR_Error, }; /// Determines whether a given calling convention is valid for the Modified: cfe/trunk/lib/Basic/Targets/OSTargets.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/OSTargets.h?rev=366617&r1=366616&r2=366617&view=diff == --- cfe/trunk/lib/Basic/Targets/OSTargets.h (original) +++ cfe/trunk/lib/Basic/Targets/OSTargets.h Fri Jul 19 14:38:34 2019 @@ -561,6 +561,10 @@ public: break; } } + TargetInfo::CallingConvCheckResult + checkCallingConvention(CallingConv CC) const override { +return (CC == CC_C) ? TargetInfo::CCCR_OK : TargetInfo::CCCR_Error; + } }; // RTEMS Target Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=366617&r1=366616&r2=366617&view=diff == --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Jul 19 14:38:34 2019 @@ -4668,6 +4668,11 @@ bool Sema::CheckCallingConvAttr(const Pa CC = CC_C; break; + case TargetInfo::CCCR_Error: +Diag(Attrs.getLoc(), diag::error_cconv_unsupported) +<< Attrs << (int)CallingConventionIgnoredReason::ForThisTarget; +break; + case TargetInfo::CCCR_Warning: { Diag(Attrs.getLoc(), diag::warn_cconv_unsupported) << Attrs << (int)CallingConventionIgnoredReason::ForThisTarget; Added: cfe/trunk/test/Sema/no_callconv.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/no_callconv.cpp?rev=366617&view=auto == --- cfe/trunk/test/Sema/no_callconv.cpp (added) +++ cfe/trunk/test/Sema/no_callconv.cpp Fri Jul 19 14:38:34 2019 @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 %s -triple x86_64-scei-ps4 -DPS4 -fsyntax-only -verify +// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -fsyntax-only -verify + +#ifdef PS4 + +// PS4 does not support these. +void __vectorcall func_vc() {} // expected-error {{'__vectorcall' calling convention is not supported for this target}} +void __regcall func_rc() {} // expected-error {{'__regcall' calling convention is not supported for this target}} +void __attribute__((vectorcall)) funcA() {} // expected-error {{'vectorcall' calling convention is not supported for this target}} +void __attribute__((regcall)) funcB() {} // expected-error {{'regcall' calling convention is not supported for this target}} +void __attribute__((ms_abi)) funcH() {} // expected-error {{'ms_abi' calling convention is not supported for this target}} +void __attribute__((intel_ocl_bicc)) funcJ() {} // expected-error {{'intel_ocl_bicc' calling convention is not supported for this target}} +void __attribute__((swiftcall)) funcK() {} // expected-error {{'swiftcall' calling convention is not supported for this target}} +void __attribute__((pascal)) funcG() {} // expected-error {{'pascal' calling convention is not supported for this target}} +void __attribute__((preserve_most)) funcL() {} // expected-error {{'preserve_most' calling con
[PATCH] D22057: Prevent devirtualization of calls to un-instantiated functions.
Sunil_Srivastava added a comment. Ping https://reviews.llvm.org/D22057 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] a844378 - Change default C dialect for PS5 to gnu17/gnu18.
Author: Sunil Srivastava Date: 2022-07-12T11:14:56-07:00 New Revision: a844378b2bc2c0a7f18e8d7cdd259b6c4d443128 URL: https://github.com/llvm/llvm-project/commit/a844378b2bc2c0a7f18e8d7cdd259b6c4d443128 DIFF: https://github.com/llvm/llvm-project/commit/a844378b2bc2c0a7f18e8d7cdd259b6c4d443128.diff LOG: Change default C dialect for PS5 to gnu17/gnu18. Differential Revision: https://reviews.llvm.org/D129404 Added: Modified: clang/lib/Basic/LangStandards.cpp clang/test/Preprocessor/init.c Removed: diff --git a/clang/lib/Basic/LangStandards.cpp b/clang/lib/Basic/LangStandards.cpp index 5bacc3b16496..a21898dd3c62 100644 --- a/clang/lib/Basic/LangStandards.cpp +++ b/clang/lib/Basic/LangStandards.cpp @@ -61,8 +61,8 @@ LangStandard::Kind clang::getDefaultLanguageStandard(clang::Language Lang, if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified) return CLANG_DEFAULT_STD_C; -// The PS4 and PS5 use C99 as the default C standard. -if (T.isPS()) +// The PS4 uses C99 as the default C standard. +if (T.isPS4()) return LangStandard::lang_gnu99; return LangStandard::lang_gnu17; case Language::ObjC: diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 61324fd5e43d..e3a24824ff19 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -1342,7 +1342,8 @@ // PS4:#define __SSE2__ 1 // PS4:#define __SSE_MATH__ 1 // PS4:#define __SSE__ 1 -// PS4:#define __STDC_VERSION__ 199901L +// PS4ONLY:#define __STDC_VERSION__ 199901L +// PS5ONLY:#define __STDC_VERSION__ 201710L // PS4:#define __UINTMAX_TYPE__ long unsigned int // PS4:#define __USER_LABEL_PREFIX__ // PS4:#define __WCHAR_MAX__ 65535 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] aa34b34 - Set default C++ level for PlayStation(r) to C++17.
Author: Sunil Srivastava Date: 2023-07-21T18:18:21-07:00 New Revision: aa34b34e93d444efec6cd894e5e55927d0e413e6 URL: https://github.com/llvm/llvm-project/commit/aa34b34e93d444efec6cd894e5e55927d0e413e6 DIFF: https://github.com/llvm/llvm-project/commit/aa34b34e93d444efec6cd894e5e55927d0e413e6.diff LOG: Set default C++ level for PlayStation(r) to C++17. Added: Modified: clang/lib/Basic/LangStandards.cpp Removed: clang/test/Preprocessor/lang-std-sie.cpp diff --git a/clang/lib/Basic/LangStandards.cpp b/clang/lib/Basic/LangStandards.cpp index 033c0efe8d4f5d..af9cf4f273920e 100644 --- a/clang/lib/Basic/LangStandards.cpp +++ b/clang/lib/Basic/LangStandards.cpp @@ -66,8 +66,6 @@ LangStandard::Kind clang::getDefaultLanguageStandard(clang::Language Lang, case Language::ObjCXX: case Language::CUDA: case Language::HIP: -if (T.isPS()) - return LangStandard::lang_gnucxx14; return LangStandard::lang_gnucxx17; case Language::RenderScript: return LangStandard::lang_c99; diff --git a/clang/test/Preprocessor/lang-std-sie.cpp b/clang/test/Preprocessor/lang-std-sie.cpp deleted file mode 100644 index e8e65690277a5b..00 --- a/clang/test/Preprocessor/lang-std-sie.cpp +++ /dev/null @@ -1,6 +0,0 @@ -/// Test that PS4/PS5 defaults to gnu++14. - -// RUN: %clang_cc1 -dM -E -triple x86_64-scei-ps4 %s | FileCheck --check-prefix=CXX14 %s -// RUN: %clang_cc1 -dM -E -triple x86_64-sie-ps5 %s | FileCheck --check-prefix=CXX14 %s - -// CXX14: #define __cplusplus 201402L ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D22057: Prevent devirtualization of calls to un-instantiated functions.
Sunil_Srivastava added inline comments. Comment at: test/CodeGen/no-devirt.cpp:16 @@ +15,3 @@ + if (a > 6) return data[a] ; // Should not devirtualize + if (a > 4) return data.func1(a); // Should devirtualize + return data.func2(a);// Should devirtualize Quuxplusone wrote: > This is a really dumb question from the peanut gallery, but, could you > explain why these two cases (lines 15 and 16) should differ? It really seems > like both calls should be able to be devirtualized, because the compiler > statically knows what they should call. > > I think you mention the difference between lines 15 and 16 here: > > > except, for some reason, when it is an operator and used with an operator > > syntax > > but you don't explain *why* the difference is desirable. Shouldn't we just > fix that difference, then? > > Is your first fix ( > > > The first fix will be in the front end to force the instantiation on > > virtual calls that are potentially devirtualizable. > > ) basically "fix the difference between lines 15 and 16", or is it talking > about something else entirely? AFAICS, The two cases (line 15 and 16) should not differ. The first fix will "fix the difference between line 15 and 16". I have the change for that ready, but once we do that, there will be no way (known to me) of testing the second "fix". Hence the second "fix" is being proposed for commit before the first. https://reviews.llvm.org/D22057 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D22057: Prevent devirtualization of calls to un-instantiated functions.
Sunil_Srivastava updated this revision to Diff 71432. Sunil_Srivastava added a comment. This is an update to address points raised by Richard Smith: 1. The bit and the access functions have been renamed from MarkedForPendingInstantiation to InstantiationIsPending. 2. It closely, though not entirely, tracks whether the function is on the PendingInstantiations list. More on this point below. 3. The test explicitly allows devirtualization if Function->isDefined(). This is also needed by the change in point 2 above. 4. The test has been enhanced to have PCH tests. Now: Why the InstantiationIsPending bit is not precisely tracking the presence in the PendingInstantiations list? Basically this is because I think that the call to Func2 in the test SHOULD get devirtualized. Func2 is not defined in this TU, an uncommon but possible situation. Given that, the compiler had no way to instantiate it, and it is a user error if Func2 does not get instantiated somewhere else. If Func2 does get instantiated somewhere else, then it is safe to devirtualize calls to it. In contrast, operator[] is defined by the user, but for some reason (which will be removed by my next checkin, in situations we know of) the compiler has decided to not instantiate it (or rather, not decided to instantiate it, to be precise). In this case we do not want to devirtualize call to it, because the definition is not required to exist somewhere else. The whole motivation of this commit is to prevent such calls from devirtualization. The instantiation loop removes items from the PendingInstantiations list and instantiates them, if the body is present. In the case of Func2, the body is not present, the function has already been removed from the list, yet it is not isDefined(). We need some way to distinguish this from the contrasting case of operator[], where the function was never put on the PendingInstantiations list. Hence in cases like Func2, I am not unsetting the InstantiationIsPending bit at the time of its removal from the list. Loosely speaking, we can say that the instantiation is indeed pending, though in some other TU. Comments in Decls.h explain this behavior, though not in such details. The expected behavior of the test will change by my next “first fix” commit, of course; in that the operator[] will get instantiated, and the call will be devirtualized. https://reviews.llvm.org/D22057 Files: include/clang/AST/Decl.h lib/CodeGen/CGClass.cpp lib/Sema/Sema.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/CodeGen/no-devirt.cpp Index: test/CodeGen/no-devirt.cpp === --- test/CodeGen/no-devirt.cpp +++ test/CodeGen/no-devirt.cpp @@ -0,0 +1,59 @@ +// RUN: %clang_cc1 %s -DUSEIT -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %s + +// Test with decls and template defs in pch, and just use in .cpp +// RUN: %clang_cc1 %s -DTMPL_DEF_IN_HEADER -triple %itanium_abi_triple -emit-pch -o %t +// RUN: %clang_cc1 %s -DTMPL_DEF_IN_HEADER -DUSEIT -triple %itanium_abi_triple -include-pch %t -emit-llvm -o - | FileCheck %s + +// Test with A in pch, and B and C in main +// Test with just decls in pch, and template defs and use in .cpp +// RUN: %clang_cc1 %s -triple %itanium_abi_triple -emit-pch -o %t +// RUN: %clang_cc1 %s -DUSEIT -triple %itanium_abi_triple -include-pch %t -emit-llvm -o - | FileCheck %s + +#ifndef HEADER +#define HEADER +template < typename T, int N = 0 > class TmplWithArray { +public: + virtual T& operator [] (int idx); + virtual T& func1 (int idx); + virtual T& func2 (int idx); + T ar[N+1]; +}; +struct Wrapper { + TmplWithArray data; + bool indexIt(int a) { +if (a > 6) return data[a] ; // Should not devirtualize +if (a > 4) return data.func1(a); // Should devirtualize +return data.func2(a);// Should devirtualize + } +}; + +#ifdef TMPL_DEF_IN_HEADER +template T& TmplWithArray::operator[](int idx) { + return ar[idx]; +} +template T& TmplWithArray::func1(int idx) { + return ar[idx]; +} +#endif // TMPL_DEF_IN_HEADER +#endif // HEADER + +#ifdef USEIT +#ifndef TMPL_DEF_IN_HEADER +template T& TmplWithArray::operator[](int idx) { + return ar[idx]; +} +template T& TmplWithArray::func1(int idx) { + return ar[idx]; +} +#endif // !TMPL_DEF_IN_HEADER +extern Wrapper ew; +bool stuff(int p) +{ + return ew.indexIt(p); +} +#endif + +// CHECK-NOT: call {{.*}} @_ZN13TmplWithArrayIbLi10EEixEi +// CHECK-DAG: call {{.*}} @_ZN13TmplWithArrayIbLi10EE5func1Ei +// CHECK-DAG: call {{.*}} @_ZN13TmplWithArrayIbLi10EE5func2Ei + Index: lib/Sema/SemaTemplateInstantiateDecl.cpp === --- lib/Sema/SemaTemplateInstantiateDecl.cpp +++ lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3580,6 +3580,7 @@ // Try again at the end of the translation unit (at which point a // definition will be required). assert(!Recursive);
[PATCH] D22057: Prevent devirtualization of calls to un-instantiated functions.
Sunil_Srivastava added a comment. ping https://reviews.llvm.org/D22057 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r276653 - Support '#pragma once' in headers when using PCH
Author: ssrivastava Date: Mon Jul 25 12:17:06 2016 New Revision: 276653 URL: http://llvm.org/viewvc/llvm-project?rev=276653&view=rev Log: Support '#pragma once' in headers when using PCH The '#pragma once' directive was erroneously ignored when encountered in the header-file specified in generate-PCH-mode. This resulted in compile-time errors in some cases with legal code, and also a misleading warning being produced. Patch by Warren Ristow! Differential Revision: http://reviews.llvm.org/D19815 Added: cfe/trunk/test/PCH/Inputs/pragma-once.h cfe/trunk/test/PCH/pragma-once.c Modified: cfe/trunk/lib/Lex/Pragma.cpp Modified: cfe/trunk/lib/Lex/Pragma.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=276653&r1=276652&r2=276653&view=diff == --- cfe/trunk/lib/Lex/Pragma.cpp (original) +++ cfe/trunk/lib/Lex/Pragma.cpp Mon Jul 25 12:17:06 2016 @@ -352,7 +352,9 @@ void Preprocessor::HandleMicrosoft__prag /// HandlePragmaOnce - Handle \#pragma once. OnceTok is the 'once'. /// void Preprocessor::HandlePragmaOnce(Token &OnceTok) { - if (isInPrimaryFile()) { + // Don't honor the 'once' when handling the primary source file, unless + // this is a prefix to a TU, which indicates we're generating a PCH file. + if (isInPrimaryFile() && TUKind != TU_Prefix) { Diag(OnceTok, diag::pp_pragma_once_in_main_file); return; } Added: cfe/trunk/test/PCH/Inputs/pragma-once.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/pragma-once.h?rev=276653&view=auto == --- cfe/trunk/test/PCH/Inputs/pragma-once.h (added) +++ cfe/trunk/test/PCH/Inputs/pragma-once.h Mon Jul 25 12:17:06 2016 @@ -0,0 +1,5 @@ +#pragma once + +/* For use with the pragma-once.c test */ + +int x = 3; Added: cfe/trunk/test/PCH/pragma-once.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/pragma-once.c?rev=276653&view=auto == --- cfe/trunk/test/PCH/pragma-once.c (added) +++ cfe/trunk/test/PCH/pragma-once.c Mon Jul 25 12:17:06 2016 @@ -0,0 +1,13 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/Inputs/pragma-once.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t %S/Inputs/pragma-once.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +// expected-no-diagnostics + +// Including "pragma-once.h" twice, to verify the 'once' aspect is honored. +#include "Inputs/pragma-once.h" +#include "Inputs/pragma-once.h" +int foo(void) { return 0; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D16788: Ps4 ABI Round 2. Actual PS4 code.
Sunil_Srivastava created this revision. Sunil_Srivastava added reviewers: rjmccall, DmitryPolukhin, rsmith, probinson. Sunil_Srivastava added a subscriber: cfe-commits. This is the round 2 of the PS4 ABI. In this round: 1) A new value PS4 has been added to TargetCXXABI::Kind. It is being used for x86_64-scei-ps4 triple only. 2) RecordLayoutBuilder.cpp has been logically reverted back to pre r257462 behavior for PS4 abi. 3) The test Sema/bitfield-layout.c has been enhanced by adding the PS4 triple, and few test entries that differ between PS4 and other triples, have been put under '#ifdef PS4'. Logically, the test has not changed for triples other than x86_64-scei-ps4. For x86_64-scei-ps4 triple, the test matches pre r257462 behavior. The test passes on all listed triples on x86 Linux and windows hosts. http://reviews.llvm.org/D16788 Files: include/clang/Basic/TargetCXXABI.h lib/AST/ASTContext.cpp lib/AST/RecordLayoutBuilder.cpp lib/Basic/Targets.cpp lib/CodeGen/CodeGenModule.cpp lib/CodeGen/ItaniumCXXABI.cpp test/Sema/bitfield-layout.c Index: test/Sema/bitfield-layout.c === --- test/Sema/bitfield-layout.c +++ test/Sema/bitfield-layout.c @@ -2,6 +2,7 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=arm-linux-gnueabihf // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=aarch64-linux-gnu // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=x86_64-pc-linux-gnu +// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=x86_64-scei-ps4 // expected-no-diagnostics #include @@ -96,9 +97,15 @@ char c; }; +#if defined(__PS4__) +CHECK_SIZE(struct, g0, 16); +CHECK_ALIGN(struct, g0, 16); +CHECK_OFFSET(struct, g0, c, 2); +#else CHECK_SIZE(struct, g0, 32); CHECK_ALIGN(struct, g0, 16); CHECK_OFFSET(struct, g0, c, 17); +#endif // Bit-field with explicit align smaller than normal. struct g1 { @@ -109,7 +116,11 @@ CHECK_SIZE(struct, g1, 4); CHECK_ALIGN(struct, g1, 4); +#if defined(__PS4__) +CHECK_OFFSET(struct, g1, c, 2); +#else CHECK_OFFSET(struct, g1, c, 3); +#endif // Same as above but without explicit align. struct g2 { @@ -130,9 +141,14 @@ char c; }; -CHECK_SIZE(struct, g3, 32); CHECK_ALIGN(struct, g3, 16); +#if defined(__PS4__) +CHECK_SIZE(struct, g3, 16); +CHECK_OFFSET(struct, g3, c, 2); +#else +CHECK_SIZE(struct, g3, 32); CHECK_OFFSET(struct, g3, c, 17); +#endif struct __attribute__((packed)) g4 { char a; @@ -142,7 +158,11 @@ CHECK_SIZE(struct, g4, 4); CHECK_ALIGN(struct, g4, 2); +#if defined(__PS4__) +CHECK_OFFSET(struct, g4, c, 2); +#else CHECK_OFFSET(struct, g4, c, 3); +#endif struct g5 { char : 1; @@ -162,28 +182,44 @@ char : 1; __attribute__((aligned(1))) int n : 25; }; +#if defined(__PS4__) +CHECK_SIZE(struct, g7, 4); +#else CHECK_SIZE(struct, g7, 8); +#endif CHECK_ALIGN(struct, g7, 4); struct __attribute__((packed)) g8 { char : 1; __attribute__((aligned(1))) int n : 25; }; +#if defined(__PS4__) +CHECK_SIZE(struct, g8, 4); +#else CHECK_SIZE(struct, g8, 5); +#endif CHECK_ALIGN(struct, g8, 1); struct g9 { __attribute__((aligned(1))) char a : 2, b : 2, c : 2, d : 2, e : 2; int i; }; +#if defined(__PS4__) +CHECK_SIZE(struct, g9, 8); +#else CHECK_SIZE(struct, g9, 12); +#endif CHECK_ALIGN(struct, g9, 4); struct __attribute__((packed)) g10 { __attribute__((aligned(1))) char a : 2, b : 2, c : 2, d : 2, e : 2; int i; }; +#if defined(__PS4__) +CHECK_SIZE(struct, g10, 6); +#else CHECK_SIZE(struct, g10, 9); +#endif CHECK_ALIGN(struct, g10, 1); struct g11 { Index: lib/CodeGen/ItaniumCXXABI.cpp === --- lib/CodeGen/ItaniumCXXABI.cpp +++ lib/CodeGen/ItaniumCXXABI.cpp @@ -480,6 +480,7 @@ return new WebAssemblyCXXABI(CGM); case TargetCXXABI::GenericItanium: + case TargetCXXABI::PS4: if (CGM.getContext().getTargetInfo().getTriple().getArch() == llvm::Triple::le32) { // For PNaCl, use ARM-style method pointers so that PNaCl code Index: lib/CodeGen/CodeGenModule.cpp === --- lib/CodeGen/CodeGenModule.cpp +++ lib/CodeGen/CodeGenModule.cpp @@ -69,6 +69,7 @@ case TargetCXXABI::WatchOS: case TargetCXXABI::GenericMIPS: case TargetCXXABI::GenericItanium: + case TargetCXXABI::PS4: case TargetCXXABI::WebAssembly: return CreateItaniumCXXABI(CGM); case TargetCXXABI::Microsoft: Index: lib/Basic/Targets.cpp === --- lib/Basic/Targets.cpp +++ lib/Basic/Targets.cpp @@ -602,6 +602,9 @@ PS4OSTargetInfo(const llvm::Triple &Triple) : OSTargetInfo(Triple) { this->WCharType = this->UnsignedShort; +// PS4 uses a variant of the C++11 ABI. +this->TheCXXABI.set(TargetCXXABI::PS4); + // On PS4, TLS variable cannot be aligned to more than 32 bytes (256 bits). this->MaxTLSAlign = 256; this->UserLabe
Re: [PATCH] D16788: PS4 ABI Round 2. Actual PS4 code.
Sunil_Srivastava updated this revision to Diff 47026. Sunil_Srivastava added a comment. Changed the patch based of feedback from John McCall. There is new bit UseExplicitBitFieldAlignment, which is set for everything except for PS4. The r257462 change has been made conditional on this bit. http://reviews.llvm.org/D16788 Files: include/clang/Basic/TargetInfo.h lib/AST/RecordLayoutBuilder.cpp lib/Basic/TargetInfo.cpp lib/Basic/Targets.cpp test/Sema/bitfield-layout.c Index: test/Sema/bitfield-layout.c === --- test/Sema/bitfield-layout.c +++ test/Sema/bitfield-layout.c @@ -2,6 +2,7 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=arm-linux-gnueabihf // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=aarch64-linux-gnu // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=x86_64-pc-linux-gnu +// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=x86_64-scei-ps4 // expected-no-diagnostics #include @@ -96,9 +97,15 @@ char c; }; +#if defined(__PS4__) +CHECK_SIZE(struct, g0, 16); +CHECK_ALIGN(struct, g0, 16); +CHECK_OFFSET(struct, g0, c, 2); +#else CHECK_SIZE(struct, g0, 32); CHECK_ALIGN(struct, g0, 16); CHECK_OFFSET(struct, g0, c, 17); +#endif // Bit-field with explicit align smaller than normal. struct g1 { @@ -109,7 +116,11 @@ CHECK_SIZE(struct, g1, 4); CHECK_ALIGN(struct, g1, 4); +#if defined(__PS4__) +CHECK_OFFSET(struct, g1, c, 2); +#else CHECK_OFFSET(struct, g1, c, 3); +#endif // Same as above but without explicit align. struct g2 { @@ -130,9 +141,14 @@ char c; }; -CHECK_SIZE(struct, g3, 32); CHECK_ALIGN(struct, g3, 16); +#if defined(__PS4__) +CHECK_SIZE(struct, g3, 16); +CHECK_OFFSET(struct, g3, c, 2); +#else +CHECK_SIZE(struct, g3, 32); CHECK_OFFSET(struct, g3, c, 17); +#endif struct __attribute__((packed)) g4 { char a; @@ -142,7 +158,11 @@ CHECK_SIZE(struct, g4, 4); CHECK_ALIGN(struct, g4, 2); +#if defined(__PS4__) +CHECK_OFFSET(struct, g4, c, 2); +#else CHECK_OFFSET(struct, g4, c, 3); +#endif struct g5 { char : 1; @@ -162,28 +182,44 @@ char : 1; __attribute__((aligned(1))) int n : 25; }; +#if defined(__PS4__) +CHECK_SIZE(struct, g7, 4); +#else CHECK_SIZE(struct, g7, 8); +#endif CHECK_ALIGN(struct, g7, 4); struct __attribute__((packed)) g8 { char : 1; __attribute__((aligned(1))) int n : 25; }; +#if defined(__PS4__) +CHECK_SIZE(struct, g8, 4); +#else CHECK_SIZE(struct, g8, 5); +#endif CHECK_ALIGN(struct, g8, 1); struct g9 { __attribute__((aligned(1))) char a : 2, b : 2, c : 2, d : 2, e : 2; int i; }; +#if defined(__PS4__) +CHECK_SIZE(struct, g9, 8); +#else CHECK_SIZE(struct, g9, 12); +#endif CHECK_ALIGN(struct, g9, 4); struct __attribute__((packed)) g10 { __attribute__((aligned(1))) char a : 2, b : 2, c : 2, d : 2, e : 2; int i; }; +#if defined(__PS4__) +CHECK_SIZE(struct, g10, 6); +#else CHECK_SIZE(struct, g10, 9); +#endif CHECK_ALIGN(struct, g10, 1); struct g11 { Index: lib/Basic/Targets.cpp === --- lib/Basic/Targets.cpp +++ lib/Basic/Targets.cpp @@ -606,6 +606,10 @@ this->MaxTLSAlign = 256; this->UserLabelPrefix = ""; +// On PS4, do not honor explicit bit field alignment, +// as in "__attribute__((aligned(2))) int b : 1;". +this->UseExplicitBitFieldAlignment = false; + switch (Triple.getArch()) { default: case llvm::Triple::x86_64: Index: lib/Basic/TargetInfo.cpp === --- lib/Basic/TargetInfo.cpp +++ lib/Basic/TargetInfo.cpp @@ -66,6 +66,7 @@ UseSignedCharForObjCBool = true; UseBitFieldTypeAlignment = true; UseZeroLengthBitfieldAlignment = false; + UseExplicitBitFieldAlignment = true; ZeroLengthBitfieldBoundary = 0; HalfFormat = &llvm::APFloat::IEEEhalf; FloatFormat = &llvm::APFloat::IEEEsingle; Index: lib/AST/RecordLayoutBuilder.cpp === --- lib/AST/RecordLayoutBuilder.cpp +++ lib/AST/RecordLayoutBuilder.cpp @@ -1600,7 +1600,8 @@ (AllowPadding && (FieldOffset & (FieldAlign-1)) + FieldSize > TypeSize)) { FieldOffset = llvm::alignTo(FieldOffset, FieldAlign); -} else if (ExplicitFieldAlign) { +} else if (ExplicitFieldAlign && + Context.getTargetInfo().useExplicitBitFieldAlignment()) { // TODO: figure it out what needs to be done on targets that don't honor // bit-field type alignment like ARM APCS ABI. FieldOffset = llvm::alignTo(FieldOffset, ExplicitFieldAlign); @@ -1612,7 +1613,8 @@ (UnpackedFieldOffset & (UnpackedFieldAlign-1)) + FieldSize > TypeSize)) UnpackedFieldOffset = llvm::alignTo(UnpackedFieldOffset, UnpackedFieldAlign); -else if (ExplicitFieldAlign) +else if (ExplicitFieldAlign && + Context.getTargetInfo().useExplicitBitFieldAlignment()) Unpacked
r259916 - Do not honor explicit alignment attribute on fields for PS4.
Author: ssrivastava Date: Fri Feb 5 14:50:02 2016 New Revision: 259916 URL: http://llvm.org/viewvc/llvm-project?rev=259916&view=rev Log: Do not honor explicit alignment attribute on fields for PS4. This change reverts r257462 for PS4 triple. Differential Revision: http://reviews.llvm.org/D16788 Modified: cfe/trunk/include/clang/Basic/TargetInfo.h cfe/trunk/lib/AST/RecordLayoutBuilder.cpp cfe/trunk/lib/Basic/TargetInfo.cpp cfe/trunk/lib/Basic/Targets.cpp cfe/trunk/test/Sema/bitfield-layout.c Modified: cfe/trunk/include/clang/Basic/TargetInfo.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=259916&r1=259915&r2=259916&view=diff == --- cfe/trunk/include/clang/Basic/TargetInfo.h (original) +++ cfe/trunk/include/clang/Basic/TargetInfo.h Fri Feb 5 14:50:02 2016 @@ -202,6 +202,9 @@ protected: /// zero-length bitfield. unsigned UseZeroLengthBitfieldAlignment : 1; + /// \brief Whether explicit bit field alignment attributes are honored. + unsigned UseExplicitBitFieldAlignment : 1; + /// If non-zero, specifies a fixed alignment value for bitfields that follow /// zero length bitfield, regardless of the zero length bitfield type. unsigned ZeroLengthBitfieldBoundary; @@ -466,6 +469,12 @@ public: return ZeroLengthBitfieldBoundary; } + /// \brief Check whether explicit bitfield alignment attributes should be + // honored, as in "__attribute__((aligned(2))) int b : 1;". + bool useExplicitBitFieldAlignment() const { +return UseExplicitBitFieldAlignment; + } + /// \brief Check whether this target support '\#pragma options align=mac68k'. bool hasAlignMac68kSupport() const { return HasAlignMac68kSupport; Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=259916&r1=259915&r2=259916&view=diff == --- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original) +++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Fri Feb 5 14:50:02 2016 @@ -1600,7 +1600,8 @@ void ItaniumRecordLayoutBuilder::LayoutB (AllowPadding && (FieldOffset & (FieldAlign-1)) + FieldSize > TypeSize)) { FieldOffset = llvm::alignTo(FieldOffset, FieldAlign); -} else if (ExplicitFieldAlign) { +} else if (ExplicitFieldAlign && + Context.getTargetInfo().useExplicitBitFieldAlignment()) { // TODO: figure it out what needs to be done on targets that don't honor // bit-field type alignment like ARM APCS ABI. FieldOffset = llvm::alignTo(FieldOffset, ExplicitFieldAlign); @@ -1612,7 +1613,8 @@ void ItaniumRecordLayoutBuilder::LayoutB (UnpackedFieldOffset & (UnpackedFieldAlign-1)) + FieldSize > TypeSize)) UnpackedFieldOffset = llvm::alignTo(UnpackedFieldOffset, UnpackedFieldAlign); -else if (ExplicitFieldAlign) +else if (ExplicitFieldAlign && + Context.getTargetInfo().useExplicitBitFieldAlignment()) UnpackedFieldOffset = llvm::alignTo(UnpackedFieldOffset, ExplicitFieldAlign); } Modified: cfe/trunk/lib/Basic/TargetInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=259916&r1=259915&r2=259916&view=diff == --- cfe/trunk/lib/Basic/TargetInfo.cpp (original) +++ cfe/trunk/lib/Basic/TargetInfo.cpp Fri Feb 5 14:50:02 2016 @@ -66,6 +66,7 @@ TargetInfo::TargetInfo(const llvm::Tripl UseSignedCharForObjCBool = true; UseBitFieldTypeAlignment = true; UseZeroLengthBitfieldAlignment = false; + UseExplicitBitFieldAlignment = true; ZeroLengthBitfieldBoundary = 0; HalfFormat = &llvm::APFloat::IEEEhalf; FloatFormat = &llvm::APFloat::IEEEsingle; Modified: cfe/trunk/lib/Basic/Targets.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=259916&r1=259915&r2=259916&view=diff == --- cfe/trunk/lib/Basic/Targets.cpp (original) +++ cfe/trunk/lib/Basic/Targets.cpp Fri Feb 5 14:50:02 2016 @@ -606,6 +606,10 @@ public: this->MaxTLSAlign = 256; this->UserLabelPrefix = ""; +// On PS4, do not honor explicit bit field alignment, +// as in "__attribute__((aligned(2))) int b : 1;". +this->UseExplicitBitFieldAlignment = false; + switch (Triple.getArch()) { default: case llvm::Triple::x86_64: Modified: cfe/trunk/test/Sema/bitfield-layout.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/bitfield-layout.c?rev=259916&r1=259915&r2=259916&view=diff == --- cfe/trunk/test/Sema/bitfield-layout.c (original) +++ cfe/trunk/test/Sema/bitfield-layout.c Fri Feb 5 14:50:02 2016 @@ -2,6
Re: [PATCH] D15095: Accept "-Weverything" in pragma clang diagnostic ...
Sunil_Srivastava added a reviewer: rsmith. Sunil_Srivastava updated this revision to Diff 47509. Sunil_Srivastava added a comment. Changed the test, but the compiler code is still same, pending reply from Richard Smith http://reviews.llvm.org/D15095 Files: lib/Basic/Diagnostic.cpp test/Preprocessor/pragma_diagnostic.c test/Preprocessor/pushable-diagnostics.c Index: test/Preprocessor/pushable-diagnostics.c === --- test/Preprocessor/pushable-diagnostics.c +++ test/Preprocessor/pushable-diagnostics.c @@ -15,3 +15,27 @@ int c = 'df'; // expected-warning{{multi-character character constant}} #pragma clang diagnostic pop // expected-warning{{pragma diagnostic pop could not pop, no matching push}} + +// Test -Weverything + +void ppo0(){} // first verify that we do not give anything on this +#pragma clang diagnostic push // now push + +#pragma clang diagnostic warning "-Weverything" +void ppr1(){} // expected-warning {{no previous prototype for function 'ppr1'}} + +#pragma clang diagnostic push // push again +#pragma clang diagnostic ignored "-Weverything" // Set to ignore in this level. +void pps2(){} +#pragma clang diagnostic warning "-Weverything" // Set to warning in this level. +void ppt2(){} // expected-warning {{no previous prototype for function 'ppt2'}} +#pragma clang diagnostic error "-Weverything" // Set to error in this level. +void ppt3(){} // expected-error {{no previous prototype for function 'ppt3'}} +#pragma clang diagnostic pop // pop should go back to warning level + +void pps1(){} // expected-warning {{no previous prototype for function 'pps1'}} + + +#pragma clang diagnostic pop // Another pop should disble it again +void ppu(){} + Index: test/Preprocessor/pragma_diagnostic.c === --- test/Preprocessor/pragma_diagnostic.c +++ test/Preprocessor/pragma_diagnostic.c @@ -30,3 +30,18 @@ #pragma GCC diagnostic error "-Winvalid-name" // expected-warning {{unknown warning group '-Winvalid-name', ignored}} + +// Testing pragma clang diagnostic with -Weverything +void ppo(){} // First test that we do not diagnose on this. + +#pragma clang diagnostic warning "-Weverything" +void ppp(){} // expected-warning {{no previous prototype for function 'ppp'}} + +#pragma clang diagnostic ignored "-Weverything" // Reset it. +void ppq(){} + +#pragma clang diagnostic error "-Weverything" // Now set to error +void ppr(){} // expected-error {{no previous prototype for function 'ppr'}} + +#pragma clang diagnostic warning "-Weverything" // This should not be effective +void pps(){} // expected-error {{no previous prototype for function 'pps'}} Index: lib/Basic/Diagnostic.cpp === --- lib/Basic/Diagnostic.cpp +++ lib/Basic/Diagnostic.cpp @@ -248,6 +248,14 @@ bool DiagnosticsEngine::setSeverityForGroup(diag::Flavor Flavor, StringRef Group, diag::Severity Map, SourceLocation Loc) { + // Special handling for pragma clang diagnostic ... "-Weverything" + // There is no formal group named "everything", so there has to be a special + // case for it. + if (Group == "everything") { + setSeverityForAll(Flavor, Map, Loc); + return false; + } + // Get the diagnostics in this group. SmallVector GroupDiags; if (Diags->getDiagnosticsInGroup(Flavor, Group, GroupDiags)) Index: test/Preprocessor/pushable-diagnostics.c === --- test/Preprocessor/pushable-diagnostics.c +++ test/Preprocessor/pushable-diagnostics.c @@ -15,3 +15,27 @@ int c = 'df'; // expected-warning{{multi-character character constant}} #pragma clang diagnostic pop // expected-warning{{pragma diagnostic pop could not pop, no matching push}} + +// Test -Weverything + +void ppo0(){} // first verify that we do not give anything on this +#pragma clang diagnostic push // now push + +#pragma clang diagnostic warning "-Weverything" +void ppr1(){} // expected-warning {{no previous prototype for function 'ppr1'}} + +#pragma clang diagnostic push // push again +#pragma clang diagnostic ignored "-Weverything" // Set to ignore in this level. +void pps2(){} +#pragma clang diagnostic warning "-Weverything" // Set to warning in this level. +void ppt2(){} // expected-warning {{no previous prototype for function 'ppt2'}} +#pragma clang diagnostic error "-Weverything" // Set to error in this level. +void ppt3(){} // expected-error {{no previous prototype for function 'ppt3'}} +#pragma clang diagnostic pop // pop should go back to warning level + +void pps1(){} // expected-warning {{no previous prototype for function 'pps1'}} + + +#pragma clang diagnostic pop // Another pop should disble it again +void ppu(){} + Index: test/Preprocessor/pragma_diagnostic.c ==
Re: [PATCH] D15095: Accept "-Weverything" in pragma clang diagnostic ...
Sunil_Srivastava added a comment. Richard, Your comment and my concern about the getDiagnosticsInGroup is still visible in the greyed out area. Given that do you still want to modify getDiagnosticsInGroup ? I have removed the separate test and added the new tests to existing files, as you suggested. http://reviews.llvm.org/D15095 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15095: Accept "-Weverything" in pragma clang diagnostic ...
Sunil_Srivastava updated this revision to Diff 47707. Sunil_Srivastava added a comment. Hi Richard, > Can you move the special case code out of DiagnosticsEngine and into the > pragma handler for now? Yes. This is that approach. http://reviews.llvm.org/D15095 Files: lib/Lex/Pragma.cpp test/Preprocessor/pragma_diagnostic.c test/Preprocessor/pushable-diagnostics.c Index: test/Preprocessor/pushable-diagnostics.c === --- test/Preprocessor/pushable-diagnostics.c +++ test/Preprocessor/pushable-diagnostics.c @@ -15,3 +15,27 @@ int c = 'df'; // expected-warning{{multi-character character constant}} #pragma clang diagnostic pop // expected-warning{{pragma diagnostic pop could not pop, no matching push}} + +// Test -Weverything + +void ppo0(){} // first verify that we do not give anything on this +#pragma clang diagnostic push // now push + +#pragma clang diagnostic warning "-Weverything" +void ppr1(){} // expected-warning {{no previous prototype for function 'ppr1'}} + +#pragma clang diagnostic push // push again +#pragma clang diagnostic ignored "-Weverything" // Set to ignore in this level. +void pps2(){} +#pragma clang diagnostic warning "-Weverything" // Set to warning in this level. +void ppt2(){} // expected-warning {{no previous prototype for function 'ppt2'}} +#pragma clang diagnostic error "-Weverything" // Set to error in this level. +void ppt3(){} // expected-error {{no previous prototype for function 'ppt3'}} +#pragma clang diagnostic pop // pop should go back to warning level + +void pps1(){} // expected-warning {{no previous prototype for function 'pps1'}} + + +#pragma clang diagnostic pop // Another pop should disble it again +void ppu(){} + Index: test/Preprocessor/pragma_diagnostic.c === --- test/Preprocessor/pragma_diagnostic.c +++ test/Preprocessor/pragma_diagnostic.c @@ -30,3 +30,18 @@ #pragma GCC diagnostic error "-Winvalid-name" // expected-warning {{unknown warning group '-Winvalid-name', ignored}} + +// Testing pragma clang diagnostic with -Weverything +void ppo(){} // First test that we do not diagnose on this. + +#pragma clang diagnostic warning "-Weverything" +void ppp(){} // expected-warning {{no previous prototype for function 'ppp'}} + +#pragma clang diagnostic ignored "-Weverything" // Reset it. +void ppq(){} + +#pragma clang diagnostic error "-Weverything" // Now set to error +void ppr(){} // expected-error {{no previous prototype for function 'ppr'}} + +#pragma clang diagnostic warning "-Weverything" // This should not be effective +void pps(){} // expected-error {{no previous prototype for function 'pps'}} Index: lib/Lex/Pragma.cpp === --- lib/Lex/Pragma.cpp +++ lib/Lex/Pragma.cpp @@ -1024,10 +1024,19 @@ return; } -if (PP.getDiagnostics().setSeverityForGroup( -WarningName[1] == 'W' ? diag::Flavor::WarningOrError - : diag::Flavor::Remark, -WarningName.substr(2), SV, DiagLoc)) +diag::Flavor Flavor = WarningName[1] == 'W' ? diag::Flavor::WarningOrError +: diag::Flavor::Remark; +StringRef Group = WarningName.substr(2); +bool unknownDiag = false; +if (Group == "everything") { + // Special handling for pragma clang diagnostic ... "-Weverything" + // There is no formal group named "everything", so there has to be a + // special case for it. + PP.getDiagnostics().setSeverityForAll(Flavor, SV, DiagLoc); +} else + unknownDiag = PP.getDiagnostics().setSeverityForGroup(Flavor, Group, SV, +DiagLoc); +if (unknownDiag) PP.Diag(StringLoc, diag::warn_pragma_diagnostic_unknown_warning) << WarningName; else if (Callbacks) Index: test/Preprocessor/pushable-diagnostics.c === --- test/Preprocessor/pushable-diagnostics.c +++ test/Preprocessor/pushable-diagnostics.c @@ -15,3 +15,27 @@ int c = 'df'; // expected-warning{{multi-character character constant}} #pragma clang diagnostic pop // expected-warning{{pragma diagnostic pop could not pop, no matching push}} + +// Test -Weverything + +void ppo0(){} // first verify that we do not give anything on this +#pragma clang diagnostic push // now push + +#pragma clang diagnostic warning "-Weverything" +void ppr1(){} // expected-warning {{no previous prototype for function 'ppr1'}} + +#pragma clang diagnostic push // push again +#pragma clang diagnostic ignored "-Weverything" // Set to ignore in this level. +void pps2(){} +#pragma clang diagnostic warning "-Weverything" // Set to warning in this level. +void ppt2(){} // expected-warning {{no previous prototype for function 'ppt2'}} +#pragma clang diagnostic error "-Wevery
Re: [PATCH] D15095: Accept "-Weverything" in pragma clang diagnostic ...
Sunil_Srivastava updated this revision to Diff 47865. Sunil_Srivastava added a comment. Hi Richard, Good point about that extra test. I suppose I need another LGTM for the new test. No other changes. http://reviews.llvm.org/D15095 Files: Preprocessor/Weverything_pragma.c Preprocessor/pragma_diagnostic.c Preprocessor/pushable-diagnostics.c Index: Preprocessor/pushable-diagnostics.c === --- Preprocessor/pushable-diagnostics.c +++ Preprocessor/pushable-diagnostics.c @@ -15,3 +15,27 @@ int c = 'df'; // expected-warning{{multi-character character constant}} #pragma clang diagnostic pop // expected-warning{{pragma diagnostic pop could not pop, no matching push}} + +// Test -Weverything + +void ppo0(){} // first verify that we do not give anything on this +#pragma clang diagnostic push // now push + +#pragma clang diagnostic warning "-Weverything" +void ppr1(){} // expected-warning {{no previous prototype for function 'ppr1'}} + +#pragma clang diagnostic push // push again +#pragma clang diagnostic ignored "-Weverything" // Set to ignore in this level. +void pps2(){} +#pragma clang diagnostic warning "-Weverything" // Set to warning in this level. +void ppt2(){} // expected-warning {{no previous prototype for function 'ppt2'}} +#pragma clang diagnostic error "-Weverything" // Set to error in this level. +void ppt3(){} // expected-error {{no previous prototype for function 'ppt3'}} +#pragma clang diagnostic pop // pop should go back to warning level + +void pps1(){} // expected-warning {{no previous prototype for function 'pps1'}} + + +#pragma clang diagnostic pop // Another pop should disble it again +void ppu(){} + Index: Preprocessor/pragma_diagnostic.c === --- Preprocessor/pragma_diagnostic.c +++ Preprocessor/pragma_diagnostic.c @@ -30,3 +30,18 @@ #pragma GCC diagnostic error "-Winvalid-name" // expected-warning {{unknown warning group '-Winvalid-name', ignored}} + +// Testing pragma clang diagnostic with -Weverything +void ppo(){} // First test that we do not diagnose on this. + +#pragma clang diagnostic warning "-Weverything" +void ppp(){} // expected-warning {{no previous prototype for function 'ppp'}} + +#pragma clang diagnostic ignored "-Weverything" // Reset it. +void ppq(){} + +#pragma clang diagnostic error "-Weverything" // Now set to error +void ppr(){} // expected-error {{no previous prototype for function 'ppr'}} + +#pragma clang diagnostic warning "-Weverything" // This should not be effective +void pps(){} // expected-error {{no previous prototype for function 'pps'}} Index: Preprocessor/Weverything_pragma.c === --- Preprocessor/Weverything_pragma.c +++ Preprocessor/Weverything_pragma.c @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -Weverything -fsyntax-only -verify %s + +// Test that the pragma overrides command line option -Weverythings, + +// a diagnostic with DefaultIgnore. This is part of a group 'unused-macro' +// but -Weverything forces it +#define UNUSED_MACRO1 1 // expected-warning{{macro is not used}} + +void foo() // expected-warning {{no previous prototype for function}} +{ + // A diagnostic without DefaultIgnore, and not part of a group. + (void) L'ab'; // expected-warning {{extraneous characters in character constant ignored}} + +#pragma clang diagnostic warning "-Weverything" // Should not change anyhting. +#define UNUSED_MACRO2 1 // expected-warning{{macro is not used}} + (void) L'cd'; // expected-warning {{extraneous characters in character constant ignored}} + +#pragma clang diagnostic ignored "-Weverything" // Ignore warnings now. +#define UNUSED_MACRO2 1 // no warning + (void) L'ef'; // no warning here + +#pragma clang diagnostic warning "-Weverything" // Revert back to warnings. +#define UNUSED_MACRO3 1 // expected-warning{{macro is not used}} + (void) L'gh'; // expected-warning {{extraneous characters in character constant ignored}} + +#pragma clang diagnostic error "-Weverything" // Give errors now. +#define UNUSED_MACRO4 1 // expected-error{{macro is not used}} + (void) L'ij'; // expected-error {{extraneous characters in character constant ignored}} +} Index: Preprocessor/pushable-diagnostics.c === --- Preprocessor/pushable-diagnostics.c +++ Preprocessor/pushable-diagnostics.c @@ -15,3 +15,27 @@ int c = 'df'; // expected-warning{{multi-character character constant}} #pragma clang diagnostic pop // expected-warning{{pragma diagnostic pop could not pop, no matching push}} + +// Test -Weverything + +void ppo0(){} // first verify that we do not give anything on this +#pragma clang diagnostic push // now push + +#pragma clang diagnostic warning "-Weverything" +void ppr1(){} // expected-warning {{no previous prototype for function 'ppr1'}} + +#pragma clang diagnostic push // push again +#p
Re: [PATCH] D15095: Accept "-Weverything" in pragma clang diagnostic ...
Sunil_Srivastava updated this revision to Diff 47866. Sunil_Srivastava added a comment. Hi Richard, Good point about that extra test. I suppose I need another LGTM for the new test. No other changes. (Sorry I had missed the code change in the last round) http://reviews.llvm.org/D15095 Files: lib/Lex/Pragma.cpp test/Preprocessor/Weverything_pragma.c test/Preprocessor/pragma_diagnostic.c test/Preprocessor/pushable-diagnostics.c Index: test/Preprocessor/pushable-diagnostics.c === --- test/Preprocessor/pushable-diagnostics.c +++ test/Preprocessor/pushable-diagnostics.c @@ -15,3 +15,27 @@ int c = 'df'; // expected-warning{{multi-character character constant}} #pragma clang diagnostic pop // expected-warning{{pragma diagnostic pop could not pop, no matching push}} + +// Test -Weverything + +void ppo0(){} // first verify that we do not give anything on this +#pragma clang diagnostic push // now push + +#pragma clang diagnostic warning "-Weverything" +void ppr1(){} // expected-warning {{no previous prototype for function 'ppr1'}} + +#pragma clang diagnostic push // push again +#pragma clang diagnostic ignored "-Weverything" // Set to ignore in this level. +void pps2(){} +#pragma clang diagnostic warning "-Weverything" // Set to warning in this level. +void ppt2(){} // expected-warning {{no previous prototype for function 'ppt2'}} +#pragma clang diagnostic error "-Weverything" // Set to error in this level. +void ppt3(){} // expected-error {{no previous prototype for function 'ppt3'}} +#pragma clang diagnostic pop // pop should go back to warning level + +void pps1(){} // expected-warning {{no previous prototype for function 'pps1'}} + + +#pragma clang diagnostic pop // Another pop should disble it again +void ppu(){} + Index: test/Preprocessor/pragma_diagnostic.c === --- test/Preprocessor/pragma_diagnostic.c +++ test/Preprocessor/pragma_diagnostic.c @@ -30,3 +30,18 @@ #pragma GCC diagnostic error "-Winvalid-name" // expected-warning {{unknown warning group '-Winvalid-name', ignored}} + +// Testing pragma clang diagnostic with -Weverything +void ppo(){} // First test that we do not diagnose on this. + +#pragma clang diagnostic warning "-Weverything" +void ppp(){} // expected-warning {{no previous prototype for function 'ppp'}} + +#pragma clang diagnostic ignored "-Weverything" // Reset it. +void ppq(){} + +#pragma clang diagnostic error "-Weverything" // Now set to error +void ppr(){} // expected-error {{no previous prototype for function 'ppr'}} + +#pragma clang diagnostic warning "-Weverything" // This should not be effective +void pps(){} // expected-error {{no previous prototype for function 'pps'}} Index: test/Preprocessor/Weverything_pragma.c === --- test/Preprocessor/Weverything_pragma.c +++ test/Preprocessor/Weverything_pragma.c @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -Weverything -fsyntax-only -verify %s + +// Test that the pragma overrides command line option -Weverythings, + +// a diagnostic with DefaultIgnore. This is part of a group 'unused-macro' +// but -Weverything forces it +#define UNUSED_MACRO1 1 // expected-warning{{macro is not used}} + +void foo() // expected-warning {{no previous prototype for function}} +{ + // A diagnostic without DefaultIgnore, and not part of a group. + (void) L'ab'; // expected-warning {{extraneous characters in character constant ignored}} + +#pragma clang diagnostic warning "-Weverything" // Should not change anyhting. +#define UNUSED_MACRO2 1 // expected-warning{{macro is not used}} + (void) L'cd'; // expected-warning {{extraneous characters in character constant ignored}} + +#pragma clang diagnostic ignored "-Weverything" // Ignore warnings now. +#define UNUSED_MACRO2 1 // no warning + (void) L'ef'; // no warning here + +#pragma clang diagnostic warning "-Weverything" // Revert back to warnings. +#define UNUSED_MACRO3 1 // expected-warning{{macro is not used}} + (void) L'gh'; // expected-warning {{extraneous characters in character constant ignored}} + +#pragma clang diagnostic error "-Weverything" // Give errors now. +#define UNUSED_MACRO4 1 // expected-error{{macro is not used}} + (void) L'ij'; // expected-error {{extraneous characters in character constant ignored}} +} Index: lib/Lex/Pragma.cpp === --- lib/Lex/Pragma.cpp +++ lib/Lex/Pragma.cpp @@ -1024,10 +1024,19 @@ return; } -if (PP.getDiagnostics().setSeverityForGroup( -WarningName[1] == 'W' ? diag::Flavor::WarningOrError - : diag::Flavor::Remark, -WarningName.substr(2), SV, DiagLoc)) +diag::Flavor Flavor = WarningName[1] == 'W' ? diag::Flavor::WarningOrError +: diag::Flavor::Remark; +StringRef Group
r260788 - Accept "-Weverything" in clang diagnistic pragmas
Author: ssrivastava Date: Fri Feb 12 19:44:05 2016 New Revision: 260788 URL: http://llvm.org/viewvc/llvm-project?rev=260788&view=rev Log: Accept "-Weverything" in clang diagnistic pragmas Differential Revision: http://reviews.llvm.org/D15095 Added: cfe/trunk/test/Preprocessor/Weverything_pragma.c Modified: cfe/trunk/lib/Lex/Pragma.cpp cfe/trunk/test/Preprocessor/pragma_diagnostic.c cfe/trunk/test/Preprocessor/pushable-diagnostics.c Modified: cfe/trunk/lib/Lex/Pragma.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=260788&r1=260787&r2=260788&view=diff == --- cfe/trunk/lib/Lex/Pragma.cpp (original) +++ cfe/trunk/lib/Lex/Pragma.cpp Fri Feb 12 19:44:05 2016 @@ -1024,10 +1024,19 @@ public: return; } -if (PP.getDiagnostics().setSeverityForGroup( -WarningName[1] == 'W' ? diag::Flavor::WarningOrError - : diag::Flavor::Remark, -WarningName.substr(2), SV, DiagLoc)) +diag::Flavor Flavor = WarningName[1] == 'W' ? diag::Flavor::WarningOrError +: diag::Flavor::Remark; +StringRef Group = WarningName.substr(2); +bool unknownDiag = false; +if (Group == "everything") { + // Special handling for pragma clang diagnostic ... "-Weverything". + // There is no formal group named "everything", so there has to be a + // special case for it. + PP.getDiagnostics().setSeverityForAll(Flavor, SV, DiagLoc); +} else + unknownDiag = PP.getDiagnostics().setSeverityForGroup(Flavor, Group, SV, +DiagLoc); +if (unknownDiag) PP.Diag(StringLoc, diag::warn_pragma_diagnostic_unknown_warning) << WarningName; else if (Callbacks) Added: cfe/trunk/test/Preprocessor/Weverything_pragma.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/Weverything_pragma.c?rev=260788&view=auto == --- cfe/trunk/test/Preprocessor/Weverything_pragma.c (added) +++ cfe/trunk/test/Preprocessor/Weverything_pragma.c Fri Feb 12 19:44:05 2016 @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -Weverything -fsyntax-only -verify %s + +// Test that the pragma overrides command line option -Weverythings, + +// a diagnostic with DefaultIgnore. This is part of a group 'unused-macro' +// but -Weverything forces it +#define UNUSED_MACRO1 1 // expected-warning{{macro is not used}} + +void foo() // expected-warning {{no previous prototype for function}} +{ + // A diagnostic without DefaultIgnore, and not part of a group. + (void) L'ab'; // expected-warning {{extraneous characters in character constant ignored}} + +#pragma clang diagnostic warning "-Weverything" // Should not change anyhting. +#define UNUSED_MACRO2 1 // expected-warning{{macro is not used}} + (void) L'cd'; // expected-warning {{extraneous characters in character constant ignored}} + +#pragma clang diagnostic ignored "-Weverything" // Ignore warnings now. +#define UNUSED_MACRO2 1 // no warning + (void) L'ef'; // no warning here + +#pragma clang diagnostic warning "-Weverything" // Revert back to warnings. +#define UNUSED_MACRO3 1 // expected-warning{{macro is not used}} + (void) L'gh'; // expected-warning {{extraneous characters in character constant ignored}} + +#pragma clang diagnostic error "-Weverything" // Give errors now. +#define UNUSED_MACRO4 1 // expected-error{{macro is not used}} + (void) L'ij'; // expected-error {{extraneous characters in character constant ignored}} +} Modified: cfe/trunk/test/Preprocessor/pragma_diagnostic.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/pragma_diagnostic.c?rev=260788&r1=260787&r2=260788&view=diff == --- cfe/trunk/test/Preprocessor/pragma_diagnostic.c (original) +++ cfe/trunk/test/Preprocessor/pragma_diagnostic.c Fri Feb 12 19:44:05 2016 @@ -30,3 +30,18 @@ #pragma GCC diagnostic error "-Winvalid-name" // expected-warning {{unknown warning group '-Winvalid-name', ignored}} + +// Testing pragma clang diagnostic with -Weverything +void ppo(){} // First test that we do not diagnose on this. + +#pragma clang diagnostic warning "-Weverything" +void ppp(){} // expected-warning {{no previous prototype for function 'ppp'}} + +#pragma clang diagnostic ignored "-Weverything" // Reset it. +void ppq(){} + +#pragma clang diagnostic error "-Weverything" // Now set to error +void ppr(){} // expected-error {{no previous prototype for function 'ppr'}} + +#pragma clang diagnostic warning "-Weverything" // This should not be effective +void pps(){} // expected-error {{no previous prototype for function 'pps'}} Modified: cfe/trunk/test/Preprocessor/pushable-diagnostics.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Prepr
r262042 - Minor tweak to match the overall style.
Author: ssrivastava Date: Fri Feb 26 12:01:12 2016 New Revision: 262042 URL: http://llvm.org/viewvc/llvm-project?rev=262042&view=rev Log: Minor tweak to match the overall style. Modified: cfe/trunk/test/Sema/bitfield-layout.c Modified: cfe/trunk/test/Sema/bitfield-layout.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/bitfield-layout.c?rev=262042&r1=262041&r2=262042&view=diff == --- cfe/trunk/test/Sema/bitfield-layout.c (original) +++ cfe/trunk/test/Sema/bitfield-layout.c Fri Feb 26 12:01:12 2016 @@ -255,7 +255,7 @@ struct g13 { CHECK_SIZE(struct, g13, 16); CHECK_ALIGN(struct, g13, 8); CHECK_OFFSET(struct, g13, c, 8); -#elif (__x86_64__) +#elif defined(__x86_64__) CHECK_SIZE(struct, g13, 9); CHECK_ALIGN(struct, g13, 1); CHECK_OFFSET(struct, g13, c, 8); @@ -274,7 +274,7 @@ struct __attribute__((packed)) g14 { CHECK_SIZE(struct, g14, 16); CHECK_ALIGN(struct, g14, 8); CHECK_OFFSET(struct, g14, c, 8); -#elif (__x86_64__) +#elif defined(__x86_64__) CHECK_SIZE(struct, g14, 9); CHECK_ALIGN(struct, g14, 1); CHECK_OFFSET(struct, g14, c, 8); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D19552: Check 'r' and 'y specifiers of freebsd_kernel_printf format strings on PS4
Sunil_Srivastava created this revision. Sunil_Srivastava added a reviewer: dim. Sunil_Srivastava added a subscriber: cfe-commits. Herald added a subscriber: emaste. This is an addendum to r229921. http://reviews.llvm.org/D19552 Files: lib/Analysis/FormatString.cpp test/Sema/format-strings-freebsd.c Index: test/Sema/format-strings-freebsd.c === --- test/Sema/format-strings-freebsd.c +++ test/Sema/format-strings-freebsd.c @@ -1,10 +1,11 @@ // RUN: %clang_cc1 -fsyntax-only -verify -triple i386-unknown-freebsd %s // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd %s +// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-scei-ps4 %s // Test FreeBSD kernel printf extensions. int freebsd_kernel_printf(const char *, ...) __attribute__((__format__(__freebsd_kprintf__, 1, 2))); -void check_freebsd_kernel_extensions(int i, long l, char *s) +void check_freebsd_kernel_extensions(int i, long l, char *s, short h) { // %b expects an int and a char * freebsd_kernel_printf("reg=%b\n", i, "\10\2BITTWO\1BITONE\n"); // no-warning @@ -32,6 +33,10 @@ freebsd_kernel_printf("%lr", i); // expected-warning{{format specifies type 'long' but the argument has type 'int'}} freebsd_kernel_printf("%lr", l); // no-warning + // h modifier expects a short + freebsd_kernel_printf("%hr", i); // expected-warning{{format specifies type 'short' but the argument has type 'int'}} + freebsd_kernel_printf("%hr", h); // no-warning + // %y expects an int freebsd_kernel_printf("%y", i); // no-warning freebsd_kernel_printf("%y", l); // expected-warning{{format specifies type 'int' but the argument has type 'long'}} Index: lib/Analysis/FormatString.cpp === --- lib/Analysis/FormatString.cpp +++ lib/Analysis/FormatString.cpp @@ -694,7 +694,7 @@ return true; case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: - return Target.getTriple().isOSFreeBSD(); + return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS4(); default: return false; } @@ -727,7 +727,7 @@ return true; case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: - return Target.getTriple().isOSFreeBSD(); + return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS4(); default: return false; } Index: test/Sema/format-strings-freebsd.c === --- test/Sema/format-strings-freebsd.c +++ test/Sema/format-strings-freebsd.c @@ -1,10 +1,11 @@ // RUN: %clang_cc1 -fsyntax-only -verify -triple i386-unknown-freebsd %s // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd %s +// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-scei-ps4 %s // Test FreeBSD kernel printf extensions. int freebsd_kernel_printf(const char *, ...) __attribute__((__format__(__freebsd_kprintf__, 1, 2))); -void check_freebsd_kernel_extensions(int i, long l, char *s) +void check_freebsd_kernel_extensions(int i, long l, char *s, short h) { // %b expects an int and a char * freebsd_kernel_printf("reg=%b\n", i, "\10\2BITTWO\1BITONE\n"); // no-warning @@ -32,6 +33,10 @@ freebsd_kernel_printf("%lr", i); // expected-warning{{format specifies type 'long' but the argument has type 'int'}} freebsd_kernel_printf("%lr", l); // no-warning + // h modifier expects a short + freebsd_kernel_printf("%hr", i); // expected-warning{{format specifies type 'short' but the argument has type 'int'}} + freebsd_kernel_printf("%hr", h); // no-warning + // %y expects an int freebsd_kernel_printf("%y", i); // no-warning freebsd_kernel_printf("%y", l); // expected-warning{{format specifies type 'int' but the argument has type 'long'}} Index: lib/Analysis/FormatString.cpp === --- lib/Analysis/FormatString.cpp +++ lib/Analysis/FormatString.cpp @@ -694,7 +694,7 @@ return true; case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: - return Target.getTriple().isOSFreeBSD(); + return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS4(); default: return false; } @@ -727,7 +727,7 @@ return true; case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: - return Target.getTriple().isOSFreeBSD(); + return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS4(); default: return false; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19552: Check 'r' and 'y specifiers of freebsd_kernel_printf format strings on PS4
Sunil_Srivastava added a comment. I had put these 'h' test lines to test the first of my changes, and this sufficed, but you are correct. I should add %y too. I am going to add '%hr' and '%hy'. Comment at: test/Sema/format-strings-freebsd.c:39 @@ -35,1 +38,3 @@ + freebsd_kernel_printf("%hr", h); // no-warning + // %y expects an int dim wrote: > It's nice to add these for %r, but is there any reason you didn't add similar > ones for %y? (This is just a minor nit.) I had put these lines to test the first of my changes, and this sufficed, but you are correct. I should add %y too. I am going to add '%hr' and '%hy'. http://reviews.llvm.org/D19552 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r267625 - Check 'r' and 'y specifiers of freebsd_kernel_printf format strings on PS4
Author: ssrivastava Date: Tue Apr 26 18:19:00 2016 New Revision: 267625 URL: http://llvm.org/viewvc/llvm-project?rev=267625&view=rev Log: Check 'r' and 'y specifiers of freebsd_kernel_printf format strings on PS4 This is an addendum to r229921. Modified: cfe/trunk/lib/Analysis/FormatString.cpp cfe/trunk/test/Sema/format-strings-freebsd.c Modified: cfe/trunk/lib/Analysis/FormatString.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/FormatString.cpp?rev=267625&r1=267624&r2=267625&view=diff == --- cfe/trunk/lib/Analysis/FormatString.cpp (original) +++ cfe/trunk/lib/Analysis/FormatString.cpp Tue Apr 26 18:19:00 2016 @@ -694,7 +694,7 @@ bool FormatSpecifier::hasValidLengthModi return true; case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: - return Target.getTriple().isOSFreeBSD(); + return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS4(); default: return false; } @@ -727,7 +727,7 @@ bool FormatSpecifier::hasValidLengthModi return true; case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: - return Target.getTriple().isOSFreeBSD(); + return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS4(); default: return false; } Modified: cfe/trunk/test/Sema/format-strings-freebsd.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings-freebsd.c?rev=267625&r1=267624&r2=267625&view=diff == --- cfe/trunk/test/Sema/format-strings-freebsd.c (original) +++ cfe/trunk/test/Sema/format-strings-freebsd.c Tue Apr 26 18:19:00 2016 @@ -1,10 +1,11 @@ // RUN: %clang_cc1 -fsyntax-only -verify -triple i386-unknown-freebsd %s // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd %s +// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-scei-ps4 %s // Test FreeBSD kernel printf extensions. int freebsd_kernel_printf(const char *, ...) __attribute__((__format__(__freebsd_kprintf__, 1, 2))); -void check_freebsd_kernel_extensions(int i, long l, char *s) +void check_freebsd_kernel_extensions(int i, long l, char *s, short h) { // %b expects an int and a char * freebsd_kernel_printf("reg=%b\n", i, "\10\2BITTWO\1BITONE\n"); // no-warning @@ -32,6 +33,12 @@ void check_freebsd_kernel_extensions(int freebsd_kernel_printf("%lr", i); // expected-warning{{format specifies type 'long' but the argument has type 'int'}} freebsd_kernel_printf("%lr", l); // no-warning + // h modifier expects a short + freebsd_kernel_printf("%hr", i); // expected-warning{{format specifies type 'short' but the argument has type 'int'}} + freebsd_kernel_printf("%hr", h); // no-warning + freebsd_kernel_printf("%hy", i); // expected-warning{{format specifies type 'short' but the argument has type 'int'}} + freebsd_kernel_printf("%hy", h); // no-warning + // %y expects an int freebsd_kernel_printf("%y", i); // no-warning freebsd_kernel_printf("%y", l); // expected-warning{{format specifies type 'int' but the argument has type 'long'}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19552: Check 'r' and 'y specifiers of freebsd_kernel_printf format strings on PS4
Sunil_Srivastava closed this revision. Sunil_Srivastava added a comment. Submitted as r267625. http://reviews.llvm.org/D19552 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r267772 - Set the default C standard to C99 when targeting the PS4.
Author: ssrivastava Date: Wed Apr 27 14:53:03 2016 New Revision: 267772 URL: http://llvm.org/viewvc/llvm-project?rev=267772&view=rev Log: Set the default C standard to C99 when targeting the PS4. Patch by Douglas Yung! Differential Revision: http://reviews.llvm.org/D19003 Modified: cfe/trunk/include/clang/Frontend/CompilerInvocation.h cfe/trunk/lib/Frontend/CompilerInvocation.cpp cfe/trunk/test/FixIt/fixit-errors.c cfe/trunk/test/Preprocessor/init.c cfe/trunk/test/Sema/attr-deprecated.c cfe/trunk/test/Sema/nullability.c cfe/trunk/test/SemaObjC/objcbridge-attribute-arc.m Modified: cfe/trunk/include/clang/Frontend/CompilerInvocation.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInvocation.h?rev=267772&r1=267771&r2=267772&view=diff == --- cfe/trunk/include/clang/Frontend/CompilerInvocation.h (original) +++ cfe/trunk/include/clang/Frontend/CompilerInvocation.h Wed Apr 27 14:53:03 2016 @@ -153,8 +153,10 @@ public: /// /// \param Opts - The LangOptions object to set up. /// \param IK - The input language. + /// \param T - The target triple. /// \param LangStd - The input language standard. static void setLangDefaults(LangOptions &Opts, InputKind IK, + const llvm::Triple &T, LangStandard::Kind LangStd = LangStandard::lang_unspecified); /// \brief Retrieve a module hash string that is suitable for uniquely Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=267772&r1=267771&r2=267772&view=diff == --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed Apr 27 14:53:03 2016 @@ -1344,6 +1344,7 @@ static void ParseHeaderSearchArgs(Header } void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, + const llvm::Triple &T, LangStandard::Kind LangStd) { // Set some properties which depend solely on the input kind; it would be nice // to move these to the language standard, and have the driver resolve the @@ -1376,7 +1377,11 @@ void CompilerInvocation::setLangDefaults case IK_PreprocessedC: case IK_ObjC: case IK_PreprocessedObjC: - LangStd = LangStandard::lang_gnu11; + // The PS4 uses C99 as the default C standard. + if (T.isPS4()) +LangStd = LangStandard::lang_gnu99; + else +LangStd = LangStandard::lang_gnu11; break; case IK_CXX: case IK_PreprocessedCXX: @@ -1529,7 +1534,8 @@ static void ParseLangArgs(LangOptions &O LangStd = OpenCLLangStd; } - CompilerInvocation::setLangDefaults(Opts, IK, LangStd); + llvm::Triple T(TargetOpts.Triple); + CompilerInvocation::setLangDefaults(Opts, IK, T, LangStd); // We abuse '-f[no-]gnu-keywords' to force overriding all GNU-extension // keywords. This behavior is provided by GCC's poorly named '-fasm' flag, @@ -1851,7 +1857,6 @@ static void ParseLangArgs(LangOptions &O // Provide diagnostic when a given target is not expected to be an OpenMP // device or host. if (Opts.OpenMP && !Opts.OpenMPIsDevice) { -llvm::Triple T(TargetOpts.Triple); switch (T.getArch()) { default: break; Modified: cfe/trunk/test/FixIt/fixit-errors.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-errors.c?rev=267772&r1=267771&r2=267772&view=diff == --- cfe/trunk/test/FixIt/fixit-errors.c (original) +++ cfe/trunk/test/FixIt/fixit-errors.c Wed Apr 27 14:53:03 2016 @@ -22,6 +22,8 @@ void test_point() { (void)get_origin->x; // expected-error {{base of member reference is a function; perhaps you meant to call it with no arguments?}} } +// These errors require C11. +#if __STDC_VERSION__ > 199901L void noreturn_1() _Noreturn; // expected-error {{must precede function declarator}} void noreturn_1() { return; // expected-warning {{should not return}} @@ -29,3 +31,4 @@ void noreturn_1() { void noreturn_2() _Noreturn { // expected-error {{must precede function declarator}} return; // expected-warning {{should not return}} } +#endif Modified: cfe/trunk/test/Preprocessor/init.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=267772&r1=267771&r2=267772&view=diff == --- cfe/trunk/test/Preprocessor/init.c (original) +++ cfe/trunk/test/Preprocessor/init.c Wed Apr 27 14:53:03 2016 @@ -88,7 +88,6 @@ // COMMON:#define __ORDER_LITTLE_ENDIAN__ 1234 // COMMON:#define __ORDER_PDP_ENDIAN__ 3412 // COMMON:#define __STDC_HOSTED__ 1 -// COMMON:#define __STDC
r265359 - Set the default C standard to C99 when targeting the PS4.
Author: ssrivastava Date: Mon Apr 4 17:56:05 2016 New Revision: 265359 URL: http://llvm.org/viewvc/llvm-project?rev=265359&view=rev Log: Set the default C standard to C99 when targeting the PS4. Patch by Douglas Yung! Differential Revision: http://reviews.llvm.org/D18708 Modified: cfe/trunk/include/clang/Frontend/CompilerInvocation.h cfe/trunk/lib/Frontend/CompilerInvocation.cpp cfe/trunk/test/Preprocessor/init.c Modified: cfe/trunk/include/clang/Frontend/CompilerInvocation.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInvocation.h?rev=265359&r1=265358&r2=265359&view=diff == --- cfe/trunk/include/clang/Frontend/CompilerInvocation.h (original) +++ cfe/trunk/include/clang/Frontend/CompilerInvocation.h Mon Apr 4 17:56:05 2016 @@ -153,8 +153,10 @@ public: /// /// \param Opts - The LangOptions object to set up. /// \param IK - The input language. + /// \param T - The target triple. /// \param LangStd - The input language standard. static void setLangDefaults(LangOptions &Opts, InputKind IK, + const llvm::Triple &T, LangStandard::Kind LangStd = LangStandard::lang_unspecified); /// \brief Retrieve a module hash string that is suitable for uniquely Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=265359&r1=265358&r2=265359&view=diff == --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Apr 4 17:56:05 2016 @@ -1355,6 +1355,7 @@ static void ParseHeaderSearchArgs(Header } void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, + const llvm::Triple &T, LangStandard::Kind LangStd) { // Set some properties which depend solely on the input kind; it would be nice // to move these to the language standard, and have the driver resolve the @@ -1387,7 +1388,11 @@ void CompilerInvocation::setLangDefaults case IK_PreprocessedC: case IK_ObjC: case IK_PreprocessedObjC: - LangStd = LangStandard::lang_gnu11; + // The PS4 uses C99 as the default C standard. + if (T.isPS4()) +LangStd = LangStandard::lang_gnu99; + else +LangStd = LangStandard::lang_gnu11; break; case IK_CXX: case IK_PreprocessedCXX: @@ -1541,7 +1546,8 @@ static void ParseLangArgs(LangOptions &O LangStd = OpenCLLangStd; } - CompilerInvocation::setLangDefaults(Opts, IK, LangStd); + llvm::Triple T(TargetOpts.Triple); + CompilerInvocation::setLangDefaults(Opts, IK, T, LangStd); // We abuse '-f[no-]gnu-keywords' to force overriding all GNU-extension // keywords. This behavior is provided by GCC's poorly named '-fasm' flag, @@ -1861,7 +1867,6 @@ static void ParseLangArgs(LangOptions &O // Provide diagnostic when a given target is not expected to be an OpenMP // device or host. if (Opts.OpenMP && !Opts.OpenMPIsDevice) { -llvm::Triple T(TargetOpts.Triple); switch (T.getArch()) { default: break; Modified: cfe/trunk/test/Preprocessor/init.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=265359&r1=265358&r2=265359&view=diff == --- cfe/trunk/test/Preprocessor/init.c (original) +++ cfe/trunk/test/Preprocessor/init.c Mon Apr 4 17:56:05 2016 @@ -8358,6 +8358,7 @@ // PS4:#define __SSE2__ 1 // PS4:#define __SSE_MATH__ 1 // PS4:#define __SSE__ 1 +// PS4:#define __STDC_VERSION__ 199901L // PS4:#define __UINTMAX_TYPE__ long unsigned int // PS4:#define __USER_LABEL_PREFIX__ // PS4:#define __WCHAR_MAX__ 65535 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D22057: Prevent devirtualization of calls to un-instantiated functions.
Sunil_Srivastava created this revision. Sunil_Srivastava added a reviewer: rsmith. Sunil_Srivastava added a subscriber: cfe-commits. This review is for a fix for PR 27895, but it requires some discussion. The bugzilla and the email exchange with Richard Smith in http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20160530/161107.html contain more details. The basic problem: When the front end sees a call to a virtual function of a template class, it treats that as an odr use, therefore requiring the instantiation; except, for some reason, when it is an operator and used with an operator syntax. In those cases, if the call gets devirtualized later, it will generate a direct call to a function that has not been instantiated. Most of the time it will still work because someone else will instantiate it for some other reason, but if not, then we have converted a potentially dead code to a link time error of a missing definition. As discussed in the email exchange, there are two alternative ways to fix the problem. Either will be sufficient, but we want to do both. The first fix will be in the front end to force the instantiation on virtual calls that are potentially devirtualizable. For reasons described below I plan on submitting this in a later checkin. The second fix, the matter of this review, is to avoid devirtualization under certain conditions. The conditions that I am choosing is to prevent devirtualization if the function could be implicitly instantiated but front end chose to not mark it for instantiation. I welcome any suggestions about improvement to this condition. The reason I am planning on submitting them in this order, is that, once the first fix is checked in, there will be no way, known to me, to write a test for the second, devirtualization fix. Now some discussion about the way I am testing the avoid-devirtualization condition: I have added a bit to FunctionDecl that I am setting whenever a function is put on the PendingInstantiations list. Then, at the time of devirtualization, if the target function isImplictlyInstantiable and does not have that bit set, I avoid the devirtualization. This change adds one bit to FunctionDecl, but the test is quite fast. However, it duplicates the information between this bit and the PendingInstantiationsList. We have considered an alternate implementation which replaces the call (in CGClass.cpp) to isMarkedForPendingInstantiation with - explcitly-test-whether-it-is-on-the-PendingInstations-list || - has-already-been-instantiated. This alternate implementation does not add anything to FunctionDecl, avoids information duplication, but the test for its presence in the list will be expensive; it will require a search in the list. It will be done only for devirtualizable calls though, which is not that common. A related point that I am not sure about is: Are there circumstances where a function on the PendingInstantiations list can fails to be instantiated for reasons other than errors? If so then this checkin is not perfect, though it is still better than nothing. I am open to suggestion as to which of these implementations makes more sense. Once this change has been approved and submitted, I will open another review for the first fix, which will force the instantiation of functions that are target of potentially devirtualizable calls. http://reviews.llvm.org/D22057 Files: include/clang/AST/Decl.h lib/CodeGen/CGClass.cpp lib/Sema/Sema.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/CodeGen/no-devirt.cpp Index: test/CodeGen/no-devirt.cpp === --- test/CodeGen/no-devirt.cpp +++ test/CodeGen/no-devirt.cpp @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 %s -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %s +template < typename T, int N = 0 > class TmplWithArray { +public: + virtual T& operator [] (int idx); + virtual T& func1 (int idx); + virtual T& func2 (int idx); + T ar[N+1]; +}; +class Wrapper { + TmplWithArray data; + bool indexIt(int a); +}; +bool Wrapper::indexIt(int a) +{ + if (a > 6) return data[a] ; // Should not devirtualize + if (a > 4) return data.func1(a); // Should devirtualize + return data.func2(a);// Should devirtualize +} +template T& TmplWithArray::operator[](int idx) { + return ar[idx]; +} +template T& TmplWithArray::func1(int idx) { + return ar[idx]; +} +// CHECK-NOT: call {{.*}} @_ZN13TmplWithArrayIbLi10EEixEi +// CHECK-DAG: call {{.*}} @_ZN13TmplWithArrayIbLi10EE5func1Ei +// CHECK-DAG: call {{.*}} @_ZN13TmplWithArrayIbLi10EE5func2Ei Index: lib/Sema/SemaTemplateInstantiateDecl.cpp === --- lib/Sema/SemaTemplateInstantiateDecl.cpp +++ lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3531,6 +3531,7 @@ // Postpone late parsed template instantiations. if (PatternDecl->isLateTemplateParsed() &&
Re: [PATCH] D22057: Prevent devirtualization of calls to un-instantiated functions.
Sunil_Srivastava added a comment. Ping. https://reviews.llvm.org/D22057 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D16607: Implementation of PS4 ABI, round 1
Sunil_Srivastava created this revision. Sunil_Srivastava added a reviewer: rsmith. Sunil_Srivastava added a subscriber: cfe-commits. We are planning to upstream changes needed for maintaining PS4 ABI across future releases. Unlike many other targets, we need to maintain, in most cases, strict object compatibility to a stable base (llvm 3.2 in this case) across releases, even in cases where the behavior differs from common x86-64 documentation or current practice. To maintain such compatibility we are proposing to introduce TargetCXXABI::PS4. This will be a variant of GenericItaniumABI, but will remain compatible to llvm 3.2 in most cases, even if the GenericItaniumABI behavior changes. One such change has recently occurred in r257462, and is the motivation of taking up this task now. This proposed change is the first step of this work. This is not a change in the compiler at all, but just an addition to a test for x86_64_pc-linux-gnu triple. Its purpose is to guard against inadvertent changes to the default x86_64 ABI by future changes, in regard to the bitfield layout. The proposed change adds a new run line with x86_64_pc-linux-gnu, along with few variants of tests where they x86_64 rules differ from other triple used In the test. The next round of changes will introduce the concept of the PS4 ABI in the compiler itself. http://reviews.llvm.org/D16607 Files: test/Sema/bitfield-layout.c Index: test/Sema/bitfield-layout.c === --- test/Sema/bitfield-layout.c +++ test/Sema/bitfield-layout.c @@ -1,6 +1,7 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=i686-apple-darwin9 // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=arm-linux-gnueabihf // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=aarch64-linux-gnu +// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=x86_64-pc-linux-gnu // expected-no-diagnostics #include @@ -190,7 +191,7 @@ __attribute__((aligned(1))) long long b : 62; char c; }; -#if defined(__arm__) || defined(__aarch64__) +#if defined(__arm__) || defined(__aarch64__) || defined(__x86_64__) CHECK_SIZE(struct, g11, 24); CHECK_ALIGN(struct, g11, 8); CHECK_OFFSET(struct, g11, c, 16); @@ -218,6 +219,10 @@ CHECK_SIZE(struct, g13, 16); CHECK_ALIGN(struct, g13, 8); CHECK_OFFSET(struct, g13, c, 8); +#elif (__x86_64__) +CHECK_SIZE(struct, g13, 9); +CHECK_ALIGN(struct, g13, 1); +CHECK_OFFSET(struct, g13, c, 8); #else CHECK_SIZE(struct, g13, 5); CHECK_ALIGN(struct, g13, 1); @@ -233,6 +238,10 @@ CHECK_SIZE(struct, g14, 16); CHECK_ALIGN(struct, g14, 8); CHECK_OFFSET(struct, g14, c, 8); +#elif (__x86_64__) +CHECK_SIZE(struct, g14, 9); +CHECK_ALIGN(struct, g14, 1); +CHECK_OFFSET(struct, g14, c, 8); #else CHECK_SIZE(struct, g14, 5); CHECK_ALIGN(struct, g14, 1); Index: test/Sema/bitfield-layout.c === --- test/Sema/bitfield-layout.c +++ test/Sema/bitfield-layout.c @@ -1,6 +1,7 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=i686-apple-darwin9 // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=arm-linux-gnueabihf // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=aarch64-linux-gnu +// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=x86_64-pc-linux-gnu // expected-no-diagnostics #include @@ -190,7 +191,7 @@ __attribute__((aligned(1))) long long b : 62; char c; }; -#if defined(__arm__) || defined(__aarch64__) +#if defined(__arm__) || defined(__aarch64__) || defined(__x86_64__) CHECK_SIZE(struct, g11, 24); CHECK_ALIGN(struct, g11, 8); CHECK_OFFSET(struct, g11, c, 16); @@ -218,6 +219,10 @@ CHECK_SIZE(struct, g13, 16); CHECK_ALIGN(struct, g13, 8); CHECK_OFFSET(struct, g13, c, 8); +#elif (__x86_64__) +CHECK_SIZE(struct, g13, 9); +CHECK_ALIGN(struct, g13, 1); +CHECK_OFFSET(struct, g13, c, 8); #else CHECK_SIZE(struct, g13, 5); CHECK_ALIGN(struct, g13, 1); @@ -233,6 +238,10 @@ CHECK_SIZE(struct, g14, 16); CHECK_ALIGN(struct, g14, 8); CHECK_OFFSET(struct, g14, c, 8); +#elif (__x86_64__) +CHECK_SIZE(struct, g14, 9); +CHECK_ALIGN(struct, g14, 1); +CHECK_OFFSET(struct, g14, c, 8); #else CHECK_SIZE(struct, g14, 5); CHECK_ALIGN(struct, g14, 1); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r259095 - Implementation of PS4 ABI, Round 1
Author: ssrivastava Date: Thu Jan 28 15:36:31 2016 New Revision: 259095 URL: http://llvm.org/viewvc/llvm-project?rev=259095&view=rev Log: Implementation of PS4 ABI, Round 1 Added a test to safeguard linux ABI. Differential Revision: http://reviews.llvm.org/D16607 Modified: cfe/trunk/test/Sema/bitfield-layout.c Modified: cfe/trunk/test/Sema/bitfield-layout.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/bitfield-layout.c?rev=259095&r1=259094&r2=259095&view=diff == --- cfe/trunk/test/Sema/bitfield-layout.c (original) +++ cfe/trunk/test/Sema/bitfield-layout.c Thu Jan 28 15:36:31 2016 @@ -1,6 +1,7 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=i686-apple-darwin9 // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=arm-linux-gnueabihf // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=aarch64-linux-gnu +// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=x86_64-pc-linux-gnu // expected-no-diagnostics #include @@ -190,7 +191,7 @@ struct g11 { __attribute__((aligned(1))) long long b : 62; char c; }; -#if defined(__arm__) || defined(__aarch64__) +#if defined(__arm__) || defined(__aarch64__) || defined(__x86_64__) CHECK_SIZE(struct, g11, 24); CHECK_ALIGN(struct, g11, 8); CHECK_OFFSET(struct, g11, c, 16); @@ -218,6 +219,10 @@ struct g13 { CHECK_SIZE(struct, g13, 16); CHECK_ALIGN(struct, g13, 8); CHECK_OFFSET(struct, g13, c, 8); +#elif (__x86_64__) +CHECK_SIZE(struct, g13, 9); +CHECK_ALIGN(struct, g13, 1); +CHECK_OFFSET(struct, g13, c, 8); #else CHECK_SIZE(struct, g13, 5); CHECK_ALIGN(struct, g13, 1); @@ -233,6 +238,10 @@ struct __attribute__((packed)) g14 { CHECK_SIZE(struct, g14, 16); CHECK_ALIGN(struct, g14, 8); CHECK_OFFSET(struct, g14, c, 8); +#elif (__x86_64__) +CHECK_SIZE(struct, g14, 9); +CHECK_ALIGN(struct, g14, 1); +CHECK_OFFSET(struct, g14, c, 8); #else CHECK_SIZE(struct, g14, 5); CHECK_ALIGN(struct, g14, 1); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D15095: Accept "-Weverything" in pragma clang diagnostic ...
Sunil_Srivastava created this revision. Sunil_Srivastava added a subscriber: cfe-commits. Special handling for “-Weverything” in ‘pragma clang diagnostic handling’ There is no formal diagnostic group named “everything”, so this code is needed. http://reviews.llvm.org/D15095 Files: lib/Basic/Diagnostic.cpp test/Frontend/Peverything.cpp Index: test/Frontend/Peverything.cpp === --- test/Frontend/Peverything.cpp +++ test/Frontend/Peverything.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify +#pragma clang diagnostic error "-Weverything" + +void ppp() // expected-error {{no previous prototype for function 'ppp'}} +{ +} Index: lib/Basic/Diagnostic.cpp === --- lib/Basic/Diagnostic.cpp +++ lib/Basic/Diagnostic.cpp @@ -248,6 +248,13 @@ bool DiagnosticsEngine::setSeverityForGroup(diag::Flavor Flavor, StringRef Group, diag::Severity Map, SourceLocation Loc) { + // Special handling for pragma clang diagnostic ... "-Weverything" + // There is no formal group named "everything", so there has to be a special + // case for it. + if (Group == "everything") { + setSeverityForAll(Flavor, Map, Loc); + return false; + } // Get the diagnostics in this group. SmallVector GroupDiags; if (Diags->getDiagnosticsInGroup(Flavor, Group, GroupDiags)) Index: test/Frontend/Peverything.cpp === --- test/Frontend/Peverything.cpp +++ test/Frontend/Peverything.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify +#pragma clang diagnostic error "-Weverything" + +void ppp() // expected-error {{no previous prototype for function 'ppp'}} +{ +} Index: lib/Basic/Diagnostic.cpp === --- lib/Basic/Diagnostic.cpp +++ lib/Basic/Diagnostic.cpp @@ -248,6 +248,13 @@ bool DiagnosticsEngine::setSeverityForGroup(diag::Flavor Flavor, StringRef Group, diag::Severity Map, SourceLocation Loc) { + // Special handling for pragma clang diagnostic ... "-Weverything" + // There is no formal group named "everything", so there has to be a special + // case for it. + if (Group == "everything") { + setSeverityForAll(Flavor, Map, Loc); + return false; + } // Get the diagnostics in this group. SmallVector GroupDiags; if (Diags->getDiagnosticsInGroup(Flavor, Group, GroupDiags)) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15095: Accept "-Weverything" in pragma clang diagnostic ...
Sunil_Srivastava added a comment. Please see the comment about getAllDiagnostics Comment at: lib/Basic/Diagnostic.cpp:251-257 @@ -250,2 +250,9 @@ SourceLocation Loc) { + // Special handling for pragma clang diagnostic ... "-Weverything" + // There is no formal group named "everything", so there has to be a special + // case for it. + if (Group == "everything") { + setSeverityForAll(Flavor, Map, Loc); + return false; + } // Get the diagnostics in this group. rsmith wrote: > If you want to handle this at the `DiagnosticsEngine` level, please do so > consistently: teach `getDiagnosticsInGroup` about this special case too, and > remove the now-redundant code in `clang::ProcessWarningOptions`. > > This is not currently setting the `EnableAllWarnings` flag correctly on the > `DiagnosticsEngine`. Hi Richard, There is a problem in teaching getDiagnosticsInGroup this special case. getDiagnosticsInGroup can get the list from getAllDiagnostics, but that list will contain disgnostics that can not be downgraded (or those for which isBuiltinWarningOrExtension() is false). Back in setSeverityForGroup, it is safe to call setSeverityForAll, because it checks isBuiltinWarningOrExtension before calling setSeverity, but the loop in setSeverityForGroup itself does not have this check. So a simplistic getAllDiagnostics for "everything" leads to an assertion failure "Cannot map errors into warnings!" in setSeverity. In fact, ProcessWarningOptions has the same issue because it also calls setSeverityForGroup. So the options are: 1) add isBuiltinWarning... test in the loop in setSeverityForGroup, similar to setSeverityForAll 2) have some variant of getAllDiagnostics that returns a trimmed down list. Please advise. The other point about EnableAllWarnings: I agree. Comment at: test/Frontend/Peverything.cpp:1 @@ +1,2 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify +#pragma clang diagnostic error "-Weverything" rsmith wrote: > This test belongs in **test/Preprocessor/pragma_diagnostic.c**. OK. And I will add push pop tests as well http://reviews.llvm.org/D15095 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] f706486 - Fix for crash in __builtin_return_address in template context.
Author: Sunil Srivastava Date: 2021-01-12T12:37:18-08:00 New Revision: f706486eaf07020b11f2088274c757e4070fe6d1 URL: https://github.com/llvm/llvm-project/commit/f706486eaf07020b11f2088274c757e4070fe6d1 DIFF: https://github.com/llvm/llvm-project/commit/f706486eaf07020b11f2088274c757e4070fe6d1.diff LOG: Fix for crash in __builtin_return_address in template context. The check for argument value needs to be guarded by !isValueDependent(). Differential Revision: https://reviews.llvm.org/D94438 Added: Modified: clang/lib/Sema/SemaChecking.cpp clang/test/Sema/builtin-returnaddress.c Removed: diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 15b5934224f0..2d3d36f4adad 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -1943,7 +1943,8 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, // -Wframe-address warning if non-zero passed to builtin // return/frame address. Expr::EvalResult Result; -if (TheCall->getArg(0)->EvaluateAsInt(Result, getASTContext()) && +if (!TheCall->getArg(0)->isValueDependent() && +TheCall->getArg(0)->EvaluateAsInt(Result, getASTContext()) && Result.Val.getInt() != 0) Diag(TheCall->getBeginLoc(), diag::warn_frame_address) << ((BuiltinID == Builtin::BI__builtin_return_address) diff --git a/clang/test/Sema/builtin-returnaddress.c b/clang/test/Sema/builtin-returnaddress.c index 3ebbdc6048d8..16d2a517ac12 100644 --- a/clang/test/Sema/builtin-returnaddress.c +++ b/clang/test/Sema/builtin-returnaddress.c @@ -1,5 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -Wframe-address -verify %s // RUN: %clang_cc1 -fsyntax-only -Wmost -verify %s +// RUN: %clang_cc1 -x c++ -fsyntax-only -Wframe-address -verify %s void* a(unsigned x) { return __builtin_return_address(0); @@ -17,3 +18,14 @@ void* d(unsigned x) { return __builtin_frame_address(1); // expected-warning{{calling '__builtin_frame_address' with a nonzero argument is unsafe}} } +#ifdef __cplusplus +template void *RA() +{ + return __builtin_return_address(N); // expected-warning{{calling '__builtin_return_address' with a nonzero argument is unsafe}} +} + +void *foo() +{ + return RA<2>(); // expected-note{{in instantiation of function template specialization 'RA<2>' requested here}} +} +#endif ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits