r316408 - Unnamed bitfields don't block constant evaluation of constexpr ctors
Author: jrose Date: Mon Oct 23 19:17:07 2017 New Revision: 316408 URL: http://llvm.org/viewvc/llvm-project?rev=316408&view=rev Log: Unnamed bitfields don't block constant evaluation of constexpr ctors C++14 [dcl.constexpr]p4 states that in the body of a constexpr constructor, > every non-variant non-static data member and base class sub-object shall be initialized However, [class.bit]p2 notes that > Unnamed bit-fields are not members and cannot be initialized. Therefore, we should make sure to filter them out of the check that all fields are initialized. Fixing this makes the constant evaluator a bit smarter, and specifically allows constexpr constructors to avoid tripping -Wglobal-constructors when the type contains unnamed bitfields. Reviewed at https://reviews.llvm.org/D39035. Modified: cfe/trunk/lib/AST/ExprConstant.cpp cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp cfe/trunk/test/SemaCXX/warn-global-constructors.cpp Modified: cfe/trunk/lib/AST/ExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=316408&r1=316407&r2=316408&view=diff == --- cfe/trunk/lib/AST/ExprConstant.cpp (original) +++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Oct 23 19:17:07 2017 @@ -1818,6 +1818,9 @@ static bool CheckConstantExpression(Eval } } for (const auto *I : RD->fields()) { + if (I->isUnnamedBitfield()) +continue; + if (!CheckConstantExpression(Info, DiagLoc, I->getType(), Value.getStructField(I->getFieldIndex( return false; Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=316408&r1=316407&r2=316408&view=diff == --- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original) +++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Mon Oct 23 19:17:07 2017 @@ -1931,6 +1931,22 @@ namespace Bitfields { }; static_assert(X::f(3) == -1, "3 should truncate to -1"); } + + struct HasUnnamedBitfield { +unsigned a; +unsigned : 20; +unsigned b; + +constexpr HasUnnamedBitfield() : a(), b() {} +constexpr HasUnnamedBitfield(unsigned a, unsigned b) : a(a), b(b) {} + }; + + void testUnnamedBitfield() { +const HasUnnamedBitfield zero{}; +int a = 1 / zero.b; // expected-warning {{division by zero is undefined}} +const HasUnnamedBitfield oneZero{1, 0}; +int b = 1 / oneZero.b; // expected-warning {{division by zero is undefined}} + } } namespace ZeroSizeTypes { Modified: cfe/trunk/test/SemaCXX/warn-global-constructors.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-global-constructors.cpp?rev=316408&r1=316407&r2=316408&view=diff == --- cfe/trunk/test/SemaCXX/warn-global-constructors.cpp (original) +++ cfe/trunk/test/SemaCXX/warn-global-constructors.cpp Mon Oct 23 19:17:07 2017 @@ -126,3 +126,22 @@ namespace pr20420 { void *array_storage[1]; const int &global_reference = *(int *)array_storage; } + +namespace bitfields { + struct HasUnnamedBitfield { +unsigned a; +unsigned : 20; +unsigned b; + +constexpr HasUnnamedBitfield() : a(), b() {} +constexpr HasUnnamedBitfield(unsigned a, unsigned b) : a(a), b(b) {} +explicit HasUnnamedBitfield(unsigned a) {} + }; + + const HasUnnamedBitfield zeroConst{}; + HasUnnamedBitfield zeroMutable{}; + const HasUnnamedBitfield explicitConst{1, 2}; + HasUnnamedBitfield explicitMutable{1, 2}; + const HasUnnamedBitfield nonConstexprConst{1}; // expected-warning {{global constructor}} + HasUnnamedBitfield nonConstexprMutable{1}; // expected-warning {{global constructor}} +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r330452 - Record whether a module came from a private module map
Author: jrose Date: Fri Apr 20 10:16:04 2018 New Revision: 330452 URL: http://llvm.org/viewvc/llvm-project?rev=330452&view=rev Log: Record whether a module came from a private module map Right now we only use this information in one place, immediately after we calculate it, but it's still nice information to have. The Swift project is going to use this to tidy up its "API notes" feature (see past discussion on cfe-dev that never quite converged). Reviewed by Bruno Cardoso Lopes. Modified: cfe/trunk/include/clang/Basic/Module.h cfe/trunk/lib/Basic/Module.cpp cfe/trunk/lib/Lex/ModuleMap.cpp cfe/trunk/lib/Serialization/ASTReader.cpp cfe/trunk/lib/Serialization/ASTWriter.cpp Modified: cfe/trunk/include/clang/Basic/Module.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Module.h?rev=330452&r1=330451&r2=330452&view=diff == --- cfe/trunk/include/clang/Basic/Module.h (original) +++ cfe/trunk/include/clang/Basic/Module.h Fri Apr 20 10:16:04 2018 @@ -258,6 +258,10 @@ public: /// and headers from used modules. unsigned NoUndeclaredIncludes : 1; + /// \brief Whether this module came from a "private" module map, found next + /// to a regular (public) module map. + unsigned ModuleMapIsPrivate : 1; + /// \brief Describes the visibility of the various names within a /// particular module. enum NameVisibilityKind { Modified: cfe/trunk/lib/Basic/Module.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Module.cpp?rev=330452&r1=330451&r2=330452&view=diff == --- cfe/trunk/lib/Basic/Module.cpp (original) +++ cfe/trunk/lib/Basic/Module.cpp Fri Apr 20 10:16:04 2018 @@ -44,7 +44,8 @@ Module::Module(StringRef Name, SourceLoc IsSystem(false), IsExternC(false), IsInferred(false), InferSubmodules(false), InferExplicitSubmodules(false), InferExportWildcard(false), ConfigMacrosExhaustive(false), - NoUndeclaredIncludes(false), NameVisibility(Hidden) { + NoUndeclaredIncludes(false), ModuleMapIsPrivate(false), + NameVisibility(Hidden) { if (Parent) { if (!Parent->isAvailable()) IsAvailable = false; @@ -54,6 +55,8 @@ Module::Module(StringRef Name, SourceLoc IsExternC = true; if (Parent->NoUndeclaredIncludes) NoUndeclaredIncludes = true; +if (Parent->ModuleMapIsPrivate) + ModuleMapIsPrivate = true; IsMissingRequirement = Parent->IsMissingRequirement; Parent->SubModuleIndex[Name] = Parent->SubModules.size(); Modified: cfe/trunk/lib/Lex/ModuleMap.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=330452&r1=330451&r2=330452&view=diff == --- cfe/trunk/lib/Lex/ModuleMap.cpp (original) +++ cfe/trunk/lib/Lex/ModuleMap.cpp Fri Apr 20 10:16:04 2018 @@ -1891,20 +1891,23 @@ void ModuleMapParser::parseModuleDecl() ActiveModule->NoUndeclaredIncludes = true; ActiveModule->Directory = Directory; + StringRef MapFileName(ModuleMapFile->getName()); + if (MapFileName.endswith("module.private.modulemap") || + MapFileName.endswith("module_private.map")) { +ActiveModule->ModuleMapIsPrivate = true; + } // Private modules named as FooPrivate, Foo.Private or similar are likely a // user error; provide warnings, notes and fixits to direct users to use // Foo_Private instead. SourceLocation StartLoc = SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID()); - StringRef MapFileName(ModuleMapFile->getName()); if (Map.HeaderInfo.getHeaderSearchOpts().ImplicitModuleMaps && !Diags.isIgnored(diag::warn_mmap_mismatched_private_submodule, StartLoc) && !Diags.isIgnored(diag::warn_mmap_mismatched_private_module_name, StartLoc) && - (MapFileName.endswith("module.private.modulemap") || - MapFileName.endswith("module_private.map"))) + ActiveModule->ModuleMapIsPrivate) diagnosePrivateModules(Map, Diags, ActiveModule, LastInlineParentLoc); bool Done = false; Modified: cfe/trunk/lib/Serialization/ASTReader.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=330452&r1=330451&r2=330452&view=diff == --- cfe/trunk/lib/Serialization/ASTReader.cpp (original) +++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Apr 20 10:16:04 2018 @@ -4980,7 +4980,7 @@ ASTReader::ReadSubmoduleBlock(ModuleFile break; case SUBMODULE_DEFINITION: { - if (Record.size() < 8) { + if (Record.size() < 12) { Error("malformed module definition"); return Failure; } @@ -4998,6 +4998,7 @@ ASTReader::ReadSubmoduleBlock(ModuleFile bool InferExplicitSubmodules = Record[Idx++]; bool
r373769 - [CMake] Clang: Don't use object libraries with Xcode
Author: jrose Date: Fri Oct 4 11:17:58 2019 New Revision: 373769 URL: http://llvm.org/viewvc/llvm-project?rev=373769&view=rev Log: [CMake] Clang: Don't use object libraries with Xcode Undoes some of the effects of r360946 when using the Xcode CMake generator---it doesn't handle object libraries correctly at all. Attempts to still honor BUILD_SHARED_LIBS for Xcode, but I didn't actually test it. Should have no effect on non-Xcode generators. https://reviews.llvm.org/D68430 Modified: cfe/trunk/cmake/modules/AddClang.cmake cfe/trunk/tools/clang-shlib/CMakeLists.txt Modified: cfe/trunk/cmake/modules/AddClang.cmake URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/modules/AddClang.cmake?rev=373769&r1=373768&r2=373769&view=diff == --- cfe/trunk/cmake/modules/AddClang.cmake (original) +++ cfe/trunk/cmake/modules/AddClang.cmake Fri Oct 4 11:17:58 2019 @@ -86,9 +86,13 @@ macro(add_clang_library name) # llvm_add_library ignores BUILD_SHARED_LIBS if STATIC is explicitly set, # so we need to handle it here. if(BUILD_SHARED_LIBS) - set(LIBTYPE SHARED OBJECT) + set(LIBTYPE SHARED) else() - set(LIBTYPE STATIC OBJECT) + set(LIBTYPE STATIC) +endif() +if(NOT XCODE) + # The Xcode generator doesn't handle object libraries correctly. + list(APPEND LIBTYPE OBJECT) endif() set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name}) endif() Modified: cfe/trunk/tools/clang-shlib/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/CMakeLists.txt?rev=373769&r1=373768&r2=373769&view=diff == --- cfe/trunk/tools/clang-shlib/CMakeLists.txt (original) +++ cfe/trunk/tools/clang-shlib/CMakeLists.txt Fri Oct 4 11:17:58 2019 @@ -6,7 +6,13 @@ endif() get_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS) foreach (lib ${clang_libs}) - list(APPEND _OBJECTS $) + if(XCODE) +# Xcode doesn't support object libraries, so we have to trick it into +# linking the static libraries instead. +list(APPEND _DEPS "-force_load" ${lib}) + else() +list(APPEND _OBJECTS $) + endif() list(APPEND _DEPS $) list(APPEND _DEPS $) endforeach () ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r374494 - Get ClangdXPC.framework building (barely) with CMake's Xcode generator
Author: jrose Date: Thu Oct 10 18:23:56 2019 New Revision: 374494 URL: http://llvm.org/viewvc/llvm-project?rev=374494&view=rev Log: Get ClangdXPC.framework building (barely) with CMake's Xcode generator The output directories for CMake's Xcode project generator are specific to the configuration, and so looking in CMAKE_LIBRARY_OUTPUT_DIRECTORY isn't going to work. Fortunately, CMake already provides generator expressions to find the output of a given target. I call this "barely" building because the built framework isn't going to respect the configuration; that is, I can't have both Debug and RelWithDebInfo variants of ClangdXPC.framework at the same time like I can with normal library or executable targets. To do that we'd have to put the framework in a configuration-specific output directory or use CMake's native support for frameworks instead. https://reviews.llvm.org/D68846 Modified: clang-tools-extra/trunk/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake Modified: clang-tools-extra/trunk/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake?rev=374494&r1=374493&r2=374494&view=diff == --- clang-tools-extra/trunk/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake (original) +++ clang-tools-extra/trunk/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake Thu Oct 10 18:23:56 2019 @@ -28,7 +28,7 @@ macro(create_clangd_xpc_framework target # Copy the framework binary. COMMAND ${CMAKE_COMMAND} -E copy - "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib${target}.dylib" + "$" "${CLANGD_FRAMEWORK_OUT_LOCATION}/${name}" # Copy the XPC Service PLIST. @@ -38,7 +38,7 @@ macro(create_clangd_xpc_framework target # Copy the Clangd binary. COMMAND ${CMAKE_COMMAND} -E copy - "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/clangd" + "$" "${CLANGD_XPC_SERVICE_OUT_LOCATION}/MacOS/clangd" COMMAND ${CMAKE_COMMAND} -E create_symlink "A" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r328276 - Sink PrettyDeclStackTrace down to the AST library
Author: jrose Date: Thu Mar 22 17:07:18 2018 New Revision: 328276 URL: http://llvm.org/viewvc/llvm-project?rev=328276&view=rev Log: Sink PrettyDeclStackTrace down to the AST library ...and add some very basic stack trace entries for module building. This would have helped track down rdar://problem/38434694 sooner. Added: cfe/trunk/include/clang/AST/PrettyDeclStackTrace.h - copied, changed from r328258, cfe/trunk/include/clang/Sema/PrettyDeclStackTrace.h Removed: cfe/trunk/include/clang/Sema/PrettyDeclStackTrace.h Modified: cfe/trunk/lib/AST/Decl.cpp cfe/trunk/lib/Frontend/CompilerInstance.cpp cfe/trunk/lib/Parse/ParseDecl.cpp cfe/trunk/lib/Parse/ParseDeclCXX.cpp cfe/trunk/lib/Parse/ParseObjc.cpp cfe/trunk/lib/Parse/ParseStmt.cpp cfe/trunk/lib/Sema/Sema.cpp cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Copied: cfe/trunk/include/clang/AST/PrettyDeclStackTrace.h (from r328258, cfe/trunk/include/clang/Sema/PrettyDeclStackTrace.h) URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/PrettyDeclStackTrace.h?p2=cfe/trunk/include/clang/AST/PrettyDeclStackTrace.h&p1=cfe/trunk/include/clang/Sema/PrettyDeclStackTrace.h&r1=328258&r2=328276&rev=328276&view=diff == --- cfe/trunk/include/clang/Sema/PrettyDeclStackTrace.h (original) +++ cfe/trunk/include/clang/AST/PrettyDeclStackTrace.h Thu Mar 22 17:07:18 2018 @@ -13,31 +13,31 @@ // //===--===// -#ifndef LLVM_CLANG_SEMA_PRETTYDECLSTACKTRACE_H -#define LLVM_CLANG_SEMA_PRETTYDECLSTACKTRACE_H +#ifndef LLVM_CLANG_AST_PRETTYDECLSTACKTRACE_H +#define LLVM_CLANG_AST_PRETTYDECLSTACKTRACE_H #include "clang/Basic/SourceLocation.h" #include "llvm/Support/PrettyStackTrace.h" namespace clang { +class ASTContext; class Decl; -class Sema; class SourceManager; /// PrettyDeclStackTraceEntry - If a crash occurs in the parser while /// parsing something related to a declaration, include that /// declaration in the stack trace. class PrettyDeclStackTraceEntry : public llvm::PrettyStackTraceEntry { - Sema &S; + ASTContext &Context; Decl *TheDecl; SourceLocation Loc; const char *Message; public: - PrettyDeclStackTraceEntry(Sema &S, Decl *D, SourceLocation Loc, + PrettyDeclStackTraceEntry(ASTContext &Ctx, Decl *D, SourceLocation Loc, const char *Msg) -: S(S), TheDecl(D), Loc(Loc), Message(Msg) {} +: Context(Ctx), TheDecl(D), Loc(Loc), Message(Msg) {} void print(raw_ostream &OS) const override; }; Removed: cfe/trunk/include/clang/Sema/PrettyDeclStackTrace.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/PrettyDeclStackTrace.h?rev=328275&view=auto == --- cfe/trunk/include/clang/Sema/PrettyDeclStackTrace.h (original) +++ cfe/trunk/include/clang/Sema/PrettyDeclStackTrace.h (removed) @@ -1,47 +0,0 @@ -//===- PrettyDeclStackTrace.h - Stack trace for decl processing -*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===--===// -// -// This file defines an llvm::PrettyStackTraceEntry object for showing -// that a particular declaration was being processed when a crash -// occurred. -// -//===--===// - -#ifndef LLVM_CLANG_SEMA_PRETTYDECLSTACKTRACE_H -#define LLVM_CLANG_SEMA_PRETTYDECLSTACKTRACE_H - -#include "clang/Basic/SourceLocation.h" -#include "llvm/Support/PrettyStackTrace.h" - -namespace clang { - -class Decl; -class Sema; -class SourceManager; - -/// PrettyDeclStackTraceEntry - If a crash occurs in the parser while -/// parsing something related to a declaration, include that -/// declaration in the stack trace. -class PrettyDeclStackTraceEntry : public llvm::PrettyStackTraceEntry { - Sema &S; - Decl *TheDecl; - SourceLocation Loc; - const char *Message; - -public: - PrettyDeclStackTraceEntry(Sema &S, Decl *D, SourceLocation Loc, -const char *Msg) -: S(S), TheDecl(D), Loc(Loc), Message(Msg) {} - - void print(raw_ostream &OS) const override; -}; - -} - -#endif Modified: cfe/trunk/lib/AST/Decl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=328276&r1=328275&r2=328276&view=diff == --- cfe/trunk/lib/AST/Decl.cpp (original) +++ cfe/trunk/lib/AST/Decl.cpp Thu Mar 22 17:07:18 2018 @@ -27,6 +27,7 @@ #include "clang/AST/ExprCXX.h" #include "clang/AST/ExternalASTSource.h" #include "cl
r328286 - Remove problematic PrettyStackTrace entry added in r328276
Author: jrose Date: Thu Mar 22 18:12:09 2018 New Revision: 328286 URL: http://llvm.org/viewvc/llvm-project?rev=328286&view=rev Log: Remove problematic PrettyStackTrace entry added in r328276 I'm not sure /why/ this is causing issues for libclang, but it is. Unbreak the buildbots since it's already consumed an hour of my time. Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=328286&r1=328285&r2=328286&view=diff == --- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Thu Mar 22 18:12:09 2018 @@ -1170,11 +1170,6 @@ compileModuleImpl(CompilerInstance &Impo llvm::CrashRecoveryContext CRC; CRC.RunSafelyOnThread( [&]() { -SmallString<64> CrashInfoMessage("While building module for '"); -CrashInfoMessage += ModuleName; -CrashInfoMessage += "'"; -llvm::PrettyStackTraceString CrashInfo(CrashInfoMessage.c_str()); - GenerateModuleFromModuleMapAction Action; Instance.ExecuteAction(Action); }, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r328354 - Fix misuse of llvm::YAML in clangd test.
Author: jrose Date: Fri Mar 23 12:16:07 2018 New Revision: 328354 URL: http://llvm.org/viewvc/llvm-project?rev=328354&view=rev Log: Fix misuse of llvm::YAML in clangd test. Caught by LLVM r328345! Modified: clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp Modified: clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp?rev=328354&r1=328353&r2=328354&view=diff == --- clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp Fri Mar 23 12:16:07 2018 @@ -41,7 +41,7 @@ bool VerifyObject(yaml::Node &N, std::ma } bool Match = true; SmallString<32> Tmp; - for (auto Prop : *M) { + for (auto &Prop : *M) { auto *K = dyn_cast_or_null(Prop.getKey()); if (!K) continue; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r290132 - Add fix-it notes to the nullability consistency warning.
Author: jrose Date: Mon Dec 19 14:58:20 2016 New Revision: 290132 URL: http://llvm.org/viewvc/llvm-project?rev=290132&view=rev Log: Add fix-it notes to the nullability consistency warning. This is especially important for arrays, since no one knows the proper syntax for putting qualifiers in arrays. nullability.h:3:26: warning: array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) void arrayParameter(int x[]); ^ nullability.h:3:26: note: insert '_Nullable' if the array parameter may be null void arrayParameter(int x[]); ^ _Nullable nullability.h:3:26: note: insert '_Nonnull' if the array parameter should never be null void arrayParameter(int x[]); ^ _Nonnull rdar://problem/29524992 Added: cfe/trunk/test/FixIt/Inputs/ cfe/trunk/test/FixIt/Inputs/nullability.h Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/FixIt/nullability.mm cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-2.h cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-3.h cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-4.h cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-5.h cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-6.h cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-7.h cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-8.h cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-arrays.h cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-system/nullability-consistency-system.h cfe/trunk/test/SemaObjCXX/Inputs/nullability-pragmas-1.h Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=290132&r1=290131&r2=290132&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Dec 19 14:58:20 2016 @@ -8770,6 +8770,10 @@ def warn_nullability_missing_array : War "array parameter is missing a nullability type specifier (_Nonnull, " "_Nullable, or _Null_unspecified)">, InGroup; +def note_nullability_fix_it : Note< + "insert '%select{_Nonnull|_Nullable|_Null_unspecified}0' if the " + "%select{pointer|block pointer|member pointer|array parameter}1 " + "%select{should never be null|may be null|should not declare nullability}0">; def warn_nullability_inferred_on_nested_type : Warning< "inferring '_Nonnull' for pointer type within %select{array|reference}0 is " Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=290132&r1=290131&r2=290132&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Mon Dec 19 14:58:20 2016 @@ -3441,6 +3441,57 @@ static FileID getNullabilityCompleteness return file; } +/// Creates a fix-it to insert a C-style nullability keyword at \p pointerLoc, +/// taking into account whitespace before and after. +static FixItHint fixItNullability(Sema &S, SourceLocation PointerLoc, + NullabilityKind Nullability) { + assert(PointerLoc.isValid()); + + SmallString<32> InsertionTextBuf{" "}; + InsertionTextBuf += getNullabilitySpelling(Nullability); + InsertionTextBuf += " "; + StringRef InsertionText = InsertionTextBuf.str(); + + SourceLocation FixItLoc = S.getLocForEndOfToken(PointerLoc); + if (const char *NextChar = S.SourceMgr.getCharacterData(FixItLoc)) { +if (isWhitespace(*NextChar)) { + InsertionText = InsertionText.drop_back(); +} else if (NextChar[-1] == '[') { + if (NextChar[0] == ']') +InsertionText = InsertionText.drop_back().drop_front(); + else +InsertionText = InsertionText.drop_front(); +} else if (!isIdentifierBody(NextChar[0], /*allow dollar*/true) && + !isIdentifierBody(NextChar[-1], /*allow dollar*/true)) { + InsertionText = InsertionText.drop_back().drop_front(); +} + } + + return FixItHint::CreateInsertion(FixItLoc, InsertionText); +} + +static void emitNullabilityConsistencyWarning(Sema &S, + SimplePointerKind PointerKind, + SourceLocation PointerLoc) { + assert(PointerLoc.isValid()); + + if (PointerKind == SimplePointerKind::Array) { +S.Diag(PointerLoc, diag::warn_nullability_missing_array); + } else { +S.Diag(PointerLoc, diag::warn_nullability_missing) + << static_cast(Pointe
r290141 - Don't try to emit nullability fix-its within/around macros.
Author: jrose Date: Mon Dec 19 16:35:24 2016 New Revision: 290141 URL: http://llvm.org/viewvc/llvm-project?rev=290141&view=rev Log: Don't try to emit nullability fix-its within/around macros. The newly-added notes from r290132 are too noisy even when the fix-it is valid. For the existing warning from r286521, it's probably the right decision 95% of the time to put the change outside the macro if the array is outside the macro and inside otherwise, but I don't want to overthink it right now. Caught by the ASan bot! More rdar://problem/29524992 Modified: cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/FixIt/Inputs/nullability.h cfe/trunk/test/FixIt/nullability.mm Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=290141&r1=290140&r2=290141&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Mon Dec 19 16:35:24 2016 @@ -3443,31 +3443,39 @@ static FileID getNullabilityCompleteness /// Creates a fix-it to insert a C-style nullability keyword at \p pointerLoc, /// taking into account whitespace before and after. -static FixItHint fixItNullability(Sema &S, SourceLocation PointerLoc, - NullabilityKind Nullability) { +static void fixItNullability(Sema &S, DiagnosticBuilder &Diag, + SourceLocation PointerLoc, + NullabilityKind Nullability) { assert(PointerLoc.isValid()); + if (PointerLoc.isMacroID()) +return; + + SourceLocation FixItLoc = S.getLocForEndOfToken(PointerLoc); + if (!FixItLoc.isValid() || FixItLoc == PointerLoc) +return; + + const char *NextChar = S.SourceMgr.getCharacterData(FixItLoc); + if (!NextChar) +return; SmallString<32> InsertionTextBuf{" "}; InsertionTextBuf += getNullabilitySpelling(Nullability); InsertionTextBuf += " "; StringRef InsertionText = InsertionTextBuf.str(); - SourceLocation FixItLoc = S.getLocForEndOfToken(PointerLoc); - if (const char *NextChar = S.SourceMgr.getCharacterData(FixItLoc)) { -if (isWhitespace(*NextChar)) { - InsertionText = InsertionText.drop_back(); -} else if (NextChar[-1] == '[') { - if (NextChar[0] == ']') -InsertionText = InsertionText.drop_back().drop_front(); - else -InsertionText = InsertionText.drop_front(); -} else if (!isIdentifierBody(NextChar[0], /*allow dollar*/true) && - !isIdentifierBody(NextChar[-1], /*allow dollar*/true)) { + if (isWhitespace(*NextChar)) { +InsertionText = InsertionText.drop_back(); + } else if (NextChar[-1] == '[') { +if (NextChar[0] == ']') InsertionText = InsertionText.drop_back().drop_front(); -} +else + InsertionText = InsertionText.drop_front(); + } else if (!isIdentifierBody(NextChar[0], /*allow dollar*/true) && + !isIdentifierBody(NextChar[-1], /*allow dollar*/true)) { +InsertionText = InsertionText.drop_back().drop_front(); } - return FixItHint::CreateInsertion(FixItLoc, InsertionText); + Diag << FixItHint::CreateInsertion(FixItLoc, InsertionText); } static void emitNullabilityConsistencyWarning(Sema &S, @@ -3482,11 +3490,14 @@ static void emitNullabilityConsistencyWa << static_cast(PointerKind); } + if (PointerLoc.isMacroID()) +return; + auto addFixIt = [&](NullabilityKind Nullability) { -S.Diag(PointerLoc, diag::note_nullability_fix_it) - << static_cast(Nullability) - << static_cast(PointerKind) - << fixItNullability(S, PointerLoc, Nullability); +auto Diag = S.Diag(PointerLoc, diag::note_nullability_fix_it); +Diag << static_cast(Nullability); +Diag << static_cast(PointerKind); +fixItNullability(S, Diag, PointerLoc, Nullability); }; addFixIt(NullabilityKind::Nullable); addFixIt(NullabilityKind::NonNull); @@ -3888,9 +3899,10 @@ static TypeSourceInfo *GetFullTypeForDec if (pointerLoc.isValid() && complainAboutInferringWithinChunk != PointerWrappingDeclaratorKind::None) { -S.Diag(pointerLoc, diag::warn_nullability_inferred_on_nested_type) - << static_cast(complainAboutInferringWithinChunk) - << fixItNullability(S, pointerLoc, NullabilityKind::NonNull); +auto Diag = +S.Diag(pointerLoc, diag::warn_nullability_inferred_on_nested_type); +Diag << static_cast(complainAboutInferringWithinChunk); +fixItNullability(S, Diag, pointerLoc, NullabilityKind::NonNull); } if (inferNullabilityInnerOnly) Modified: cfe/trunk/test/FixIt/Inputs/nullability.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/Inputs/nullability.h?rev=290141&r1=290140&r2=290141&view=diff == --- cfe/trunk/test/FixIt/Inputs/nullability.h (original) +++ cfe/trunk/test/
r292571 - [AST Printer] Print attributes on enum constants
Author: jrose Date: Thu Jan 19 21:33:42 2017 New Revision: 292571 URL: http://llvm.org/viewvc/llvm-project?rev=292571&view=rev Log: [AST Printer] Print attributes on enum constants The AST printer was dropping attributes on enumerators (enum constants). Now it's not. Modified: cfe/trunk/lib/AST/DeclPrinter.cpp cfe/trunk/test/Sema/ast-print.c Modified: cfe/trunk/lib/AST/DeclPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=292571&r1=292570&r2=292571&view=diff == --- cfe/trunk/lib/AST/DeclPrinter.cpp (original) +++ cfe/trunk/lib/AST/DeclPrinter.cpp Thu Jan 19 21:33:42 2017 @@ -464,6 +464,7 @@ void DeclPrinter::VisitRecordDecl(Record void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) { Out << *D; + prettyPrintAttributes(D); if (Expr *Init = D->getInitExpr()) { Out << " = "; Init->printPretty(Out, nullptr, Policy, Indentation); Modified: cfe/trunk/test/Sema/ast-print.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ast-print.c?rev=292571&r1=292570&r2=292571&view=diff == --- cfe/trunk/test/Sema/ast-print.c (original) +++ cfe/trunk/test/Sema/ast-print.c Thu Jan 19 21:33:42 2017 @@ -65,3 +65,12 @@ void initializers() { // CHECK: } z = {(struct Z){}}; } z = {(struct Z){}}; } + +// CHECK-LABEL: enum EnumWithAttributes { +enum EnumWithAttributes { + // CHECK-NEXT: EnumWithAttributesFoo __attribute__((deprecated(""))), + EnumWithAttributesFoo __attribute__((deprecated)), + // CHECK-NEXT: EnumWithAttributesBar __attribute__((unavailable(""))) = 50 + EnumWithAttributesBar __attribute__((unavailable)) = 50 + // CHECK-NEXT: } __attribute__((deprecated(""))) +} __attribute__((deprecated)); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r302966 - Remove unused tracking of owning module for MacroInfo objects.
Hi, Richard. Swift was using this information in order to put imported macros in a particular context. It wouldn't surprise me to hear that we were doing it wrong, and that there's a better way to go from a macro back to a module, but is there a recommended replacement? Thanks, Jordan > On May 12, 2017, at 16:40, Richard Smith via cfe-commits > wrote: > > Author: rsmith > Date: Fri May 12 18:40:52 2017 > New Revision: 302966 > > URL: http://llvm.org/viewvc/llvm-project?rev=302966&view=rev > Log: > Remove unused tracking of owning module for MacroInfo objects. > > Modified: >cfe/trunk/include/clang/Lex/MacroInfo.h >cfe/trunk/include/clang/Lex/Preprocessor.h >cfe/trunk/lib/Lex/MacroInfo.cpp >cfe/trunk/lib/Lex/PPDirectives.cpp >cfe/trunk/lib/Lex/Preprocessor.cpp >cfe/trunk/lib/Serialization/ASTReader.cpp >cfe/trunk/lib/Serialization/ASTWriter.cpp > > Modified: cfe/trunk/include/clang/Lex/MacroInfo.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/MacroInfo.h?rev=302966&r1=302965&r2=302966&view=diff > == > --- cfe/trunk/include/clang/Lex/MacroInfo.h (original) > +++ cfe/trunk/include/clang/Lex/MacroInfo.h Fri May 12 18:40:52 2017 > @@ -105,9 +105,6 @@ class MacroInfo { > /// \brief Must warn if the macro is unused at the end of translation unit. > bool IsWarnIfUnused : 1; > > - /// \brief Whether this macro info was loaded from an AST file. > - bool FromASTFile : 1; > - > /// \brief Whether this macro was used as header guard. > bool UsedForHeaderGuard : 1; > > @@ -264,34 +261,16 @@ public: > IsDisabled = true; > } > > - /// \brief Determine whether this macro info came from an AST file (such as > - /// a precompiled header or module) rather than having been parsed. > - bool isFromASTFile() const { return FromASTFile; } > - > /// \brief Determine whether this macro was used for a header guard. > bool isUsedForHeaderGuard() const { return UsedForHeaderGuard; } > > void setUsedForHeaderGuard(bool Val) { UsedForHeaderGuard = Val; } > > - /// \brief Retrieve the global ID of the module that owns this particular > - /// macro info. > - unsigned getOwningModuleID() const { > -if (isFromASTFile()) > - return *(const unsigned *)(this + 1); > - > -return 0; > - } > - > void dump() const; > > private: > unsigned getDefinitionLengthSlow(const SourceManager &SM) const; > > - void setOwningModuleID(unsigned ID) { > -assert(isFromASTFile()); > -*(unsigned *)(this + 1) = ID; > - } > - > friend class Preprocessor; > }; > > > Modified: cfe/trunk/include/clang/Lex/Preprocessor.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=302966&r1=302965&r2=302966&view=diff > == > --- cfe/trunk/include/clang/Lex/Preprocessor.h (original) > +++ cfe/trunk/include/clang/Lex/Preprocessor.h Fri May 12 18:40:52 2017 > @@ -644,14 +644,6 @@ class Preprocessor { > /// of that list. > MacroInfoChain *MIChainHead; > > - struct DeserializedMacroInfoChain { > -MacroInfo MI; > -unsigned OwningModuleID; // MUST be immediately after the MacroInfo > object > - // so it can be accessed by > MacroInfo::getOwningModuleID(). > -DeserializedMacroInfoChain *Next; > - }; > - DeserializedMacroInfoChain *DeserialMIChainHead; > - > void updateOutOfDateIdentifier(IdentifierInfo &II) const; > > public: > @@ -1669,10 +1661,6 @@ public: > /// \brief Allocate a new MacroInfo object with the provided SourceLocation. > MacroInfo *AllocateMacroInfo(SourceLocation L); > > - /// \brief Allocate a new MacroInfo object loaded from an AST file. > - MacroInfo *AllocateDeserializedMacroInfo(SourceLocation L, > - unsigned SubModuleID); > - > /// \brief Turn the specified lexer token into a fully checked and spelled > /// filename, e.g. as an operand of \#include. > /// > @@ -1764,9 +1752,6 @@ private: > /// macro name. > void updateModuleMacroInfo(const IdentifierInfo *II, ModuleMacroInfo &Info); > > - /// \brief Allocate a new MacroInfo object. > - MacroInfo *AllocateMacroInfo(); > - > DefMacroDirective *AllocateDefMacroDirective(MacroInfo *MI, >SourceLocation Loc); > UndefMacroDirective *AllocateUndefMacroDirective(SourceLocation UndefLoc); > > Modified: cfe/trunk/lib/Lex/MacroInfo.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/MacroInfo.cpp?rev=302966&r1=302965&r2=302966&view=diff > == > --- cfe/trunk/lib/Lex/MacroInfo.cpp (original) > +++ cfe/trunk/lib/Lex/MacroInfo.cpp Fri May 12 18:40:52 2017 > @@ -29,7 +29,6 @@ MacroInfo::MacroInfo(SourceLocation DefL > IsUsed(false), > IsAllowRedefinitions
Re: r302966 - Remove unused tracking of owning module for MacroInfo objects.
Thanks, this is helpful! > On May 16, 2017, at 12:26, Richard Smith wrote: > > On 15 May 2017 at 10:28, Jordan Rose via cfe-commits > mailto:cfe-commits@lists.llvm.org>> wrote: > Hi, Richard. Swift was using this information in order to put imported macros > in a particular context. It wouldn't surprise me to hear that we were doing > it wrong, and that there's a better way to go from a macro back to a module, > but is there a recommended replacement? > > The recommended way to connect macros to modules is via the ModuleMacro > objects, which represent a macro exported from a module. You can query the > exported macro for a (module, identifier) pair with > Preprocessor::getModuleMacro, or walk the ModuleMacro graph for an identifier > by starting from Preprocessor::getLeafModuleMacros. > > If you alternatively want to know the set of macros that would be visible > with a given set of imports, after setting up that state you can walk the > range produced by Preprocessor::macros(true) and query getActiveModuleMacros > on each MacroState. > > If you want to know "what is the set of macros exported directly by this > module?", we don't have a prebuilt mechanism for that, since no in-tree > client wants that information, but one way would be to walk macros(true) and > query getModuleMacro(module, identifier) on each one. > > Thanks, > Jordan > > > > On May 12, 2017, at 16:40, Richard Smith via cfe-commits > > mailto:cfe-commits@lists.llvm.org>> wrote: > > > > Author: rsmith > > Date: Fri May 12 18:40:52 2017 > > New Revision: 302966 > > > > URL: http://llvm.org/viewvc/llvm-project?rev=302966&view=rev > > <http://llvm.org/viewvc/llvm-project?rev=302966&view=rev> > > Log: > > Remove unused tracking of owning module for MacroInfo objects. > > > > Modified: > >cfe/trunk/include/clang/Lex/MacroInfo.h > >cfe/trunk/include/clang/Lex/Preprocessor.h > >cfe/trunk/lib/Lex/MacroInfo.cpp > >cfe/trunk/lib/Lex/PPDirectives.cpp > >cfe/trunk/lib/Lex/Preprocessor.cpp > >cfe/trunk/lib/Serialization/ASTReader.cpp > >cfe/trunk/lib/Serialization/ASTWriter.cpp > > > > Modified: cfe/trunk/include/clang/Lex/MacroInfo.h > > URL: > > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/MacroInfo.h?rev=302966&r1=302965&r2=302966&view=diff > > > > <http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/MacroInfo.h?rev=302966&r1=302965&r2=302966&view=diff> > > == > > --- cfe/trunk/include/clang/Lex/MacroInfo.h (original) > > +++ cfe/trunk/include/clang/Lex/MacroInfo.h Fri May 12 18:40:52 2017 > > @@ -105,9 +105,6 @@ class MacroInfo { > > /// \brief Must warn if the macro is unused at the end of translation > > unit. > > bool IsWarnIfUnused : 1; > > > > - /// \brief Whether this macro info was loaded from an AST file. > > - bool FromASTFile : 1; > > - > > /// \brief Whether this macro was used as header guard. > > bool UsedForHeaderGuard : 1; > > > > @@ -264,34 +261,16 @@ public: > > IsDisabled = true; > > } > > > > - /// \brief Determine whether this macro info came from an AST file (such > > as > > - /// a precompiled header or module) rather than having been parsed. > > - bool isFromASTFile() const { return FromASTFile; } > > - > > /// \brief Determine whether this macro was used for a header guard. > > bool isUsedForHeaderGuard() const { return UsedForHeaderGuard; } > > > > void setUsedForHeaderGuard(bool Val) { UsedForHeaderGuard = Val; } > > > > - /// \brief Retrieve the global ID of the module that owns this particular > > - /// macro info. > > - unsigned getOwningModuleID() const { > > -if (isFromASTFile()) > > - return *(const unsigned *)(this + 1); > > - > > -return 0; > > - } > > - > > void dump() const; > > > > private: > > unsigned getDefinitionLengthSlow(const SourceManager &SM) const; > > > > - void setOwningModuleID(unsigned ID) { > > -assert(isFromASTFile()); > > -*(unsigned *)(this + 1) = ID; > > - } > > - > > friend class Preprocessor; > > }; > > > > > > Modified: cfe/trunk/include/clang/Lex/Preprocessor.h > > URL: > > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=302966&r1=302965&r2=302966&view=diff > > > >
[PATCH] D25850: [WIP] Accept nullability annotations (_Nullable) on array parameters
jordan_rose created this revision. jordan_rose added reviewers: aprantl, doug.gregor. jordan_rose added a subscriber: cfe-commits. jordan_rose set the repository for this revision to rL LLVM. Last year Apple added new qualifiers to pointer types: `_Nullable`, `_Nonnull`, and `_Null_unspecified`. This patch extends that to array types used in function declarations, which should have always been supported since they immediately decay to pointers. I'm not really happy with the invariants I've had to break for this to work, though. Previously a DecayedType always contained a PointerType; now it may contain an AttributedType wrapped around a PointerType. Are there any other places where this is going to cause problems besides debug info? Still to do: - Tests (I've been ad-hoc testing with -ast-dump) - Probably fix up cases involving typedefs - Figure out how this affects `#pragma clang assume_nonnull` (in a follow-up commit) Part of rdar://problem/25846421 Repository: rL LLVM https://reviews.llvm.org/D25850 Files: include/clang/AST/Type.h include/clang/Sema/Sema.h lib/AST/ASTContext.cpp lib/CodeGen/CGDebugInfo.cpp lib/Parse/ParseDecl.cpp lib/Sema/SemaAPINotes.cpp lib/Sema/SemaType.cpp Index: lib/Sema/SemaType.cpp === --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -5808,6 +5808,7 @@ NullabilityKind nullability, SourceLocation nullabilityLoc, bool isContextSensitive, + bool isPrototypeContext, bool implicit, bool overrideExisting) { if (!implicit) { @@ -5889,7 +5890,8 @@ } // If this definitely isn't a pointer type, reject the specifier. - if (!desugared->canHaveNullability()) { + if (!desugared->canHaveNullability() && + !(isPrototypeContext && desugared->isArrayType())) { if (!implicit) { Diag(nullabilityLoc, diag::err_nullability_nonpointer) << DiagNullabilityKind(nullability, isContextSensitive) << type; @@ -6647,12 +6649,14 @@ // don't want to distribute the nullability specifier past any // dependent type, because that complicates the user model. if (type->canHaveNullability() || type->isDependentType() || + type->isArrayType() || !distributeNullabilityTypeAttr(state, type, attr)) { if (state.getSema().checkNullabilityTypeSpecifier( type, mapNullabilityAttrKind(attr.getKind()), attr.getLoc(), attr.isContextSensitiveKeywordAttribute(), + state.getDeclarator().isPrototypeContext(), /*implicit=*/false)) { attr.setInvalid(); } Index: lib/Sema/SemaAPINotes.cpp === --- lib/Sema/SemaAPINotes.cpp +++ lib/Sema/SemaAPINotes.cpp @@ -46,25 +46,30 @@ } QualType type; + bool isPrototypeContext; // Nullability for a function/method appertains to the retain type. if (auto function = dyn_cast(decl)) { type = function->getReturnType(); +isPrototypeContext = true; } else if (auto method = dyn_cast(decl)) { type = method->getReturnType(); +isPrototypeContext = true; } else if (auto value = dyn_cast(decl)) { type = value->getType(); +isPrototypeContext = isa(value); } else if (auto property = dyn_cast(decl)) { type = property->getType(); +isPrototypeContext = false; } else { return; } // Check the nullability specifier on this type. QualType origType = type; S.checkNullabilityTypeSpecifier(type, nullability, decl->getLocation(), /*isContextSensitive=*/false, - /*implicit=*/true, + isPrototypeContext, /*implicit=*/true, overrideExisting); if (type.getTypePtr() == origType.getTypePtr()) return; Index: lib/Parse/ParseDecl.cpp === --- lib/Parse/ParseDecl.cpp +++ lib/Parse/ParseDecl.cpp @@ -6275,16 +6275,15 @@ T.consumeClose(); - ParsedAttributes attrs(AttrFactory); - MaybeParseCXX11Attributes(attrs); + MaybeParseCXX11Attributes(DS.getAttributes()); // Remember that we parsed a array type, and remember its features. D.AddTypeInfo(DeclaratorChunk::getArray(DS.getTypeQualifiers(), StaticLoc.isValid(), isStar, NumElements.get(), T.getOpenLocation(), T.getCloseLocation()), -attrs, T.getCloseLocation()); +DS.getAttributes(), T.ge
[PATCH] D25850: [WIP] Accept nullability annotations (_Nullable) on array parameters
jordan_rose added inline comments. Comment at: lib/CodeGen/CGDebugInfo.cpp:2493-2499 case Type::Adjusted: - case Type::Decayed: + case Type::Decayed: { // Decayed and adjusted types use the adjusted type in LLVM and DWARF. -return CreateType( -cast(cast(Ty)->getAdjustedType()), Unit); +QualType Adjusted = cast(Ty)->getAdjustedType(); +(void)AttributedType::stripOuterNullability(Adjusted); +return CreateType(cast(Adjusted), Unit); + } rsmith wrote: > I think this should be handled by `UnwrapTypeForDebugInfo` instead of here; > this is after all just a type sugar node. Getting back to this today. I'm inclined to say we should just drop the AdjustedType node altogether in UnwrapTypeForDebugInfo. What do you think? (also for @aprantl) Repository: rL LLVM https://reviews.llvm.org/D25850 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25850: [WIP] Accept nullability annotations (_Nullable) on array parameters
jordan_rose added a comment. > `_Nonnull` in this position seems very similar to `static` (which typically > also implies non-nullness). I wasn't actually sure if it was okay to assume this, but the standard does seem pretty clear: > If the keyword `static` also appears within the `[` and `]` of the array type > derivation, then for each call to the function, the value of the > corresponding actual argument shall provide access to the first element of an > array with at least as many elements as specified by the size expression. > (C11 6.7.6.3p7) We can pick this up on the Swift side. Repository: rL LLVM https://reviews.llvm.org/D25850 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25850: Accept nullability annotations (_Nullable) on array parameters
jordan_rose retitled this revision from "[WIP] Accept nullability annotations (_Nullable) on array parameters" to "Accept nullability annotations (_Nullable) on array parameters". jordan_rose updated the summary for this revision. jordan_rose updated this revision to Diff 75820. jordan_rose added a comment. Updated based on feedback from Richard, fixed typedef support, added tests. Are there additional tests I should add? Repository: rL LLVM https://reviews.llvm.org/D25850 Files: include/clang/AST/Type.h include/clang/Sema/Sema.h lib/AST/ASTContext.cpp lib/CodeGen/CGDebugInfo.cpp lib/Lex/PPMacroExpansion.cpp lib/Parse/ParseDecl.cpp lib/Sema/SemaAPINotes.cpp lib/Sema/SemaType.cpp test/Parser/nullability.c test/Sema/nullability.c test/SemaCXX/nullability.cpp test/SemaObjC/nullability.m Index: test/SemaObjC/nullability.m === --- test/SemaObjC/nullability.m +++ test/SemaObjC/nullability.m @@ -256,3 +256,26 @@ p = c ? noneP : unspecifiedP; p = c ? noneP : noneP; } + +typedef int INTS[4]; +@interface ArraysInMethods +- (void)simple:(int [_Nonnull 2])x; +- (void)nested:(void *_Nullable [_Nonnull 2])x; +- (void)nestedBad:(int [2][_Nonnull 2])x; // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'int [2]'}} + +- (void)withTypedef:(INTS _Nonnull)x; +- (void)withTypedefBad:(INTS _Nonnull[2])x; // expected-error{{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'INTS' (aka 'int [4]')}} + +- (void)simpleSugar:(nonnull int [2])x; +- (void)nestedSugar:(nonnull void *_Nullable [2])x; // expected-error {{nullability keyword 'nonnull' cannot be applied to multi-level pointer type 'void * _Nullable [2]'}} expected-note {{use nullability type specifier '_Nonnull' to affect the innermost pointer type of 'void * _Nullable [2]'}} +- (void)sugarWithTypedef:(nonnull INTS)x; +@end + +void test(ArraysInMethods *obj) { + [obj simple:0]; // expected-warning {{null passed to a callee that requires a non-null argument}} + [obj nested:0]; // expected-warning {{null passed to a callee that requires a non-null argument}} + [obj withTypedef:0]; // expected-warning {{null passed to a callee that requires a non-null argument}} + + [obj simpleSugar:0]; // expected-warning {{null passed to a callee that requires a non-null argument}} + [obj sugarWithTypedef:0]; // expected-warning {{null passed to a callee that requires a non-null argument}} +} Index: test/SemaCXX/nullability.cpp === --- test/SemaCXX/nullability.cpp +++ test/SemaCXX/nullability.cpp @@ -117,3 +117,16 @@ p = c ? nullableD : nonnullB; // expected-warning{{implicit conversion from nullable pointer 'Base * _Nullable' to non-nullable pointer type 'Base * _Nonnull}} p = c ? nullableD : nullableB; // expected-warning{{implicit conversion from nullable pointer 'Base * _Nullable' to non-nullable pointer type 'Base * _Nonnull}} } + +void arraysInLambdas() { + typedef int INTS[4]; + auto simple = [](int [_Nonnull 2]) {}; + simple(nullptr); // expected-warning {{null passed to a callee that requires a non-null argument}} + auto nested = [](void *_Nullable [_Nonnull 2]) {}; + nested(nullptr); // expected-warning {{null passed to a callee that requires a non-null argument}} + auto nestedBad = [](int [2][_Nonnull 2]) {}; // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'int [2]'}} + + auto withTypedef = [](INTS _Nonnull) {}; + withTypedef(nullptr); // expected-warning {{null passed to a callee that requires a non-null argument}} + auto withTypedefBad = [](INTS _Nonnull[2]) {}; // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'INTS' (aka 'int [4]')}} +} Index: test/Sema/nullability.c === --- test/Sema/nullability.c +++ test/Sema/nullability.c @@ -195,3 +195,55 @@ p = noneP ?: unspecifiedP; p = noneP ?: noneP; } + +extern int GLOBAL_LENGTH; + +// Nullability can appear on arrays when the arrays are in parameter lists. +void arrays(int ints[_Nonnull], +void *ptrs[_Nullable], +void **nestedPtrs[_Nullable], +void * _Null_unspecified * _Nonnull nestedPtrs2[_Nullable], +int fixedSize[_Nonnull 2], +int staticSize[_Nonnull static 2], +int staticSize2[static _Nonnull 2], +int starSize[_Nonnull *], +int vla[_Nonnull GLOBAL_LENGTH], +void ** _Nullable reference); +void testDecayedType() { + int produceAnErrorMessage = arrays; // expected-warning {{incompatible pointer to integer conversion initializing 'int' with an expression of type 'void (int * _Nonnull, void ** _Nullable, void *** _Nullable, void * _Null_unspecified * _Nonnull * _Nullable, int * _Nonnull, int * _Nonnull, int * _Nonnull, int * _
[PATCH] D25850: Accept nullability annotations (_Nullable) on array parameters
jordan_rose marked an inline comment as done. jordan_rose added a comment. Oops. Ignore the API notes file, which is only in Swift's branch of Clang right now. Repository: rL LLVM https://reviews.llvm.org/D25850 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25993: [Objective-C] Add objc_subclassing_restricted attribute
jordan_rose added a comment. Looks good from my end. Repository: rL LLVM https://reviews.llvm.org/D25993 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26108: Add -Wnullability-completeness-on-arrays.
jordan_rose created this revision. jordan_rose added a reviewer: doug.gregor. jordan_rose added a subscriber: cfe-commits. jordan_rose set the repository for this revision to rL LLVM. jordan_rose added a dependency: D25850: Accept nullability annotations (_Nullable) on array parameters. This is an addition to (and sub-warning of) -Wnullability-completeness that warns when an array parameter is missing nullability. When the specific warning is switched off, the compiler falls back to only warning on pointer types written as pointer types. Note that use of nullability //within// an array triggers the completeness checks regardless of whether or not the array-specific warning is enabled; the intent there is simply to determine whether a particular header is trying to be nullability-aware at all. Depends on https://reviews.llvm.org/D25850. Part of rdar://problem/25846421. Repository: rL LLVM https://reviews.llvm.org/D26108 Files: include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaType.cpp test/SemaObjCXX/Inputs/nullability-consistency-arrays.h test/SemaObjCXX/nullability-consistency-arrays.mm Index: test/SemaObjCXX/nullability-consistency-arrays.mm === --- /dev/null +++ test/SemaObjCXX/nullability-consistency-arrays.mm @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs %s -D ARRAYS_CHECKED=1 -verify +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs %s -D ARRAYS_CHECKED=0 -Wno-nullability-completeness-on-arrays -verify +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs %s -Wno-nullability-completeness -Werror +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -x objective-c %s -D ARRAYS_CHECKED=1 -verify +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -x objective-c %s -D ARRAYS_CHECKED=0 -Wno-nullability-completeness-on-arrays -verify +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -x objective-c %s -Wno-nullability-completeness -Werror + +#include "nullability-consistency-arrays.h" + +void h1(int *ptr) { } // don't warn + +void h2(int * _Nonnull p) { } Index: test/SemaObjCXX/Inputs/nullability-consistency-arrays.h === --- /dev/null +++ test/SemaObjCXX/Inputs/nullability-consistency-arrays.h @@ -0,0 +1,87 @@ +void firstThingInTheFileThatNeedsNullabilityIsAnArray(int ints[]); +#if ARRAYS_CHECKED +// expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif + +int *secondThingInTheFileThatNeedsNullabilityIsAPointer; +#if !ARRAYS_CHECKED +// expected-warning@-2 {{pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif + +int *_Nonnull triggerConsistencyWarnings; + +void test( +int ints[], +#if ARRAYS_CHECKED +// expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif +void *ptrs[], // expected-warning {{pointer is missing a nullability type specifier}} +#if ARRAYS_CHECKED +// expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif +void **nestedPtrs[]); // expected-warning 2 {{pointer is missing a nullability type specifier}} +#if ARRAYS_CHECKED +// expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif + +void testArraysOK( +int ints[_Nonnull], +void *ptrs[_Nonnull], // expected-warning {{pointer is missing a nullability type specifier}} +void **nestedPtrs[_Nonnull]); // expected-warning 2 {{pointer is missing a nullability type specifier}} +void testAllOK( +int ints[_Nonnull], +void * _Nullable ptrs[_Nonnull], +void * _Nullable * _Nullable nestedPtrs[_Nonnull]); + +void nestedArrays(int x[5][1]) {} +#if ARRAYS_CHECKED +// expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif +void nestedArraysOK(int x[_Nonnull 5][1]) {} + +#if !__cplusplus +void staticOK(int x[static 5][1]){} +#endif + +int globalArraysDoNotNeedNullability[5]; + +typedef int INTS[4]; + +void typedefTest( +INTS x, +#if ARRAYS_CHECKED +// expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif +INTS _Nonnull x2, +_Nonnull INTS x3, +INTS y[2], +#if ARRAYS_CHECKED +// expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif +INTS y2[_Nonnull 2]); + + +#pragma clang assume_nonnull begin +void testAssumeNonnull( + int ints[], +#if ARRAYS_CHECKED +// expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} +#endif
[PATCH] D26109: Warn when 'assume_nonnull' infers nullability within an array.
jordan_rose created this revision. jordan_rose added a reviewer: doug.gregor. jordan_rose added a subscriber: cfe-commits. jordan_rose set the repository for this revision to rL LLVM. jordan_rose added a dependency: D25850: Accept nullability annotations (_Nullable) on array parameters. ...or within a reference. Both of these add an extra level of indirection that make us less certain that the pointer really was supposed to be non-nullable. However, changing the default behavior would be a breaking change, so we'll just make it a warning instead. Depends on https://reviews.llvm.org/D25850. Part of rdar://problem/25846421. Repository: rL LLVM https://reviews.llvm.org/D26109 Files: include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaType.cpp test/FixIt/nullability.mm test/SemaObjCXX/nullability-consistency-arrays.mm Index: test/SemaObjCXX/nullability-consistency-arrays.mm === --- test/SemaObjCXX/nullability-consistency-arrays.mm +++ test/SemaObjCXX/nullability-consistency-arrays.mm @@ -1,9 +1,9 @@ -// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs %s -D ARRAYS_CHECKED=1 -verify -// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs %s -D ARRAYS_CHECKED=0 -Wno-nullability-completeness-on-arrays -verify -// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs %s -Wno-nullability-completeness -Werror -// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -x objective-c %s -D ARRAYS_CHECKED=1 -verify -// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -x objective-c %s -D ARRAYS_CHECKED=0 -Wno-nullability-completeness-on-arrays -verify -// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -x objective-c %s -Wno-nullability-completeness -Werror +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -Wno-nullability-inferred-on-nested-type %s -D ARRAYS_CHECKED=1 -verify +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -Wno-nullability-inferred-on-nested-type %s -D ARRAYS_CHECKED=0 -Wno-nullability-completeness-on-arrays -verify +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -Wno-nullability-inferred-on-nested-type %s -Wno-nullability-completeness -Werror +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -Wno-nullability-inferred-on-nested-type -x objective-c %s -D ARRAYS_CHECKED=1 -verify +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -Wno-nullability-inferred-on-nested-type -x objective-c %s -D ARRAYS_CHECKED=0 -Wno-nullability-completeness-on-arrays -verify +// RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs -Wno-nullability-inferred-on-nested-type -x objective-c %s -Wno-nullability-completeness -Werror #include "nullability-consistency-arrays.h" Index: test/FixIt/nullability.mm === --- /dev/null +++ test/FixIt/nullability.mm @@ -0,0 +1,68 @@ +// RUN: %clang_cc1 -fsyntax-only -fblocks -std=gnu++11 -verify %s +// RUN: not %clang_cc1 -fdiagnostics-parseable-fixits -fblocks -std=gnu++11 %s 2>&1 | FileCheck %s + +#pragma clang assume_nonnull begin + +extern void *array[2]; // expected-warning {{inferring '_Nonnull' for pointer type within array is deprecated}} +// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:14}:" _Nonnull " + +extern void* array2[2]; // expected-warning {{inferring '_Nonnull' for pointer type within array is deprecated}} +// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:" _Nonnull" + +extern void *nestedArray[2][3]; // expected-warning {{inferring '_Nonnull' for pointer type within array is deprecated}} +// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:14}:" _Nonnull " + + +typedef const void *CFTypeRef; + +extern CFTypeRef typedefArray[2]; // expected-warning {{inferring '_Nonnull' for pointer type within array is deprecated}} +// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:17-[[@LINE-1]]:17}:" _Nonnull" + + +extern void *&ref; // expected-warning {{inferring '_Nonnull' for pointer type within reference is deprecated}} +// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:14}:"_Nonnull" + +extern void * &ref2; // expected-warning {{inferring '_Nonnull' for pointer type within reference is deprecated}} +// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:14}:" _Nonnull" + +extern void *&&ref3; // expected-warning {{inferring '_Nonnull' for pointer type within reference is deprecated}} +// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:14}:"_Nonnull" + +extern void * &&ref4; // expected-warning {{inferring '_Nonnull' for pointer type within reference is deprecated}} +// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:14}:" _Nonnull" + +extern void *(&arrayRef)[2]; // expected-warning {{inferring '_Nonnull' for pointer type within array is deprecated}} +// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:14}:"_Nonnull" + +extern void * (&arrayRef2)[2]; // expected-warning {{inferring '_Nonnull' for pointer type within array is deprec
[PATCH] D26226: Don't require nullability on template parameters in typedefs.
jordan_rose created this revision. jordan_rose added reviewers: doug.gregor, rsmith. jordan_rose added a subscriber: cfe-commits. jordan_rose set the repository for this revision to rL LLVM. Previously the following code would warn on the use of `T`: template struct X { typedef T *type; }; ...because nullability is //allowed// on template parameters (because they could be pointers). (Actually putting nullability on this use of `T` will of course break if the argument is a non-pointer type.) This fix doesn't handle the case where a template parameter is used //outside// of a typedef. That seems trickier, especially in parameter position. Repository: rL LLVM https://reviews.llvm.org/D26226 Files: lib/Sema/SemaType.cpp test/SemaObjCXX/Inputs/nullability-consistency-1.h Index: test/SemaObjCXX/Inputs/nullability-consistency-1.h === --- test/SemaObjCXX/Inputs/nullability-consistency-1.h +++ test/SemaObjCXX/Inputs/nullability-consistency-1.h @@ -13,5 +13,13 @@ int X:: *memptr; // expected-warning{{member pointer is missing a nullability type specifier}} }; +template +struct Typedefs { + typedef T *Base; // no-warning + typedef Base *type; // expected-warning{{pointer is missing a nullability type specifier}} +}; + +Typedefs xx; +Typedefs yy; Index: lib/Sema/SemaType.cpp === --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -3662,7 +3662,15 @@ // inner pointers. complainAboutMissingNullability = CAMN_InnerPointers; -if (T->canHaveNullability() && !T->getNullability(S.Context)) { +auto isDependentNonPointerType = [](QualType T) -> bool { + // FIXME: This just duplicates logic inside Type::canHaveNullability. + return T->isDependentType() && !T->isAnyPointerType() && +!T->isBlockPointerType() && !T->isMemberPointerType(); +}; + +if (T->canHaveNullability() && !T->getNullability(S.Context) && +!isDependentNonPointerType(T)) { + // Note that we allow but don't require nullability on dependent types. ++NumPointersRemaining; } Index: test/SemaObjCXX/Inputs/nullability-consistency-1.h === --- test/SemaObjCXX/Inputs/nullability-consistency-1.h +++ test/SemaObjCXX/Inputs/nullability-consistency-1.h @@ -13,5 +13,13 @@ int X:: *memptr; // expected-warning{{member pointer is missing a nullability type specifier}} }; +template +struct Typedefs { + typedef T *Base; // no-warning + typedef Base *type; // expected-warning{{pointer is missing a nullability type specifier}} +}; + +Typedefs xx; +Typedefs yy; Index: lib/Sema/SemaType.cpp === --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -3662,7 +3662,15 @@ // inner pointers. complainAboutMissingNullability = CAMN_InnerPointers; -if (T->canHaveNullability() && !T->getNullability(S.Context)) { +auto isDependentNonPointerType = [](QualType T) -> bool { + // FIXME: This just duplicates logic inside Type::canHaveNullability. + return T->isDependentType() && !T->isAnyPointerType() && +!T->isBlockPointerType() && !T->isMemberPointerType(); +}; + +if (T->canHaveNullability() && !T->getNullability(S.Context) && +!isDependentNonPointerType(T)) { + // Note that we allow but don't require nullability on dependent types. ++NumPointersRemaining; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26227: Don't require nullability on 'va_list'.
jordan_rose created this revision. jordan_rose added reviewers: doug.gregor, rsmith. jordan_rose added a subscriber: cfe-commits. jordan_rose set the repository for this revision to rL LLVM. jordan_rose added dependencies: D26226: Don't require nullability on template parameters in typedefs., D25850: Accept nullability annotations (_Nullable) on array parameters. There are many non-portable typedefs, but va_list is one that nobody ever thinks of as a pointer or an array. (When's the last time you saw someone check for a NULL va_list?) Make an exception for this one special type. (Is this the best way to do this?) Part of rdar://problem/25846421. Depends on https://reviews.llvm.org/D26226 and https://reviews.llvm.org/D25850. Repository: rL LLVM https://reviews.llvm.org/D26227 Files: lib/Sema/SemaType.cpp test/SemaObjCXX/Inputs/nullability-consistency-arrays.h Index: test/SemaObjCXX/Inputs/nullability-consistency-arrays.h === --- test/SemaObjCXX/Inputs/nullability-consistency-arrays.h +++ test/SemaObjCXX/Inputs/nullability-consistency-arrays.h @@ -1,3 +1,5 @@ +#include + void firstThingInTheFileThatNeedsNullabilityIsAnArray(int ints[]); #if ARRAYS_CHECKED // expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} @@ -33,6 +35,26 @@ void * _Nullable ptrs[_Nonnull], void * _Nullable * _Nullable nestedPtrs[_Nonnull]); +void testVAList(va_list ok); // no warning + +#if __cplusplus +// Carefully construct a test case such that if a platform's va_list is an array +// or pointer type, it gets tested, but otherwise it does not. +template +struct pointer_like_or { typedef F type; }; +template +struct pointer_like_or { typedef T *type; }; +template +struct pointer_like_or { typedef T * const type; }; +template +struct pointer_like_or { typedef T type[]; }; +template +struct pointer_like_or { typedef T type[size]; }; + +void testVAListWithNullability( + pointer_like_or::type _Nonnull x); // no errors +#endif + void nestedArrays(int x[5][1]) {} #if ARRAYS_CHECKED // expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} Index: lib/Sema/SemaType.cpp === --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -3894,8 +3894,22 @@ attr->setUsedAsTypeAttr(); } } + +auto isVaList = [&S](QualType T) -> bool { + auto *typedefTy = T->getAs(); + if (!typedefTy) +return false; + TypedefDecl *vaListTypedef = S.Context.getBuiltinVaListDecl(); + do { +if (typedefTy->getDecl() == vaListTypedef) + return true; +typedefTy = typedefTy->desugar()->getAs(); + } while (typedefTy); + return false; +}; + if (complainAboutMissingNullability == CAMN_Yes && -T->isArrayType() && !T->getNullability(S.Context) && +T->isArrayType() && !T->getNullability(S.Context) && !isVaList(T) && D.isPrototypeContext() && !hasOuterPointerLikeChunk(D, D.getNumTypeObjects())) { checkNullabilityConsistency(S, SimplePointerKind::Array, Index: test/SemaObjCXX/Inputs/nullability-consistency-arrays.h === --- test/SemaObjCXX/Inputs/nullability-consistency-arrays.h +++ test/SemaObjCXX/Inputs/nullability-consistency-arrays.h @@ -1,3 +1,5 @@ +#include + void firstThingInTheFileThatNeedsNullabilityIsAnArray(int ints[]); #if ARRAYS_CHECKED // expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} @@ -33,6 +35,26 @@ void * _Nullable ptrs[_Nonnull], void * _Nullable * _Nullable nestedPtrs[_Nonnull]); +void testVAList(va_list ok); // no warning + +#if __cplusplus +// Carefully construct a test case such that if a platform's va_list is an array +// or pointer type, it gets tested, but otherwise it does not. +template +struct pointer_like_or { typedef F type; }; +template +struct pointer_like_or { typedef T *type; }; +template +struct pointer_like_or { typedef T * const type; }; +template +struct pointer_like_or { typedef T type[]; }; +template +struct pointer_like_or { typedef T type[size]; }; + +void testVAListWithNullability( + pointer_like_or::type _Nonnull x); // no errors +#endif + void nestedArrays(int x[5][1]) {} #if ARRAYS_CHECKED // expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} Index: lib/Sema/SemaType.cpp === --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -3894,8 +3894,22 @@ attr->setUsedAsTypeAttr(); } } + +auto isVaList = [&S](QualType T) -> bool { + auto *typedefTy = T->getAs(); + if (!typ
r285856 - Don't require nullability on template parameters in typedefs.
Author: jrose Date: Wed Nov 2 15:44:07 2016 New Revision: 285856 URL: http://llvm.org/viewvc/llvm-project?rev=285856&view=rev Log: Don't require nullability on template parameters in typedefs. Previously the following code would warn on the use of "T": template struct X { typedef T *type; }; ...because nullability is /allowed/ on template parameters (because they could be pointers). (Actually putting nullability on this use of 'T' will of course break if the argument is a non-pointer type.) This fix doesn't handle the case where a template parameter is used /outside/ of a typedef. That seems trickier, especially in parameter position. Modified: cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=285856&r1=285855&r2=285856&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Wed Nov 2 15:44:07 2016 @@ -3600,7 +3600,17 @@ static TypeSourceInfo *GetFullTypeForDec // inner pointers. complainAboutMissingNullability = CAMN_InnerPointers; -if (T->canHaveNullability() && !T->getNullability(S.Context)) { +auto isDependentNonPointerType = [](QualType T) -> bool { + // Note: This is intended to be the same check as Type::canHaveNullability + // except with all of the ambiguous cases being treated as 'false' rather + // than 'true'. + return T->isDependentType() && !T->isAnyPointerType() && +!T->isBlockPointerType() && !T->isMemberPointerType(); +}; + +if (T->canHaveNullability() && !T->getNullability(S.Context) && +!isDependentNonPointerType(T)) { + // Note that we allow but don't require nullability on dependent types. ++NumPointersRemaining; } Modified: cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h?rev=285856&r1=285855&r2=285856&view=diff == --- cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h (original) +++ cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h Wed Nov 2 15:44:07 2016 @@ -13,5 +13,13 @@ class X { int X:: *memptr; // expected-warning{{member pointer is missing a nullability type specifier}} }; +template +struct Typedefs { + typedef T *Base; // no-warning + typedef Base *type; // expected-warning{{pointer is missing a nullability type specifier}} +}; + +Typedefs xx; +Typedefs yy; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26226: Don't require nullability on template parameters in typedefs.
jordan_rose closed this revision. jordan_rose added a comment. Committed in r285856. Repository: rL LLVM https://reviews.llvm.org/D26226 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r285856 - Don't require nullability on template parameters in typedefs.
> On Nov 2, 2016, at 14:31, Richard Smith wrote: > > On 2 Nov 2016 1:53 pm, "Jordan Rose via cfe-commits" > mailto:cfe-commits@lists.llvm.org>> wrote: > Author: jrose > Date: Wed Nov 2 15:44:07 2016 > New Revision: 285856 > > URL: http://llvm.org/viewvc/llvm-project?rev=285856&view=rev > <http://llvm.org/viewvc/llvm-project?rev=285856&view=rev> > Log: > Don't require nullability on template parameters in typedefs. > > Previously the following code would warn on the use of "T": > > template > struct X { > typedef T *type; > }; > > ...because nullability is /allowed/ on template parameters (because > they could be pointers). (Actually putting nullability on this use of > 'T' will of course break if the argument is a non-pointer type.) > > This doesn't make any sense to me. Why would T need to be a pointer type for > a nullability qualifier to be valid on a T*? Sorry, this is referring to the following change to the example: template struct X { typedef T _Nullable *type; }; This is legal, but of course `X` then produces an error. So we want to accept nullability in this position (in case T is implicitly required to be a pointer type by the definition of X) but not warn when it’s missing (in case it isn’t). Jordan > > This fix doesn't handle the case where a template parameter is used > /outside/ of a typedef. That seems trickier, especially in parameter > position. > > Modified: > cfe/trunk/lib/Sema/SemaType.cpp > cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h > > Modified: cfe/trunk/lib/Sema/SemaType.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=285856&r1=285855&r2=285856&view=diff > > <http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=285856&r1=285855&r2=285856&view=diff> > == > --- cfe/trunk/lib/Sema/SemaType.cpp (original) > +++ cfe/trunk/lib/Sema/SemaType.cpp Wed Nov 2 15:44:07 2016 > @@ -3600,7 +3600,17 @@ static TypeSourceInfo *GetFullTypeForDec > // inner pointers. > complainAboutMissingNullability = CAMN_InnerPointers; > > -if (T->canHaveNullability() && !T->getNullability(S.Context)) { > +auto isDependentNonPointerType = [](QualType T) -> bool { > + // Note: This is intended to be the same check as > Type::canHaveNullability > + // except with all of the ambiguous cases being treated as 'false' > rather > + // than 'true'. > + return T->isDependentType() && !T->isAnyPointerType() && > +!T->isBlockPointerType() && !T->isMemberPointerType(); > +}; > + > +if (T->canHaveNullability() && !T->getNullability(S.Context) && > +!isDependentNonPointerType(T)) { > + // Note that we allow but don't require nullability on dependent types. >++NumPointersRemaining; > } > > > Modified: cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h?rev=285856&r1=285855&r2=285856&view=diff > > <http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h?rev=285856&r1=285855&r2=285856&view=diff> > == > --- cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h (original) > +++ cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h Wed Nov 2 > 15:44:07 2016 > @@ -13,5 +13,13 @@ class X { >int X:: *memptr; // expected-warning{{member pointer is missing a > nullability type specifier}} > }; > > +template > +struct Typedefs { > + typedef T *Base; // no-warning > + typedef Base *type; // expected-warning{{pointer is missing a nullability > type specifier}} > +}; > + > +Typedefs xx; > +Typedefs yy; > > > > > ___ > cfe-commits mailing list > cfe-commits@lists.llvm.org <mailto:cfe-commits@lists.llvm.org> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits > <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits> > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r285856 - Don't require nullability on template parameters in typedefs.
> On Nov 2, 2016, at 15:48, Richard Smith wrote: > > On Wed, Nov 2, 2016 at 2:34 PM, Jordan Rose via cfe-commits > mailto:cfe-commits@lists.llvm.org>> wrote: > >> On Nov 2, 2016, at 14:31, Richard Smith > <mailto:rich...@metafoo.co.uk>> wrote: >> >> On 2 Nov 2016 1:53 pm, "Jordan Rose via cfe-commits" >> mailto:cfe-commits@lists.llvm.org>> wrote: >> Author: jrose >> Date: Wed Nov 2 15:44:07 2016 >> New Revision: 285856 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=285856&view=rev >> <http://llvm.org/viewvc/llvm-project?rev=285856&view=rev> >> Log: >> Don't require nullability on template parameters in typedefs. >> >> Previously the following code would warn on the use of "T": >> >> template >> struct X { >> typedef T *type; >> }; >> >> ...because nullability is /allowed/ on template parameters (because >> they could be pointers). (Actually putting nullability on this use of >> 'T' will of course break if the argument is a non-pointer type.) >> >> This doesn't make any sense to me. Why would T need to be a pointer type for >> a nullability qualifier to be valid on a T*? > > Sorry, this is referring to the following change to the example: > > template > struct X { > typedef T _Nullable *type; > }; > > This is legal, but of course `X` then produces an error. So we want to > accept nullability in this position (in case T is implicitly required to be a > pointer type by the definition of X) but not warn when it’s missing (in case > it isn’t). > > Oh, I see. Your testcase is very confusing, though, since it wraps the > problematic use of T in a completely-unrelated pointer type. The actual > problem being fixed is much more obvious in a case like this: > > int *_Nullable p; > template struct X { > T t; // warns without your fix > }; > > It'd be easier on future readers of this code to use the more obvious test > case here. Ah, that case doesn’t actually trigger the issue, because a typedef doesn’t require nullability on its outermost pointer type. (It’s assumed that the use site may need to make some uses of the typedef nullable and some non-nullable.) We do still see this issue for fields of type ’T’, but that seemed trickier to deal with. I might have been overthinking it, though. Jordan ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r285856 - Don't require nullability on template parameters in typedefs.
> On Nov 2, 2016, at 16:20, Richard Smith wrote: > > On Wed, Nov 2, 2016 at 3:51 PM, Jordan Rose via cfe-commits > mailto:cfe-commits@lists.llvm.org>> wrote: > >> On Nov 2, 2016, at 15:48, Richard Smith > <mailto:rich...@metafoo.co.uk>> wrote: >> >> On Wed, Nov 2, 2016 at 2:34 PM, Jordan Rose via cfe-commits >> mailto:cfe-commits@lists.llvm.org>> wrote: >> >>> On Nov 2, 2016, at 14:31, Richard Smith >> <mailto:rich...@metafoo.co.uk>> wrote: >>> >>> On 2 Nov 2016 1:53 pm, "Jordan Rose via cfe-commits" >>> mailto:cfe-commits@lists.llvm.org>> wrote: >>> Author: jrose >>> Date: Wed Nov 2 15:44:07 2016 >>> New Revision: 285856 >>> >>> URL: http://llvm.org/viewvc/llvm-project?rev=285856&view=rev >>> <http://llvm.org/viewvc/llvm-project?rev=285856&view=rev> >>> Log: >>> Don't require nullability on template parameters in typedefs. >>> >>> Previously the following code would warn on the use of "T": >>> >>> template >>> struct X { >>> typedef T *type; >>> }; >>> >>> ...because nullability is /allowed/ on template parameters (because >>> they could be pointers). (Actually putting nullability on this use of >>> 'T' will of course break if the argument is a non-pointer type.) >>> >>> This doesn't make any sense to me. Why would T need to be a pointer type >>> for a nullability qualifier to be valid on a T*? >> >> Sorry, this is referring to the following change to the example: >> >> template >> struct X { >> typedef T _Nullable *type; >> }; >> >> This is legal, but of course `X` then produces an error. So we want to >> accept nullability in this position (in case T is implicitly required to be >> a pointer type by the definition of X) but not warn when it’s missing (in >> case it isn’t). >> >> Oh, I see. Your testcase is very confusing, though, since it wraps the >> problematic use of T in a completely-unrelated pointer type. The actual >> problem being fixed is much more obvious in a case like this: >> >> int *_Nullable p; >> template struct X { >> T t; // warns without your fix >> }; >> >> It'd be easier on future readers of this code to use the more obvious test >> case here. > > Ah, that case doesn’t actually trigger the issue, because a typedef doesn’t > require nullability on its outermost pointer type. (It’s assumed that the use > site may need to make some uses of the typedef nullable and some > non-nullable.) > > The testcase I gave above definitely produces a bogus warning before your > patch. I've not actually checked whether the patch fixes it, though. > Oops, sorry, I misread it thinking it still said ‘typedef’. Yes, that does warn, and no, this patch does not fix it. Jordan ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26317: Fix use-of-temporary with StringRef in code coverage
jordan_rose created this revision. jordan_rose added a reviewer: vsk. jordan_rose added a subscriber: cfe-commits. jordan_rose set the repository for this revision to rL LLVM. The fixed code is basically identical to the same loop below, which might indicate an opportunity for refactoring. I just wanted to fix the use-of-temporary issue. Caught by adding a similar check to StringRef as r283798 did for ArrayRef. I'll be upstreaming that soon. Repository: rL LLVM https://reviews.llvm.org/D26317 Files: lib/CodeGen/CoverageMappingGen.cpp Index: lib/CodeGen/CoverageMappingGen.cpp === --- lib/CodeGen/CoverageMappingGen.cpp +++ lib/CodeGen/CoverageMappingGen.cpp @@ -1034,10 +1034,15 @@ std::vector Filenames; std::vector Expressions; std::vector Regions; +llvm::SmallVector FilenameStrs; llvm::SmallVector FilenameRefs; +FilenameStrs.resize(FileEntries.size()); FilenameRefs.resize(FileEntries.size()); -for (const auto &Entry : FileEntries) - FilenameRefs[Entry.second] = normalizeFilename(Entry.first->getName()); +for (const auto &Entry : FileEntries) { + auto I = Entry.second; + FilenameStrs[I] = normalizeFilename(Entry.first->getName()); + FilenameRefs[I] = FilenameStrs[I]; +} RawCoverageMappingReader Reader(CoverageMapping, FilenameRefs, Filenames, Expressions, Regions); if (Reader.read()) Index: lib/CodeGen/CoverageMappingGen.cpp === --- lib/CodeGen/CoverageMappingGen.cpp +++ lib/CodeGen/CoverageMappingGen.cpp @@ -1034,10 +1034,15 @@ std::vector Filenames; std::vector Expressions; std::vector Regions; +llvm::SmallVector FilenameStrs; llvm::SmallVector FilenameRefs; +FilenameStrs.resize(FileEntries.size()); FilenameRefs.resize(FileEntries.size()); -for (const auto &Entry : FileEntries) - FilenameRefs[Entry.second] = normalizeFilename(Entry.first->getName()); +for (const auto &Entry : FileEntries) { + auto I = Entry.second; + FilenameStrs[I] = normalizeFilename(Entry.first->getName()); + FilenameRefs[I] = FilenameStrs[I]; +} RawCoverageMappingReader Reader(CoverageMapping, FilenameRefs, Filenames, Expressions, Regions); if (Reader.read()) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r286122 - Fix use-of-temporary with StringRef in code coverage
Author: jrose Date: Mon Nov 7 11:28:04 2016 New Revision: 286122 URL: http://llvm.org/viewvc/llvm-project?rev=286122&view=rev Log: Fix use-of-temporary with StringRef in code coverage The fixed code is basically identical to the same loop below, which might indicate an opportunity for refactoring. I just wanted to fix the use-of-temporary issue. Caught by adding a similar check to StringRef as r283798 did for ArrayRef. I'll be upstreaming that soon. Reviewed by Vedant Kumar as https://reviews.llvm.org/D26317. Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp?rev=286122&r1=286121&r2=286122&view=diff == --- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original) +++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Mon Nov 7 11:28:04 2016 @@ -1039,10 +1039,15 @@ void CoverageMappingModuleGen::addFuncti std::vector Filenames; std::vector Expressions; std::vector Regions; +llvm::SmallVector FilenameStrs; llvm::SmallVector FilenameRefs; +FilenameStrs.resize(FileEntries.size()); FilenameRefs.resize(FileEntries.size()); -for (const auto &Entry : FileEntries) - FilenameRefs[Entry.second] = normalizeFilename(Entry.first->getName()); +for (const auto &Entry : FileEntries) { + auto I = Entry.second; + FilenameStrs[I] = normalizeFilename(Entry.first->getName()); + FilenameRefs[I] = FilenameStrs[I]; +} RawCoverageMappingReader Reader(CoverageMapping, FilenameRefs, Filenames, Expressions, Regions); if (Reader.read()) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26317: Fix use-of-temporary with StringRef in code coverage
jordan_rose closed this revision. jordan_rose added a comment. Committed as r286122. Repository: rL LLVM https://reviews.llvm.org/D26317 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26108: Add -Wnullability-completeness-on-arrays.
jordan_rose added a comment. It works fine for me, though note the "depends on https://reviews.llvm.org/D25850";. The other patches in the series do seem to have been thrown off by https://reviews.llvm.org/D26226 landing first, though, so I'll update those. Repository: rL LLVM https://reviews.llvm.org/D26108 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26227: Don't require nullability on 'va_list'.
jordan_rose added a dependency: D26108: Add -Wnullability-completeness-on-arrays.. jordan_rose added a comment. Depends on https://reviews.llvm.org/D26108 too (for the tests to apply cleanly). Repository: rL LLVM https://reviews.llvm.org/D26227 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26109: Warn when 'assume_nonnull' infers nullability within an array.
jordan_rose added a dependency: D26108: Add -Wnullability-completeness-on-arrays.. jordan_rose added a comment. Depends on https://reviews.llvm.org/D26108 too, for the tests to apply cleanly. Repository: rL LLVM https://reviews.llvm.org/D26109 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26108: Add -Wnullability-completeness-on-arrays.
jordan_rose added a comment. Ah, my apologies, @ahatanak. I was testing against the Swift branch of Clang. Repository: rL LLVM https://reviews.llvm.org/D26108 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26108: Add -Wnullability-completeness-on-arrays.
jordan_rose added inline comments. Comment at: lib/Sema/SemaType.cpp:3988 // Allow arrays of auto if we are a generic lambda parameter. // i.e. [](auto (&array)[5]) { return array[0]; }; OK if (AT && D.getContext() != Declarator::LambdaExprParameterContext) { ahatanak wrote: > This isn't something that is related to the changes made in this patch, but > it looks like we issue a -Wnullability-completeness warning when there is a > generic lambda like this: > > ``` > auto G2 = [](auto a){}; > ``` > > Is this expected? It's not desired, but it's not a regression either. D26226 mentions how this comes up with explicit templates, so it doesn't surprise me that it happens with generic lambdas too. Repository: rL LLVM https://reviews.llvm.org/D26108 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r286522 - Don't require nullability on 'va_list'.
Author: jrose Date: Thu Nov 10 17:28:34 2016 New Revision: 286522 URL: http://llvm.org/viewvc/llvm-project?rev=286522&view=rev Log: Don't require nullability on 'va_list'. There are many non-portable typedefs, but va_list is one that nobody ever thinks of as a pointer or an array. (When's the last time you saw someone check for a NULL va_list?) Make an exception for this one special type. Part of rdar://problem/25846421. Modified: cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-arrays.h Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=286522&r1=286521&r2=286522&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Thu Nov 10 17:28:34 2016 @@ -3919,8 +3919,22 @@ static TypeSourceInfo *GetFullTypeForDec attr->setUsedAsTypeAttr(); } } + +auto isVaList = [&S](QualType T) -> bool { + auto *typedefTy = T->getAs(); + if (!typedefTy) +return false; + TypedefDecl *vaListTypedef = S.Context.getBuiltinVaListDecl(); + do { +if (typedefTy->getDecl() == vaListTypedef) + return true; +typedefTy = typedefTy->desugar()->getAs(); + } while (typedefTy); + return false; +}; + if (complainAboutMissingNullability == CAMN_Yes && -T->isArrayType() && !T->getNullability(S.Context) && +T->isArrayType() && !T->getNullability(S.Context) && !isVaList(T) && D.isPrototypeContext() && !hasOuterPointerLikeChunk(D, D.getNumTypeObjects())) { checkNullabilityConsistency(S, SimplePointerKind::Array, Modified: cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-arrays.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-arrays.h?rev=286522&r1=286521&r2=286522&view=diff == --- cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-arrays.h (original) +++ cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-arrays.h Thu Nov 10 17:28:34 2016 @@ -1,3 +1,5 @@ +#include + void firstThingInTheFileThatNeedsNullabilityIsAnArray(int ints[]); #if ARRAYS_CHECKED // expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} @@ -33,6 +35,26 @@ void testAllOK( void * _Nullable ptrs[_Nonnull], void * _Nullable * _Nullable nestedPtrs[_Nonnull]); +void testVAList(va_list ok); // no warning + +#if __cplusplus +// Carefully construct a test case such that if a platform's va_list is an array +// or pointer type, it gets tested, but otherwise it does not. +template +struct pointer_like_or { typedef F type; }; +template +struct pointer_like_or { typedef T *type; }; +template +struct pointer_like_or { typedef T * const type; }; +template +struct pointer_like_or { typedef T type[]; }; +template +struct pointer_like_or { typedef T type[size]; }; + +void testVAListWithNullability( + pointer_like_or::type _Nonnull x); // no errors +#endif + void nestedArrays(int x[5][1]) {} #if ARRAYS_CHECKED // expected-warning@-2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r286521 - Warn when 'assume_nonnull' infers nullability within an array.
Author: jrose Date: Thu Nov 10 17:28:30 2016 New Revision: 286521 URL: http://llvm.org/viewvc/llvm-project?rev=286521&view=rev Log: Warn when 'assume_nonnull' infers nullability within an array. ...or within a reference. Both of these add an extra level of indirection that make us less certain that the pointer really was supposed to be non-nullable. However, changing the default behavior would be a breaking change, so we'll just make it a warning instead. Part of rdar://problem/25846421 Added: cfe/trunk/test/FixIt/nullability.mm Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/SemaObjCXX/nullability-consistency-arrays.mm Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=286521&r1=286520&r2=286521&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Thu Nov 10 17:28:30 2016 @@ -277,6 +277,7 @@ def ModuleFileExtension : DiagGroup<"mod def NewlineEOF : DiagGroup<"newline-eof">; def Nullability : DiagGroup<"nullability">; def NullabilityDeclSpec : DiagGroup<"nullability-declspec">; +def NullabilityInferredOnNestedType : DiagGroup<"nullability-inferred-on-nested-type">; def NullableToNonNullConversion : DiagGroup<"nullable-to-nonnull-conversion">; def NullabilityCompletenessOnArrays : DiagGroup<"nullability-completeness-on-arrays">; def NullabilityCompleteness : DiagGroup<"nullability-completeness", Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=286521&r1=286520&r2=286521&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Nov 10 17:28:30 2016 @@ -8737,6 +8737,11 @@ def warn_nullability_missing_array : War "_Nullable, or _Null_unspecified)">, InGroup; +def warn_nullability_inferred_on_nested_type : Warning< + "inferring '_Nonnull' for pointer type within %select{array|reference}0 is " + "deprecated">, + InGroup; + def err_objc_type_arg_explicit_nullability : Error< "type argument %0 cannot explicitly specify nullability">; Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=286521&r1=286520&r2=286521&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Thu Nov 10 17:28:30 2016 @@ -3274,15 +3274,27 @@ namespace { // NSError** NSErrorPointerPointer, }; + + /// Describes a declarator chunk wrapping a pointer that marks inference as + /// unexpected. + // These values must be kept in sync with diagnostics. + enum class PointerWrappingDeclaratorKind { +/// Pointer is top-level. +None = -1, +/// Pointer is an array element. +Array = 0, +/// Pointer is the referent type of a C++ reference. +Reference = 1 + }; } // end anonymous namespace /// Classify the given declarator, whose type-specified is \c type, based on /// what kind of pointer it refers to. /// /// This is used to determine the default nullability. -static PointerDeclaratorKind classifyPointerDeclarator(Sema &S, - QualType type, - Declarator &declarator) { +static PointerDeclaratorKind +classifyPointerDeclarator(Sema &S, QualType type, Declarator &declarator, + PointerWrappingDeclaratorKind &wrappingKind) { unsigned numNormalPointers = 0; // For any dependent type, we consider it a non-pointer. @@ -3294,6 +3306,10 @@ static PointerDeclaratorKind classifyPoi DeclaratorChunk &chunk = declarator.getTypeObject(i); switch (chunk.Kind) { case DeclaratorChunk::Array: + if (numNormalPointers == 0) +wrappingKind = PointerWrappingDeclaratorKind::Array; + break; + case DeclaratorChunk::Function: case DeclaratorChunk::Pipe: break; @@ -3304,14 +3320,18 @@ static PointerDeclaratorKind classifyPoi : PointerDeclaratorKind::SingleLevelPointer; case DeclaratorChunk::Paren: + break; + case DeclaratorChunk::Reference: - continue; + if (numNormalPointers == 0) +wrappingKind = PointerWrappingDeclaratorKind::Reference; + break; case DeclaratorChunk::Pointer: ++numNormalPointers; if (numNormalPointers > 2) return PointerDeclaratorKind::MultiLevelPointer; - con
r286520 - Add -Wnullability-completeness-on-arrays.
Author: jrose Date: Thu Nov 10 17:28:26 2016 New Revision: 286520 URL: http://llvm.org/viewvc/llvm-project?rev=286520&view=rev Log: Add -Wnullability-completeness-on-arrays. This is an addition to (and sub-warning of) -Wnullability-completeness that warns when an array parameter is missing nullability. When the specific warning is switched off, the compiler falls back to only warning on pointer types written as pointer types. Note that use of nullability /within/ an array triggers the completeness checks regardless of whether or not the array-specific warning is enabled; the intent there is simply to determine whether a particular header is trying to be nullability-aware at all. Part of rdar://problem/25846421. Added: cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-arrays.h cfe/trunk/test/SemaObjCXX/nullability-consistency-arrays.mm Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaType.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=286520&r1=286519&r2=286520&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Thu Nov 10 17:28:26 2016 @@ -278,7 +278,9 @@ def NewlineEOF : DiagGroup<"newline-eof" def Nullability : DiagGroup<"nullability">; def NullabilityDeclSpec : DiagGroup<"nullability-declspec">; def NullableToNonNullConversion : DiagGroup<"nullable-to-nonnull-conversion">; -def NullabilityCompleteness : DiagGroup<"nullability-completeness">; +def NullabilityCompletenessOnArrays : DiagGroup<"nullability-completeness-on-arrays">; +def NullabilityCompleteness : DiagGroup<"nullability-completeness", +[NullabilityCompletenessOnArrays]>; def NullArithmetic : DiagGroup<"null-arithmetic">; def NullCharacter : DiagGroup<"null-character">; def NullDereference : DiagGroup<"null-dereference">; Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=286520&r1=286519&r2=286520&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Nov 10 17:28:26 2016 @@ -8732,6 +8732,10 @@ def warn_nullability_missing : Warning< "%select{pointer|block pointer|member pointer}0 is missing a nullability " "type specifier (_Nonnull, _Nullable, or _Null_unspecified)">, InGroup; +def warn_nullability_missing_array : Warning< + "array parameter is missing a nullability type specifier (_Nonnull, " + "_Nullable, or _Null_unspecified)">, + InGroup; def err_objc_type_arg_explicit_nullability : Error< "type argument %0 cannot explicitly specify nullability">; Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=286520&r1=286519&r2=286520&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Thu Nov 10 17:28:26 2016 @@ -3212,6 +3212,7 @@ namespace { Pointer, BlockPointer, MemberPointer, +Array, }; } // end anonymous namespace @@ -3453,12 +3454,15 @@ static FileID getNullabilityCompleteness return file; } -/// Check for consistent use of nullability. -static void checkNullabilityConsistency(TypeProcessingState &state, +/// Complains about missing nullability if the file containing \p pointerLoc +/// has other uses of nullability (either the keywords or the \c assume_nonnull +/// pragma). +/// +/// If the file has \e not seen other uses of nullability, this particular +/// pointer is saved for possible later diagnosis. See recordNullabilitySeen(). +static void checkNullabilityConsistency(Sema &S, SimplePointerKind pointerKind, SourceLocation pointerLoc) { - Sema &S = state.getSema(); - // Determine which file we're performing consistency checking for. FileID file = getNullabilityCompletenessCheckFileID(S, pointerLoc); if (file.isInvalid()) @@ -3468,10 +3472,16 @@ static void checkNullabilityConsistency( // about anything. FileNullability &fileNullability = S.NullabilityMap[file]; if (!fileNullability.SawTypeNullability) { -// If this is the first pointer declarator in the file, record it. +// If this is the first pointer declarator in the file, and the appropriate +// warning is on, record it in case we need to diagnose it retroactively. +diag::kind diagKind; +if (pointerKind == SimplePointerKind::Array)
r286519 - Accept nullability qualifiers on array parameters.
Author: jrose Date: Thu Nov 10 17:28:17 2016 New Revision: 286519 URL: http://llvm.org/viewvc/llvm-project?rev=286519&view=rev Log: Accept nullability qualifiers on array parameters. Since array parameters decay to pointers, '_Nullable' and friends should be available for use there as well. This is especially important for parameters that are typedefs of arrays. The unsugared syntax for this follows the syntax for 'static'-sized arrays in C: void test(int values[_Nullable]); This syntax was previously accepted but the '_Nullable' (and any other attributes) were silently discarded. However, applying '_Nullable' to a typedef was previously rejected and is now accepted; therefore, it may be necessary to test for the presence of this feature: #if __has_feature(nullability_on_arrays) One important change here is that DecayedTypes don't always immediately contain PointerTypes anymore; they may contain an AttributedType instead. This only affected one place in-tree, so I would guess it's not likely to cause problems elsewhere. This commit does not change -Wnullability-completeness just yet. I want to think about whether it's worth doing something special to avoid breaking existing clients that compile with -Werror. It also doesn't change '#pragma clang assume_nonnull' behavior, which currently treats the following two declarations as equivalent: #pragma clang assume_nonnull begin void test(void *pointers[]); #pragma clang assume_nonnull end void test(void * _Nonnull pointers[]); This is not the desired behavior, but changing it would break backwards-compatibility. Most likely the best answer is going to be adding a new warning. Part of rdar://problem/25846421 Modified: cfe/trunk/include/clang/AST/Type.h cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/AST/ASTContext.cpp cfe/trunk/lib/CodeGen/CGDebugInfo.cpp cfe/trunk/lib/Lex/PPMacroExpansion.cpp cfe/trunk/lib/Parse/ParseDecl.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/Parser/nullability.c cfe/trunk/test/Sema/nullability.c cfe/trunk/test/SemaCXX/nullability.cpp cfe/trunk/test/SemaObjC/nullability.m Modified: cfe/trunk/include/clang/AST/Type.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=286519&r1=286518&r2=286519&view=diff == --- cfe/trunk/include/clang/AST/Type.h (original) +++ cfe/trunk/include/clang/AST/Type.h Thu Nov 10 17:28:17 2016 @@ -2266,19 +2266,15 @@ public: /// Represents a pointer type decayed from an array or function type. class DecayedType : public AdjustedType { - DecayedType(QualType OriginalType, QualType DecayedPtr, QualType CanonicalPtr) - : AdjustedType(Decayed, OriginalType, DecayedPtr, CanonicalPtr) { -assert(isa(getAdjustedType())); - } + inline + DecayedType(QualType OriginalType, QualType Decayed, QualType Canonical); friend class ASTContext; // ASTContext creates these. public: QualType getDecayedType() const { return getAdjustedType(); } - QualType getPointeeType() const { -return cast(getDecayedType())->getPointeeType(); - } + inline QualType getPointeeType() const; static bool classof(const Type *T) { return T->getTypeClass() == Decayed; } }; @@ -5962,6 +5958,23 @@ inline const ArrayType *Type::castAsArra return cast(getUnqualifiedDesugaredType()); } +DecayedType::DecayedType(QualType OriginalType, QualType DecayedPtr, + QualType CanonicalPtr) +: AdjustedType(Decayed, OriginalType, DecayedPtr, CanonicalPtr) { +#ifndef NDEBUG + QualType Adjusted = getAdjustedType(); + (void)AttributedType::stripOuterNullability(Adjusted); + assert(isa(Adjusted)); +#endif +} + +QualType DecayedType::getPointeeType() const { + QualType Decayed = getDecayedType(); + (void)AttributedType::stripOuterNullability(Decayed); + return cast(Decayed)->getPointeeType(); +} + + } // end namespace clang #endif Modified: cfe/trunk/include/clang/Sema/Sema.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=286519&r1=286518&r2=286519&view=diff == --- cfe/trunk/include/clang/Sema/Sema.h (original) +++ cfe/trunk/include/clang/Sema/Sema.h Thu Nov 10 17:28:17 2016 @@ -3122,10 +3122,14 @@ public: /// method) or an Objective-C property attribute, rather than as an /// underscored type specifier. /// + /// \param allowArrayTypes Whether to accept nullability specifiers on an + /// array type (e.g., because it will decay to a pointer). + /// /// \returns true if nullability cannot be applied, false otherwise. bool checkNullabilityTypeSpecifier(QualType &type, NullabilityKind nullability, SourceLocation nullabilityLoc, - bool isContextSensitive); + bool isContextSensitiv
r286525 - [Sema] Fix-up for MSVC, which is stricter about template types.
Author: jrose Date: Thu Nov 10 17:41:18 2016 New Revision: 286525 URL: http://llvm.org/viewvc/llvm-project?rev=286525&view=rev Log: [Sema] Fix-up for MSVC, which is stricter about template types. Modified: cfe/trunk/lib/Sema/SemaType.cpp Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=286525&r1=286524&r2=286525&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Thu Nov 10 17:41:18 2016 @@ -3545,7 +3545,7 @@ static void recordNullabilitySeen(Sema & S.Diag(fileNullability.PointerLoc, diag::warn_nullability_missing_array); } else { S.Diag(fileNullability.PointerLoc, diag::warn_nullability_missing) - << fileNullability.PointerKind; + << static_cast(fileNullability.PointerKind); } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r286531 - Don't require nullability on 'va_list' harder.
Author: jrose Date: Thu Nov 10 18:23:59 2016 New Revision: 286531 URL: http://llvm.org/viewvc/llvm-project?rev=286531&view=rev Log: Don't require nullability on 'va_list' harder. Platform headers don't always define 'va_list' in terms of Clang's '__builtin_va_list', so in addition to checking for our own synthesized decl, also just look for typedefs literally named 'va_list'. Better to err on the side of false negatives here. Fix-up for rdar://problem/25846421. Modified: cfe/trunk/lib/Sema/SemaType.cpp Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=286531&r1=286530&r2=286531&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Thu Nov 10 18:23:59 2016 @@ -3928,6 +3928,9 @@ static TypeSourceInfo *GetFullTypeForDec do { if (typedefTy->getDecl() == vaListTypedef) return true; +if (auto *name = typedefTy->getDecl()->getIdentifier()) + if (name->isStr("va_list")) +return true; typedefTy = typedefTy->desugar()->getAs(); } while (typedefTy); return false; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25850: Accept nullability annotations (_Nullable) on array parameters
jordan_rose closed this revision. jordan_rose added a comment. Committed as https://reviews.llvm.org/rL286519. Repository: rL LLVM https://reviews.llvm.org/D25850 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26108: Add -Wnullability-completeness-on-arrays.
jordan_rose closed this revision. jordan_rose added a comment. Committed as https://reviews.llvm.org/rL286520, with a slight fix-up for MSVC in https://reviews.llvm.org/rL286525. Repository: rL LLVM https://reviews.llvm.org/D26108 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26109: Warn when 'assume_nonnull' infers nullability within an array.
jordan_rose closed this revision. jordan_rose added a comment. Committed as https://reviews.llvm.org/rL286521. Repository: rL LLVM https://reviews.llvm.org/D26109 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26227: Don't require nullability on 'va_list'.
jordan_rose closed this revision. jordan_rose added a comment. Committed in https://reviews.llvm.org/rL286522, with a fix-up to make the check for va_lists more conservative in https://reviews.llvm.org/rL286531. Repository: rL LLVM https://reviews.llvm.org/D26227 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r286533 - Speculative fix for va_list/nullability test on Hexagon and PPC.
Author: jrose Date: Thu Nov 10 18:55:14 2016 New Revision: 286533 URL: http://llvm.org/viewvc/llvm-project?rev=286533&view=rev Log: Speculative fix for va_list/nullability test on Hexagon and PPC. PowerPC's va_list, at least, is a typedef for an array, which means it decays to a pointer in parameter position. Since the decayed type is built from the array element type, the typedef sugar is lost. More rdar://problem/25846421. Modified: cfe/trunk/lib/Sema/SemaType.cpp Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=286533&r1=286532&r2=286533&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Thu Nov 10 18:55:14 2016 @@ -3921,6 +3921,10 @@ static TypeSourceInfo *GetFullTypeForDec } auto isVaList = [&S](QualType T) -> bool { + // Handle array va_list parameters that decayed to pointers. + if (auto *decayedTy = T->getAs()) +T = decayedTy->getOriginalType(); + auto *typedefTy = T->getAs(); if (!typedefTy) return false; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r286542 - Don't require nullability on 'va_list', even when it's a pointer.
Author: jrose Date: Thu Nov 10 19:29:18 2016 New Revision: 286542 URL: http://llvm.org/viewvc/llvm-project?rev=286542&view=rev Log: Don't require nullability on 'va_list', even when it's a pointer. Take 3! This should finally fix the Hexagon, PPC, and Windows bots. rdar://problem/25846421 Modified: cfe/trunk/lib/Sema/SemaType.cpp Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=286542&r1=286541&r2=286542&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Thu Nov 10 19:29:18 2016 @@ -3827,6 +3827,23 @@ static TypeSourceInfo *GetFullTypeForDec } } + // Local function that returns true if its argument looks like a va_list. + auto isVaList = [&S](QualType T) -> bool { +auto *typedefTy = T->getAs(); +if (!typedefTy) + return false; +TypedefDecl *vaListTypedef = S.Context.getBuiltinVaListDecl(); +do { + if (typedefTy->getDecl() == vaListTypedef) +return true; + if (auto *name = typedefTy->getDecl()->getIdentifier()) +if (name->isStr("va_list")) + return true; + typedefTy = typedefTy->desugar()->getAs(); +} while (typedefTy); +return false; + }; + // Local function that checks the nullability for a given pointer declarator. // Returns true if _Nonnull was inferred. auto inferPointerNullability = [&](SimplePointerKind pointerKind, @@ -3905,37 +3922,27 @@ static TypeSourceInfo *GetFullTypeForDec // nullability and perform consistency checking. if (S.ActiveTemplateInstantiations.empty()) { if (T->canHaveNullability() && !T->getNullability(S.Context)) { - SimplePointerKind pointerKind = SimplePointerKind::Pointer; - if (T->isBlockPointerType()) -pointerKind = SimplePointerKind::BlockPointer; - else if (T->isMemberPointerType()) -pointerKind = SimplePointerKind::MemberPointer; - - if (auto *attr = inferPointerNullability( - pointerKind, D.getDeclSpec().getTypeSpecTypeLoc(), - D.getMutableDeclSpec().getAttributes().getListRef())) { -T = Context.getAttributedType( - AttributedType::getNullabilityAttrKind(*inferNullability), T, T); -attr->setUsedAsTypeAttr(); + if (isVaList(T)) { +// Record that we've seen a pointer, but do nothing else. +if (NumPointersRemaining > 0) + --NumPointersRemaining; + } else { +SimplePointerKind pointerKind = SimplePointerKind::Pointer; +if (T->isBlockPointerType()) + pointerKind = SimplePointerKind::BlockPointer; +else if (T->isMemberPointerType()) + pointerKind = SimplePointerKind::MemberPointer; + +if (auto *attr = inferPointerNullability( + pointerKind, D.getDeclSpec().getTypeSpecTypeLoc(), + D.getMutableDeclSpec().getAttributes().getListRef())) { + T = Context.getAttributedType( +AttributedType::getNullabilityAttrKind(*inferNullability),T,T); + attr->setUsedAsTypeAttr(); +} } } -auto isVaList = [&S](QualType T) -> bool { - auto *typedefTy = T->getAs(); - if (!typedefTy) -return false; - TypedefDecl *vaListTypedef = S.Context.getBuiltinVaListDecl(); - do { -if (typedefTy->getDecl() == vaListTypedef) - return true; -if (auto *name = typedefTy->getDecl()->getIdentifier()) - if (name->isStr("va_list")) -return true; -typedefTy = typedefTy->desugar()->getAs(); - } while (typedefTy); - return false; -}; - if (complainAboutMissingNullability == CAMN_Yes && T->isArrayType() && !T->getNullability(S.Context) && !isVaList(T) && D.isPrototypeContext() && ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r286541 - Revert "Speculative fix for va_list/nullability test on Hexagon and PPC."
Author: jrose Date: Thu Nov 10 19:29:15 2016 New Revision: 286541 URL: http://llvm.org/viewvc/llvm-project?rev=286541&view=rev Log: Revert "Speculative fix for va_list/nullability test on Hexagon and PPC." This reverts commit r286533. At this point an array really is still an array, but the problem is with /non-/array va_lists anyway. Modified: cfe/trunk/lib/Sema/SemaType.cpp Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=286541&r1=286540&r2=286541&view=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Thu Nov 10 19:29:15 2016 @@ -3921,10 +3921,6 @@ static TypeSourceInfo *GetFullTypeForDec } auto isVaList = [&S](QualType T) -> bool { - // Handle array va_list parameters that decayed to pointers. - if (auto *decayedTy = T->getAs()) -T = decayedTy->getOriginalType(); - auto *typedefTy = T->getAs(); if (!typedefTy) return false; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26227: Don't require nullability on 'va_list'.
jordan_rose added a comment. One more fix-up in https://reviews.llvm.org/rL286542. Hopefully the last one. Repository: rL LLVM https://reviews.llvm.org/D26227 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12780: [analyzer] Add generateErrorNode() APIs to CheckerContext
jordan_rose added inline comments. Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h:321 @@ +320,3 @@ +// sink, we assume that a client requesting a transition to a state that is +// the same as the predecessor state has made a mistake. We return the +// predecessor and rather than cache out. What does "has made a mistake" mean? What is the mistake and how will they discover it? http://reviews.llvm.org/D12780 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12652: [Static Analyzer] Lambda support.
jordan_rose added a comment. A few comments coming late… Comment at: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h:515-517 @@ -511,1 +514,5 @@ + /// Returns true if lambdas should be inlined. Otherwise a sink node will be + /// generated each time a LambdaExpr is visited. + bool shouldInlineLambdas(); + "inline" is kind of a misnomer, since we may not actually inline lambdas. I would have suggested "model lambdas" or "lambda support". Comment at: lib/StaticAnalyzer/Core/MemRegion.cpp:740-741 @@ -739,3 +739,4 @@ const DeclContext *DC, - const VarDecl *VD) { + const VarDecl *VD, + MemRegionManager *Mmgr) { while (LC) { Why the extra parameter? http://reviews.llvm.org/D12652 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12780: [analyzer] Add generateErrorNode() APIs to CheckerContext
jordan_rose added inline comments. Comment at: lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp:53 @@ -52,3 +52,3 @@ - if (ExplodedNode *N = C.addTransition()) { + if (ExplodedNode *N = C.generateNonFatalErrorNode()) { if (!BT) zaks.anna wrote: > Can this ever fail? In some cases we just assume it won't in others we tests.. > > Maybe it only fails when we cache out? It does fail when we cache out, and I think we can still cache out if Pred has a different tag the second time around. http://reviews.llvm.org/D12780 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12726: [analyzer] A fix for symbolic element region index lifetime.
jordan_rose added a comment. Hm, interesting. I'm not sure this is even sufficient, though: what if I have a FieldRegion that's a sub-region of an ElementRegion with a symbolic index? RegionStore does everything by base regions, so we won't ever see that intermediate region with the symbolic index. http://reviews.llvm.org/D12726 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D5102: [analyzer][Bugfix/improvement] Fix for PR16833
jordan_rose accepted this revision. jordan_rose added a comment. This revision is now accepted and ready to land. Thanks for all the changes. This looks good to me! (And good catch for the constant expression case.) http://reviews.llvm.org/D5102 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r247999 - [analyzer] Update links to developer.apple.com.
Author: jrose Date: Fri Sep 18 11:12:16 2015 New Revision: 247999 URL: http://llvm.org/viewvc/llvm-project?rev=247999&view=rev Log: [analyzer] Update links to developer.apple.com. The content at the new links is /also/ a little dated, but that's our (Apple's) problem. Modified: cfe/trunk/www/analyzer/scan-build.html cfe/trunk/www/analyzer/xcode.html Modified: cfe/trunk/www/analyzer/scan-build.html URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/analyzer/scan-build.html?rev=247999&r1=247998&r2=247999&view=diff == --- cfe/trunk/www/analyzer/scan-build.html (original) +++ cfe/trunk/www/analyzer/scan-build.html Fri Sep 18 11:12:16 2015 @@ -309,11 +309,11 @@ steps they need to take (e.g., setup cod Recommendation: use "Build and Analyze" -The absolute easiest way to analyze iPhone projects is to use the http://developer.apple.com/mac/library/featuredarticles/StaticAnalysis/index.html";>Build -and Analyze feature in Xcode 3.2 (which is based on the Clang Static -Analyzer). There a user can analyze their project with the click of a button -without most of the setup described later. +The absolute easiest way to analyze iPhone projects is to use the +https://developer.apple.com/library/ios/recipes/xcode_help-source_editor/chapters/Analyze.html#//apple_ref/doc/uid/TP40009975-CH4-SW1";>Analyze +feature in Xcode (which is based on the Clang Static Analyzer). There a +user can analyze their project right from a menu without most of the setup +described later. Instructions are available on this website on how to use open source builds of the analyzer as a replacement for Modified: cfe/trunk/www/analyzer/xcode.html URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/analyzer/xcode.html?rev=247999&r1=247998&r2=247999&view=diff == --- cfe/trunk/www/analyzer/xcode.html (original) +++ cfe/trunk/www/analyzer/xcode.html Fri Sep 18 11:12:16 2015 @@ -22,7 +22,7 @@ Since Xcode 3.2, users have been able to run the Clang Static Analyzer https://developer.apple.com/library/mac/documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/060-Debug_Your_App/debug_app.html#//apple_ref/doc/uid/TP40010215-CH3-SW17";>directly +href="https://developer.apple.com/library/ios/recipes/xcode_help-source_editor/chapters/Analyze.html#//apple_ref/doc/uid/TP40009975-CH4-SW1";>directly within Xcode. It integrates directly with the Xcode build system and @@ -54,7 +54,7 @@ presents analysis results directly withi Xcode is available as a free download from Apple on the https://itunes.apple.com/us/app/xcode/id497799835?mt=12";>Mac App Store, with https://developer.apple.com/library/mac/documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/060-Debug_Your_App/debug_app.html#//apple_ref/doc/uid/TP40010215-CH3-SW17";>instructions +href="https://developer.apple.com/library/ios/recipes/xcode_help-source_editor/chapters/Analyze.html#//apple_ref/doc/uid/TP40009975-CH4-SW1";>instructions available for using the analyzer. Using open source analyzer builds with Xcode ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [cfe-commits] r171885 - in /cfe/trunk/www/analyzer: annotations.html available_checks.html dev_cxx.html index.html xcode.html
Thanks, updated these links in r247999. In the future Anna's probably the right person to ping. Jordan > On Sep 17, 2015, at 6:57 , Aaron Ballman wrote: > > Sorry to resurrect an ancient commit, but... > > On Tue, Jan 8, 2013 at 2:29 PM, Jordan Rose wrote: >> Author: jrose >> Date: Tue Jan 8 13:29:37 2013 >> New Revision: 171885 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=171885&view=rev >> Log: >> Various tweaks and updates to the analyzer website. >> >> Modified: >>cfe/trunk/www/analyzer/annotations.html >>cfe/trunk/www/analyzer/available_checks.html >>cfe/trunk/www/analyzer/dev_cxx.html >>cfe/trunk/www/analyzer/index.html >>cfe/trunk/www/analyzer/xcode.html >> >> Modified: cfe/trunk/www/analyzer/annotations.html > > > >> >> Modified: cfe/trunk/www/analyzer/xcode.html >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/www/analyzer/xcode.html?rev=171885&r1=171884&r2=171885&view=diff >> == >> --- cfe/trunk/www/analyzer/xcode.html (original) >> +++ cfe/trunk/www/analyzer/xcode.html Tue Jan 8 13:29:37 2013 >> @@ -2,7 +2,7 @@ >> "http://www.w3.org/TR/html4/strict.dtd";> >> >> >> - Build and Analyze: running the analyzer within Xcode >> + Running the analyzer within Xcode >> >> >> >> @@ -14,15 +14,16 @@ >> >> >> >> -Build and Analyze: running the analyzer within Xcode >> +Running the analyzer within Xcode >> >> > cellspacing="0"> >> >> >> What is it? >> -Build and Analyze is an Xcode feature (introduced in Xcode 3.2) >> that >> -allows users to run the Clang Static Analyzer > -href="http://developer.apple.com/mac/library/featuredarticles/StaticAnalysis/index.html";>directly >> + >> +Since Xcode 3.2, users have been able to run the Clang Static Analyzer >> +> +href="https://developer.apple.com/library/mac/documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/060-Debug_Your_App/debug_app.html#//apple_ref/doc/uid/TP40010215-CH3-SW17";>directly >> within Xcode. > > This link is currently broken, and I do not know what the replacement > link should be. > >> It integrates directly with the Xcode build system and >> @@ -45,23 +46,24 @@ >> single keystroke or mouse click. >> Transparency: Works effortlessly with Xcode projects (including >> iPhone projects). >> Cons: Doesn't work well with non-Xcode projects. For those, >> - consider using scan-build. >> + consider using scan-build. >> >> >> >> Getting Started >> >> -Xcode 3.2 is available as a free download from Apple, with > -href="http://developer.apple.com/mac/library/featuredarticles/StaticAnalysis/index.html";>instructions >> available >> -for using Build and Analyze. >> +Xcode is available as a free download from Apple on the > +href="https://itunes.apple.com/us/app/xcode/id497799835?mt=12";>Mac >> +App Store, with > +href="https://developer.apple.com/library/mac/documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/060-> >> >> Debug_Your_App/debug_app.html#//apple_ref/doc/uid/TP40010215-CH3-SW17">instructions >> +available for using the analyzer. > > Same with this link. > > ~Aaron > > On Tue, Jan 8, 2013 at 2:29 PM, Jordan Rose wrote: >> Author: jrose >> Date: Tue Jan 8 13:29:37 2013 >> New Revision: 171885 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=171885&view=rev >> Log: >> Various tweaks and updates to the analyzer website. >> >> Modified: >>cfe/trunk/www/analyzer/annotations.html >>cfe/trunk/www/analyzer/available_checks.html >>cfe/trunk/www/analyzer/dev_cxx.html >>cfe/trunk/www/analyzer/index.html >>cfe/trunk/www/analyzer/xcode.html >> >> Modified: cfe/trunk/www/analyzer/annotations.html >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/www/analyzer/annotations.html?rev=171885&r1=171884&r2=171885&view=diff >> == >> --- cfe/trunk/www/analyzer/annotations.html (original) >> +++ cfe/trunk/www/analyzer/annotations.html Tue Jan 8 13:29:37 2013 >> @@ -127,7 +127,10 @@ >> >> One can educate the analyzer (and others who read your code) about >> methods or >> functions that deviate from the Cocoa and Core Foundation conventions using >> the >> -attributes described here. >> +attributes described here. However, you should consider using proper naming >> +conventions or the > +href="http://clang.llvm.org/docs/LanguageExtensions.html#the-objc-method-family-attribute";>objc_method_family >> +attribute, if applicable. >> >> Attribute 'ns_returns_retained' >> (Clang-specific) >> @@ -135,7 +138,9 @@ >> The GCC-style (Clang-specific) attribute 'ns_returns_retained' allows one >> to >> annotate an Objective-C method or C function as returning a retained Cocoa >> object that the caller is responsible for releasing (via sending a >> -release message to the object). >> +release message to the object). The Foundation framework defines a >> +macro NS_RETURNS_RETAINED that is funct
Re: [PATCH] D13453: Always generate cmake config files
jordan_rose resigned from this revision. jordan_rose edited reviewers, added: beanz; removed: jordan_rose. jordan_rose added a comment. I just get things to build with CMake, and I'm not involved with Clang so much these days. This is more about controlling what gets installed, which should be covered by someone else. ChrisB is spearheading the effort to ditch autoconf, so adding him instead. http://reviews.llvm.org/D13453 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13973: CFG: Delay creating Dtors for CompoundStmts which end in ReturnStmt
jordan_rose added a subscriber: dcoughlin. jordan_rose added a comment. Hm. On the one hand, getting this right seems like a nice property, and even adding another loop wouldn't change the order of growth. On the other hand, not having the extra destructors seems like the same sort of property as not having unreachable statements, and if you //do// have unreachable statements then also having unreachable destructors seems reasonably consistent. Devin, what would you think? http://reviews.llvm.org/D13973 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D14277: [Analyzer] Make referenced SymbolMetadata live even if its region is dead
jordan_rose added a comment. The intent here was that a metadata symbol represents //metadata about a region.// That means if the region is dead, and the symbol isn't directly referenceable, we won't be able to recreate it. The advantage of `&&` was that checkers didn't have to track when regions were no longer live. Of course, the example shows that a symbol doesn't have to be directly referenceable to be used, so it didn't exactly pan out. But making this change without a corresponding change to every checker using metadata symbols (in-tree, just CStringChecker) means that those checkers will now keep the symbols alive forever. (And if we wanted to do that, we wouldn't have to use `markInUse`; just `markLive`.) I think this needs a little more thought. Repository: rL LLVM http://reviews.llvm.org/D14277 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D5102: [analyzer][Bugfix/improvement] Fix for PR16833
jordan_rose added a comment. I guess the regular pings didn't work, so it was worth trying the gentle one? Sorry! This seems mostly ready to me, but I still have a few comments. Comment at: lib/StaticAnalyzer/Core/ExprEngine.cpp:1646-1650 @@ -1644,2 +1645,7 @@ DefinedOrUnknownSVal CondV = CondV_untested.castAs(); + if (CondV.isUnknown()) { +CondV = state->getStateManager().getSValBuilder().conjureSymbolVal(nullptr, + CondE, LCtx, builder.getBuilderContext()->blockCount()); +state = state->BindExpr(CondE, LCtx, CondV); + } What's the purpose of this? As I understand it, a switch condition value will never be reused in later states, so there's no point in adding constraints to it unless it's already symbolic. (And not bothering to do this would remove the need to pass the NodeBuilderContext through.) Comment at: lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp:199-200 @@ +198,4 @@ +// Just add the constraint to the expression without trying to simplify. +SymbolRef Sym = Value.getAsSymExpr(); +return assumeSymWithinInclusiveRange(State, Sym, From, To, InRange); + } Will this ever return a null symbol? Maybe add an assertion? Comment at: lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp:215-220 @@ +214,8 @@ + return assumeSymWithinInclusiveRange(State, Sym, From, To, InRange); +return State; + } // end switch + + case nonloc::ConcreteIntKind: { +const llvm::APSInt &IntVal = Value.castAs().getValue(); +bool IsInRange = IntVal >= From && IntVal <= To; +bool isFeasible = (IsInRange == InRange); This is still relevant. Comment at: test/Analysis/switch-case.c:1 @@ +1,2 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=debug.ExprInspection -verify %s + All tests should include the "core" checkers. At some point we'll probably make that implicit, but for now please add that to the -analyzer-checker list. Comment at: test/Analysis/switch-case.c:24-25 @@ +23,4 @@ + case 3 ... 10: +clang_analyzer_eval(t > 1);// expected-warning{{TRUE}} +clang_analyzer_eval(t + 2 <= 11); // expected-warning{{TRUE}} +clang_analyzer_eval(t + 1 == 3); // expected-warning{{UNKNOWN}} Can you include at least one more check here: `clang_analyzer_eval(t > 2)`? (Which should be unknown.) Comment at: test/Analysis/switch-case.c:122 @@ +121,3 @@ + +void testDefaultBrachRange(int arg) { + switch (arg) { Typo: "Brach" http://reviews.llvm.org/D5102 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D11842: [analyzer]Don't issue alarm in ObjCSuperCallChecker for the super class itself.
jordan_rose accepted this revision. jordan_rose added a comment. This revision is now accepted and ready to land. Thanks for fixing this. http://reviews.llvm.org/D11842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D21111: Avoid accessing an invalid PresumedLoc
jordan_rose created this revision. jordan_rose added a reviewer: rsmith. jordan_rose added a subscriber: cfe-commits. jordan_rose set the repository for this revision to rL LLVM. DiagnosticNoteRenderer asserts trying to emit its "while building module Foo imported from bar.h:5" note when the presumed location of the import is invalid. This assertion was added in r267914, where //most// uses of `getFilename` were updated to test `isValid` instead. I can't come up with a test because this location is always valid in C-based code, but external clients that manually import modules (*cough*Swift*cough*) sometimes provide invalid SourceLocations. Repository: rL LLVM http://reviews.llvm.org/D2 Files: lib/Frontend/DiagnosticRenderer.cpp Index: lib/Frontend/DiagnosticRenderer.cpp === --- lib/Frontend/DiagnosticRenderer.cpp +++ lib/Frontend/DiagnosticRenderer.cpp @@ -618,7 +618,7 @@ // Generate a note indicating the include location. SmallString<200> MessageStorage; llvm::raw_svector_ostream Message(MessageStorage); - if (PLoc.getFilename()) + if (PLoc.isValid()) Message << "while building module '" << ModuleName << "' imported from " << PLoc.getFilename() << ':' << PLoc.getLine() << ":"; else Index: lib/Frontend/DiagnosticRenderer.cpp === --- lib/Frontend/DiagnosticRenderer.cpp +++ lib/Frontend/DiagnosticRenderer.cpp @@ -618,7 +618,7 @@ // Generate a note indicating the include location. SmallString<200> MessageStorage; llvm::raw_svector_ostream Message(MessageStorage); - if (PLoc.getFilename()) + if (PLoc.isValid()) Message << "while building module '" << ModuleName << "' imported from " << PLoc.getFilename() << ':' << PLoc.getLine() << ":"; else ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21111: Avoid accessing an invalid PresumedLoc
jordan_rose added a comment. *ping* I'm happy to have someone else review this (or "LGTM" this), but it's so small that I'm not sure who else to ask. I'd rather not just commit it cause it's been a while since I've touched Clang. Repository: rL LLVM http://reviews.llvm.org/D2 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r273976 - Avoid accessing an invalid PresumedLoc.
Author: jrose Date: Mon Jun 27 20:02:31 2016 New Revision: 273976 URL: http://llvm.org/viewvc/llvm-project?rev=273976&view=rev Log: Avoid accessing an invalid PresumedLoc. DiagnosticNoteRenderer asserts trying to emit its "while building module Foo imported from bar.h:5" note when the presumed location of the import is invalid. This assertion was added in r267914, where most uses of 'getFilename' were updated to test 'isValid' instead. This one must have been missed. I can't come up with a test because this location is always valid in C-based code, but external clients that manually import modules (*cough*Swift*cough*) sometimes provide invalid SourceLocations. rdar://problem/26099576 http://reviews.llvm.org/D2 Modified: cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp Modified: cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp?rev=273976&r1=273975&r2=273976&view=diff == --- cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp (original) +++ cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp Mon Jun 27 20:02:31 2016 @@ -618,7 +618,7 @@ DiagnosticNoteRenderer::emitBuildingModu // Generate a note indicating the include location. SmallString<200> MessageStorage; llvm::raw_svector_ostream Message(MessageStorage); - if (PLoc.getFilename()) + if (PLoc.isValid()) Message << "while building module '" << ModuleName << "' imported from " << PLoc.getFilename() << ':' << PLoc.getLine() << ":"; else ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21111: Avoid accessing an invalid PresumedLoc
jordan_rose closed this revision. jordan_rose added a comment. Committed as r273976. Repository: rL LLVM http://reviews.llvm.org/D2 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r263295 - Fix ObjCMethodDecl::findPropertyDecl for class properties.
Author: jrose Date: Fri Mar 11 15:14:40 2016 New Revision: 263295 URL: http://llvm.org/viewvc/llvm-project?rev=263295&view=rev Log: Fix ObjCMethodDecl::findPropertyDecl for class properties. This affects code completion and a few other things; hopefully the code completion test is sufficient to catch regressions. Added: cfe/trunk/test/CodeCompletion/documentation.m Modified: cfe/trunk/lib/AST/DeclObjC.cpp Modified: cfe/trunk/lib/AST/DeclObjC.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=263295&r1=263294&r2=263295&view=diff == --- cfe/trunk/lib/AST/DeclObjC.cpp (original) +++ cfe/trunk/lib/AST/DeclObjC.cpp Fri Mar 11 15:14:40 2016 @@ -1234,23 +1234,29 @@ ObjCMethodDecl::findPropertyDecl(bool Ch if (NumArgs > 1) return nullptr; - if (!isInstanceMethod()) -return nullptr; - if (isPropertyAccessor()) { const ObjCContainerDecl *Container = cast(getParent()); bool IsGetter = (NumArgs == 0); +bool IsInstance = isInstanceMethod(); /// Local function that attempts to find a matching property within the /// given Objective-C container. auto findMatchingProperty = [&](const ObjCContainerDecl *Container) -> const ObjCPropertyDecl * { - - for (const auto *I : Container->instance_properties()) { -Selector NextSel = IsGetter ? I->getGetterName() -: I->getSetterName(); -if (NextSel == Sel) - return I; + if (IsInstance) { +for (const auto *I : Container->instance_properties()) { + Selector NextSel = IsGetter ? I->getGetterName() + : I->getSetterName(); + if (NextSel == Sel) +return I; +} + } else { +for (const auto *I : Container->class_properties()) { + Selector NextSel = IsGetter ? I->getGetterName() + : I->getSetterName(); + if (NextSel == Sel) +return I; +} } return nullptr; Added: cfe/trunk/test/CodeCompletion/documentation.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/documentation.m?rev=263295&view=auto == --- cfe/trunk/test/CodeCompletion/documentation.m (added) +++ cfe/trunk/test/CodeCompletion/documentation.m Fri Mar 11 15:14:40 2016 @@ -0,0 +1,25 @@ +// Note: the run lines follow their respective tests, since line/column +// matter in this test. + +@interface Base +@end + +@interface Test : Base +/// Instance! +@property id instanceProp; +/// Class! +@property (class) id classProp; +@end + +void test(Test *obj) { + [obj instanceProp]; + [Test classProp]; +} + +// RUN: %clang_cc1 -fsyntax-only -code-completion-brief-comments -code-completion-at=%s:15:8 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s +// CHECK-CC1: instanceProp : [#id#]instanceProp : Instance! +// CHECK-CC1: setInstanceProp: : [#void#]setInstanceProp:<#(id)#> : Instance! + +// RUN: %clang_cc1 -fsyntax-only -code-completion-brief-comments -code-completion-at=%s:16:9 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s +// CHECK-CC2: classProp : [#id#]classProp : Class! +// CHECK-CC2: setClassProp: : [#void#]setClassProp:<#(id)#> : Class! ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D18268: [Objective-c] Fix a crash in WeakObjectProfileTy::getBaseInfo
jordan_rose accepted this revision. jordan_rose added a comment. This revision is now accepted and ready to land. Ah, of course! Thanks for catching this, Akira. Can you add this case to the table in the doc comment for WeakObjectProfileTy? (That's how I convinced myself it was correct.) http://reviews.llvm.org/D18268 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D18268: [Objective-c] Fix a crash in WeakObjectProfileTy::getBaseInfo
No, that case worked already. The case you fixed is the one where Base is 'foo' and Property is 'prop'…and actually, thinking more about it, this should not be considered "exact". *sigh* The point of "exact" is "if you see this Base and Property again, are you sure it's really the same Base?". I thought the answer was yes because the receiver is a class and the property identifies the class, but unfortunately it could be a subclass (i.e. "NSResponder.classProp.prop" vs. "NSView.classProp.prop"). These might use the same declaration (and even definition) for 'classProp' but nonetheless return different values. We could ignore this whole thing if we stored an arbitrary-length key, but there's diminishing returns there and this is already not a cheap check. Please change it to set IsExact to false (and update the table). Jordan > On Mar 18, 2016, at 12:21 , Akira Hatanaka wrote: > > Thanks Jordan. I’ve committed the patch in r263818. > > I didn’t understand your comment on WeakObjectProfileTy’s table (I’m assuming > you are talking about the table in ScopeInfo.h:183). It looks like the entry > MyClass.prop in the table already covers the case this patch fixed (in the > test case I added, Base is NSBundle and Property is the method “foo”)? > >> On Mar 18, 2016, at 9:55 AM, Jordan Rose via cfe-commits >> wrote: >> >> jordan_rose accepted this revision. >> jordan_rose added a comment. >> This revision is now accepted and ready to land. >> >> Ah, of course! Thanks for catching this, Akira. Can you add this case to the >> table in the doc comment for WeakObjectProfileTy? (That's how I convinced >> myself it was correct.) >> >> >> http://reviews.llvm.org/D18268 >> >> >> >> ___ >> cfe-commits mailing list >> cfe-commits@lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D18268: [Objective-c] Fix a crash in WeakObjectProfileTy::getBaseInfo
Yes, that looks good. For bonus points, add a similar test using the new property syntax @property (class) NSBundle *foo2; instead of the method. (I expect that version to behave nearly the same, including the "may" in the diagnostic.) Jordan > On Mar 21, 2016, at 12:36, Akira Hatanaka wrote: > > Jordan, > > Does the attached patch look OK? > >> On Mar 18, 2016, at 1:19 PM, Jordan Rose > <mailto:jordan_r...@apple.com>> wrote: >> >> No, that case worked already. The case you fixed is the one where Base is >> 'foo' and Property is 'prop'…and actually, thinking more about it, this >> should not be considered "exact". *sigh* The point of "exact" is "if you see >> this Base and Property again, are you sure it's really the same Base?". I >> thought the answer was yes because the receiver is a class and the property >> identifies the class, but unfortunately it could be a subclass (i.e. >> "NSResponder.classProp.prop" vs. "NSView.classProp.prop"). These might use >> the same declaration (and even definition) for 'classProp' but nonetheless >> return different values. >> >> We could ignore this whole thing if we stored an arbitrary-length key, but >> there's diminishing returns there and this is already not a cheap check. >> >> Please change it to set IsExact to false (and update the table). >> >> Jordan >> >> >>> On Mar 18, 2016, at 12:21 , Akira Hatanaka >> <mailto:ahatan...@apple.com>> wrote: >>> >>> Thanks Jordan. I’ve committed the patch in r263818. >>> >>> I didn’t understand your comment on WeakObjectProfileTy’s table (I’m >>> assuming you are talking about the table in ScopeInfo.h:183). It looks like >>> the entry MyClass.prop in the table already covers the case this patch >>> fixed (in the test case I added, Base is NSBundle and Property is the >>> method “foo”)? >>> >>>> On Mar 18, 2016, at 9:55 AM, Jordan Rose via cfe-commits >>>> mailto:cfe-commits@lists.llvm.org>> wrote: >>>> >>>> jordan_rose accepted this revision. >>>> jordan_rose added a comment. >>>> This revision is now accepted and ready to land. >>>> >>>> Ah, of course! Thanks for catching this, Akira. Can you add this case to >>>> the table in the doc comment for WeakObjectProfileTy? (That's how I >>>> convinced myself it was correct.) >>>> >>>> >>>> http://reviews.llvm.org/D18268 <http://reviews.llvm.org/D18268> >>>> >>>> >>>> >>>> ___ >>>> cfe-commits mailing list >>>> cfe-commits@lists.llvm.org <mailto:cfe-commits@lists.llvm.org> >>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits >>> >> > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13973: CFG: Delay creating Dtors for CompoundStmts which end in ReturnStmt
jordan_rose accepted this revision. jordan_rose added a comment. This revision is now accepted and ready to land. Let's just go with your simple version that makes the common case better. There are a lot of problems with `throw`, so I wouldn't worry about that right now. (By the way, we don't remove unreachable blocks because we want to be able to diagnose unreachable code.) http://reviews.llvm.org/D13973 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D14277: [Analyzer] Make referenced SymbolMetadata live even if its region is dead
jordan_rose added a comment. So we just throw out the whole notion of "metadata in use"? That can work. There are two things I'd be concerned about changing here: - What happens when you take a string's length, test it against something, throw it away, then remeasure the string? In this case we'd be okay because CStringChecker still hangs on to the symbol in its map until the region is invalidated. - Will we keep more symbols alive than we did previously, increasing the analyzer's memory use? I think the answer is "yes", but not by very much: the live/dead checking is two-pass, so we'll mark a metadata symbol live in `checkLiveSymbols` but then find out we could have dropped it in `checkDeadSymbols` when the region is found to be dead. It'll get cleaned up the next time around, but I think that sort of conditional liveness is what the old mechanism was trying to accomplish. Do you have any ideas for how we could make that better? I can think of a complicated case where you use `markInUse` if the metadata symbol exactly matches the key, but `markLive` otherwise…but at some point I'm not sure it's worth the complexity cost. (In particular, after this change, I'm not sure metadata symbols behave any differently from regular conjured symbols. This is a good thing.) (We've also talked about having better REGISTER_MAP_WITH_PROGRAMSTATE that auto-remove any keys for dead symbols or dead regions. I'm sure Anna and Devin would be happy to see someone pick that up.) Comment at: lib/StaticAnalyzer/Checkers/CStringChecker.cpp:2137-2141 @@ -2139,10 +2136,7 @@ - CStringLengthTy::Factory &F = state->get_context(); - for (CStringLengthTy::iterator I = Entries.begin(), E = Entries.end(); - I != E; ++I) { -SVal Len = I.getData(); -if (SymbolRef Sym = Len.getAsSymbol()) { - if (SR.isDead(Sym)) -Entries = F.remove(Entries, I.getKey()); -} + auto &F = state->get_context(); + for (auto I = Entries.begin(), E = Entries.end(); I != E; ++I) { +const MemRegion *MR = I.getKey(); +if (!SR.isLiveRegion(MR)) + Entries = F.remove(Entries, MR); } Huh, this is probably an improvement anyway! Repository: rL LLVM http://reviews.llvm.org/D14277 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits