[PATCH] D45045: [DebugInfo] Generate debug information for labels.
HsiangKai added a comment. In https://reviews.llvm.org/D45045#1247427, @vitalybuka wrote: > Reverted in r343183 > https://bugs.llvm.org/show_bug.cgi?id=39094 > > http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-autoconf/builds/29356/steps/build%20release%20tsan%20with%20clang/logs/stdio I have fixed the bug in https://reviews.llvm.org/D52927 and it has landed in master branch. Could I recommit this patch? Repository: rL LLVM https://reviews.llvm.org/D45045 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53487: [Driver] Support sanitized libraries on Fuchsia
phosek created this revision. phosek added a reviewer: mcgrathr. Herald added a subscriber: cfe-commits. When using sanitizers, add //lib/ to the list of library paths to support using sanitized version of runtime libraries if available. Repository: rC Clang https://reviews.llvm.org/D53487 Files: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Driver/ToolChains/CommonArgs.h clang/lib/Driver/ToolChains/Fuchsia.cpp clang/test/Driver/fuchsia.c Index: clang/test/Driver/fuchsia.c === --- clang/test/Driver/fuchsia.c +++ clang/test/Driver/fuchsia.c @@ -66,22 +66,28 @@ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: -fuse-ld=lld \ // RUN: | FileCheck %s -check-prefix=CHECK-ASAN-X86 +// CHECK-ASAN-X86: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" // CHECK-ASAN-X86: "-fsanitize=address" // CHECK-ASAN-X86: "-fsanitize-address-globals-dead-stripping" // CHECK-ASAN-X86: "-dynamic-linker" "asan/ld.so.1" -// CHECK-ASAN-X86: "{{.*[/\\]}}libclang_rt.asan.so" -// CHECK-ASAN-X86: "{{.*[/\\]}}libclang_rt.asan-preinit.a" +// CHECK-ASAN-X86: "-L[[RESOURCE_DIR]]{{/|}}x86_64-fuchsia{{/|}}lib{{/|}}asan" +// CHECK-ASAN-X86: "-L[[RESOURCE_DIR]]{{/|}}x86_64-fuchsia{{/|}}lib" +// CHECK-ASAN-X86: "[[RESOURCE_DIR]]{{/|}}x86_64-fuchsia{{/|}}lib{{/|}}libclang_rt.asan.so" +// CHECK-ASAN-X86: "[[RESOURCE_DIR]]{{/|}}x86_64-fuchsia{{/|}}lib{{/|}}libclang_rt.asan-preinit.a" // RUN: %clang %s -### --target=aarch64-fuchsia \ // RUN: -fsanitize=address 2>&1 \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: -fuse-ld=lld \ // RUN: | FileCheck %s -check-prefix=CHECK-ASAN-AARCH64 +// CHECK-ASAN-AARCH64: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" // CHECK-ASAN-AARCH64: "-fsanitize=address" // CHECK-ASAN-AARCH64: "-fsanitize-address-globals-dead-stripping" // CHECK-ASAN-AARCH64: "-dynamic-linker" "asan/ld.so.1" -// CHECK-ASAN-AARCH64: "{{.*[/\\]}}libclang_rt.asan.so" -// CHECK-ASAN-AARCH64: "{{.*[/\\]}}libclang_rt.asan-preinit.a" +// CHECK-ASAN-AARCH64: "-L[[RESOURCE_DIR]]{{/|}}aarch64-fuchsia{{/|}}lib{{/|}}asan" +// CHECK-ASAN-AARCH64: "-L[[RESOURCE_DIR]]{{/|}}aarch64-fuchsia{{/|}}lib" +// CHECK-ASAN-AARCH64: "[[RESOURCE_DIR]]{{/|}}aarch64-fuchsia{{/|}}lib{{/|}}libclang_rt.asan.so" +// CHECK-ASAN-AARCH64: "[[RESOURCE_DIR]]{{/|}}aarch64-fuchsia{{/|}}lib{{/|}}libclang_rt.asan-preinit.a" // RUN: %clang %s -### --target=x86_64-fuchsia \ // RUN: -fsanitize=address -fPIC -shared 2>&1 \ Index: clang/lib/Driver/ToolChains/Fuchsia.cpp === --- clang/lib/Driver/ToolChains/Fuchsia.cpp +++ clang/lib/Driver/ToolChains/Fuchsia.cpp @@ -9,7 +9,6 @@ #include "Fuchsia.h" #include "CommonArgs.h" -#include "clang/Basic/VirtualFileSystem.h" #include "clang/Config/config.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" @@ -100,16 +99,7 @@ Args.AddAllArgs(CmdArgs, options::OPT_L); Args.AddAllArgs(CmdArgs, options::OPT_u); - if (SanArgs.needsAsanRt()) { -for (const auto &LibPath : ToolChain.getLibraryPaths()) { - if(LibPath.length() > 0) { -SmallString<128> P(LibPath); -llvm::sys::path::append(P, "asan"); -if (ToolChain.getVFS().exists(P)) - CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath)); - } -} - } + addSanitizerPathLibArgs(ToolChain, Args, CmdArgs); ToolChain.AddFilePathLibArgs(Args, CmdArgs); Index: clang/lib/Driver/ToolChains/CommonArgs.h === --- clang/lib/Driver/ToolChains/CommonArgs.h +++ clang/lib/Driver/ToolChains/CommonArgs.h @@ -32,6 +32,10 @@ bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs); +void addSanitizerPathLibArgs(const ToolChain &TC, + const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs); + void linkSanitizerRuntimeDeps(const ToolChain &TC, llvm::opt::ArgStringList &CmdArgs); Index: clang/lib/Driver/ToolChains/CommonArgs.cpp === --- clang/lib/Driver/ToolChains/CommonArgs.cpp +++ clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -560,6 +560,40 @@ return false; } +static void addSanitizerLibPath(const ToolChain &TC, const ArgList &Args, +ArgStringList &CmdArgs, StringRef Name) { + for (const auto &LibPath : TC.getLibraryPaths()) { +if(LibPath.length() > 0) { + SmallString<128> P(LibPath); + llvm::sys::path::append(P, Name); + if (TC.getVFS().exists(P)) +CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + P)); +} +
[PATCH] D53392: [RISCV] Collect library directories and triples for riscv64 triple too
edward-jones updated this revision to Diff 170373. edward-jones added a comment. I've incorporated your suggested changes and added riscv32/64-linux-gnu entrys to the Triple + LibDirs lists. Is it worth also updating the riscv32-toolchain.c test in this patch to rename riscv32-linux-unknown-elf to riscv32-unknown-linux-gnu? It looks like "riscv32-linux-unknown-elf" has been there since the the driver was introduced. https://reviews.llvm.org/D53392 Files: lib/Driver/ToolChains/Gnu.cpp test/Driver/Inputs/basic_riscv64_tree/bin/riscv64-unknown-elf-ld test/Driver/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/crtbegin.o test/Driver/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/crtend.o test/Driver/Inputs/basic_riscv64_tree/riscv64-unknown-elf/include/c++/8.0.1/.keep test/Driver/Inputs/basic_riscv64_tree/riscv64-unknown-elf/lib/crt0.o test/Driver/riscv64-toolchain.c Index: test/Driver/riscv64-toolchain.c === --- test/Driver/riscv64-toolchain.c +++ test/Driver/riscv64-toolchain.c @@ -3,6 +3,102 @@ // RUN: %clang %s -### -no-canonical-prefixes -target riscv64 2>&1 | FileCheck -check-prefix=CC1 %s // CC1: clang{{.*}} "-cc1" "-triple" "riscv64" +// RUN: %clang %s -### -no-canonical-prefixes \ +// RUN: -target riscv64-unknown-elf \ +// RUN: --gcc-toolchain=%S/Inputs/basic_riscv64_tree \ +// RUN: --sysroot=%S/Inputs/basic_riscv64_tree/riscv64-unknown-elf 2>&1 \ +// RUN: | FileCheck -check-prefix=C-RV64-BAREMETAL-LP64 %s + +// C-RV64-BAREMETAL-LP64: "-fuse-init-array" +// C-RV64-BAREMETAL-LP64: "{{.*}}Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/../../../../bin{{/|}}riscv64-unknown-elf-ld" +// C-RV64-BAREMETAL-LP64: "--sysroot={{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf" +// C-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf/lib{{/|}}crt0.o" +// C-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtbegin.o" +// C-RV64-BAREMETAL-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf/lib" +// C-RV64-BAREMETAL-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1" +// C-RV64-BAREMETAL-LP64: "--start-group" "-lc" "-lgloss" "--end-group" "-lgcc" +// C-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o" + +// RUN: %clang %s -### -no-canonical-prefixes \ +// RUN: -target riscv64-unknown-elf \ +// RUN: --sysroot= \ +// RUN: --gcc-toolchain=%S/Inputs/basic_riscv64_tree 2>&1 \ +// RUN: | FileCheck -check-prefix=C-RV64-BAREMETAL-NOSYSROOT-LP64 %s + +// C-RV64-BAREMETAL-NOSYSROOT-LP64: "-fuse-init-array" +// C-RV64-BAREMETAL-NOSYSROOT-LP64: "{{.*}}Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/../../../../bin{{/|}}riscv64-unknown-elf-ld" +// C-RV64-BAREMETAL-NOSYSROOT-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/../../../../riscv64-unknown-elf/lib{{/|}}crt0.o" +// C-RV64-BAREMETAL-NOSYSROOT-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtbegin.o" +// C-RV64-BAREMETAL-NOSYSROOT-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/../../../../riscv64-unknown-elf{{/|}}lib" +// C-RV64-BAREMETAL-NOSYSROOT-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1" +// C-RV64-BAREMETAL-NOSYSROOT-LP64: "--start-group" "-lc" "-lgloss" "--end-group" "-lgcc" +// C-RV64-BAREMETAL-NOSYSROOT-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o" + +// RUN: %clangxx %s -### -no-canonical-prefixes \ +// RUN: -target riscv64-unknown-elf -stdlib=libstdc++ \ +// RUN: --gcc-toolchain=%S/Inputs/basic_riscv64_tree \ +// RUN: --sysroot=%S/Inputs/basic_riscv64_tree/riscv64-unknown-elf 2>&1 \ +// RUN: | FileCheck -check-prefix=CXX-RV64-BAREMETAL-LP64 %s + +// CXX-RV64-BAREMETAL-LP64: "-fuse-init-array" +// CXX-RV64-BAREMETAL-LP64: "-internal-isystem" "{{.*}}Inputs/basic_riscv64_tree/riscv64-unknown-elf/include/c++{{/|}}8.0.1" +// CXX-RV64-BAREMETAL-LP64: "{{.*}}Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/../../../../bin{{/|}}riscv64-unknown-elf-ld" +// CXX-RV64-BAREMETAL-LP64: "--sysroot={{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf" +// CXX-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf/lib{{/|}}crt0.o" +// CXX-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtbegin.o" +// CXX-RV64-BAREMETAL-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf/lib" +// CXX-RV64-BAREMETAL-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1" +// CXX-RV64-BAREMETAL-LP64: "-lstdc++" "--start-group" "-lc" "-lgloss" "--end-group" "-lgcc" +// CXX-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{
[PATCH] D53392: [RISCV] Collect library directories and triples for riscv64 triple too
edward-jones updated this revision to Diff 170374. edward-jones marked 2 inline comments as done. https://reviews.llvm.org/D53392 Files: lib/Driver/ToolChains/Gnu.cpp test/Driver/Inputs/basic_riscv64_tree/bin/riscv64-unknown-elf-ld test/Driver/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/crtbegin.o test/Driver/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/crtend.o test/Driver/Inputs/basic_riscv64_tree/riscv64-unknown-elf/include/c++/8.0.1/.keep test/Driver/Inputs/basic_riscv64_tree/riscv64-unknown-elf/lib/crt0.o test/Driver/riscv64-toolchain.c Index: test/Driver/riscv64-toolchain.c === --- test/Driver/riscv64-toolchain.c +++ test/Driver/riscv64-toolchain.c @@ -3,6 +3,102 @@ // RUN: %clang %s -### -no-canonical-prefixes -target riscv64 2>&1 | FileCheck -check-prefix=CC1 %s // CC1: clang{{.*}} "-cc1" "-triple" "riscv64" +// RUN: %clang %s -### -no-canonical-prefixes \ +// RUN: -target riscv64-unknown-elf \ +// RUN: --gcc-toolchain=%S/Inputs/basic_riscv64_tree \ +// RUN: --sysroot=%S/Inputs/basic_riscv64_tree/riscv64-unknown-elf 2>&1 \ +// RUN: | FileCheck -check-prefix=C-RV64-BAREMETAL-LP64 %s + +// C-RV64-BAREMETAL-LP64: "-fuse-init-array" +// C-RV64-BAREMETAL-LP64: "{{.*}}Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/../../../../bin{{/|}}riscv64-unknown-elf-ld" +// C-RV64-BAREMETAL-LP64: "--sysroot={{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf" +// C-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf/lib{{/|}}crt0.o" +// C-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtbegin.o" +// C-RV64-BAREMETAL-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf/lib" +// C-RV64-BAREMETAL-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1" +// C-RV64-BAREMETAL-LP64: "--start-group" "-lc" "-lgloss" "--end-group" "-lgcc" +// C-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o" + +// RUN: %clang %s -### -no-canonical-prefixes \ +// RUN: -target riscv64-unknown-elf \ +// RUN: --sysroot= \ +// RUN: --gcc-toolchain=%S/Inputs/basic_riscv64_tree 2>&1 \ +// RUN: | FileCheck -check-prefix=C-RV64-BAREMETAL-NOSYSROOT-LP64 %s + +// C-RV64-BAREMETAL-NOSYSROOT-LP64: "-fuse-init-array" +// C-RV64-BAREMETAL-NOSYSROOT-LP64: "{{.*}}Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/../../../../bin{{/|}}riscv64-unknown-elf-ld" +// C-RV64-BAREMETAL-NOSYSROOT-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/../../../../riscv64-unknown-elf/lib{{/|}}crt0.o" +// C-RV64-BAREMETAL-NOSYSROOT-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtbegin.o" +// C-RV64-BAREMETAL-NOSYSROOT-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/../../../../riscv64-unknown-elf{{/|}}lib" +// C-RV64-BAREMETAL-NOSYSROOT-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1" +// C-RV64-BAREMETAL-NOSYSROOT-LP64: "--start-group" "-lc" "-lgloss" "--end-group" "-lgcc" +// C-RV64-BAREMETAL-NOSYSROOT-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o" + +// RUN: %clangxx %s -### -no-canonical-prefixes \ +// RUN: -target riscv64-unknown-elf -stdlib=libstdc++ \ +// RUN: --gcc-toolchain=%S/Inputs/basic_riscv64_tree \ +// RUN: --sysroot=%S/Inputs/basic_riscv64_tree/riscv64-unknown-elf 2>&1 \ +// RUN: | FileCheck -check-prefix=CXX-RV64-BAREMETAL-LP64 %s + +// CXX-RV64-BAREMETAL-LP64: "-fuse-init-array" +// CXX-RV64-BAREMETAL-LP64: "-internal-isystem" "{{.*}}Inputs/basic_riscv64_tree/riscv64-unknown-elf/include/c++{{/|}}8.0.1" +// CXX-RV64-BAREMETAL-LP64: "{{.*}}Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/../../../../bin{{/|}}riscv64-unknown-elf-ld" +// CXX-RV64-BAREMETAL-LP64: "--sysroot={{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf" +// CXX-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf/lib{{/|}}crt0.o" +// CXX-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtbegin.o" +// CXX-RV64-BAREMETAL-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf/lib" +// CXX-RV64-BAREMETAL-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1" +// CXX-RV64-BAREMETAL-LP64: "-lstdc++" "--start-group" "-lc" "-lgloss" "--end-group" "-lgcc" +// CXX-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o" + +// RUN: %clangxx %s -### -no-canonical-prefixes \ +// RUN: -target riscv64-unknown-elf -stdlib=libstdc++ \ +// RUN: --sysroot= \ +// RUN: --gcc-toolchain=%S/Inputs/basic_riscv64_tree 2>&1 \ +// RUN: | FileCheck -check-prefix=CXX-RV64-BAREMETAL-NOSYSROOT-LP64 %s + +// CXX-RV64-BAREMETAL-NOSYSROOT-L
r344889 - [CodeComplete] Fix accessibility of protected members when accessing members implicitly.
Author: ioeric Date: Mon Oct 22 01:47:31 2018 New Revision: 344889 URL: http://llvm.org/viewvc/llvm-project?rev=344889&view=rev Log: [CodeComplete] Fix accessibility of protected members when accessing members implicitly. Reviewers: ilya-biryukov Subscribers: arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D53369 Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp cfe/trunk/test/Index/complete-access-checks.cpp Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=344889&r1=344888&r2=344889&view=diff == --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original) +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Mon Oct 22 01:47:31 2018 @@ -3686,13 +3686,20 @@ void Sema::CodeCompleteOrdinaryName(Scop } // If we are in a C++ non-static member function, check the qualifiers on - // the member function to filter/prioritize the results list. - if (CXXMethodDecl *CurMethod = dyn_cast(CurContext)) -if (CurMethod->isInstance()) + // the member function to filter/prioritize the results list and set the + // context to the record context so that accessibility check in base class + // works correctly. + RecordDecl *MemberCompletionRecord = nullptr; + if (CXXMethodDecl *CurMethod = dyn_cast(CurContext)) { +if (CurMethod->isInstance()) { Results.setObjectTypeQualifiers( Qualifiers::fromCVRMask(CurMethod->getTypeQualifiers())); + MemberCompletionRecord = CurMethod->getParent(); +} + } - CodeCompletionDeclConsumer Consumer(Results, CurContext); + CodeCompletionDeclConsumer Consumer(Results, CurContext, /*FixIts=*/{}, + MemberCompletionRecord); LookupVisibleDecls(S, LookupOrdinaryName, Consumer, CodeCompleter->includeGlobals(), CodeCompleter->loadExternal()); Modified: cfe/trunk/test/Index/complete-access-checks.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-access-checks.cpp?rev=344889&r1=344888&r2=344889&view=diff == --- cfe/trunk/test/Index/complete-access-checks.cpp (original) +++ cfe/trunk/test/Index/complete-access-checks.cpp Mon Oct 22 01:47:31 2018 @@ -29,8 +29,11 @@ void Y::doSomething() { // RUN: c-index-test -code-completion-at=%s:30:9 %s | FileCheck -check-prefix=CHECK-SUPER-ACCESS %s this->; + // RUN: c-index-test -code-completion-at=%s:33:3 %s | FileCheck -check-prefix=CHECK-SUPER-ACCESS-IMPLICIT %s + + Z that; - // RUN: c-index-test -code-completion-at=%s:34:8 %s | FileCheck -check-prefix=CHECK-ACCESS %s + // RUN: c-index-test -code-completion-at=%s:37:8 %s | FileCheck -check-prefix=CHECK-ACCESS %s that. } @@ -48,6 +51,14 @@ void Y::doSomething() { // CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{Informative X::}{TypedText ~X}{LeftParen (}{RightParen )} (81) // CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{TypedText ~Y}{LeftParen (}{RightParen )} (79) +// CHECK-SUPER-ACCESS-IMPLICIT: CXXMethod:{ResultType void}{TypedText doSomething}{LeftParen (}{RightParen )} (34) +// CHECK-SUPER-ACCESS-IMPLICIT: CXXMethod:{ResultType void}{TypedText func1}{LeftParen (}{RightParen )} (36) +// CHECK-SUPER-ACCESS-IMPLICIT: CXXMethod:{ResultType void}{TypedText func2}{LeftParen (}{RightParen )} (36){{$}} +// CHECK-SUPER-ACCESS-IMPLICIT: CXXMethod:{ResultType void}{TypedText func3}{LeftParen (}{RightParen )} (36) (inaccessible) +// CHECK-SUPER-ACCESS-IMPLICIT: FieldDecl:{ResultType int}{TypedText member1} (37) +// CHECK-SUPER-ACCESS-IMPLICIT: FieldDecl:{ResultType int}{TypedText member2} (37){{$}} +// CHECK-SUPER-ACCESS-IMPLICIT: FieldDecl:{ResultType int}{TypedText member3} (37) (inaccessible) + // CHECK-ACCESS: CXXMethod:{ResultType void}{TypedText func1}{LeftParen (}{RightParen )} (34) // CHECK-ACCESS: CXXMethod:{ResultType void}{TypedText func2}{LeftParen (}{RightParen )} (34) (inaccessible) // CHECK-ACCESS: CXXMethod:{ResultType void}{TypedText func3}{LeftParen (}{RightParen )} (34) (inaccessible) @@ -69,9 +80,9 @@ public: }; void f(P x, Q y) { - // RUN: c-index-test -code-completion-at=%s:73:5 %s | FileCheck -check-prefix=CHECK-USING-INACCESSIBLE %s + // RUN: c-index-test -code-completion-at=%s:84:5 %s | FileCheck -check-prefix=CHECK-USING-INACCESSIBLE %s x.; // member is inaccessible - // RUN: c-index-test -code-completion-at=%s:75:5 %s | FileCheck -check-prefix=CHECK-USING-ACCESSIBLE %s + // RUN: c-index-test -code-completion-at=%s:86:5 %s | FileCheck -check-prefix=CHECK-USING-ACCESSIBLE %s y.; // member is accessible } @@ -102,11 +113,11 @@ class D : public C { }; void D::f(::B *that) { - // RUN: c-index-test -code-completion-at=%s:106:9 %s | FileCheck -check-prefix=CHECK-PRIVATE-SUPER-THIS %s + // RUN:
[PATCH] D53369: [CodeComplete] Fix accessibility of protected members when accessing members implicitly.
This revision was automatically updated to reflect the committed changes. Closed by commit rC344889: [CodeComplete] Fix accessibility of protected members when accessing members… (authored by ioeric, committed by ). Changed prior to commit: https://reviews.llvm.org/D53369?vs=169995&id=170377#toc Repository: rC Clang https://reviews.llvm.org/D53369 Files: lib/Sema/SemaCodeComplete.cpp test/Index/complete-access-checks.cpp Index: lib/Sema/SemaCodeComplete.cpp === --- lib/Sema/SemaCodeComplete.cpp +++ lib/Sema/SemaCodeComplete.cpp @@ -3686,13 +3686,20 @@ } // If we are in a C++ non-static member function, check the qualifiers on - // the member function to filter/prioritize the results list. - if (CXXMethodDecl *CurMethod = dyn_cast(CurContext)) -if (CurMethod->isInstance()) + // the member function to filter/prioritize the results list and set the + // context to the record context so that accessibility check in base class + // works correctly. + RecordDecl *MemberCompletionRecord = nullptr; + if (CXXMethodDecl *CurMethod = dyn_cast(CurContext)) { +if (CurMethod->isInstance()) { Results.setObjectTypeQualifiers( Qualifiers::fromCVRMask(CurMethod->getTypeQualifiers())); + MemberCompletionRecord = CurMethod->getParent(); +} + } - CodeCompletionDeclConsumer Consumer(Results, CurContext); + CodeCompletionDeclConsumer Consumer(Results, CurContext, /*FixIts=*/{}, + MemberCompletionRecord); LookupVisibleDecls(S, LookupOrdinaryName, Consumer, CodeCompleter->includeGlobals(), CodeCompleter->loadExternal()); Index: test/Index/complete-access-checks.cpp === --- test/Index/complete-access-checks.cpp +++ test/Index/complete-access-checks.cpp @@ -29,8 +29,11 @@ // RUN: c-index-test -code-completion-at=%s:30:9 %s | FileCheck -check-prefix=CHECK-SUPER-ACCESS %s this->; + // RUN: c-index-test -code-completion-at=%s:33:3 %s | FileCheck -check-prefix=CHECK-SUPER-ACCESS-IMPLICIT %s + + Z that; - // RUN: c-index-test -code-completion-at=%s:34:8 %s | FileCheck -check-prefix=CHECK-ACCESS %s + // RUN: c-index-test -code-completion-at=%s:37:8 %s | FileCheck -check-prefix=CHECK-ACCESS %s that. } @@ -48,6 +51,14 @@ // CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{Informative X::}{TypedText ~X}{LeftParen (}{RightParen )} (81) // CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{TypedText ~Y}{LeftParen (}{RightParen )} (79) +// CHECK-SUPER-ACCESS-IMPLICIT: CXXMethod:{ResultType void}{TypedText doSomething}{LeftParen (}{RightParen )} (34) +// CHECK-SUPER-ACCESS-IMPLICIT: CXXMethod:{ResultType void}{TypedText func1}{LeftParen (}{RightParen )} (36) +// CHECK-SUPER-ACCESS-IMPLICIT: CXXMethod:{ResultType void}{TypedText func2}{LeftParen (}{RightParen )} (36){{$}} +// CHECK-SUPER-ACCESS-IMPLICIT: CXXMethod:{ResultType void}{TypedText func3}{LeftParen (}{RightParen )} (36) (inaccessible) +// CHECK-SUPER-ACCESS-IMPLICIT: FieldDecl:{ResultType int}{TypedText member1} (37) +// CHECK-SUPER-ACCESS-IMPLICIT: FieldDecl:{ResultType int}{TypedText member2} (37){{$}} +// CHECK-SUPER-ACCESS-IMPLICIT: FieldDecl:{ResultType int}{TypedText member3} (37) (inaccessible) + // CHECK-ACCESS: CXXMethod:{ResultType void}{TypedText func1}{LeftParen (}{RightParen )} (34) // CHECK-ACCESS: CXXMethod:{ResultType void}{TypedText func2}{LeftParen (}{RightParen )} (34) (inaccessible) // CHECK-ACCESS: CXXMethod:{ResultType void}{TypedText func3}{LeftParen (}{RightParen )} (34) (inaccessible) @@ -69,9 +80,9 @@ }; void f(P x, Q y) { - // RUN: c-index-test -code-completion-at=%s:73:5 %s | FileCheck -check-prefix=CHECK-USING-INACCESSIBLE %s + // RUN: c-index-test -code-completion-at=%s:84:5 %s | FileCheck -check-prefix=CHECK-USING-INACCESSIBLE %s x.; // member is inaccessible - // RUN: c-index-test -code-completion-at=%s:75:5 %s | FileCheck -check-prefix=CHECK-USING-ACCESSIBLE %s + // RUN: c-index-test -code-completion-at=%s:86:5 %s | FileCheck -check-prefix=CHECK-USING-ACCESSIBLE %s y.; // member is accessible } @@ -102,11 +113,11 @@ }; void D::f(::B *that) { - // RUN: c-index-test -code-completion-at=%s:106:9 %s | FileCheck -check-prefix=CHECK-PRIVATE-SUPER-THIS %s + // RUN: c-index-test -code-completion-at=%s:117:9 %s | FileCheck -check-prefix=CHECK-PRIVATE-SUPER-THIS %s this->; // CHECK-PRIVATE-SUPER-THIS: FieldDecl:{ResultType int}{Informative B::}{TypedText member} (37) (inaccessible) - // RUN: c-index-test -code-completion-at=%s:110:9 %s | FileCheck -check-prefix=CHECK-PRIVATE-SUPER-THAT %s + // RUN: c-index-test -code-completion-at=%s:121:9 %s | FileCheck -check-prefix=CHECK-PRIVATE-SUPER-THAT %s that->; // CHECK-PRIVATE-SUPER-THAT: FieldDecl:{ResultType int}{TypedText member} (35) (in
[PATCH] D53483: [analyzer] Restrict AnalyzerOptions' interface so that non-checker objects have to be registered
xazax.hun added a comment. Overall looks good if the community agrees with the directions. Some comments inline. Comment at: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h:243 + /// specified. + StringRef getStringOption(StringRef Name, StringRef DefaultVal); If you want the devs to maintain an explicit getter for each analyzer option rather than making this one public at some point, please document expectation this somewhere. Comment at: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp:157 + .getAsInteger(10, Ret); + assert(!HasFailed && "analyzer-config option should be numeric"); + (void)HasFailed; Can this assert be triggered using a bad invocation of the analyzer? I wonder if it is a good idea to use asserts to validate user input. Maybe it would be better to generate a warning and return the default value? Comment at: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp:205 + .getAsInteger(10, Ret); + assert(!HasFailed && "analyzer-config option should be numeric"); + (void)HasFailed; Same as above. Repository: rC Clang https://reviews.llvm.org/D53483 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53488: [clang-tidy] Catching narrowing from double to float.
gchatelet created this revision. gchatelet added a reviewer: hokein. Herald added subscribers: cfe-commits, kbarton, xazax.hun, nemanjai. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53488 Files: clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp test/clang-tidy/cppcoreguidelines-narrowing-conversions.cpp Index: test/clang-tidy/cppcoreguidelines-narrowing-conversions.cpp === --- test/clang-tidy/cppcoreguidelines-narrowing-conversions.cpp +++ test/clang-tidy/cppcoreguidelines-narrowing-conversions.cpp @@ -9,12 +9,12 @@ namespace floats { struct ConvertsToFloat { - operator float() const { return 0.5; } + operator float() const { return 0.5f; } }; -float operator "" _Pa(unsigned long long); +float operator"" _float(unsigned long long); -void not_ok(double d) { +void narrow_double_to_int_not_ok(double d) { int i = 0; i = d; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'double' to 'int' [cppcoreguidelines-narrowing-conversions] @@ -24,11 +24,11 @@ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'float' to 'int' [cppcoreguidelines-narrowing-conversions] i = ConvertsToFloat(); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'float' to 'int' [cppcoreguidelines-narrowing-conversions] - i = 15_Pa; + i = 15_float; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'float' to 'int' [cppcoreguidelines-narrowing-conversions] } -void not_ok_binary_ops(double d) { +void narrow_double_to_int_not_ok_binary_ops(double d) { int i = 0; i += 0.5; // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: narrowing conversion from 'double' to 'int' [cppcoreguidelines-narrowing-conversions] @@ -52,6 +52,43 @@ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: narrowing conversion from 'double' to 'int' [cppcoreguidelines-narrowing-conversions] } +double operator"" _double(unsigned long long); + +float narrow_double_to_float_return() { + return 0.5; + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: narrowing conversion from 'double' to 'float' [cppcoreguidelines-narrowing-conversions] +} + +void narrow_double_to_float_not_ok(double d) { + float f = 0; + f = d; + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'double' to 'float' [cppcoreguidelines-narrowing-conversions] + f = 0.5; + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'double' to 'float' [cppcoreguidelines-narrowing-conversions] + f = 15_double; + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'double' to 'float' [cppcoreguidelines-narrowing-conversions] +} + +void narrow_double_to_float_not_ok_binary_ops(double d) { + float f = 0; + f += 0.5; + // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: narrowing conversion from 'double' to 'float' [cppcoreguidelines-narrowing-conversions] + f += d; + // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: narrowing conversion from 'double' to 'float' [cppcoreguidelines-narrowing-conversions] + // We warn on the following even though it's not dangerous because there is no + // reason to use a double literal here. + // TODO(courbet): Provide an automatic fix. + f += 2.0; + // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: narrowing conversion from 'double' to 'float' [cppcoreguidelines-narrowing-conversions] + + f *= 0.5; + // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: narrowing conversion from 'double' to 'float' [cppcoreguidelines-narrowing-conversions] + f /= 0.5; + // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: narrowing conversion from 'double' to 'float' [cppcoreguidelines-narrowing-conversions] + f += (double)0.5f; + // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: narrowing conversion from 'double' to 'float' [cppcoreguidelines-narrowing-conversions] +} + void ok(double d) { int i = 0; i = 1; @@ -89,15 +126,19 @@ void template_context() { f(1, 2); + f(1, .5f); f(1, .5); + f(1, .5l); } #define DERP(i, j) (i += j) void macro_context() { int i = 0; DERP(i, 2); + DERP(i, .5f); DERP(i, .5); + DERP(i, .5l); } -} // namespace floats +} // namespace floats Index: clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp === --- clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp +++ clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp @@ -27,42 +27,59 @@ const auto IsFloatExpr = expr(hasType(realFloatingPointType()), unless(IsCeilFloorCall)); - // casts: + // Casts: // i = 0.5; // void f(int); f(0.5); - Finder->addMatcher(implicitCastExpr(hasImplicitDestinationType(isInteger()), - hasSourceExpression(IsFloatExpr), - unless(hasParent(castExpr())), - unless(isInTemplateInstantiation())) - .b
[PATCH] D53296: [analyzer] New flag to print all -analyzer-config options
xazax.hun added a comment. Overall looks good, minor comments inline. Comment at: lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp:166 + "\n\n"; + out << " clang [CLANG_OPTIONS] -analyzer-config OPTION1=VALUE, " + "-analyzer-config OPTION2=VALUE, ...\n\n"; Is `analyzer-config` a cc1 or a driver argument? Just make sure if it is cc1, to add the corresponding flags or the `-Xclang` passthrough in the help string. Comment at: lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp:195 +// If the buffer's length is greater then PadForDesc, print a newline. +if (FOut.getColumn() > PadForDesc) { + FOut << '\n'; Redundant braces. https://reviews.llvm.org/D53296 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53280: [analyzer] Emit a warning for unknown -analyzer-config options
xazax.hun added a comment. I agree with NoQ. Forward and backward compatibility might be important for CodeChecker as well. But I wonder if it make sense to have analyzer-config compatibility mode on a per config basis? E.g., if we have two configs: - One did not exist in earlier clang versions, but a tool (like CodeChecker) would like to pass this to the analyzer without doing a version check first. Passing this in a compatibility mode makes sense. This could be the regural `-analyzer-config` - The second option also did not exist in earlier clang versions, but we do not want to support those versions. In the case passing this config in a more strict mode makes sense. This could be something like `-analyzer-config-strict`. Or we could choose the deafults the other way around. What do you think? Does it make sense to have the compatibility mode on a per config bases or too much code for too little gain? Comment at: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h:323 + std::vector getConfigOptionList() const { +return { +#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC) \ I wonder if it is worth to store this in a static object, have it sorted and use binary search for the warning. If we do not expect to have a lot more options in the future I am fine with the current solution. https://reviews.llvm.org/D53280 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53277: [analyzer][NFC] Collect all -analyzer-config options in a .def file
xazax.hun added inline comments. Comment at: include/clang/StaticAnalyzer/Core/AnalyzerOptions.def:445 + +ANALYZER_OPTION_GEN_FN(StringRef, ModelPath, "model-path", "", "", getModelPath) + Should we explain the feature in the commad line path? The description might be somethinge like: `(string) The analyzer can inline an alternative implementation written in C at the call site if the called function's body is not available. This is a path where to look for those alternative implementations (called models).` https://reviews.llvm.org/D53277 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53489: [change-namespace] Enhance detection of conflicting namespaces.
ioeric created this revision. ioeric added a reviewer: hokein. Herald added a subscriber: cfe-commits. For example: namespace util { class Base; } namespace new { namespace util { class Internal; } } namespace old { util::Base b1; } When changing `old::` to `new::`, `util::` in namespace "new::" will conflict with "new::util::" unless a leading "::" is added. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53489 Files: change-namespace/ChangeNamespace.cpp unittests/change-namespace/ChangeNamespaceTests.cpp Index: unittests/change-namespace/ChangeNamespaceTests.cpp === --- unittests/change-namespace/ChangeNamespaceTests.cpp +++ unittests/change-namespace/ChangeNamespaceTests.cpp @@ -2244,6 +2244,39 @@ EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code)); } +TEST_F(ChangeNamespaceTest, FullyQualifyConflictNamespace) { + std::string Code = + "namespace x { namespace util { class Some {}; } }\n" + "namespace x { namespace y {namespace base { class Base {}; } } }\n" + "namespace util { class Status {}; }\n" + "namespace base { class Base {}; }\n" + "namespace na {\n" + "namespace nb {\n" + "void f() {\n" + " util::Status s1; x::util::Some s2;\n" + " base::Base b1; x::y::base::Base b2;\n" + "}\n" + "} // namespace nb\n" + "} // namespace na\n"; + + std::string Expected = + "namespace x { namespace util { class Some {}; } }\n" + "namespace x { namespace y {namespace base { class Base {}; } } }\n" + "namespace util { class Status {}; }\n" + "namespace base { class Base {}; }\n" + "\n" + "namespace x {\n" + "namespace y {\n" + "void f() {\n" + " ::util::Status s1; util::Some s2;\n" + " ::base::Base b1; base::Base b2;\n" + "}\n" + "} // namespace y\n" + "} // namespace x\n"; + + EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code)); +} + } // anonymous namespace } // namespace change_namespace } // namespace clang Index: change-namespace/ChangeNamespace.cpp === --- change-namespace/ChangeNamespace.cpp +++ change-namespace/ChangeNamespace.cpp @@ -7,8 +7,10 @@ // //===--===// #include "ChangeNamespace.h" +#include "clang/AST/ASTContext.h" #include "clang/Format/Format.h" #include "clang/Lex/Lexer.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" using namespace clang::ast_matchers; @@ -283,23 +285,48 @@ } // Given a qualified symbol name, returns true if the symbol will be -// incorrectly qualified without leading "::". -bool conflictInNamespace(llvm::StringRef QualifiedSymbol, +// incorrectly qualified without leading "::". For example, a symbol +// "nx::ny::Foo" in namespace "na::nx::ny" without leading "::"; a symbol +// "util::X" in namespace "na" can potentially conflict with "na::util" (if this +// exists). +bool conflictInNamespace(const ASTContext &AST, llvm::StringRef QualifiedSymbol, llvm::StringRef Namespace) { auto SymbolSplitted = splitSymbolName(QualifiedSymbol.trim(":")); assert(!SymbolSplitted.empty()); SymbolSplitted.pop_back(); // We are only interested in namespaces. - if (SymbolSplitted.size() > 1 && !Namespace.empty()) { + if (SymbolSplitted.size() >= 1 && !Namespace.empty()) { +auto SymbolTopNs = SymbolSplitted.front(); auto NsSplitted = splitSymbolName(Namespace.trim(":")); assert(!NsSplitted.empty()); -// We do not check the outermost namespace since it would not be a conflict -// if it equals to the symbol's outermost namespace and the symbol name -// would have been shortened. + +auto LookupDecl = [&AST](const Decl &Scope, + llvm::StringRef Name) -> const NamedDecl * { + const auto *DC = llvm::dyn_cast(&Scope); + if (!DC) +return nullptr; + auto LookupRes = DC->lookup(DeclarationName(&AST.Idents.get(Name))); + if (LookupRes.empty()) +return nullptr; + return LookupRes.front(); +}; +// We do not check the outermost namespace since it would not be a +// conflict if it equals to the symbol's outermost namespace and the +// symbol name would have been shortened. +const NamedDecl *Scope = +LookupDecl(*AST.getTranslationUnitDecl(), NsSplitted.front()); for (auto I = NsSplitted.begin() + 1, E = NsSplitted.end(); I != E; ++I) { - if (*I == SymbolSplitted.front()) + if (*I == SymbolTopNs) // Handles "::ny" in "::nx::ny" case. return true; + // Handles "::util" and "::nx::util" conflicts. + if (Scope) { +if (LookupDecl(*Scope, SymbolTopNs)) + return true; +Scope = LookupDecl(*Scope, *I); + } } +if (Scope && LookupDecl(*Scope, SymbolTopNs
r344890 - [ARM][AArch64] Add LLVM_FALLTHROUGH to silence warning [NFC]
Author: psmith Date: Mon Oct 22 03:40:52 2018 New Revision: 344890 URL: http://llvm.org/viewvc/llvm-project?rev=344890&view=rev Log: [ARM][AArch64] Add LLVM_FALLTHROUGH to silence warning [NFC] A follow up to D52784 to add in LLVM_FALLTHROUGH where there is an intentional fall through in a switch statement. This will hopefully silence a GCC warning. Differential Revision: https://reviews.llvm.org/D52784 Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=344890&r1=344889&r2=344890&view=diff == --- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Mon Oct 22 03:40:52 2018 @@ -239,6 +239,7 @@ static bool isArmBigEndian(const llvm::T case llvm::Triple::armeb: case llvm::Triple::thumbeb: IsBigEndian = true; +LLVM_FALLTHROUGH; case llvm::Triple::arm: case llvm::Triple::thumb: if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r344891 - [OpenCL] Fix definitions of __builtin_(add|sub|mul)_overflow
Author: mantognini Date: Mon Oct 22 03:41:07 2018 New Revision: 344891 URL: http://llvm.org/viewvc/llvm-project?rev=344891&view=rev Log: [OpenCL] Fix definitions of __builtin_(add|sub|mul)_overflow Ensure __builtin_(add|sub|mul)_overflow return bool instead of void as per specification (LanguageExtensions). Differential Revision: https://reviews.llvm.org/D52875 Modified: cfe/trunk/include/clang/Basic/Builtins.def Modified: cfe/trunk/include/clang/Basic/Builtins.def URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=344891&r1=344890&r2=344891&view=diff == --- cfe/trunk/include/clang/Basic/Builtins.def (original) +++ cfe/trunk/include/clang/Basic/Builtins.def Mon Oct 22 03:41:07 2018 @@ -1398,9 +1398,9 @@ BUILTIN(__builtin_subcl, "ULiULiCULiCULi BUILTIN(__builtin_subcll, "ULLiULLiCULLiCULLiCULLi*", "n") // Checked Arithmetic Builtins for Security. -BUILTIN(__builtin_add_overflow, "v.", "nt") -BUILTIN(__builtin_sub_overflow, "v.", "nt") -BUILTIN(__builtin_mul_overflow, "v.", "nt") +BUILTIN(__builtin_add_overflow, "b.", "nt") +BUILTIN(__builtin_sub_overflow, "b.", "nt") +BUILTIN(__builtin_mul_overflow, "b.", "nt") BUILTIN(__builtin_uadd_overflow, "bUiCUiCUi*", "n") BUILTIN(__builtin_uaddl_overflow, "bULiCULiCULi*", "n") BUILTIN(__builtin_uaddll_overflow, "bULLiCULLiCULLi*", "n") ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52784: [ARM][AArch64] Pass through endianness flags to the GNU assembler and linker
peter.smith added a comment. Added LLVM_FALLTHROUGH; in r344890. Repository: rC Clang https://reviews.llvm.org/D52784 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52875: Fix definitions of __builtin_(add|sub|mul)_overflow
This revision was automatically updated to reflect the committed changes. Closed by commit rC344891: [OpenCL] Fix definitions of __builtin_(add|sub|mul)_overflow (authored by mantognini, committed by ). Repository: rC Clang https://reviews.llvm.org/D52875 Files: include/clang/Basic/Builtins.def Index: include/clang/Basic/Builtins.def === --- include/clang/Basic/Builtins.def +++ include/clang/Basic/Builtins.def @@ -1398,9 +1398,9 @@ BUILTIN(__builtin_subcll, "ULLiULLiCULLiCULLiCULLi*", "n") // Checked Arithmetic Builtins for Security. -BUILTIN(__builtin_add_overflow, "v.", "nt") -BUILTIN(__builtin_sub_overflow, "v.", "nt") -BUILTIN(__builtin_mul_overflow, "v.", "nt") +BUILTIN(__builtin_add_overflow, "b.", "nt") +BUILTIN(__builtin_sub_overflow, "b.", "nt") +BUILTIN(__builtin_mul_overflow, "b.", "nt") BUILTIN(__builtin_uadd_overflow, "bUiCUiCUi*", "n") BUILTIN(__builtin_uaddl_overflow, "bULiCULiCULi*", "n") BUILTIN(__builtin_uaddll_overflow, "bULLiCULLiCULLi*", "n") Index: include/clang/Basic/Builtins.def === --- include/clang/Basic/Builtins.def +++ include/clang/Basic/Builtins.def @@ -1398,9 +1398,9 @@ BUILTIN(__builtin_subcll, "ULLiULLiCULLiCULLiCULLi*", "n") // Checked Arithmetic Builtins for Security. -BUILTIN(__builtin_add_overflow, "v.", "nt") -BUILTIN(__builtin_sub_overflow, "v.", "nt") -BUILTIN(__builtin_mul_overflow, "v.", "nt") +BUILTIN(__builtin_add_overflow, "b.", "nt") +BUILTIN(__builtin_sub_overflow, "b.", "nt") +BUILTIN(__builtin_mul_overflow, "b.", "nt") BUILTIN(__builtin_uadd_overflow, "bUiCUiCUi*", "n") BUILTIN(__builtin_uaddl_overflow, "bULiCULiCULi*", "n") BUILTIN(__builtin_uaddll_overflow, "bULLiCULLiCULLi*", "n") ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r344892 - Fix MSVC "not all control paths return a value" warning. NFCI.
Author: rksimon Date: Mon Oct 22 03:46:37 2018 New Revision: 344892 URL: http://llvm.org/viewvc/llvm-project?rev=344892&view=rev Log: Fix MSVC "not all control paths return a value" warning. NFCI. Modified: cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp Modified: cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp?rev=344892&r1=344891&r2=344892&view=diff == --- cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp Mon Oct 22 03:46:37 2018 @@ -69,6 +69,7 @@ static std::unique_ptr generat case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirstLocationQueue: return WorkList::makeUnexploredFirstPriorityLocationQueue(); } + llvm_unreachable("Unknown AnalyzerOptions::ExplorationStrategyKind"); } CoreEngine::CoreEngine(SubEngine &subengine, FunctionSummariesTy *FS, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53481: [clangd] Support passing a relative path to -compile-commands-dir
DaanDeMeyer updated this revision to Diff 170384. DaanDeMeyer added a comment. Updated diff according to comments. https://reviews.llvm.org/D53481 Files: clangd/tool/ClangdMain.cpp Index: clangd/tool/ClangdMain.cpp === --- clangd/tool/ClangdMain.cpp +++ clangd/tool/ClangdMain.cpp @@ -251,16 +251,24 @@ // If --compile-commands-dir arg was invoked, check value and override default // path. Optional CompileCommandsDirPath; - if (CompileCommandsDir.empty()) { -CompileCommandsDirPath = None; - } else if (!sys::path::is_absolute(CompileCommandsDir) || - !sys::fs::exists(CompileCommandsDir)) { -errs() << "Path specified by --compile-commands-dir either does not " - "exist or is not an absolute " - "path. The argument will be ignored.\n"; -CompileCommandsDirPath = None; - } else { -CompileCommandsDirPath = CompileCommandsDir; + if (!CompileCommandsDir.empty()) { +if (sys::fs::exists(CompileCommandsDir)) { + // We support passing both relative and absolute paths to the + // --compile-commands-dir argument, but we assume the path is absolute in + // the rest of clangd so we make sure the path is absolute before + // continuing. + SmallString<128> Path(CompileCommandsDir); + if (std::error_code EC = sys::fs::make_absolute(Path)) { +errs() << "Error while converting the relative path specified by " + "--compile-commands-dir to an absolute path: " + << EC.message() << ". The argument will be ignored.\n"; + } else { +CompileCommandsDirPath = Path.str(); + } +} else { + errs() << "Path specified by --compile-commands-dir does not exist. The " +"argument will be ignored.\n"; +} } ClangdServer::Options Opts; Index: clangd/tool/ClangdMain.cpp === --- clangd/tool/ClangdMain.cpp +++ clangd/tool/ClangdMain.cpp @@ -251,16 +251,24 @@ // If --compile-commands-dir arg was invoked, check value and override default // path. Optional CompileCommandsDirPath; - if (CompileCommandsDir.empty()) { -CompileCommandsDirPath = None; - } else if (!sys::path::is_absolute(CompileCommandsDir) || - !sys::fs::exists(CompileCommandsDir)) { -errs() << "Path specified by --compile-commands-dir either does not " - "exist or is not an absolute " - "path. The argument will be ignored.\n"; -CompileCommandsDirPath = None; - } else { -CompileCommandsDirPath = CompileCommandsDir; + if (!CompileCommandsDir.empty()) { +if (sys::fs::exists(CompileCommandsDir)) { + // We support passing both relative and absolute paths to the + // --compile-commands-dir argument, but we assume the path is absolute in + // the rest of clangd so we make sure the path is absolute before + // continuing. + SmallString<128> Path(CompileCommandsDir); + if (std::error_code EC = sys::fs::make_absolute(Path)) { +errs() << "Error while converting the relative path specified by " + "--compile-commands-dir to an absolute path: " + << EC.message() << ". The argument will be ignored.\n"; + } else { +CompileCommandsDirPath = Path.str(); + } +} else { + errs() << "Path specified by --compile-commands-dir does not exist. The " +"argument will be ignored.\n"; +} } ClangdServer::Options Opts; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52879: Derive builtin return type from its definition
mantognini added a comment. ping Repository: rC Clang https://reviews.llvm.org/D52879 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53489: [change-namespace] Enhance detection of conflicting namespaces.
hokein accepted this revision. hokein added a comment. This revision is now accepted and ready to land. LGTM Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53489 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r344897 - [change-namespace] Enhance detection of conflicting namespaces.
Author: ioeric Date: Mon Oct 22 05:48:49 2018 New Revision: 344897 URL: http://llvm.org/viewvc/llvm-project?rev=344897&view=rev Log: [change-namespace] Enhance detection of conflicting namespaces. Summary: For example: ``` namespace util { class Base; } namespace new { namespace util { class Internal; } } namespace old { util::Base b1; } ``` When changing `old::` to `new::`, `util::` in namespace "new::" will conflict with "new::util::" unless a leading "::" is added. Reviewers: hokein Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D53489 Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=344897&r1=344896&r2=344897&view=diff == --- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original) +++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Mon Oct 22 05:48:49 2018 @@ -7,8 +7,10 @@ // //===--===// #include "ChangeNamespace.h" +#include "clang/AST/ASTContext.h" #include "clang/Format/Format.h" #include "clang/Lex/Lexer.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" using namespace clang::ast_matchers; @@ -283,23 +285,48 @@ bool isDeclVisibleAtLocation(const Sourc } // Given a qualified symbol name, returns true if the symbol will be -// incorrectly qualified without leading "::". -bool conflictInNamespace(llvm::StringRef QualifiedSymbol, +// incorrectly qualified without leading "::". For example, a symbol +// "nx::ny::Foo" in namespace "na::nx::ny" without leading "::"; a symbol +// "util::X" in namespace "na" can potentially conflict with "na::util" (if this +// exists). +bool conflictInNamespace(const ASTContext &AST, llvm::StringRef QualifiedSymbol, llvm::StringRef Namespace) { auto SymbolSplitted = splitSymbolName(QualifiedSymbol.trim(":")); assert(!SymbolSplitted.empty()); SymbolSplitted.pop_back(); // We are only interested in namespaces. - if (SymbolSplitted.size() > 1 && !Namespace.empty()) { + if (SymbolSplitted.size() >= 1 && !Namespace.empty()) { +auto SymbolTopNs = SymbolSplitted.front(); auto NsSplitted = splitSymbolName(Namespace.trim(":")); assert(!NsSplitted.empty()); -// We do not check the outermost namespace since it would not be a conflict -// if it equals to the symbol's outermost namespace and the symbol name -// would have been shortened. + +auto LookupDecl = [&AST](const Decl &Scope, + llvm::StringRef Name) -> const NamedDecl * { + const auto *DC = llvm::dyn_cast(&Scope); + if (!DC) +return nullptr; + auto LookupRes = DC->lookup(DeclarationName(&AST.Idents.get(Name))); + if (LookupRes.empty()) +return nullptr; + return LookupRes.front(); +}; +// We do not check the outermost namespace since it would not be a +// conflict if it equals to the symbol's outermost namespace and the +// symbol name would have been shortened. +const NamedDecl *Scope = +LookupDecl(*AST.getTranslationUnitDecl(), NsSplitted.front()); for (auto I = NsSplitted.begin() + 1, E = NsSplitted.end(); I != E; ++I) { - if (*I == SymbolSplitted.front()) + if (*I == SymbolTopNs) // Handles "::ny" in "::nx::ny" case. return true; + // Handles "::util" and "::nx::util" conflicts. + if (Scope) { +if (LookupDecl(*Scope, SymbolTopNs)) + return true; +Scope = LookupDecl(*Scope, *I); + } } +if (Scope && LookupDecl(*Scope, SymbolTopNs)) + return true; } return false; } @@ -844,15 +871,16 @@ void ChangeNamespaceTool::replaceQualifi } } } + bool Conflict = conflictInNamespace(DeclCtx->getParentASTContext(), + ReplaceName, NewNamespace); // If the new nested name in the new namespace is the same as it was in the - // old namespace, we don't create replacement. - if (NestedName == ReplaceName || + // old namespace, we don't create replacement unless there can be ambiguity. + if ((NestedName == ReplaceName && !Conflict) || (NestedName.startswith("::") && NestedName.drop_front(2) == ReplaceName)) return; // If the reference need to be fully-qualified, add a leading "::" unless // NewNamespace is the global namespace. - if (ReplaceName == FromDeclName && !NewNamespace.empty() && - conflictInNamespace(ReplaceName, NewNamespace)) + if (ReplaceName == FromDeclName && !NewNamespace.empty() && Conflict) ReplaceName = "::" + ReplaceName; addReplacementOrDie(Start, End, ReplaceN
[PATCH] D53489: [change-namespace] Enhance detection of conflicting namespaces.
This revision was automatically updated to reflect the committed changes. Closed by commit rL344897: [change-namespace] Enhance detection of conflicting namespaces. (authored by ioeric, committed by ). Herald added a subscriber: llvm-commits. Repository: rL LLVM https://reviews.llvm.org/D53489 Files: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp Index: clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp === --- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp +++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp @@ -2244,6 +2244,39 @@ EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code)); } +TEST_F(ChangeNamespaceTest, FullyQualifyConflictNamespace) { + std::string Code = + "namespace x { namespace util { class Some {}; } }\n" + "namespace x { namespace y {namespace base { class Base {}; } } }\n" + "namespace util { class Status {}; }\n" + "namespace base { class Base {}; }\n" + "namespace na {\n" + "namespace nb {\n" + "void f() {\n" + " util::Status s1; x::util::Some s2;\n" + " base::Base b1; x::y::base::Base b2;\n" + "}\n" + "} // namespace nb\n" + "} // namespace na\n"; + + std::string Expected = + "namespace x { namespace util { class Some {}; } }\n" + "namespace x { namespace y {namespace base { class Base {}; } } }\n" + "namespace util { class Status {}; }\n" + "namespace base { class Base {}; }\n" + "\n" + "namespace x {\n" + "namespace y {\n" + "void f() {\n" + " ::util::Status s1; util::Some s2;\n" + " ::base::Base b1; base::Base b2;\n" + "}\n" + "} // namespace y\n" + "} // namespace x\n"; + + EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code)); +} + } // anonymous namespace } // namespace change_namespace } // namespace clang Index: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp === --- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp +++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp @@ -7,8 +7,10 @@ // //===--===// #include "ChangeNamespace.h" +#include "clang/AST/ASTContext.h" #include "clang/Format/Format.h" #include "clang/Lex/Lexer.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" using namespace clang::ast_matchers; @@ -283,23 +285,48 @@ } // Given a qualified symbol name, returns true if the symbol will be -// incorrectly qualified without leading "::". -bool conflictInNamespace(llvm::StringRef QualifiedSymbol, +// incorrectly qualified without leading "::". For example, a symbol +// "nx::ny::Foo" in namespace "na::nx::ny" without leading "::"; a symbol +// "util::X" in namespace "na" can potentially conflict with "na::util" (if this +// exists). +bool conflictInNamespace(const ASTContext &AST, llvm::StringRef QualifiedSymbol, llvm::StringRef Namespace) { auto SymbolSplitted = splitSymbolName(QualifiedSymbol.trim(":")); assert(!SymbolSplitted.empty()); SymbolSplitted.pop_back(); // We are only interested in namespaces. - if (SymbolSplitted.size() > 1 && !Namespace.empty()) { + if (SymbolSplitted.size() >= 1 && !Namespace.empty()) { +auto SymbolTopNs = SymbolSplitted.front(); auto NsSplitted = splitSymbolName(Namespace.trim(":")); assert(!NsSplitted.empty()); -// We do not check the outermost namespace since it would not be a conflict -// if it equals to the symbol's outermost namespace and the symbol name -// would have been shortened. + +auto LookupDecl = [&AST](const Decl &Scope, + llvm::StringRef Name) -> const NamedDecl * { + const auto *DC = llvm::dyn_cast(&Scope); + if (!DC) +return nullptr; + auto LookupRes = DC->lookup(DeclarationName(&AST.Idents.get(Name))); + if (LookupRes.empty()) +return nullptr; + return LookupRes.front(); +}; +// We do not check the outermost namespace since it would not be a +// conflict if it equals to the symbol's outermost namespace and the +// symbol name would have been shortened. +const NamedDecl *Scope = +LookupDecl(*AST.getTranslationUnitDecl(), NsSplitted.front()); for (auto I = NsSplitted.begin() + 1, E = NsSplitted.end(); I != E; ++I) { - if (*I == SymbolSplitted.front()) + if (*I == SymbolTopNs) // Handles "::ny" in "::nx::ny" case. return true; + // Handles "::util" and "::nx::util" conflicts. + if (Scope) { +if (LookupDecl(*Scope, SymbolTopNs)) + return true; +Scope = LookupDecl(*Scope, *I); + } } +if (Scop
r344898 - Silence the -Wshadow warning for enumerators shadowing a type.
Author: aaronballman Date: Mon Oct 22 06:05:53 2018 New Revision: 344898 URL: http://llvm.org/viewvc/llvm-project?rev=344898&view=rev Log: Silence the -Wshadow warning for enumerators shadowing a type. Amends r344259 so that enumerators shadowing types are not diagnosed, as shadowing under those circumstances is rarely (if ever) an issue in practice. Modified: cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/test/Sema/warn-shadow.c cfe/trunk/test/SemaCXX/warn-shadow.cpp Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=344898&r1=344897&r2=344898&view=diff == --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Oct 22 06:05:53 2018 @@ -16295,7 +16295,7 @@ Decl *Sema::ActOnEnumConstant(Scope *S, return nullptr; if (PrevDecl) { -if (!TheEnumDecl->isScoped()) { +if (!TheEnumDecl->isScoped() && isa(PrevDecl)) { // Check for other kinds of shadowing not already handled. CheckShadow(New, PrevDecl, R); } Modified: cfe/trunk/test/Sema/warn-shadow.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-shadow.c?rev=344898&r1=344897&r2=344898&view=diff == --- cfe/trunk/test/Sema/warn-shadow.c (original) +++ cfe/trunk/test/Sema/warn-shadow.c Mon Oct 22 06:05:53 2018 @@ -64,3 +64,10 @@ enum PR24718_1{pr24718}; // expected-not void PR24718(void) { enum PR24718_2{pr24718}; // expected-warning {{declaration shadows a variable in the global scope}} } + +struct PR24718_3; +struct PR24718_4 { + enum { +PR24718_3 // Does not shadow a type. + }; +}; Modified: cfe/trunk/test/SemaCXX/warn-shadow.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-shadow.cpp?rev=344898&r1=344897&r2=344898&view=diff == --- cfe/trunk/test/SemaCXX/warn-shadow.cpp (original) +++ cfe/trunk/test/SemaCXX/warn-shadow.cpp Mon Oct 22 06:05:53 2018 @@ -225,3 +225,10 @@ void f(int a) { int PR24718; enum class X { PR24718 }; // Ok, not shadowing + +struct PR24718_1; +struct PR24718_2 { + enum { +PR24718_1 // Does not shadow a type. + }; +}; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52400: Improve -Wshadow warnings with enumerators
aaron.ballman added a comment. In https://reviews.llvm.org/D52400#1267731, @aaron.ballman wrote: > In https://reviews.llvm.org/D52400#1267499, @sberg wrote: > > > (and in any case, "declaration shadows a variable" sounds wrong when the > > shadowed entity is a class type. thats why I thought something is not quite > > right with this new code yet) > > > Definitely agreed. I think I'm convinced that this should be silenced when > the conflict is with a type rather than a value. I'll try to look into this > next week when I'm back from WG14 meetings. I've silenced this scenario in r344898, thank you for raising the issue! https://reviews.llvm.org/D52400 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53460: [X86] When checking the bits in cpu_features for function multiversioning dispatcher in the resolver, make sure all the required bits are set. Not just one of them
erichkeane added a comment. Yikes, good catch! Repository: rL LLVM https://reviews.llvm.org/D53460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r344901 - Always search sysroot for GCC installs
Author: greened Date: Mon Oct 22 06:46:12 2018 New Revision: 344901 URL: http://llvm.org/viewvc/llvm-project?rev=344901&view=rev Log: Always search sysroot for GCC installs Previously, if clang was configured with -DGCC_INSTALL_PREFIX, then it would not search a provided sysroot for a gcc install. This caused a number of regression tests to fail. If a sysroot is given, skip searching GCC_INSTALL_PREFIX as it is likely not valid for the provided sysroot. Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=344901&r1=344900&r2=344901&view=diff == --- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Mon Oct 22 06:46:12 2018 @@ -1651,10 +1651,18 @@ Generic_GCC::GCCVersion Generic_GCC::GCC return GoodVersion; } -static llvm::StringRef getGCCToolchainDir(const ArgList &Args) { +static llvm::StringRef getGCCToolchainDir(const ArgList &Args, + llvm::StringRef SysRoot) { const Arg *A = Args.getLastArg(clang::driver::options::OPT_gcc_toolchain); if (A) return A->getValue(); + + // If we have a SysRoot, ignore GCC_INSTALL_PREFIX. + // GCC_INSTALL_PREFIX specifies the gcc installation for the default + // sysroot and is likely not valid with a different sysroot. + if (!SysRoot.empty()) +return ""; + return GCC_INSTALL_PREFIX; } @@ -1686,7 +1694,7 @@ void Generic_GCC::GCCInstallationDetecto SmallVector Prefixes(D.PrefixDirs.begin(), D.PrefixDirs.end()); - StringRef GCCToolchainDir = getGCCToolchainDir(Args); + StringRef GCCToolchainDir = getGCCToolchainDir(Args, D.SysRoot); if (GCCToolchainDir != "") { if (GCCToolchainDir.back() == '/') GCCToolchainDir = GCCToolchainDir.drop_back(); // remove the / ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53497: [AST] Do not align virtual bases in `MicrosoftRecordLayoutBuilder` when an external layout is used
aleksandr.urakov created this revision. aleksandr.urakov added reviewers: rnk, rsmith, zturner, mstorsjo, majnemer. aleksandr.urakov added a project: clang. Herald added a subscriber: cfe-commits. The patch removes alignment of virtual bases when an external layout is used. We have two cases: - the external layout source has an information about virtual bases offsets, so we just use them; - the external source has no information about virtual bases offsets. In this case we can't predict where the base will be located. If we will align it but there will be something like `#pragma pack(push, 1)` really, then likely our layout will not fit into the real structure size, and then some asserts will hit. The asserts look reasonable, so I don't think that we need to remove them. May be it would be better instead don't align fields / bases etc. (so treat it always as `#pragma pack(push, 1)`) when an external layout source is used but no info about a field location is presented. This one is related to https://reviews.llvm.org/D49871 Also it seems that `MicrosoftRecordLayoutBuilder` with an external source and without one differ considerably, may be it is worth to split this and to create two different builders? I think that it would make the logic simpler. What do you think about it? Repository: rC Clang https://reviews.llvm.org/D53497 Files: lib/AST/RecordLayoutBuilder.cpp test/CodeGenCXX/Inputs/override-layout-packed-base.layout test/CodeGenCXX/override-layout-packed-base.cpp Index: test/CodeGenCXX/override-layout-packed-base.cpp === --- test/CodeGenCXX/override-layout-packed-base.cpp +++ test/CodeGenCXX/override-layout-packed-base.cpp @@ -1,26 +1,40 @@ -// RUN: %clang_cc1 -w -fdump-record-layouts-simple -foverride-record-layout=%S/Inputs/override-layout-packed-base.layout %s | FileCheck %s +// RUN: %clang_cc1 -triple i686-windows-msvc -w -fdump-record-layouts-simple -foverride-record-layout=%S/Inputs/override-layout-packed-base.layout %s | FileCheck %s + +//#pragma pack(push, 1) // CHECK: Type: class B<0> +// CHECK: Size:40 // CHECK: FieldOffsets: [0, 32] // CHECK: Type: class B<1> +// CHECK: Size:40 // CHECK: FieldOffsets: [0, 32] -//#pragma pack(push, 1) template class B { int _b1; char _b2; }; -//#pragma pack(pop) // CHECK: Type: class C +// CHECK: Size:88 // CHECK: FieldOffsets: [80] class C : B<0>, B<1> { char _c; }; +// CHECK: Type: class D +// CHECK: Size:120 +// CHECK: FieldOffsets: [32] + +class D : virtual B<0>, virtual B<1> { + char _d; +}; + +//#pragma pack(pop) + void use_structs() { C cs[sizeof(C)]; + D ds[sizeof(D)]; } Index: test/CodeGenCXX/Inputs/override-layout-packed-base.layout === --- test/CodeGenCXX/Inputs/override-layout-packed-base.layout +++ test/CodeGenCXX/Inputs/override-layout-packed-base.layout @@ -3,16 +3,26 @@ Type: class B<0> Layout: *** Dumping AST Record Layout Type: class B<1> Layout: *** Dumping AST Record Layout Type: class C Layout: + +*** Dumping AST Record Layout +Type: class D + +Layout: Index: lib/AST/RecordLayoutBuilder.cpp === --- lib/AST/RecordLayoutBuilder.cpp +++ lib/AST/RecordLayoutBuilder.cpp @@ -2829,15 +2829,14 @@ CharUnits BaseOffset; // Respect the external AST source base offset, if present. -bool FoundBase = false; if (UseExternalLayout) { - FoundBase = External.getExternalVBaseOffset(BaseDecl, BaseOffset); - if (FoundBase) -assert(BaseOffset >= Size && "base offset already allocated"); -} -if (!FoundBase) + if (!External.getExternalVBaseOffset(BaseDecl, BaseOffset)) +BaseOffset = Size; +} else BaseOffset = Size.alignTo(Info.Alignment); +assert(BaseOffset >= Size && "base offset already allocated"); + VBases.insert(std::make_pair(BaseDecl, ASTRecordLayout::VBaseInfo(BaseOffset, HasVtordisp))); Size = BaseOffset + BaseLayout.getNonVirtualSize(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D49244: Always search sysroot for GCC installs
greened closed this revision. greened added a comment. Fixed in r344901. Repository: rC Clang https://reviews.llvm.org/D49244 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53308: [Fixed Point Arithmetic] Fixed Point to Boolean Cast
ebevhan added inline comments. Comment at: clang/lib/CodeGen/CGExprScalar.cpp:2026 +return EmitScalarConversion(Visit(E), E->getType(), DestTy, +CE->getExprLoc()); rjmccall wrote: > Why are you pushing these casts through `EmitScalarConversion` when the cast > kind already tells you which operation you're doing? It could be useful to enable EmitScalarConversion to handle any of the conversions so it can be used in other contexts than expanding a cast. Repository: rC Clang https://reviews.llvm.org/D53308 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [libcxx] r342073 - Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955
On Tue, Oct 2, 2018 at 10:33 AM Christof Douma wrote: > Hi Marshall. > > I think that this patch breaks backwards compatibility. Assumes that the > header file "version" is used by C++ projects that use a C++ standard that > did not specify a 'version' header. Many toolchains will put search paths > specified with -I in front of the system search path. The result is that > the application header file is included whenever a standard header file is > included. That is unexpected and can break builds. > > Do you agree this is an issue or do you consider this an issue with the > way toolchains handle include search paths? Christof - I've been thinking about this the last few days. We can ameliorate this in libc++, (See Richard's suggestion on __version) but anything we do will be a short-term solution. The first time someone includes another header file that #include , they're back to square one. That header is supposed to be "the place to go" for information about your standard library, and people are going to use it. For example, I expect that Boost.Config will start using it soon (if it doesn't already) A better solution (and not just because it would require other people to do the work) would be to have the build systems either: * Stop using VERSION as a file name - use something like VERSION.STAMP instead. * Use '-iquote' instead of '-I' to manage the list of include directories. I agree that it's annoying for people's builds to be broken when they upgrade their development tools, and especially when they didn't do anything "wrong". -- Marshall ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53498: Re-word command help for clang-query
steveire created this revision. steveire added a reviewer: aaron.ballman. Herald added a subscriber: cfe-commits. This will make it possible to easily - Add new commands which accept parameters - Extend the list of features Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53498 Files: clang-query/Query.cpp Index: clang-query/Query.cpp === --- clang-query/Query.cpp +++ clang-query/Query.cpp @@ -43,12 +43,17 @@ "Set whether to bind the root matcher to \"root\".\n" " set print-matcher (true|false)" "Set whether to print the current matcher,\n" -" set output (diag|print|dump) " -"Set whether to print bindings as diagnostics,\n" -"" -"AST pretty prints or AST dumps.\n" +" set output " +"Set whether to output only content.\n" " quit, q " -"Terminates the query session.\n\n"; +"Terminates the query session.\n\n" +"Several commands accept a parameter. The available features are:\n\n" +" print " +"pretty-print bound nodes\n" +" diag " +"diagnostic location for bound nodes\n" +" dump " +"Detailed AST output for bound nodes\n\n"; return true; } Index: clang-query/Query.cpp === --- clang-query/Query.cpp +++ clang-query/Query.cpp @@ -43,12 +43,17 @@ "Set whether to bind the root matcher to \"root\".\n" " set print-matcher (true|false)" "Set whether to print the current matcher,\n" -" set output (diag|print|dump) " -"Set whether to print bindings as diagnostics,\n" -"" -"AST pretty prints or AST dumps.\n" +" set output " +"Set whether to output only content.\n" " quit, q " -"Terminates the query session.\n\n"; +"Terminates the query session.\n\n" +"Several commands accept a parameter. The available features are:\n\n" +" print " +"pretty-print bound nodes\n" +" diag " +"diagnostic location for bound nodes\n" +" dump " +"Detailed AST output for bound nodes\n\n"; return true; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53500: Add 'detailed-ast' output as an alias for 'dump'
steveire created this revision. steveire added a reviewer: aaron.ballman. Herald added a subscriber: cfe-commits. Future development can then dump other content than AST. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53500 Files: clang-query/Query.cpp clang-query/Query.h clang-query/QueryParser.cpp Index: clang-query/QueryParser.cpp === --- clang-query/QueryParser.cpp +++ clang-query/QueryParser.cpp @@ -111,10 +111,11 @@ unsigned OutKind = LexOrCompleteWord(this, ValStr) .Case("diag", OK_Diag) .Case("print", OK_Print) - .Case("dump", OK_Dump) + .Case("detailed-ast", OK_DetailedAST) + .Case("dump", OK_DetailedAST) .Default(~0u); if (OutKind == ~0u) { -return new InvalidQuery("expected 'diag', 'print' or 'dump', got '" + +return new InvalidQuery("expected 'diag', 'print', 'detailed-ast' or 'dump', got '" + ValStr + "'"); } return new SetQuery(&QuerySession::OutKind, OutputKind(OutKind)); Index: clang-query/Query.h === --- clang-query/Query.h +++ clang-query/Query.h @@ -18,7 +18,7 @@ namespace clang { namespace query { -enum OutputKind { OK_Diag, OK_Print, OK_Dump }; +enum OutputKind { OK_Diag, OK_Print, OK_DetailedAST }; enum QueryKind { QK_Invalid, Index: clang-query/Query.cpp === --- clang-query/Query.cpp +++ clang-query/Query.cpp @@ -52,8 +52,10 @@ "pretty-print bound nodes\n" " diag " "diagnostic location for bound nodes\n" +" detailed-ast " +"Detailed AST output for bound nodes\n" " dump " -"Detailed AST output for bound nodes\n\n"; +"Detailed AST output for bound nodes (alias of deatiled-ast)\n\n"; return true; } @@ -123,7 +125,7 @@ OS << "\n"; break; } -case OK_Dump: { +case OK_DetailedAST: { OS << "Binding for \"" << BI->first << "\":\n"; BI->second.dump(OS, AST->getSourceManager()); OS << "\n"; Index: clang-query/QueryParser.cpp === --- clang-query/QueryParser.cpp +++ clang-query/QueryParser.cpp @@ -111,10 +111,11 @@ unsigned OutKind = LexOrCompleteWord(this, ValStr) .Case("diag", OK_Diag) .Case("print", OK_Print) - .Case("dump", OK_Dump) + .Case("detailed-ast", OK_DetailedAST) + .Case("dump", OK_DetailedAST) .Default(~0u); if (OutKind == ~0u) { -return new InvalidQuery("expected 'diag', 'print' or 'dump', got '" + +return new InvalidQuery("expected 'diag', 'print', 'detailed-ast' or 'dump', got '" + ValStr + "'"); } return new SetQuery(&QuerySession::OutKind, OutputKind(OutKind)); Index: clang-query/Query.h === --- clang-query/Query.h +++ clang-query/Query.h @@ -18,7 +18,7 @@ namespace clang { namespace query { -enum OutputKind { OK_Diag, OK_Print, OK_Dump }; +enum OutputKind { OK_Diag, OK_Print, OK_DetailedAST }; enum QueryKind { QK_Invalid, Index: clang-query/Query.cpp === --- clang-query/Query.cpp +++ clang-query/Query.cpp @@ -52,8 +52,10 @@ "pretty-print bound nodes\n" " diag " "diagnostic location for bound nodes\n" +" detailed-ast " +"Detailed AST output for bound nodes\n" " dump " -"Detailed AST output for bound nodes\n\n"; +"Detailed AST output for bound nodes (alias of deatiled-ast)\n\n"; return true; } @@ -123,7 +125,7 @@ OS << "\n"; break; } -case OK_Dump: { +case OK_DetailedAST: { OS << "Binding for \"" << BI->first << "\":\n"; BI->second.dump(OS, AST->getSourceManager()); OS << "\n"; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53277: [analyzer][NFC] Collect all -analyzer-config options in a .def file
Szelethus updated this revision to Diff 170417. Szelethus added a comment. - Removed redundant information (like the type or default value of the command line argument), these are now auto-generated in followup patches - Added description for `"model-path"`. https://reviews.llvm.org/D53277 Files: include/clang/StaticAnalyzer/Core/AnalyzerOptions.def include/clang/StaticAnalyzer/Core/AnalyzerOptions.h lib/StaticAnalyzer/Core/AnalyzerOptions.cpp lib/StaticAnalyzer/Core/CoreEngine.cpp Index: lib/StaticAnalyzer/Core/CoreEngine.cpp === --- lib/StaticAnalyzer/Core/CoreEngine.cpp +++ lib/StaticAnalyzer/Core/CoreEngine.cpp @@ -56,17 +56,17 @@ static std::unique_ptr generateWorkList(AnalyzerOptions &Opts, SubEngine &subengine) { switch (Opts.getExplorationStrategy()) { -case AnalyzerOptions::ExplorationStrategyKind::DFS: +case ExplorationStrategyKind::DFS: return WorkList::makeDFS(); -case AnalyzerOptions::ExplorationStrategyKind::BFS: +case ExplorationStrategyKind::BFS: return WorkList::makeBFS(); -case AnalyzerOptions::ExplorationStrategyKind::BFSBlockDFSContents: +case ExplorationStrategyKind::BFSBlockDFSContents: return WorkList::makeBFSBlockDFSContents(); -case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirst: +case ExplorationStrategyKind::UnexploredFirst: return WorkList::makeUnexploredFirst(); -case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirstQueue: +case ExplorationStrategyKind::UnexploredFirstQueue: return WorkList::makeUnexploredFirstPriorityQueue(); -case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirstLocationQueue: +case ExplorationStrategyKind::UnexploredFirstLocationQueue: return WorkList::makeUnexploredFirstPriorityLocationQueue(); } } Index: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp === --- lib/StaticAnalyzer/Core/AnalyzerOptions.cpp +++ lib/StaticAnalyzer/Core/AnalyzerOptions.cpp @@ -49,91 +49,87 @@ return Result; } -AnalyzerOptions::UserModeKind AnalyzerOptions::getUserMode() { +UserModeKind AnalyzerOptions::getUserMode() { if (!UserMode.hasValue()) { -StringRef ModeStr = getOptionAsString("mode", "deep"); -UserMode = llvm::StringSwitch>(ModeStr) - .Case("shallow", UMK_Shallow) - .Case("deep", UMK_Deep) - .Default(None); -assert(UserMode.getValue() && "User mode is invalid."); +UserMode = getOptionAsString("mode", "deep"); } - return UserMode.getValue(); + + auto K = llvm::StringSwitch>(*UserMode) +.Case("shallow", UMK_Shallow) +.Case("deep", UMK_Deep) +.Default(None); + assert(UserMode.hasValue() && "User mode is invalid."); + return K.getValue(); } -AnalyzerOptions::ExplorationStrategyKind +ExplorationStrategyKind AnalyzerOptions::getExplorationStrategy() { if (!ExplorationStrategy.hasValue()) { -StringRef StratStr = getOptionAsString("exploration_strategy", - "unexplored_first_queue"); -ExplorationStrategy = -llvm::StringSwitch>(StratStr) -.Case("dfs", ExplorationStrategyKind::DFS) -.Case("bfs", ExplorationStrategyKind::BFS) -.Case("unexplored_first", - ExplorationStrategyKind::UnexploredFirst) -.Case("unexplored_first_queue", - ExplorationStrategyKind::UnexploredFirstQueue) -.Case("unexplored_first_location_queue", - ExplorationStrategyKind::UnexploredFirstLocationQueue) -.Case("bfs_block_dfs_contents", - ExplorationStrategyKind::BFSBlockDFSContents) -.Default(None); -assert(ExplorationStrategy.hasValue() && - "User mode is invalid."); +ExplorationStrategy = getOptionAsString("exploration_strategy", +"unexplored_first_queue"); } - return ExplorationStrategy.getValue(); + auto K = +llvm::StringSwitch>( + *ExplorationStrategy) + .Case("dfs", ExplorationStrategyKind::DFS) + .Case("bfs", ExplorationStrategyKind::BFS) + .Case("unexplored_first", +ExplorationStrategyKind::UnexploredFirst) + .Case("unexplored_first_queue", +ExplorationStrategyKind::UnexploredFirstQueue) + .Case("unexplored_first_location_queue", +ExplorationStrategyKind::UnexploredFirstLocationQueue) + .Case("bfs_block_dfs_contents", +ExplorationStrategyKind::BFSBlockDFSContents) + .Default(None); + assert(K.hasValue() && "User mode is invalid."); + return K.getValue(); } IPAKind AnalyzerOptions::getIPAMode() { if (!IPAMode.hasValue()) { -// Use the User Mode to set the default I
[PATCH] D53025: [clang-tidy] implement new check for const return types.
ymandel updated this revision to Diff 170418. ymandel added a comment. Expanded test cases. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53025 Files: clang-tidy/readability/CMakeLists.txt clang-tidy/readability/ConstValueReturnCheck.cpp clang-tidy/readability/ConstValueReturnCheck.h clang-tidy/readability/ReadabilityTidyModule.cpp clang-tidy/utils/LexerUtils.cpp clang-tidy/utils/LexerUtils.h docs/ReleaseNotes.rst docs/clang-tidy/checks/list.rst docs/clang-tidy/checks/readability-const-value-return.rst test/clang-tidy/readability-const-value-return.cpp Index: test/clang-tidy/readability-const-value-return.cpp === --- /dev/null +++ test/clang-tidy/readability-const-value-return.cpp @@ -0,0 +1,201 @@ +// RUN: %check_clang_tidy %s readability-const-value-return %t -- -- -isystem + +// p# = positive test +// n# = negative test + +#include + +const int p1() { +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qualified hindering compiler optimizations +// CHECK-FIXES: int p1() { + return 1; +} + +const int p15(); +// CHECK-FIXES: int p15(); + +template +const int p31(T v) { return 2; } +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qu +// CHECK-FIXES: int p31(T v) { return 2; } + +template class Klazz {}; + +class Clazz { + public: + Clazz *const p2() { +// CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'Clazz *const' is 'co +// CHECK-FIXES: Clazz *p2() { +return this; + } + + Clazz *const p3(); + // CHECK-FIXES: Clazz *p3(); + + const int p4() const { +// CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const int' is 'const +// CHECK-FIXES: int p4() const { +return 4; + } + + const Klazz* const p5() const; + // CHECK-FIXES: const Klazz* p5() const; + + const Clazz operator++(int x) { // p12 + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const Clazz' is 'const + // CHECK-FIXES: Clazz operator++(int x) { + } + + struct Strukt { +int i; + }; + + const Strukt p6() {} + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const Clazz::Strukt' i + // CHECK-FIXES: Strukt p6() {} + + // No warning is emitted here, because this is only the declaration. The + // warning will be associated with the definition, below. + const Strukt* const p7(); + // CHECK-FIXES: const Strukt* p7(); + + static const int p8() {} + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const int' is 'const'- + // CHECK-FIXES: static int p8() {} + + static const Strukt p9() {} + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const Clazz::Strukt' i + // CHECK-FIXES: static Strukt p9() {} + + int n0() const { return 0; } + const Klazz& n11(const Klazz) const; +}; + +Clazz *const Clazz::p3() { + // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'Clazz *const' is 'cons + // CHECK-FIXES: Clazz *Clazz::p3() { + return this; +} + +const Klazz* const Clazz::p5() const {} +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz * +// CHECK-FIXES: const Klazz* Clazz::p5() const {} + +const Clazz::Strukt* const Clazz::p7() {} +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Clazz::Strukt *con +// CHECK-FIXES: const Clazz::Strukt* Clazz::p7() {} + +Clazz *const p10(); +// CHECK-FIXES: Clazz *p10(); + +Clazz *const p10() { + // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'Clazz *const' is 'cons + // CHECK-FIXES: Clazz *p10() { + return new Clazz(); +} + +const Clazz bar; +const Clazz *const p11() { + // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Clazz *const' is + // CHECK-FIXES: const Clazz *p11() { + return &bar; +} + +const Klazz p12() {} +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz' +// CHECK-FIXES: Klazz p12() {} + +const Klazz* const p13() {} +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz * +// CHECK-FIXES: const Klazz* p13() {} + +// re-declaration of p15. +const int p15(); +// CHECK-FIXES: int p15(); + +const int p15() { +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: +// CHECK-FIXES: int p15() { + return 0; +} + +// Exercise the lexer. + +const /* comment */ /* another comment*/ int p16() { return 0; } +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: +// CHECK-FIXES: /* comment */ /* another comment*/ int p16() { return 0; } + +/* comment */ const +// CHECK-MESSAGES: [[@LINE-1]]:15: warning: +// CHECK-FIXES: /* comment */ +// more +/* another comment*/ int p17() { return 0; } + +// Test cases where the `const` token lexically is hidden behind some form of +// indirection. + +#define CONSTINT const int +CONSTINT p18() {} +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qu + +#define CONST const +CONST int p19() {} +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qu + +using ty = const int; +ty p21() {} +// CHECK-MESSAGES: [[@L
[PATCH] D53025: [clang-tidy] implement new check for const return types.
ymandel marked an inline comment as done. ymandel added inline comments. Comment at: test/clang-tidy/readability-const-value-return.cpp:174 +int **const * n_multiple_ptr(); +int *const & n_pointer_ref(); aaron.ballman wrote: > I'd like to see some more complex examples, like: > ``` > int const foo(); > int const * const foo(); > > std::add_const foo(); > > template > std::add_const foo(); > > auto foo() -> const int; > auto foo() -> int const; > > template > auto foo() -> std::add_const; > ``` > I'm also very curious to hear how often this triggers on large code bases, > especially ones that claim decent const-correctness. I've added examples along the lines you suggested. However, the code cannot currently catch the "auto foo() -> type" form, and I couldn't find an easy way to change this. I've noted as much in the comments. Also, the template version (whether trailing or normal return) does not trigger the matchers at all, from which I surmise that clang doesn't consider the type const qualified when it is not materialized with an actual type. I've noted as much in the comments, but please correct me if I've misunderstood. Finally, as for triggering: I ran this over Google's C++ codebase and found quite a few hits (10k < X < 100k; not sure I'm allowed to specify a more precise value for X, but if you need it, let me know and I'll ask). I sampled 100 of them and confirmed that all were correct. I also looked at LLVM and found ~130 hits. I sampled 10 and again found them all correct. I'm happy to post all of the llvm hits if you think that would be helpful. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53025 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53498: Re-word command help for clang-query
steveire updated this revision to Diff 170419. steveire added a comment. Format Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53498 Files: clang-query/Query.cpp Index: clang-query/Query.cpp === --- clang-query/Query.cpp +++ clang-query/Query.cpp @@ -43,12 +43,18 @@ "Set whether to bind the root matcher to \"root\".\n" " set print-matcher (true|false)" "Set whether to print the current matcher,\n" -" set output (diag|print|dump) " -"Set whether to print bindings as diagnostics,\n" -"" -"AST pretty prints or AST dumps.\n" +" set output " +"Set whether to output only content.\n" " quit, q " -"Terminates the query session.\n\n"; +"Terminates the query session.\n\n" +"Several commands accept a parameter. The available features " +"are:\n\n" +" print " +"pretty-print bound nodes\n" +" diag " +"diagnostic location for bound nodes\n" +" dump " +"Detailed AST output for bound nodes\n\n"; return true; } Index: clang-query/Query.cpp === --- clang-query/Query.cpp +++ clang-query/Query.cpp @@ -43,12 +43,18 @@ "Set whether to bind the root matcher to \"root\".\n" " set print-matcher (true|false)" "Set whether to print the current matcher,\n" -" set output (diag|print|dump) " -"Set whether to print bindings as diagnostics,\n" -"" -"AST pretty prints or AST dumps.\n" +" set output " +"Set whether to output only content.\n" " quit, q " -"Terminates the query session.\n\n"; +"Terminates the query session.\n\n" +"Several commands accept a parameter. The available features " +"are:\n\n" +" print " +"pretty-print bound nodes\n" +" diag " +"diagnostic location for bound nodes\n" +" dump " +"Detailed AST output for bound nodes\n\n"; return true; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53500: Add 'detailed-ast' output as an alias for 'dump'
steveire updated this revision to Diff 170420. steveire added a comment. Format Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53500 Files: clang-query/Query.cpp clang-query/Query.h clang-query/QueryParser.cpp Index: clang-query/QueryParser.cpp === --- clang-query/QueryParser.cpp +++ clang-query/QueryParser.cpp @@ -111,11 +111,13 @@ unsigned OutKind = LexOrCompleteWord(this, ValStr) .Case("diag", OK_Diag) .Case("print", OK_Print) - .Case("dump", OK_Dump) + .Case("detailed-ast", OK_DetailedAST) + .Case("dump", OK_DetailedAST) .Default(~0u); if (OutKind == ~0u) { -return new InvalidQuery("expected 'diag', 'print' or 'dump', got '" + -ValStr + "'"); +return new InvalidQuery( +"expected 'diag', 'print', 'detailed-ast' or 'dump', got '" + ValStr + +"'"); } return new SetQuery(&QuerySession::OutKind, OutputKind(OutKind)); } Index: clang-query/Query.h === --- clang-query/Query.h +++ clang-query/Query.h @@ -18,7 +18,7 @@ namespace clang { namespace query { -enum OutputKind { OK_Diag, OK_Print, OK_Dump }; +enum OutputKind { OK_Diag, OK_Print, OK_DetailedAST }; enum QueryKind { QK_Invalid, Index: clang-query/Query.cpp === --- clang-query/Query.cpp +++ clang-query/Query.cpp @@ -53,8 +53,10 @@ "pretty-print bound nodes\n" " diag " "diagnostic location for bound nodes\n" +" detailed-ast " +"Detailed AST output for bound nodes\n" " dump " -"Detailed AST output for bound nodes\n\n"; +"Detailed AST output for bound nodes (alias of deatiled-ast)\n\n"; return true; } @@ -124,7 +126,7 @@ OS << "\n"; break; } -case OK_Dump: { +case OK_DetailedAST: { OS << "Binding for \"" << BI->first << "\":\n"; BI->second.dump(OS, AST->getSourceManager()); OS << "\n"; Index: clang-query/QueryParser.cpp === --- clang-query/QueryParser.cpp +++ clang-query/QueryParser.cpp @@ -111,11 +111,13 @@ unsigned OutKind = LexOrCompleteWord(this, ValStr) .Case("diag", OK_Diag) .Case("print", OK_Print) - .Case("dump", OK_Dump) + .Case("detailed-ast", OK_DetailedAST) + .Case("dump", OK_DetailedAST) .Default(~0u); if (OutKind == ~0u) { -return new InvalidQuery("expected 'diag', 'print' or 'dump', got '" + -ValStr + "'"); +return new InvalidQuery( +"expected 'diag', 'print', 'detailed-ast' or 'dump', got '" + ValStr + +"'"); } return new SetQuery(&QuerySession::OutKind, OutputKind(OutKind)); } Index: clang-query/Query.h === --- clang-query/Query.h +++ clang-query/Query.h @@ -18,7 +18,7 @@ namespace clang { namespace query { -enum OutputKind { OK_Diag, OK_Print, OK_Dump }; +enum OutputKind { OK_Diag, OK_Print, OK_DetailedAST }; enum QueryKind { QK_Invalid, Index: clang-query/Query.cpp === --- clang-query/Query.cpp +++ clang-query/Query.cpp @@ -53,8 +53,10 @@ "pretty-print bound nodes\n" " diag " "diagnostic location for bound nodes\n" +" detailed-ast " +"Detailed AST output for bound nodes\n" " dump " -"Detailed AST output for bound nodes\n\n"; +"Detailed AST output for bound nodes (alias of deatiled-ast)\n\n"; return true; } @@ -124,7 +126,7 @@ OS << "\n"; break; } -case OK_Dump: { +case OK_DetailedAST: { OS << "Binding for \"" << BI->first << "\":\n"; BI->second.dump(OS, AST->getSourceManager()); OS << "\n"; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53501: [clang-query] Refactor Output settings to booleans
steveire created this revision. steveire added a reviewer: aaron.ballman. Herald added a subscriber: cfe-commits. This will make it possible to add non-exclusive mode output. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53501 Files: clang-query/Query.cpp clang-query/Query.h clang-query/QueryParser.cpp clang-query/QuerySession.h Index: clang-query/QuerySession.h === --- clang-query/QuerySession.h +++ clang-query/QuerySession.h @@ -25,11 +25,16 @@ class QuerySession { public: QuerySession(llvm::ArrayRef> ASTs) - : ASTs(ASTs), OutKind(OK_Diag), BindRoot(true), PrintMatcher(false), + : ASTs(ASTs), PrintOutput(true), DiagOutput(true), +DetailedASTOutput(false), BindRoot(true), PrintMatcher(false), Terminate(false) {} llvm::ArrayRef> ASTs; - OutputKind OutKind; + + bool PrintOutput; + bool DiagOutput; + bool DetailedASTOutput; + bool BindRoot; bool PrintMatcher; bool Terminate; Index: clang-query/QueryParser.cpp === --- clang-query/QueryParser.cpp +++ clang-query/QueryParser.cpp @@ -119,7 +119,17 @@ "expected 'diag', 'print', 'detailed-ast' or 'dump', got '" + ValStr + "'"); } - return new SetQuery(&QuerySession::OutKind, OutputKind(OutKind)); + + switch (OutKind) { + case OK_DetailedAST: +return new SetExclusiveOutputQuery(&QuerySession::DetailedASTOutput); + case OK_Diag: +return new SetExclusiveOutputQuery(&QuerySession::DiagOutput); + case OK_Print: +return new SetExclusiveOutputQuery(&QuerySession::PrintOutput); + } + + llvm_unreachable("Invalid output kind"); } QueryRef QueryParser::endQuery(QueryRef Q) { Index: clang-query/Query.h === --- clang-query/Query.h +++ clang-query/Query.h @@ -10,9 +10,11 @@ #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_QUERY_QUERY_H #define LLVM_CLANG_TOOLS_EXTRA_CLANG_QUERY_QUERY_H +#include "QuerySession.h" #include "clang/ASTMatchers/Dynamic/VariantValue.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/Optional.h" + #include namespace clang { @@ -133,6 +135,23 @@ T Value; }; +// Implements the exclusive 'set output dump|diag|print' options +struct SetExclusiveOutputQuery : Query { + SetExclusiveOutputQuery(bool QuerySession::*Var) + : Query(QK_SetOutputKind), Var(Var) {} + bool run(llvm::raw_ostream &OS, QuerySession &QS) const override { +QS.DiagOutput = false; +QS.DetailedASTOutput = false; +QS.PrintOutput = false; +QS.*Var = true; +return true; + } + + static bool classof(const Query *Q) { return Q->Kind == QK_SetOutputKind; } + + bool QuerySession::*Var; +}; + } // namespace query } // namespace clang Index: clang-query/Query.cpp === --- clang-query/Query.cpp +++ clang-query/Query.cpp @@ -107,8 +107,7 @@ for (auto BI = MI->getMap().begin(), BE = MI->getMap().end(); BI != BE; ++BI) { -switch (QS.OutKind) { -case OK_Diag: { +if (QS.DiagOutput) { clang::SourceRange R = BI->second.getSourceRange(); if (R.isValid()) { TextDiagnostic TD(OS, AST->getASTContext().getLangOpts(), @@ -120,19 +119,18 @@ } break; } -case OK_Print: { +if (QS.PrintOutput) { OS << "Binding for \"" << BI->first << "\":\n"; BI->second.print(OS, AST->getASTContext().getPrintingPolicy()); OS << "\n"; break; } -case OK_DetailedAST: { +if (QS.DetailedASTOutput) { OS << "Binding for \"" << BI->first << "\":\n"; BI->second.dump(OS, AST->getSourceManager()); OS << "\n"; break; } -} } if (MI->getMap().empty()) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53025: [clang-tidy] implement new check for const return types.
ymandel updated this revision to Diff 170423. ymandel marked an inline comment as done. ymandel added a comment. Fix some message comments in tests. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53025 Files: clang-tidy/readability/CMakeLists.txt clang-tidy/readability/ConstValueReturnCheck.cpp clang-tidy/readability/ConstValueReturnCheck.h clang-tidy/readability/ReadabilityTidyModule.cpp clang-tidy/utils/LexerUtils.cpp clang-tidy/utils/LexerUtils.h docs/ReleaseNotes.rst docs/clang-tidy/checks/list.rst docs/clang-tidy/checks/readability-const-value-return.rst test/clang-tidy/readability-const-value-return.cpp Index: test/clang-tidy/readability-const-value-return.cpp === --- /dev/null +++ test/clang-tidy/readability-const-value-return.cpp @@ -0,0 +1,203 @@ +// RUN: %check_clang_tidy %s readability-const-value-return %t -- -- -isystem + +// p# = positive test +// n# = negative test + +#include + +const int p1() { +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qualified hindering compiler optimizations +// CHECK-FIXES: int p1() { + return 1; +} + +const int p15(); +// CHECK-FIXES: int p15(); + +template +const int p31(T v) { return 2; } +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qu +// CHECK-FIXES: int p31(T v) { return 2; } + +template class Klazz {}; + +class Clazz { + public: + Clazz *const p2() { +// CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'Clazz *const' is 'co +// CHECK-FIXES: Clazz *p2() { +return this; + } + + Clazz *const p3(); + // CHECK-FIXES: Clazz *p3(); + + const int p4() const { +// CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const int' is 'const +// CHECK-FIXES: int p4() const { +return 4; + } + + const Klazz* const p5() const; + // CHECK-FIXES: const Klazz* p5() const; + + const Clazz operator++(int x) { // p12 + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const Clazz' is 'const + // CHECK-FIXES: Clazz operator++(int x) { + } + + struct Strukt { +int i; + }; + + const Strukt p6() {} + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const Clazz::Strukt' i + // CHECK-FIXES: Strukt p6() {} + + // No warning is emitted here, because this is only the declaration. The + // warning will be associated with the definition, below. + const Strukt* const p7(); + // CHECK-FIXES: const Strukt* p7(); + + static const int p8() {} + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const int' is 'const'- + // CHECK-FIXES: static int p8() {} + + static const Strukt p9() {} + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const Clazz::Strukt' i + // CHECK-FIXES: static Strukt p9() {} + + int n0() const { return 0; } + const Klazz& n11(const Klazz) const; +}; + +Clazz *const Clazz::p3() { + // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'Clazz *const' is 'cons + // CHECK-FIXES: Clazz *Clazz::p3() { + return this; +} + +const Klazz* const Clazz::p5() const {} +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz * +// CHECK-FIXES: const Klazz* Clazz::p5() const {} + +const Clazz::Strukt* const Clazz::p7() {} +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Clazz::Strukt *con +// CHECK-FIXES: const Clazz::Strukt* Clazz::p7() {} + +Clazz *const p10(); +// CHECK-FIXES: Clazz *p10(); + +Clazz *const p10() { + // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'Clazz *const' is 'cons + // CHECK-FIXES: Clazz *p10() { + return new Clazz(); +} + +const Clazz bar; +const Clazz *const p11() { + // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Clazz *const' is + // CHECK-FIXES: const Clazz *p11() { + return &bar; +} + +const Klazz p12() {} +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz' +// CHECK-FIXES: Klazz p12() {} + +const Klazz* const p13() {} +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz * +// CHECK-FIXES: const Klazz* p13() {} + +// re-declaration of p15. +const int p15(); +// CHECK-FIXES: int p15(); + +const int p15() { +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: +// CHECK-FIXES: int p15() { + return 0; +} + +// Exercise the lexer. + +const /* comment */ /* another comment*/ int p16() { return 0; } +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: +// CHECK-FIXES: /* comment */ /* another comment*/ int p16() { return 0; } + +/* comment */ const +// CHECK-MESSAGES: [[@LINE-1]]:15: warning: +// CHECK-FIXES: /* comment */ +// more +/* another comment*/ int p17() { return 0; } + +// Test cases where the `const` token lexically is hidden behind some form of +// indirection. + +#define CONSTINT const int +CONSTINT p18() {} +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qu + +#define CONST const +CONST int p19() {} +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qu + +us
[PATCH] D53025: [clang-tidy] implement new check for const return types.
ymandel added a comment. Correction: the code *catches* the trailing return cases, I just couldn't find a way to *fix* them; specifically, I was not able to get the necessary source ranges to re-lex the trailing return type. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53025 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53503: [clangd] Support URISchemes configuration in BackgroundIndex.
ioeric created this revision. ioeric added a reviewer: sammccall. Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, ilya-biryukov. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53503 Files: clangd/index/Background.cpp clangd/index/Background.h Index: clangd/index/Background.h === --- clangd/index/Background.h +++ clangd/index/Background.h @@ -18,7 +18,9 @@ #include "llvm/Support/SHA1.h" #include #include +#include #include +#include namespace clang { namespace clangd { @@ -31,7 +33,8 @@ public: // FIXME: resource-dir injection should be hoisted somewhere common. BackgroundIndex(Context BackgroundContext, StringRef ResourceDir, - const FileSystemProvider &); + const FileSystemProvider &, + ArrayRef URISchemes = {}); ~BackgroundIndex(); // Blocks while the current task finishes. // Enqueue a translation unit for indexing. @@ -54,6 +57,7 @@ std::string ResourceDir; const FileSystemProvider &FSProvider; Context BackgroundContext; + std::vector URISchemes; // index state llvm::Error index(tooling::CompileCommand); Index: clangd/index/Background.cpp === --- clangd/index/Background.cpp +++ clangd/index/Background.cpp @@ -24,10 +24,11 @@ BackgroundIndex::BackgroundIndex(Context BackgroundContext, StringRef ResourceDir, - const FileSystemProvider &FSProvider) + const FileSystemProvider &FSProvider, + ArrayRef URISchemes) : SwapIndex(make_unique()), ResourceDir(ResourceDir), FSProvider(FSProvider), BackgroundContext(std::move(BackgroundContext)), - Thread([this] { run(); }) {} + URISchemes(URISchemes), Thread([this] { run(); }) {} BackgroundIndex::~BackgroundIndex() { stop(); @@ -185,7 +186,7 @@ // FIXME: this should rebuild once-in-a-while, not after every file. // At that point we should use Dex, too. vlog("Rebuilding automatic index"); - reset(IndexedSymbols.buildIndex(IndexType::Light)); + reset(IndexedSymbols.buildIndex(IndexType::Light, URISchemes)); return Error::success(); } Index: clangd/index/Background.h === --- clangd/index/Background.h +++ clangd/index/Background.h @@ -18,7 +18,9 @@ #include "llvm/Support/SHA1.h" #include #include +#include #include +#include namespace clang { namespace clangd { @@ -31,7 +33,8 @@ public: // FIXME: resource-dir injection should be hoisted somewhere common. BackgroundIndex(Context BackgroundContext, StringRef ResourceDir, - const FileSystemProvider &); + const FileSystemProvider &, + ArrayRef URISchemes = {}); ~BackgroundIndex(); // Blocks while the current task finishes. // Enqueue a translation unit for indexing. @@ -54,6 +57,7 @@ std::string ResourceDir; const FileSystemProvider &FSProvider; Context BackgroundContext; + std::vector URISchemes; // index state llvm::Error index(tooling::CompileCommand); Index: clangd/index/Background.cpp === --- clangd/index/Background.cpp +++ clangd/index/Background.cpp @@ -24,10 +24,11 @@ BackgroundIndex::BackgroundIndex(Context BackgroundContext, StringRef ResourceDir, - const FileSystemProvider &FSProvider) + const FileSystemProvider &FSProvider, + ArrayRef URISchemes) : SwapIndex(make_unique()), ResourceDir(ResourceDir), FSProvider(FSProvider), BackgroundContext(std::move(BackgroundContext)), - Thread([this] { run(); }) {} + URISchemes(URISchemes), Thread([this] { run(); }) {} BackgroundIndex::~BackgroundIndex() { stop(); @@ -185,7 +186,7 @@ // FIXME: this should rebuild once-in-a-while, not after every file. // At that point we should use Dex, too. vlog("Rebuilding automatic index"); - reset(IndexedSymbols.buildIndex(IndexType::Light)); + reset(IndexedSymbols.buildIndex(IndexType::Light, URISchemes)); return Error::success(); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53500: Add 'detailed-ast' output as an alias for 'dump'
steveire updated this revision to Diff 170427. steveire added a comment. Update tests Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53500 Files: clang-query/Query.cpp clang-query/Query.h clang-query/QueryParser.cpp unittests/clang-query/QueryEngineTest.cpp unittests/clang-query/QueryParserTest.cpp Index: unittests/clang-query/QueryParserTest.cpp === --- unittests/clang-query/QueryParserTest.cpp +++ unittests/clang-query/QueryParserTest.cpp @@ -70,22 +70,27 @@ Q = parse("set output"); ASSERT_TRUE(isa(Q)); - EXPECT_EQ("expected 'diag', 'print' or 'dump', got ''", + EXPECT_EQ("expected 'diag', 'print', 'detailed-ast' or 'dump', got ''", cast(Q)->ErrStr); Q = parse("set bind-root true foo"); ASSERT_TRUE(isa(Q)); EXPECT_EQ("unexpected extra input: ' foo'", cast(Q)->ErrStr); Q = parse("set output foo"); ASSERT_TRUE(isa(Q)); - EXPECT_EQ("expected 'diag', 'print' or 'dump', got 'foo'", + EXPECT_EQ("expected 'diag', 'print', 'detailed-ast' or 'dump', got 'foo'", cast(Q)->ErrStr); Q = parse("set output dump"); ASSERT_TRUE(isa >(Q)); EXPECT_EQ(&QuerySession::OutKind, cast >(Q)->Var); - EXPECT_EQ(OK_Dump, cast >(Q)->Value); + EXPECT_EQ(OK_DetailedAST, cast>(Q)->Value); + + Q = parse("set output detailed-ast"); + ASSERT_TRUE(isa>(Q)); + EXPECT_EQ(&QuerySession::OutKind, cast>(Q)->Var); + EXPECT_EQ(OK_DetailedAST, cast>(Q)->Value); Q = parse("set bind-root foo"); ASSERT_TRUE(isa(Q)); Index: unittests/clang-query/QueryEngineTest.cpp === --- unittests/clang-query/QueryEngineTest.cpp +++ unittests/clang-query/QueryEngineTest.cpp @@ -103,7 +103,8 @@ Str.clear(); - EXPECT_TRUE(SetQuery(&QuerySession::OutKind, OK_Dump).run(OS, S)); + EXPECT_TRUE( + SetQuery(&QuerySession::OutKind, OK_DetailedAST).run(OS, S)); EXPECT_TRUE(MatchQuery(FooMatcherString, FooMatcher).run(OS, S)); EXPECT_TRUE(OS.str().find("FunctionDecl") != std::string::npos); Index: clang-query/QueryParser.cpp === --- clang-query/QueryParser.cpp +++ clang-query/QueryParser.cpp @@ -111,11 +111,13 @@ unsigned OutKind = LexOrCompleteWord(this, ValStr) .Case("diag", OK_Diag) .Case("print", OK_Print) - .Case("dump", OK_Dump) + .Case("detailed-ast", OK_DetailedAST) + .Case("dump", OK_DetailedAST) .Default(~0u); if (OutKind == ~0u) { -return new InvalidQuery("expected 'diag', 'print' or 'dump', got '" + -ValStr + "'"); +return new InvalidQuery( +"expected 'diag', 'print', 'detailed-ast' or 'dump', got '" + ValStr + +"'"); } return new SetQuery(&QuerySession::OutKind, OutputKind(OutKind)); } Index: clang-query/Query.h === --- clang-query/Query.h +++ clang-query/Query.h @@ -18,7 +18,7 @@ namespace clang { namespace query { -enum OutputKind { OK_Diag, OK_Print, OK_Dump }; +enum OutputKind { OK_Diag, OK_Print, OK_DetailedAST }; enum QueryKind { QK_Invalid, Index: clang-query/Query.cpp === --- clang-query/Query.cpp +++ clang-query/Query.cpp @@ -53,8 +53,10 @@ "pretty-print bound nodes\n" " diag " "diagnostic location for bound nodes\n" +" detailed-ast " +"Detailed AST output for bound nodes\n" " dump " -"Detailed AST output for bound nodes\n\n"; +"Detailed AST output for bound nodes (alias of deatiled-ast)\n\n"; return true; } @@ -124,7 +126,7 @@ OS << "\n"; break; } -case OK_Dump: { +case OK_DetailedAST: { OS << "Binding for \"" << BI->first << "\":\n"; BI->second.dump(OS, AST->getSourceManager()); OS << "\n"; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r344912 - [clangd] Support URISchemes configuration in BackgroundIndex.
Author: ioeric Date: Mon Oct 22 08:37:58 2018 New Revision: 344912 URL: http://llvm.org/viewvc/llvm-project?rev=344912&view=rev Log: [clangd] Support URISchemes configuration in BackgroundIndex. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D53503 Modified: clang-tools-extra/trunk/clangd/index/Background.cpp clang-tools-extra/trunk/clangd/index/Background.h Modified: clang-tools-extra/trunk/clangd/index/Background.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=344912&r1=344911&r2=344912&view=diff == --- clang-tools-extra/trunk/clangd/index/Background.cpp (original) +++ clang-tools-extra/trunk/clangd/index/Background.cpp Mon Oct 22 08:37:58 2018 @@ -24,10 +24,11 @@ namespace clangd { BackgroundIndex::BackgroundIndex(Context BackgroundContext, StringRef ResourceDir, - const FileSystemProvider &FSProvider) + const FileSystemProvider &FSProvider, + ArrayRef URISchemes) : SwapIndex(make_unique()), ResourceDir(ResourceDir), FSProvider(FSProvider), BackgroundContext(std::move(BackgroundContext)), - Thread([this] { run(); }) {} + URISchemes(URISchemes), Thread([this] { run(); }) {} BackgroundIndex::~BackgroundIndex() { stop(); @@ -185,7 +186,7 @@ Error BackgroundIndex::index(tooling::Co // FIXME: this should rebuild once-in-a-while, not after every file. // At that point we should use Dex, too. vlog("Rebuilding automatic index"); - reset(IndexedSymbols.buildIndex(IndexType::Light)); + reset(IndexedSymbols.buildIndex(IndexType::Light, URISchemes)); return Error::success(); } Modified: clang-tools-extra/trunk/clangd/index/Background.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.h?rev=344912&r1=344911&r2=344912&view=diff == --- clang-tools-extra/trunk/clangd/index/Background.h (original) +++ clang-tools-extra/trunk/clangd/index/Background.h Mon Oct 22 08:37:58 2018 @@ -18,7 +18,9 @@ #include "llvm/Support/SHA1.h" #include #include +#include #include +#include namespace clang { namespace clangd { @@ -31,7 +33,8 @@ class BackgroundIndex : public SwapIndex public: // FIXME: resource-dir injection should be hoisted somewhere common. BackgroundIndex(Context BackgroundContext, StringRef ResourceDir, - const FileSystemProvider &); + const FileSystemProvider &, + ArrayRef URISchemes = {}); ~BackgroundIndex(); // Blocks while the current task finishes. // Enqueue a translation unit for indexing. @@ -54,6 +57,7 @@ private: std::string ResourceDir; const FileSystemProvider &FSProvider; Context BackgroundContext; + std::vector URISchemes; // index state llvm::Error index(tooling::CompileCommand); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53503: [clangd] Support URISchemes configuration in BackgroundIndex.
This revision was automatically updated to reflect the committed changes. Closed by commit rL344912: [clangd] Support URISchemes configuration in BackgroundIndex. (authored by ioeric, committed by ). Herald added a subscriber: llvm-commits. Repository: rL LLVM https://reviews.llvm.org/D53503 Files: clang-tools-extra/trunk/clangd/index/Background.cpp clang-tools-extra/trunk/clangd/index/Background.h Index: clang-tools-extra/trunk/clangd/index/Background.h === --- clang-tools-extra/trunk/clangd/index/Background.h +++ clang-tools-extra/trunk/clangd/index/Background.h @@ -18,7 +18,9 @@ #include "llvm/Support/SHA1.h" #include #include +#include #include +#include namespace clang { namespace clangd { @@ -31,7 +33,8 @@ public: // FIXME: resource-dir injection should be hoisted somewhere common. BackgroundIndex(Context BackgroundContext, StringRef ResourceDir, - const FileSystemProvider &); + const FileSystemProvider &, + ArrayRef URISchemes = {}); ~BackgroundIndex(); // Blocks while the current task finishes. // Enqueue a translation unit for indexing. @@ -54,6 +57,7 @@ std::string ResourceDir; const FileSystemProvider &FSProvider; Context BackgroundContext; + std::vector URISchemes; // index state llvm::Error index(tooling::CompileCommand); Index: clang-tools-extra/trunk/clangd/index/Background.cpp === --- clang-tools-extra/trunk/clangd/index/Background.cpp +++ clang-tools-extra/trunk/clangd/index/Background.cpp @@ -24,10 +24,11 @@ BackgroundIndex::BackgroundIndex(Context BackgroundContext, StringRef ResourceDir, - const FileSystemProvider &FSProvider) + const FileSystemProvider &FSProvider, + ArrayRef URISchemes) : SwapIndex(make_unique()), ResourceDir(ResourceDir), FSProvider(FSProvider), BackgroundContext(std::move(BackgroundContext)), - Thread([this] { run(); }) {} + URISchemes(URISchemes), Thread([this] { run(); }) {} BackgroundIndex::~BackgroundIndex() { stop(); @@ -185,7 +186,7 @@ // FIXME: this should rebuild once-in-a-while, not after every file. // At that point we should use Dex, too. vlog("Rebuilding automatic index"); - reset(IndexedSymbols.buildIndex(IndexType::Light)); + reset(IndexedSymbols.buildIndex(IndexType::Light, URISchemes)); return Error::success(); } Index: clang-tools-extra/trunk/clangd/index/Background.h === --- clang-tools-extra/trunk/clangd/index/Background.h +++ clang-tools-extra/trunk/clangd/index/Background.h @@ -18,7 +18,9 @@ #include "llvm/Support/SHA1.h" #include #include +#include #include +#include namespace clang { namespace clangd { @@ -31,7 +33,8 @@ public: // FIXME: resource-dir injection should be hoisted somewhere common. BackgroundIndex(Context BackgroundContext, StringRef ResourceDir, - const FileSystemProvider &); + const FileSystemProvider &, + ArrayRef URISchemes = {}); ~BackgroundIndex(); // Blocks while the current task finishes. // Enqueue a translation unit for indexing. @@ -54,6 +57,7 @@ std::string ResourceDir; const FileSystemProvider &FSProvider; Context BackgroundContext; + std::vector URISchemes; // index state llvm::Error index(tooling::CompileCommand); Index: clang-tools-extra/trunk/clangd/index/Background.cpp === --- clang-tools-extra/trunk/clangd/index/Background.cpp +++ clang-tools-extra/trunk/clangd/index/Background.cpp @@ -24,10 +24,11 @@ BackgroundIndex::BackgroundIndex(Context BackgroundContext, StringRef ResourceDir, - const FileSystemProvider &FSProvider) + const FileSystemProvider &FSProvider, + ArrayRef URISchemes) : SwapIndex(make_unique()), ResourceDir(ResourceDir), FSProvider(FSProvider), BackgroundContext(std::move(BackgroundContext)), - Thread([this] { run(); }) {} + URISchemes(URISchemes), Thread([this] { run(); }) {} BackgroundIndex::~BackgroundIndex() { stop(); @@ -185,7 +186,7 @@ // FIXME: this should rebuild once-in-a-while, not after every file. // At that point we should use Dex, too. vlog("Rebuilding automatic index"); - reset(IndexedSymbols.buildIndex(IndexType::Light)); + reset(IndexedSymbols.buildIndex(IndexType::Light, URISchemes)); return Error::success(); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-co
[PATCH] D53501: [clang-query] Refactor Output settings to booleans
steveire updated this revision to Diff 170431. steveire added a comment. Update tests Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53501 Files: clang-query/Query.cpp clang-query/Query.h clang-query/QueryParser.cpp clang-query/QuerySession.h unittests/clang-query/QueryEngineTest.cpp unittests/clang-query/QueryParserTest.cpp Index: unittests/clang-query/QueryParserTest.cpp === --- unittests/clang-query/QueryParserTest.cpp +++ unittests/clang-query/QueryParserTest.cpp @@ -83,14 +83,12 @@ cast(Q)->ErrStr); Q = parse("set output dump"); - ASSERT_TRUE(isa >(Q)); - EXPECT_EQ(&QuerySession::OutKind, cast >(Q)->Var); - EXPECT_EQ(OK_DetailedAST, cast>(Q)->Value); + ASSERT_TRUE(isa(Q)); + EXPECT_EQ(&QuerySession::DetailedASTOutput, cast(Q)->Var); Q = parse("set output detailed-ast"); - ASSERT_TRUE(isa>(Q)); - EXPECT_EQ(&QuerySession::OutKind, cast>(Q)->Var); - EXPECT_EQ(OK_DetailedAST, cast>(Q)->Value); + ASSERT_TRUE(isa(Q)); + EXPECT_EQ(&QuerySession::DetailedASTOutput, cast(Q)->Var); Q = parse("set bind-root foo"); ASSERT_TRUE(isa(Q)); Index: unittests/clang-query/QueryEngineTest.cpp === --- unittests/clang-query/QueryEngineTest.cpp +++ unittests/clang-query/QueryEngineTest.cpp @@ -95,16 +95,16 @@ Str.clear(); EXPECT_TRUE( - SetQuery(&QuerySession::OutKind, OK_Print).run(OS, S)); + SetExclusiveOutputQuery(&QuerySession::PrintOutput).run(OS, S)); EXPECT_TRUE(MatchQuery(FooMatcherString, FooMatcher).run(OS, S)); EXPECT_TRUE(OS.str().find("Binding for \"root\":\nvoid foo1()") != std::string::npos); Str.clear(); EXPECT_TRUE( - SetQuery(&QuerySession::OutKind, OK_DetailedAST).run(OS, S)); + SetExclusiveOutputQuery(&QuerySession::DetailedASTOutput).run(OS, S)); EXPECT_TRUE(MatchQuery(FooMatcherString, FooMatcher).run(OS, S)); EXPECT_TRUE(OS.str().find("FunctionDecl") != std::string::npos); Index: clang-query/QuerySession.h === --- clang-query/QuerySession.h +++ clang-query/QuerySession.h @@ -25,11 +25,16 @@ class QuerySession { public: QuerySession(llvm::ArrayRef> ASTs) - : ASTs(ASTs), OutKind(OK_Diag), BindRoot(true), PrintMatcher(false), + : ASTs(ASTs), PrintOutput(false), DiagOutput(true), +DetailedASTOutput(false), BindRoot(true), PrintMatcher(false), Terminate(false) {} llvm::ArrayRef> ASTs; - OutputKind OutKind; + + bool PrintOutput; + bool DiagOutput; + bool DetailedASTOutput; + bool BindRoot; bool PrintMatcher; bool Terminate; Index: clang-query/QueryParser.cpp === --- clang-query/QueryParser.cpp +++ clang-query/QueryParser.cpp @@ -119,7 +119,17 @@ "expected 'diag', 'print', 'detailed-ast' or 'dump', got '" + ValStr + "'"); } - return new SetQuery(&QuerySession::OutKind, OutputKind(OutKind)); + + switch (OutKind) { + case OK_DetailedAST: +return new SetExclusiveOutputQuery(&QuerySession::DetailedASTOutput); + case OK_Diag: +return new SetExclusiveOutputQuery(&QuerySession::DiagOutput); + case OK_Print: +return new SetExclusiveOutputQuery(&QuerySession::PrintOutput); + } + + llvm_unreachable("Invalid output kind"); } QueryRef QueryParser::endQuery(QueryRef Q) { Index: clang-query/Query.h === --- clang-query/Query.h +++ clang-query/Query.h @@ -10,9 +10,11 @@ #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_QUERY_QUERY_H #define LLVM_CLANG_TOOLS_EXTRA_CLANG_QUERY_QUERY_H +#include "QuerySession.h" #include "clang/ASTMatchers/Dynamic/VariantValue.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/Optional.h" + #include namespace clang { @@ -133,6 +135,23 @@ T Value; }; +// Implements the exclusive 'set output dump|diag|print' options +struct SetExclusiveOutputQuery : Query { + SetExclusiveOutputQuery(bool QuerySession::*Var) + : Query(QK_SetOutputKind), Var(Var) {} + bool run(llvm::raw_ostream &OS, QuerySession &QS) const override { +QS.DiagOutput = false; +QS.DetailedASTOutput = false; +QS.PrintOutput = false; +QS.*Var = true; +return true; + } + + static bool classof(const Query *Q) { return Q->Kind == QK_SetOutputKind; } + + bool QuerySession::*Var; +}; + } // namespace query } // namespace clang Index: clang-query/Query.cpp === --- clang-query/Query.cpp +++ clang-query/Query.cpp @@ -107,8 +107,7 @@ for (auto BI = MI->getMap().begin(), BE = MI->getMap().end(); BI != BE; ++BI) { -switch (QS.OutKind) { -case OK_Diag: { +if (QS.DiagOutput) { clang::SourceRange R = BI->second.getSourceRange();
[PATCH] D53296: [analyzer] New flag to print all -analyzer-config options
Szelethus updated this revision to Diff 170432. Szelethus edited the summary of this revision. Szelethus added a comment. Fixes according to inline comments, type and default value are generated now. https://reviews.llvm.org/D53296 Files: include/clang/Driver/CC1Options.td include/clang/StaticAnalyzer/Core/AnalyzerOptions.h include/clang/StaticAnalyzer/Frontend/FrontendActions.h lib/Frontend/CompilerInvocation.cpp lib/FrontendTool/ExecuteCompilerInvocation.cpp lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp test/Analysis/analyzer-list-configs.c Index: test/Analysis/analyzer-list-configs.c === --- /dev/null +++ test/Analysis/analyzer-list-configs.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -analyzer-config-help 2>&1 | FileCheck %s +// CHECK: OVERVIEW: Clang Static Analyzer -analyzer-config Option List +// +// CHECK: USAGE: clang -cc1 [CLANG_OPTIONS] -analyzer-config +// +// CHCEK: clang -cc1 [CLANG_OPTIONS] -analyzer-config OPTION1=VALUE, -analyzer-config OPTION2=VALUE, ... +// +// CHECK: clang [CLANG_OPTIONS] -Xclang -analyzer-config -Xclang +// +// CHECK: clang [CLANG_OPTIONS] -Xclang -analyzer-config -Xclang OPTION1=VALUE, -Xclang -analyzer-config -Xclang OPTION2=VALUE, ... +// +// +// CHECK: OPTIONS: Index: lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp === --- lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp +++ lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp @@ -22,6 +22,7 @@ #include "clang/StaticAnalyzer/Frontend/FrontendActions.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/DynamicLibrary.h" +#include "llvm/Support/FormattedStream.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include @@ -157,3 +158,75 @@ SmallVector checkerOpts = getCheckerOptList(opts); ClangCheckerRegistry(plugins).printList(out, checkerOpts); } + +void ento::printAnalyzerConfigList(raw_ostream &out) { + out << "OVERVIEW: Clang Static Analyzer -analyzer-config Option List\n\n"; + out << "USAGE: clang -cc1 [CLANG_OPTIONS] -analyzer-config " +"\n\n"; + out << " clang -cc1 [CLANG_OPTIONS] -analyzer-config OPTION1=VALUE, " + "-analyzer-config OPTION2=VALUE, ...\n\n"; + out << " clang [CLANG_OPTIONS] -Xclang -analyzer-config -Xclang" +"\n\n"; + out << " clang [CLANG_OPTIONS] -Xclang -analyzer-config -Xclang " + "OPTION1=VALUE, -Xclang -analyzer-config -Xclang " + "OPTION2=VALUE, ...\n\n"; + out << "OPTIONS:\n\n"; + + using OptionAndDescriptionTy = std::pair; + OptionAndDescriptionTy PrintableOptions[] = { +#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL)\ +{ \ + CMDFLAG, \ + llvm::Twine(llvm::Twine() + "(" +\ + (#TYPE == "StringRef" ? "string" : #TYPE ) + ") " DESC \ + " (default: " #DEFAULT_VAL ")").str()\ +}, + +#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC,\ + SHALLOW_VAL, DEEP_VAL)\ +{ \ + CMDFLAG, \ + llvm::Twine(llvm::Twine() + "(" +\ + (#TYPE == "StringRef" ? "string" : #TYPE ) + ") " DESC \ + " (default: " #SHALLOW_VAL " in shallow mode, " #DEEP_VAL\ + " in deep mode)").str() \ +}, +#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def" +#undef ANALYZER_OPTION +#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE + }; + + llvm::sort(PrintableOptions, [](const OptionAndDescriptionTy &LHS, + const OptionAndDescriptionTy &RHS) { +return LHS.first < RHS.first; + }); + + constexpr size_t MinLineWidth = 70; + constexpr size_t PadForOpt = 2; + constexpr size_t OptionWidth = 30; + constexpr size_t PadForDesc = PadForOpt + OptionWidth; + static_assert(MinLineWidth > PadForDesc, "MinLineWidth must be greater!"); + + llvm::formatted_raw_ostream FOut(out); + + for (const auto &Pair : PrintableOptions) { +FOut.PadToColumn(PadForOpt) << Pair.first; + +// If the buffer's length is greater then PadForDesc, print a newline. +if (FOut.getColumn() > PadForDesc) { + FOut << '\n'; +} + +FOut.PadToColumn(PadForDesc); + +for (char C : Pair.second) { + if (FOut.getColumn() > MinLineWidth && C == '
[PATCH] D53459: Ensure sanitizer check function calls have a !dbg location
aprantl updated this revision to Diff 170433. aprantl added a comment. Simplify testcase https://reviews.llvm.org/D53459 Files: lib/CodeGen/CGExpr.cpp test/CodeGenCXX/ubsan-check-debuglocs.cpp Index: test/CodeGenCXX/ubsan-check-debuglocs.cpp === --- /dev/null +++ test/CodeGenCXX/ubsan-check-debuglocs.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited \ +// RUN: -fsanitize=null %s -o - | FileCheck %s + +// Check that santizer check calls have a !dbg location. +// CHECK: define {{.*}}acquire{{.*}} !dbg +// CHECK-NOT: define +// CHECK: call void {{.*}}@__ubsan_handle_type_mismatch_v1 +// CHECK-SAME: !dbg + +class SourceLocation { +public: + SourceLocation acquire() {}; +}; +extern "C" void __ubsan_handle_type_mismatch_v1(SourceLocation *Loc); +static void handleTypeMismatchImpl(SourceLocation *Loc) { Loc->acquire(); } +void __ubsan_handle_type_mismatch_v1(SourceLocation *Loc) { + handleTypeMismatchImpl(Loc); +} Index: lib/CodeGen/CGExpr.cpp === --- lib/CodeGen/CGExpr.cpp +++ lib/CodeGen/CGExpr.cpp @@ -2867,6 +2867,9 @@ CheckRecoverableKind RecoverKind, bool IsFatal, llvm::BasicBlock *ContBB) { assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable); + auto *DI = CGF.getDebugInfo(); + SourceLocation Loc = DI ? DI->getLocation() : SourceLocation(); + auto DL = ApplyDebugLocation::CreateDefaultArtificial(CGF, Loc); bool NeedsAbortSuffix = IsFatal && RecoverKind != CheckRecoverableKind::Unrecoverable; bool MinimalRuntime = CGF.CGM.getCodeGenOpts().SanitizeMinimalRuntime; Index: test/CodeGenCXX/ubsan-check-debuglocs.cpp === --- /dev/null +++ test/CodeGenCXX/ubsan-check-debuglocs.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited \ +// RUN: -fsanitize=null %s -o - | FileCheck %s + +// Check that santizer check calls have a !dbg location. +// CHECK: define {{.*}}acquire{{.*}} !dbg +// CHECK-NOT: define +// CHECK: call void {{.*}}@__ubsan_handle_type_mismatch_v1 +// CHECK-SAME: !dbg + +class SourceLocation { +public: + SourceLocation acquire() {}; +}; +extern "C" void __ubsan_handle_type_mismatch_v1(SourceLocation *Loc); +static void handleTypeMismatchImpl(SourceLocation *Loc) { Loc->acquire(); } +void __ubsan_handle_type_mismatch_v1(SourceLocation *Loc) { + handleTypeMismatchImpl(Loc); +} Index: lib/CodeGen/CGExpr.cpp === --- lib/CodeGen/CGExpr.cpp +++ lib/CodeGen/CGExpr.cpp @@ -2867,6 +2867,9 @@ CheckRecoverableKind RecoverKind, bool IsFatal, llvm::BasicBlock *ContBB) { assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable); + auto *DI = CGF.getDebugInfo(); + SourceLocation Loc = DI ? DI->getLocation() : SourceLocation(); + auto DL = ApplyDebugLocation::CreateDefaultArtificial(CGF, Loc); bool NeedsAbortSuffix = IsFatal && RecoverKind != CheckRecoverableKind::Unrecoverable; bool MinimalRuntime = CGF.CGM.getCodeGenOpts().SanitizeMinimalRuntime; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53459: Ensure sanitizer check function calls have a !dbg location
aprantl updated this revision to Diff 170434. aprantl added a comment. further simplify testcase https://reviews.llvm.org/D53459 Files: lib/CodeGen/CGExpr.cpp test/CodeGenCXX/ubsan-check-debuglocs.cpp Index: test/CodeGenCXX/ubsan-check-debuglocs.cpp === --- /dev/null +++ test/CodeGenCXX/ubsan-check-debuglocs.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited \ +// RUN: -fsanitize=null %s -o - | FileCheck %s + +// Check that santizer check calls have a !dbg location. +// CHECK: define {{.*}}acquire{{.*}} !dbg +// CHECK-NOT: define +// CHECK: call void {{.*}}@__ubsan_handle_type_mismatch_v1 +// CHECK-SAME: !dbg + +struct SourceLocation { + SourceLocation acquire() {}; +}; +extern "C" void __ubsan_handle_type_mismatch_v1(SourceLocation *Loc); +static void handleTypeMismatchImpl(SourceLocation *Loc) { Loc->acquire(); } +void __ubsan_handle_type_mismatch_v1(SourceLocation *Loc) { + handleTypeMismatchImpl(Loc); +} Index: lib/CodeGen/CGExpr.cpp === --- lib/CodeGen/CGExpr.cpp +++ lib/CodeGen/CGExpr.cpp @@ -2867,6 +2867,9 @@ CheckRecoverableKind RecoverKind, bool IsFatal, llvm::BasicBlock *ContBB) { assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable); + auto *DI = CGF.getDebugInfo(); + SourceLocation Loc = DI ? DI->getLocation() : SourceLocation(); + auto DL = ApplyDebugLocation::CreateDefaultArtificial(CGF, Loc); bool NeedsAbortSuffix = IsFatal && RecoverKind != CheckRecoverableKind::Unrecoverable; bool MinimalRuntime = CGF.CGM.getCodeGenOpts().SanitizeMinimalRuntime; Index: test/CodeGenCXX/ubsan-check-debuglocs.cpp === --- /dev/null +++ test/CodeGenCXX/ubsan-check-debuglocs.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited \ +// RUN: -fsanitize=null %s -o - | FileCheck %s + +// Check that santizer check calls have a !dbg location. +// CHECK: define {{.*}}acquire{{.*}} !dbg +// CHECK-NOT: define +// CHECK: call void {{.*}}@__ubsan_handle_type_mismatch_v1 +// CHECK-SAME: !dbg + +struct SourceLocation { + SourceLocation acquire() {}; +}; +extern "C" void __ubsan_handle_type_mismatch_v1(SourceLocation *Loc); +static void handleTypeMismatchImpl(SourceLocation *Loc) { Loc->acquire(); } +void __ubsan_handle_type_mismatch_v1(SourceLocation *Loc) { + handleTypeMismatchImpl(Loc); +} Index: lib/CodeGen/CGExpr.cpp === --- lib/CodeGen/CGExpr.cpp +++ lib/CodeGen/CGExpr.cpp @@ -2867,6 +2867,9 @@ CheckRecoverableKind RecoverKind, bool IsFatal, llvm::BasicBlock *ContBB) { assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable); + auto *DI = CGF.getDebugInfo(); + SourceLocation Loc = DI ? DI->getLocation() : SourceLocation(); + auto DL = ApplyDebugLocation::CreateDefaultArtificial(CGF, Loc); bool NeedsAbortSuffix = IsFatal && RecoverKind != CheckRecoverableKind::Unrecoverable; bool MinimalRuntime = CGF.CGM.getCodeGenOpts().SanitizeMinimalRuntime; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52857: [clang-query] Add non-exclusive output API
steveire updated this revision to Diff 170435. steveire retitled this revision from "[clang-query] Add non-exclusive output API " to "[clang-query] Add non-exclusive output API". steveire added a comment. New design Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D52857 Files: clang-query/Query.h clang-query/QueryParser.cpp clang-query/QueryParser.h unittests/clang-query/QueryEngineTest.cpp unittests/clang-query/QueryParserTest.cpp Index: unittests/clang-query/QueryParserTest.cpp === --- unittests/clang-query/QueryParserTest.cpp +++ unittests/clang-query/QueryParserTest.cpp @@ -90,6 +90,14 @@ ASSERT_TRUE(isa(Q)); EXPECT_EQ(&QuerySession::DetailedASTOutput, cast(Q)->Var); + Q = parse("set enable-output detailed-ast"); + ASSERT_TRUE(isa(Q)); + EXPECT_EQ(&QuerySession::DetailedASTOutput, cast(Q)->Var); + + Q = parse("set disable-output detailed-ast"); + ASSERT_TRUE(isa(Q)); + EXPECT_EQ(&QuerySession::DetailedASTOutput, cast(Q)->Var); + Q = parse("set bind-root foo"); ASSERT_TRUE(isa(Q)); EXPECT_EQ("expected 'true' or 'false', got 'foo'", Index: unittests/clang-query/QueryEngineTest.cpp === --- unittests/clang-query/QueryEngineTest.cpp +++ unittests/clang-query/QueryEngineTest.cpp @@ -111,6 +111,21 @@ Str.clear(); + EXPECT_TRUE( + EnableOutputQuery(&QuerySession::DiagOutput).run(OS, S)); + EXPECT_TRUE( + EnableOutputQuery(&QuerySession::DetailedASTOutput).run(OS, S)); + EXPECT_TRUE(MatchQuery(FooMatcherString, FooMatcher).run(OS, S)); + + { +auto Output = OS.str(); +EXPECT_TRUE(Output.find("FunctionDecl") != std::string::npos); +EXPECT_TRUE(Output.find("foo.cc:1:1: note: \"root\" binds here") != +std::string::npos); + } + + Str.clear(); + EXPECT_TRUE(SetQuery(&QuerySession::BindRoot, false).run(OS, S)); EXPECT_TRUE(MatchQuery(FooMatcherString, FooMatcher).run(OS, S)); Index: clang-query/QueryParser.h === --- clang-query/QueryParser.h +++ clang-query/QueryParser.h @@ -44,6 +44,7 @@ template struct LexOrCompleteWord; QueryRef parseSetBool(bool QuerySession::*Var); + template QueryRef parseSetOutputKind(); QueryRef completeMatcherExpression(); Index: clang-query/QueryParser.cpp === --- clang-query/QueryParser.cpp +++ clang-query/QueryParser.cpp @@ -106,6 +106,7 @@ return new SetQuery(Var, Value); } +template QueryRef QueryParser::parseSetOutputKind() { StringRef ValStr; unsigned OutKind = LexOrCompleteWord(this, ValStr) @@ -122,11 +123,11 @@ switch (OutKind) { case OK_DetailedAST: -return new SetExclusiveOutputQuery(&QuerySession::DetailedASTOutput); +return new QueryType(&QuerySession::DetailedASTOutput); case OK_Diag: -return new SetExclusiveOutputQuery(&QuerySession::DiagOutput); +return new QueryType(&QuerySession::DiagOutput); case OK_Print: -return new SetExclusiveOutputQuery(&QuerySession::PrintOutput); +return new QueryType(&QuerySession::PrintOutput); } llvm_unreachable("Invalid output kind"); @@ -157,6 +158,8 @@ enum ParsedQueryVariable { PQV_Invalid, PQV_Output, + PQV_EnableOutput, + PQV_DisableOutput, PQV_BindRoot, PQV_PrintMatcher }; @@ -245,6 +248,8 @@ ParsedQueryVariable Var = LexOrCompleteWord(this, VarStr) .Case("output", PQV_Output) +.Case("enable-output", PQV_EnableOutput) +.Case("disable-output", PQV_DisableOutput) .Case("bind-root", PQV_BindRoot) .Case("print-matcher", PQV_PrintMatcher) .Default(PQV_Invalid); @@ -256,7 +261,13 @@ QueryRef Q; switch (Var) { case PQV_Output: - Q = parseSetOutputKind(); + Q = parseSetOutputKind(); + break; +case PQV_EnableOutput: + Q = parseSetOutputKind(); + break; +case PQV_DisableOutput: + Q = parseSetOutputKind(); break; case PQV_BindRoot: Q = parseSetBool(&QuerySession::BindRoot); Index: clang-query/Query.h === --- clang-query/Query.h +++ clang-query/Query.h @@ -152,6 +152,30 @@ bool QuerySession::*Var; }; +// Implements the non-exclusive 'set output dump|diag|print' options +struct SetNonExclusiveOutputQuery : Query { + SetNonExclusiveOutputQuery(bool QuerySession::*Var, bool Value) : Query(QK_SetOutputKind), Var(Var), Value(Value) {} + bool run(llvm::raw_ostream &OS, QuerySession &QS) const override { +QS.*Var = Value; +return true; + } + + static bool classof(const Query *Q) { return Q->Kind == QK_SetOutputKind; } + + bool QuerySession::*Var; + bool Value; +}; + +struct EnableOutputQuery : SetNonExclusiveOutputQuery +{ + EnableOutputQuery(bool QuerySession:
[PATCH] D45045: [DebugInfo] Generate debug information for labels.
aprantl added a comment. In https://reviews.llvm.org/D45045#1270442, @HsiangKai wrote: > In https://reviews.llvm.org/D45045#1247427, @vitalybuka wrote: > > > Reverted in r343183 > > https://bugs.llvm.org/show_bug.cgi?id=39094 > > > > http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-autoconf/builds/29356/steps/build%20release%20tsan%20with%20clang/logs/stdio > > > I have fixed the bug in https://reviews.llvm.org/D52927 and it has landed in > master branch. Could I recommit this patch? As long as you keep a close eye on the bots that should be fine, yes. Repository: rL LLVM https://reviews.llvm.org/D45045 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53296: [analyzer] New flag to print all -analyzer-config options
Szelethus updated this revision to Diff 170438. https://reviews.llvm.org/D53296 Files: include/clang/Driver/CC1Options.td include/clang/StaticAnalyzer/Core/AnalyzerOptions.h include/clang/StaticAnalyzer/Frontend/FrontendActions.h lib/Frontend/CompilerInvocation.cpp lib/FrontendTool/ExecuteCompilerInvocation.cpp lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp test/Analysis/analyzer-list-configs.c Index: test/Analysis/analyzer-list-configs.c === --- /dev/null +++ test/Analysis/analyzer-list-configs.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -analyzer-config-help 2>&1 | FileCheck %s +// CHECK: OVERVIEW: Clang Static Analyzer -analyzer-config Option List +// +// CHECK: USAGE: clang -cc1 [CLANG_OPTIONS] -analyzer-config +// +// CHCEK: clang -cc1 [CLANG_OPTIONS] -analyzer-config OPTION1=VALUE, -analyzer-config OPTION2=VALUE, ... +// +// CHECK: clang [CLANG_OPTIONS] -Xclang -analyzer-config -Xclang +// +// CHECK: clang [CLANG_OPTIONS] -Xclang -analyzer-config -Xclang OPTION1=VALUE, -Xclang -analyzer-config -Xclang OPTION2=VALUE, ... +// +// +// CHECK: OPTIONS: Index: lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp === --- lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp +++ lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp @@ -22,6 +22,7 @@ #include "clang/StaticAnalyzer/Frontend/FrontendActions.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/DynamicLibrary.h" +#include "llvm/Support/FormattedStream.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include @@ -157,3 +158,74 @@ SmallVector checkerOpts = getCheckerOptList(opts); ClangCheckerRegistry(plugins).printList(out, checkerOpts); } + +void ento::printAnalyzerConfigList(raw_ostream &out) { + out << "OVERVIEW: Clang Static Analyzer -analyzer-config Option List\n\n"; + out << "USAGE: clang -cc1 [CLANG_OPTIONS] -analyzer-config " +"\n\n"; + out << " clang -cc1 [CLANG_OPTIONS] -analyzer-config OPTION1=VALUE, " + "-analyzer-config OPTION2=VALUE, ...\n\n"; + out << " clang [CLANG_OPTIONS] -Xclang -analyzer-config -Xclang" +"\n\n"; + out << " clang [CLANG_OPTIONS] -Xclang -analyzer-config -Xclang " + "OPTION1=VALUE, -Xclang -analyzer-config -Xclang " + "OPTION2=VALUE, ...\n\n"; + out << "OPTIONS:\n\n"; + + using OptionAndDescriptionTy = std::pair; + OptionAndDescriptionTy PrintableOptions[] = { +#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL)\ +{ \ + CMDFLAG, \ + llvm::Twine(llvm::Twine() + "(" +\ + (#TYPE == "StringRef" ? "string" : #TYPE ) + ") " DESC \ + " (default: " #DEFAULT_VAL ")").str()\ +}, + +#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC,\ + SHALLOW_VAL, DEEP_VAL)\ +{ \ + CMDFLAG, \ + llvm::Twine(llvm::Twine() + "(" +\ + (#TYPE == "StringRef" ? "string" : #TYPE ) + ") " DESC \ + " (default: " #SHALLOW_VAL " in shallow mode, " #DEEP_VAL\ + " in deep mode)").str() \ +}, +#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def" +#undef ANALYZER_OPTION +#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE + }; + + llvm::sort(PrintableOptions, [](const OptionAndDescriptionTy &LHS, + const OptionAndDescriptionTy &RHS) { +return LHS.first < RHS.first; + }); + + constexpr size_t MinLineWidth = 70; + constexpr size_t PadForOpt = 2; + constexpr size_t OptionWidth = 30; + constexpr size_t PadForDesc = PadForOpt + OptionWidth; + static_assert(MinLineWidth > PadForDesc, "MinLineWidth must be greater!"); + + llvm::formatted_raw_ostream FOut(out); + + for (const auto &Pair : PrintableOptions) { +FOut.PadToColumn(PadForOpt) << Pair.first; + +// If the buffer's length is greater then PadForDesc, print a newline. +if (FOut.getColumn() > PadForDesc) + FOut << '\n'; + +FOut.PadToColumn(PadForDesc); + +for (char C : Pair.second) { + if (FOut.getColumn() > MinLineWidth && C == ' ') { +FOut << '\n'; +FOut.PadToColumn(PadForDesc); +continue; + } + FOut << C; +} +FOut << "\n\n"; + } +} Index: lib/Fro
[PATCH] D52857: [clang-query] Add non-exclusive output API
steveire updated this revision to Diff 170439. steveire added a comment. Update docs Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D52857 Files: clang-query/Query.cpp clang-query/Query.h clang-query/QueryParser.cpp clang-query/QueryParser.h unittests/clang-query/QueryEngineTest.cpp unittests/clang-query/QueryParserTest.cpp Index: unittests/clang-query/QueryParserTest.cpp === --- unittests/clang-query/QueryParserTest.cpp +++ unittests/clang-query/QueryParserTest.cpp @@ -90,6 +90,14 @@ ASSERT_TRUE(isa(Q)); EXPECT_EQ(&QuerySession::DetailedASTOutput, cast(Q)->Var); + Q = parse("set enable-output detailed-ast"); + ASSERT_TRUE(isa(Q)); + EXPECT_EQ(&QuerySession::DetailedASTOutput, cast(Q)->Var); + + Q = parse("set disable-output detailed-ast"); + ASSERT_TRUE(isa(Q)); + EXPECT_EQ(&QuerySession::DetailedASTOutput, cast(Q)->Var); + Q = parse("set bind-root foo"); ASSERT_TRUE(isa(Q)); EXPECT_EQ("expected 'true' or 'false', got 'foo'", Index: unittests/clang-query/QueryEngineTest.cpp === --- unittests/clang-query/QueryEngineTest.cpp +++ unittests/clang-query/QueryEngineTest.cpp @@ -111,6 +111,21 @@ Str.clear(); + EXPECT_TRUE( + EnableOutputQuery(&QuerySession::DiagOutput).run(OS, S)); + EXPECT_TRUE( + EnableOutputQuery(&QuerySession::DetailedASTOutput).run(OS, S)); + EXPECT_TRUE(MatchQuery(FooMatcherString, FooMatcher).run(OS, S)); + + { +auto Output = OS.str(); +EXPECT_TRUE(Output.find("FunctionDecl") != std::string::npos); +EXPECT_TRUE(Output.find("foo.cc:1:1: note: \"root\" binds here") != +std::string::npos); + } + + Str.clear(); + EXPECT_TRUE(SetQuery(&QuerySession::BindRoot, false).run(OS, S)); EXPECT_TRUE(MatchQuery(FooMatcherString, FooMatcher).run(OS, S)); Index: clang-query/QueryParser.h === --- clang-query/QueryParser.h +++ clang-query/QueryParser.h @@ -44,6 +44,7 @@ template struct LexOrCompleteWord; QueryRef parseSetBool(bool QuerySession::*Var); + template QueryRef parseSetOutputKind(); QueryRef completeMatcherExpression(); Index: clang-query/QueryParser.cpp === --- clang-query/QueryParser.cpp +++ clang-query/QueryParser.cpp @@ -106,6 +106,7 @@ return new SetQuery(Var, Value); } +template QueryRef QueryParser::parseSetOutputKind() { StringRef ValStr; unsigned OutKind = LexOrCompleteWord(this, ValStr) @@ -122,11 +123,11 @@ switch (OutKind) { case OK_DetailedAST: -return new SetExclusiveOutputQuery(&QuerySession::DetailedASTOutput); +return new QueryType(&QuerySession::DetailedASTOutput); case OK_Diag: -return new SetExclusiveOutputQuery(&QuerySession::DiagOutput); +return new QueryType(&QuerySession::DiagOutput); case OK_Print: -return new SetExclusiveOutputQuery(&QuerySession::PrintOutput); +return new QueryType(&QuerySession::PrintOutput); } llvm_unreachable("Invalid output kind"); @@ -157,6 +158,8 @@ enum ParsedQueryVariable { PQV_Invalid, PQV_Output, + PQV_EnableOutput, + PQV_DisableOutput, PQV_BindRoot, PQV_PrintMatcher }; @@ -245,6 +248,8 @@ ParsedQueryVariable Var = LexOrCompleteWord(this, VarStr) .Case("output", PQV_Output) +.Case("enable-output", PQV_EnableOutput) +.Case("disable-output", PQV_DisableOutput) .Case("bind-root", PQV_BindRoot) .Case("print-matcher", PQV_PrintMatcher) .Default(PQV_Invalid); @@ -256,7 +261,13 @@ QueryRef Q; switch (Var) { case PQV_Output: - Q = parseSetOutputKind(); + Q = parseSetOutputKind(); + break; +case PQV_EnableOutput: + Q = parseSetOutputKind(); + break; +case PQV_DisableOutput: + Q = parseSetOutputKind(); break; case PQV_BindRoot: Q = parseSetBool(&QuerySession::BindRoot); Index: clang-query/Query.h === --- clang-query/Query.h +++ clang-query/Query.h @@ -152,6 +152,30 @@ bool QuerySession::*Var; }; +// Implements the non-exclusive 'set output dump|diag|print' options +struct SetNonExclusiveOutputQuery : Query { + SetNonExclusiveOutputQuery(bool QuerySession::*Var, bool Value) : Query(QK_SetOutputKind), Var(Var), Value(Value) {} + bool run(llvm::raw_ostream &OS, QuerySession &QS) const override { +QS.*Var = Value; +return true; + } + + static bool classof(const Query *Q) { return Q->Kind == QK_SetOutputKind; } + + bool QuerySession::*Var; + bool Value; +}; + +struct EnableOutputQuery : SetNonExclusiveOutputQuery +{ + EnableOutputQuery(bool QuerySession::*Var) : SetNonExclusiveOutputQuery(Var, true) { } +}; + +struct DisableOutputQuery : SetNonExclusiveOutputQue
[PATCH] D53433: [clangd] auto-index stores symbols per-file instead of per-TU.
ioeric added inline comments. Comment at: clangd/index/FileIndex.h:49 +/// rename the existing FileSymbols to something else e.g. TUSymbols? +class SymbolsGroupedByFiles { +public: sammccall wrote: > `FileSymbols` isn't actually that opinionated about the data it manages: > - the keys ("filenames") just identify shards so we can tell whether a new > shard is an addition or replaces an existing one. > - the values (tu symbols/refs) are merged using pretty generic logic, we > don't look at the details. > > I think we should be able to use `FileSymbols` mostly unmodified, and store > digests in parallel, probably in `BackgroundIndexer`. Is there a strong > reason to store "main file" digests separately to header digests? > > There are a couple of weak points: > - The merging makes subtle assumptions: for symbols it picks one copy > arbitrarily, assuming there are many copies (merging would be expensive) and > they're mostly interchangeable duplicates. We could add a constructor or > `buildIndex()` param to FileSymbols to control this, similar to the IndexType > param. (For refs it assumes no duplicates and simply concatenates, which is > also fine for our purposes). > - `FileSymbols` locks internally to be threadsafe while keeping critical > sections small. To keep digests in sync with FileSymbols contents we probably > have to lock externally with a second mutex. This is a little ugly but not a > real problem I think. Good idea! Thanks! > FileSymbols locks internally to be threadsafe while keeping critical sections > small. To keep digests in sync with FileSymbols contents we probably have to > lock externally with a second mutex. This is a little ugly but not a real > problem I think. This doesn't seem to be a problem as `Background::index()` currently assumes single-thread? I can either make it thread-safe now or add a `FIXME`. WDYT? Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53433 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53433: [clangd] *Prototype* auto-index stores symbols per-file instead of per-TU.
ioeric updated this revision to Diff 170440. ioeric marked 2 inline comments as done. ioeric added a comment. - address review comments - minor cleanup Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53433 Files: clangd/index/Background.cpp clangd/index/Background.h clangd/index/FileIndex.cpp clangd/index/FileIndex.h clangd/index/IndexAction.cpp clangd/index/IndexAction.h clangd/index/SymbolCollector.cpp clangd/index/SymbolCollector.h clangd/indexer/IndexerMain.cpp unittests/clangd/BackgroundIndexTests.cpp unittests/clangd/FileIndexTests.cpp unittests/clangd/SyncAPI.cpp unittests/clangd/SyncAPI.h Index: unittests/clangd/SyncAPI.h === --- unittests/clangd/SyncAPI.h +++ unittests/clangd/SyncAPI.h @@ -52,6 +52,7 @@ SymbolSlab runFuzzyFind(const SymbolIndex &Index, StringRef Query); SymbolSlab runFuzzyFind(const SymbolIndex &Index, const FuzzyFindRequest &Req); +RefSlab getRefs(const SymbolIndex &Index, SymbolID ID); } // namespace clangd } // namespace clang Index: unittests/clangd/SyncAPI.cpp === --- unittests/clangd/SyncAPI.cpp +++ unittests/clangd/SyncAPI.cpp @@ -8,6 +8,7 @@ //===--===// #include "SyncAPI.h" +#include "index/Index.h" using namespace llvm; namespace clang { @@ -138,5 +139,14 @@ return std::move(Builder).build(); } +RefSlab getRefs(const SymbolIndex &Index, SymbolID ID) { + RefsRequest Req; + Req.IDs = {ID}; + RefSlab::Builder Slab; + Index.refs(Req, [&](const Ref &S) { Slab.insert(ID, S); }); + return std::move(Slab).build(); +} + + } // namespace clangd } // namespace clang Index: unittests/clangd/FileIndexTests.cpp === --- unittests/clangd/FileIndexTests.cpp +++ unittests/clangd/FileIndexTests.cpp @@ -14,6 +14,7 @@ #include "TestFS.h" #include "TestTU.h" #include "index/FileIndex.h" +#include "index/Index.h" #include "clang/Frontend/CompilerInvocation.h" #include "clang/Frontend/PCHContainerOperations.h" #include "clang/Frontend/Utils.h" @@ -39,6 +40,7 @@ } MATCHER_P(FileURI, F, "") { return arg.Location.FileURI == F; } MATCHER_P(DeclURI, U, "") { return arg.CanonicalDeclaration.FileURI == U; } +MATCHER_P(DefURI, U, "") { return arg.Definition.FileURI == U; } MATCHER_P(QName, N, "") { return (arg.Scope + arg.Name).str() == N; } using namespace llvm; @@ -73,14 +75,6 @@ return llvm::make_unique(std::move(Slab).build()); } -RefSlab getRefs(const SymbolIndex &I, SymbolID ID) { - RefsRequest Req; - Req.IDs = {ID}; - RefSlab::Builder Slab; - I.refs(Req, [&](const Ref &S) { Slab.insert(ID, S); }); - return std::move(Slab).build(); -} - TEST(FileSymbolsTest, UpdateAndGet) { FileSymbols FS; EXPECT_THAT(runFuzzyFind(*FS.buildIndex(IndexType::Light), ""), IsEmpty()); @@ -102,6 +96,26 @@ QName("4"), QName("5"))); } +TEST(FileSymbolsTest, MergeOverlap) { + FileSymbols FS; + auto OneSymboSlab = [](Symbol Sym) { +SymbolSlab::Builder S; +S.insert(Sym); +return make_unique(std::move(S).build()); + }; + auto X1 = symbol("x"); + X1.CanonicalDeclaration.FileURI = "file:///x1"; + auto X2 = symbol("x"); + X2.Definition.FileURI = "file:///x2"; + + FS.update("f1", OneSymboSlab(X1), nullptr); + FS.update("f2", OneSymboSlab(X2), nullptr); + for (auto Type : {IndexType::Light, IndexType::Heavy}) +EXPECT_THAT(runFuzzyFind(*FS.buildIndex(Type, /*MergeSymbols=*/true), "x"), +UnorderedElementsAre(AllOf(QName("x"), DeclURI("file:///x1"), + DefURI("file:///x2"; +} + TEST(FileSymbolsTest, SnapshotAliveAfterRemove) { FileSymbols FS; Index: unittests/clangd/BackgroundIndexTests.cpp === --- unittests/clangd/BackgroundIndexTests.cpp +++ unittests/clangd/BackgroundIndexTests.cpp @@ -4,33 +4,74 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" +using testing::_; +using testing::AllOf; +using testing::Not; using testing::UnorderedElementsAre; namespace clang { namespace clangd { MATCHER_P(Named, N, "") { return arg.Name == N; } +MATCHER(Declared, "") { return !arg.CanonicalDeclaration.FileURI.empty(); } +MATCHER(Defined, "") { return !arg.Definition.FileURI.empty(); } + +MATCHER_P(FileURI, F, "") { return arg.Location.FileURI == F; } +testing::Matcher +RefsAre(std::vector> Matchers) { + return ElementsAre(testing::Pair(_, UnorderedElementsAreArray(Matchers))); +} TEST(BackgroundIndexTest, IndexTwoFiles) { MockFSProvider FS; // a.h yields different symbols when included by A.cc vs B.cc. // Currently we store symbols for each TU, so we get both. - FS.Files[testPath("root/A.h")] = "void a_h(); void NAME(){}"; - FS.Files[testPath("root/A.cc")] = "#
[PATCH] D53459: Ensure sanitizer check function calls have a !dbg location
vsk accepted this revision. vsk added a comment. This revision is now accepted and ready to land. Thanks! https://reviews.llvm.org/D53459 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53508: [SemaCXX] Unconfuse Clang when std::align_val_t is unscoped in C++03
EricWF created this revision. EricWF added a reviewer: rsmith. When -faligned-allocation is specified in C++03 libc++ defines std::align_val_t as an unscoped enumeration type (because Clang didn't provide scoped enumerations as an extension until 8.0). Unfortunately Clang confuses the `align_val_t` overloads of delete with the sized deallocation overloads which aren't enabled. This caused Clang to call the aligned deallocation function as if it were the sized deallocation overload. For example: https://godbolt.org/z/xXJELh This patch fixes the confusion. Repository: rC Clang https://reviews.llvm.org/D53508 Files: lib/Sema/SemaExprCXX.cpp test/SemaCXX/cxx03-aligned-allocation-unscoped-enum.cpp Index: test/SemaCXX/cxx03-aligned-allocation-unscoped-enum.cpp === --- /dev/null +++ test/SemaCXX/cxx03-aligned-allocation-unscoped-enum.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -std=c++03 %s -faligned-allocation \ +// RUN: -emit-llvm -o - | FileCheck %s + +// Ensure Clang doesn't confuse std::align_val_t with the sized deallocation +// parameter when the enum type is unscoped. Libc++ does this in C++03 in order +// to support aligned allocation in that dialect. + +using size_t = __decltype(sizeof(0)); + +namespace std { +enum align_val_t { zero = size_t(0), + max = size_t(-1) }; +} + +// CHECK-LABEL: define void @_Z1fPi( +void f(int *p) { + // CHECK-NOT: call void @_ZdlPvSt11align_val_t( + // CHECK: call void @_ZdlPv( + // CHECK: ret void + delete p; +} Index: lib/Sema/SemaExprCXX.cpp === --- lib/Sema/SemaExprCXX.cpp +++ lib/Sema/SemaExprCXX.cpp @@ -1515,8 +1515,9 @@ if (FD->getNumParams() == NumBaseParams + 2) HasAlignValT = HasSizeT = true; else if (FD->getNumParams() == NumBaseParams + 1) { -HasSizeT = FD->getParamDecl(NumBaseParams)->getType()->isIntegerType(); -HasAlignValT = !HasSizeT; +QualType ParamTy = FD->getParamDecl(NumBaseParams)->getType(); +HasAlignValT = ParamTy->isAlignValT(); +HasSizeT = !HasAlignValT && ParamTy->isIntegerType(); } // In CUDA, determine how much we'd like / dislike to call this. Index: test/SemaCXX/cxx03-aligned-allocation-unscoped-enum.cpp === --- /dev/null +++ test/SemaCXX/cxx03-aligned-allocation-unscoped-enum.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -std=c++03 %s -faligned-allocation \ +// RUN: -emit-llvm -o - | FileCheck %s + +// Ensure Clang doesn't confuse std::align_val_t with the sized deallocation +// parameter when the enum type is unscoped. Libc++ does this in C++03 in order +// to support aligned allocation in that dialect. + +using size_t = __decltype(sizeof(0)); + +namespace std { +enum align_val_t { zero = size_t(0), + max = size_t(-1) }; +} + +// CHECK-LABEL: define void @_Z1fPi( +void f(int *p) { + // CHECK-NOT: call void @_ZdlPvSt11align_val_t( + // CHECK: call void @_ZdlPv( + // CHECK: ret void + delete p; +} Index: lib/Sema/SemaExprCXX.cpp === --- lib/Sema/SemaExprCXX.cpp +++ lib/Sema/SemaExprCXX.cpp @@ -1515,8 +1515,9 @@ if (FD->getNumParams() == NumBaseParams + 2) HasAlignValT = HasSizeT = true; else if (FD->getNumParams() == NumBaseParams + 1) { -HasSizeT = FD->getParamDecl(NumBaseParams)->getType()->isIntegerType(); -HasAlignValT = !HasSizeT; +QualType ParamTy = FD->getParamDecl(NumBaseParams)->getType(); +HasAlignValT = ParamTy->isAlignValT(); +HasSizeT = !HasAlignValT && ParamTy->isIntegerType(); } // In CUDA, determine how much we'd like / dislike to call this. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r344915 - Ensure sanitizer check function calls have a !dbg location
Author: adrian Date: Mon Oct 22 09:27:41 2018 New Revision: 344915 URL: http://llvm.org/viewvc/llvm-project?rev=344915&view=rev Log: Ensure sanitizer check function calls have a !dbg location Function calls without a !dbg location inside a function that has a DISubprogram make it impossible to construct inline information and are rejected by the verifier. This patch ensures that sanitizer check function calls have a !dbg location, by carrying forward the location of the preceding instruction or by inserting an artificial location if necessary. This fixes a crash when compiling the attached testcase with -Os. rdar://problem/45311226 Differential Revision: https://reviews.llvm.org/D53459 Added: cfe/trunk/test/CodeGenCXX/ubsan-check-debuglocs.cpp Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=344915&r1=344914&r2=344915&view=diff == --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Oct 22 09:27:41 2018 @@ -2867,6 +2867,9 @@ static void emitCheckHandlerCall(CodeGen CheckRecoverableKind RecoverKind, bool IsFatal, llvm::BasicBlock *ContBB) { assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable); + auto *DI = CGF.getDebugInfo(); + SourceLocation Loc = DI ? DI->getLocation() : SourceLocation(); + auto DL = ApplyDebugLocation::CreateDefaultArtificial(CGF, Loc); bool NeedsAbortSuffix = IsFatal && RecoverKind != CheckRecoverableKind::Unrecoverable; bool MinimalRuntime = CGF.CGM.getCodeGenOpts().SanitizeMinimalRuntime; Added: cfe/trunk/test/CodeGenCXX/ubsan-check-debuglocs.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ubsan-check-debuglocs.cpp?rev=344915&view=auto == --- cfe/trunk/test/CodeGenCXX/ubsan-check-debuglocs.cpp (added) +++ cfe/trunk/test/CodeGenCXX/ubsan-check-debuglocs.cpp Mon Oct 22 09:27:41 2018 @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited \ +// RUN: -fsanitize=null %s -o - | FileCheck %s + +// Check that santizer check calls have a !dbg location. +// CHECK: define {{.*}}acquire{{.*}} !dbg +// CHECK-NOT: define +// CHECK: call void {{.*}}@__ubsan_handle_type_mismatch_v1 +// CHECK-SAME: !dbg + +struct SourceLocation { + SourceLocation acquire() {}; +}; +extern "C" void __ubsan_handle_type_mismatch_v1(SourceLocation *Loc); +static void handleTypeMismatchImpl(SourceLocation *Loc) { Loc->acquire(); } +void __ubsan_handle_type_mismatch_v1(SourceLocation *Loc) { + handleTypeMismatchImpl(Loc); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53459: Ensure sanitizer check function calls have a !dbg location
This revision was automatically updated to reflect the committed changes. Closed by commit rC344915: Ensure sanitizer check function calls have a !dbg location (authored by adrian, committed by ). Repository: rC Clang https://reviews.llvm.org/D53459 Files: lib/CodeGen/CGExpr.cpp test/CodeGenCXX/ubsan-check-debuglocs.cpp Index: lib/CodeGen/CGExpr.cpp === --- lib/CodeGen/CGExpr.cpp +++ lib/CodeGen/CGExpr.cpp @@ -2867,6 +2867,9 @@ CheckRecoverableKind RecoverKind, bool IsFatal, llvm::BasicBlock *ContBB) { assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable); + auto *DI = CGF.getDebugInfo(); + SourceLocation Loc = DI ? DI->getLocation() : SourceLocation(); + auto DL = ApplyDebugLocation::CreateDefaultArtificial(CGF, Loc); bool NeedsAbortSuffix = IsFatal && RecoverKind != CheckRecoverableKind::Unrecoverable; bool MinimalRuntime = CGF.CGM.getCodeGenOpts().SanitizeMinimalRuntime; Index: test/CodeGenCXX/ubsan-check-debuglocs.cpp === --- test/CodeGenCXX/ubsan-check-debuglocs.cpp +++ test/CodeGenCXX/ubsan-check-debuglocs.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited \ +// RUN: -fsanitize=null %s -o - | FileCheck %s + +// Check that santizer check calls have a !dbg location. +// CHECK: define {{.*}}acquire{{.*}} !dbg +// CHECK-NOT: define +// CHECK: call void {{.*}}@__ubsan_handle_type_mismatch_v1 +// CHECK-SAME: !dbg + +struct SourceLocation { + SourceLocation acquire() {}; +}; +extern "C" void __ubsan_handle_type_mismatch_v1(SourceLocation *Loc); +static void handleTypeMismatchImpl(SourceLocation *Loc) { Loc->acquire(); } +void __ubsan_handle_type_mismatch_v1(SourceLocation *Loc) { + handleTypeMismatchImpl(Loc); +} Index: lib/CodeGen/CGExpr.cpp === --- lib/CodeGen/CGExpr.cpp +++ lib/CodeGen/CGExpr.cpp @@ -2867,6 +2867,9 @@ CheckRecoverableKind RecoverKind, bool IsFatal, llvm::BasicBlock *ContBB) { assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable); + auto *DI = CGF.getDebugInfo(); + SourceLocation Loc = DI ? DI->getLocation() : SourceLocation(); + auto DL = ApplyDebugLocation::CreateDefaultArtificial(CGF, Loc); bool NeedsAbortSuffix = IsFatal && RecoverKind != CheckRecoverableKind::Unrecoverable; bool MinimalRuntime = CGF.CGM.getCodeGenOpts().SanitizeMinimalRuntime; Index: test/CodeGenCXX/ubsan-check-debuglocs.cpp === --- test/CodeGenCXX/ubsan-check-debuglocs.cpp +++ test/CodeGenCXX/ubsan-check-debuglocs.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited \ +// RUN: -fsanitize=null %s -o - | FileCheck %s + +// Check that santizer check calls have a !dbg location. +// CHECK: define {{.*}}acquire{{.*}} !dbg +// CHECK-NOT: define +// CHECK: call void {{.*}}@__ubsan_handle_type_mismatch_v1 +// CHECK-SAME: !dbg + +struct SourceLocation { + SourceLocation acquire() {}; +}; +extern "C" void __ubsan_handle_type_mismatch_v1(SourceLocation *Loc); +static void handleTypeMismatchImpl(SourceLocation *Loc) { Loc->acquire(); } +void __ubsan_handle_type_mismatch_v1(SourceLocation *Loc) { + handleTypeMismatchImpl(Loc); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53406: [clangd] Provide excuses for bad code completions, based on diagnostics. C++ API only.
kadircet added inline comments. Comment at: clangd/CodeComplete.cpp:700 + unsigned DiagLoc = Loc.second; + if (DiagLoc < StartOfLine || DiagLoc > Offset) + return; There are also a lot of cases where we can't find an include file(usually due to confused compile commands) and fail miserably. Maybe in addition to checking current line, we could also check for lines that are starting with `#include` or diags of type `diag::err_pp_file_not_found` ? Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53406 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50563: Fixed frontend clang tests in windows read-only container
justice_adams added a comment. @cfe-commits ping requesting a review on this patch https://reviews.llvm.org/D50563 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53433: [clangd] auto-index stores symbols per-file instead of per-TU.
sammccall added inline comments. Comment at: clangd/index/Background.h:68 + FileSymbols IndexedSymbols; + FileDigests IndexedFileDigests; // Keyed by file URIs. Keying this with file URIs seems suspicious to me - why this change? It seems to be motivated by the current implementation where the partitioning is done post-hoc by looking at strings that contain file URIs. But this seems likely to change in the long term, and producing data that's sharded in the first place. At that point it'll be just as natural and semantically cleaner just to use file paths, I think. If performance of converting URI -> path is a concern in the meantime, can we just add a cache to that loop? Comment at: clangd/index/FileIndex.cpp:121 + if (MergeSymbols) { +// Merge slabs into a single slab and only keep alive the merged. +SymbolSlab::Builder Merged; I don't think you want to build a new slab and copy all the strings here. This seems like it's saving data (you're not keeping everything alive!) but in practice that only allows GC of data that changes, and most data doesn't change. So mostly this just introduces another copy of the data. So I think you just want a `vector MergedSymbols`, and either push all the pointers in there or use `concat(make_pointee_range(SymbolPointers), MergedSymbols)` Comment at: clangd/index/FileIndex.h:49 +/// rename the existing FileSymbols to something else e.g. TUSymbols? +class SymbolsGroupedByFiles { +public: ioeric wrote: > sammccall wrote: > > `FileSymbols` isn't actually that opinionated about the data it manages: > > - the keys ("filenames") just identify shards so we can tell whether a new > > shard is an addition or replaces an existing one. > > - the values (tu symbols/refs) are merged using pretty generic logic, we > > don't look at the details. > > > > I think we should be able to use `FileSymbols` mostly unmodified, and store > > digests in parallel, probably in `BackgroundIndexer`. Is there a strong > > reason to store "main file" digests separately to header digests? > > > > There are a couple of weak points: > > - The merging makes subtle assumptions: for symbols it picks one copy > > arbitrarily, assuming there are many copies (merging would be expensive) > > and they're mostly interchangeable duplicates. We could add a constructor > > or `buildIndex()` param to FileSymbols to control this, similar to the > > IndexType param. (For refs it assumes no duplicates and simply > > concatenates, which is also fine for our purposes). > > - `FileSymbols` locks internally to be threadsafe while keeping critical > > sections small. To keep digests in sync with FileSymbols contents we > > probably have to lock externally with a second mutex. This is a little ugly > > but not a real problem I think. > Good idea! Thanks! > > > FileSymbols locks internally to be threadsafe while keeping critical > > sections small. To keep digests in sync with FileSymbols contents we > > probably have to lock externally with a second mutex. This is a little ugly > > but not a real problem I think. > This doesn't seem to be a problem as `Background::index()` currently assumes > single-thread? I can either make it thread-safe now or add a `FIXME`. WDYT? Right, currently we're only reading/writing with a single thread. The mutex thing is more for the future. Don't bother with a FIXME, when we add multiple threads we'll need to work out what to lock. Comment at: clangd/index/FileIndex.h:41 +using FileDigest = decltype(llvm::SHA1::hash({})); +using FileDigests = llvm::StringMap; + as noted elsewhere I think this is the wrong place for this decl. The values are somewhat self-explanatory, but the keys need to be documented. Comment at: clangd/index/FileIndex.h:68 // The index keeps the symbols alive. + // If \p MergeSymbols is true, this will merge symbols from different files; + // otherwise, a random one is picked, which is less accurate but faster to can we pull out something like `enum class DuplicateHandling { PickOne, Merge }`? I think that's much clearer at the callsite than `/*MergeSymbols=*/true`, and not really longer. Comment at: clangd/index/IndexAction.h:12 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_ACTION_H +#include "FileIndex.h" #include "SymbolCollector.h" This looks like an inverted dependency. The FileDigests struct should be part of symbolcollector, no? Comment at: clangd/index/IndexAction.h:33 +std::function RefsCallback, +std::function FileDigestsCallback); thinking about what we eventually want here: - the index action needs to tell the auto-indexer what the file content or digests are - the auto-indexer needs to tell the index action which files to index symbols from
Re: [libcxx] r342073 - Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955
Hi Marshall and others. After this discussion and some internal discussions I agree with the idea that files without extension are treated as C++ header files and non-header files should either move out of the C++ code base or have a proper extension. The VERSION case is just the most visible case of it. The introduction of new headers that break existing projects can be handled with the use of -iquote or by using project specific names if people care about future proofing their projects. Makes me wonder if clang should make -I to mean -iquote and have an -iangle option for the language headers instead. Anyway, I’m happy to leave it at this. Thanks for everybody’s time and thoughts on this. Thanks, Christof From: Marshall Clow Date: Monday, 22 October 2018 at 15:41 To: Christof Douma Cc: "cfe-commits@lists.llvm.org" , nd , Arnaud De Grandmaison , Jonathan Wakely Subject: Re: [libcxx] r342073 - Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 On Tue, Oct 2, 2018 at 10:33 AM Christof Douma mailto:christof.do...@arm.com>> wrote: Hi Marshall. I think that this patch breaks backwards compatibility. Assumes that the header file "version" is used by C++ projects that use a C++ standard that did not specify a 'version' header. Many toolchains will put search paths specified with -I in front of the system search path. The result is that the application header file is included whenever a standard header file is included. That is unexpected and can break builds. Do you agree this is an issue or do you consider this an issue with the way toolchains handle include search paths? Christof - I've been thinking about this the last few days. We can ameliorate this in libc++, (See Richard's suggestion on __version) but anything we do will be a short-term solution. The first time someone includes another header file that #include , they're back to square one. That header is supposed to be "the place to go" for information about your standard library, and people are going to use it. For example, I expect that Boost.Config will start using it soon (if it doesn't already) A better solution (and not just because it would require other people to do the work) would be to have the build systems either: * Stop using VERSION as a file name - use something like VERSION.STAMP instead. * Use '-iquote' instead of '-I' to manage the list of include directories. I agree that it's annoying for people's builds to be broken when they upgrade their development tools, and especially when they didn't do anything "wrong". -- Marshall ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53497: [AST] Do not align virtual bases in `MicrosoftRecordLayoutBuilder` when an external layout is used
rnk accepted this revision. rnk added a comment. This revision is now accepted and ready to land. > Also it seems that MicrosoftRecordLayoutBuilder with an external source and > without one differ considerably, may be it is worth to split this and to > create two different builders? I think that it would make the logic simpler. > What do you think about it? Yes, I recall when reading the Itanium record layout code that it was riddled with extra checks for external layouts. Back then I thought it would be nicer to have a separate code path for external layouts. I appreciated that when we separated out the MS code, it was clean and not filled with these checks. But, of course, now here we are adding them in. If you want to do the work to come up with a separate, more minimal code path that produces ASTRecordLayouts from external layouts, I'd definitely help review it. This change is pretty small and targeted, so feel free to land it as is first. Thanks! Repository: rC Clang https://reviews.llvm.org/D53497 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53513: [OPENMP] Add support for 'atomic_default_mem_order' clause on requires directive
patricklyster created this revision. patricklyster added reviewers: ABataev, Hahnfeld, RaviNarayanaswamy, mikerice, kkwli0, hfinkel, gtbercea. patricklyster added projects: clang, OpenMP. Herald added subscribers: cfe-commits, jfb, arphaman, guansong. Added new `atomic_default_mem_order` clause with `seq_cst`, `acq_rel` and `relaxed` modifiers to OMP5.0 `requires` directive. Renamed test files relating to requires tests. Repository: rC Clang https://reviews.llvm.org/D53513 Files: clang/include/clang/AST/OpenMPClause.h clang/include/clang/AST/RecursiveASTVisitor.h clang/include/clang/Basic/OpenMPKinds.def clang/include/clang/Basic/OpenMPKinds.h clang/include/clang/Sema/Sema.h clang/lib/AST/DeclPrinter.cpp clang/lib/AST/OpenMPClause.cpp clang/lib/AST/StmtProfile.cpp clang/lib/Basic/OpenMPKinds.cpp clang/lib/CodeGen/CGStmtOpenMP.cpp clang/lib/Parse/ParseOpenMP.cpp clang/lib/Sema/SemaOpenMP.cpp clang/lib/Sema/TreeTransform.h clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTWriter.cpp clang/test/OpenMP/requires_acq_rel_print.cpp clang/test/OpenMP/requires_ast_print.cpp clang/test/OpenMP/requires_messages.cpp clang/test/OpenMP/requires_relaxed_print.cpp clang/test/OpenMP/requires_unified_address_ast_print.cpp clang/test/OpenMP/requires_unified_address_messages.cpp clang/tools/libclang/CIndex.cpp Index: clang/tools/libclang/CIndex.cpp === --- clang/tools/libclang/CIndex.cpp +++ clang/tools/libclang/CIndex.cpp @@ -2219,6 +2219,9 @@ void OMPClauseEnqueue::VisitOMPDynamicAllocatorsClause( const OMPDynamicAllocatorsClause *) {} +void OMPClauseEnqueue::VisitOMPAtomicDefaultMemOrderClause( +const OMPAtomicDefaultMemOrderClause *) {} + void OMPClauseEnqueue::VisitOMPDeviceClause(const OMPDeviceClause *C) { Visitor->AddStmt(C->getDevice()); } Index: clang/test/OpenMP/requires_unified_address_messages.cpp === --- clang/test/OpenMP/requires_unified_address_messages.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s - -#pragma omp requires unified_address // expected-note {{unified_address clause previously used here}} expected-note {{unified_address clause previously used here}} expected-note {{unified_address clause previously used here}} expected-note {{unified_address clause previously used here}} expected-note {{unified_address clause previously used here}} expected-note{{unified_address clause previously used here}} - -#pragma omp requires unified_shared_memory // expected-note {{unified_shared_memory clause previously used here}} expected-note{{unified_shared_memory clause previously used here}} - -#pragma omp requires unified_shared_memory, unified_shared_memory // expected-error {{Only one unified_shared_memory clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'unified_shared_memory' clause}} - -#pragma omp requires unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}} - -#pragma omp requires unified_address, unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'unified_address' clause}} - -#pragma omp requires reverse_offload // expected-note {{reverse_offload clause previously used here}} expected-note {{reverse_offload clause previously used here}} - -#pragma omp requires reverse_offload, reverse_offload // expected-error {{Only one reverse_offload clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'reverse_offload' clause}} - -#pragma omp requires dynamic_allocators // expected-note {{dynamic_allocators clause previously used here}} expected-note {{dynamic_allocators clause previously used here}} - -#pragma omp requires dynamic_allocators, dynamic_allocators // expected-error {{Only one dynamic_allocators clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'dynamic_allocators' clause}} - - -#pragma omp requires // expected-error {{expected at least one clause on '#pragma omp requires' directive}} - -#pragma omp requires invalid_clause // expected-warning {{extra tokens at the end of '#pragma omp requires' are ignored}} expected-error {{expected at least one clause on '#pragma omp requires' directive}} - -#pragma omp requires nowait // expected-error {{unexpected OpenMP clause 'nowait' in directive '#pragma omp requires'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}} - -#pragma omp requ
LLVM buildmaster will be restarted tonight
Hello everyone, LLVM buildmaster will be updated and restarted after 6PM Pacific time today. Thanks Galina ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53457: clang-cl: Add "/Xdriver:" pass-through arg support.
rnk added a comment. In https://reviews.llvm.org/D53457#1269769, @hans wrote: > I haven't started looking at the code yet. > > I'm not completely convinced that we want this. So far we've used the > strategy of promoting clang options that are also useful in clang-cl to core > options, and if someone wants to use more clang than that, maybe clang-cl > isn't the right driver for that use-case. > > But I suppose an argument could be made for having an escape hatch from > clang-cl if it doesn't add too much complexity to the code. Personally, I really want to get out of the role of being a gatekeeper for GCC-style driver flags. I want users to be able to solve their own problems without building clang-cl from scratch or waiting for the next 6 month release. I'm personally in favor of moving clang-cl to a blacklist model instead of a whitelist model so that we go even further in this direction, but it doesn't address what to do about conflicting or ambiguous options like `-MD`. An escape hatch like `[-/]Xdriver:` seems like a useful thing to have when that arises. > I'm not sure I'm a fan of calling it /Xdriver: though, because what does it > mean - clang-cl is the driver, but the option refers to the clang driver. The > natural name would of course be -Xclang but that already means something > else. Maybe we could just call it /clang: Huh, I like that. You'd also be able to spell it `-clang:`, so the leading `/` is less of a disambiguator, but the colon is clearly a sign that this is a CL-style option. Repository: rC Clang https://reviews.llvm.org/D53457 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53514: os_log: make buffer size an integer constant expression.
t.p.northover created this revision. Herald added a subscriber: mcrosier. The size of an os_log buffer is known at any stage of compilation, so making it a constant expression means that the common idiom of declaring a buffer for it won't result in a VLA. That allows the compiler to skip saving and restoring the stack pointer around such buffers. There can be hundreds or even thousands of such calls, even in firmware projects, so the code size savings add up. Repository: rC Clang https://reviews.llvm.org/D53514 Files: clang/lib/AST/ExprConstant.cpp clang/lib/CodeGen/CGBuiltin.cpp clang/test/CodeGen/builtins.c Index: clang/test/CodeGen/builtins.c === --- clang/test/CodeGen/builtins.c +++ clang/test/CodeGen/builtins.c @@ -729,25 +729,28 @@ // CHECK-LABEL: define void @test_builtin_os_log_errno void test_builtin_os_log_errno() { - // CHECK: %[[VLA:.*]] = alloca i8, i64 4, align 16 - // CHECK: call void @__os_log_helper_16_2_1_0_96(i8* %[[VLA]]) + // CHECK-NOT: @stacksave + // CHECK: %[[BUF:.*]] = alloca [4 x i8], align 1 + // CHECK: %[[DECAY:.*]] = getelementptr inbounds [4 x i8], [4 x i8]* %[[BUF]], i32 0, i32 0 + // CHECK: call void @__os_log_helper_1_2_1_0_96(i8* %[[DECAY]]) + // CHECK-NOT: @stackrestore char buf[__builtin_os_log_format_buffer_size("%m")]; __builtin_os_log_format(buf, "%m"); } -// CHECK-LABEL: define linkonce_odr hidden void @__os_log_helper_16_2_1_0_96 +// CHECK-LABEL: define linkonce_odr hidden void @__os_log_helper_1_2_1_0_96 // CHECK: (i8* %[[BUFFER:.*]]) // CHECK: %[[BUFFER_ADDR:.*]] = alloca i8*, align 8 // CHECK: store i8* %[[BUFFER]], i8** %[[BUFFER_ADDR]], align 8 // CHECK: %[[BUF:.*]] = load i8*, i8** %[[BUFFER_ADDR]], align 8 // CHECK: %[[SUMMARY:.*]] = getelementptr i8, i8* %[[BUF]], i64 0 -// CHECK: store i8 2, i8* %[[SUMMARY]], align 16 +// CHECK: store i8 2, i8* %[[SUMMARY]], align 1 // CHECK: %[[NUMARGS:.*]] = getelementptr i8, i8* %[[BUF]], i64 1 // CHECK: store i8 1, i8* %[[NUMARGS]], align 1 // CHECK: %[[ARGDESCRIPTOR:.*]] = getelementptr i8, i8* %[[BUF]], i64 2 -// CHECK: store i8 96, i8* %[[ARGDESCRIPTOR]], align 2 +// CHECK: store i8 96, i8* %[[ARGDESCRIPTOR]], align 1 // CHECK: %[[ARGSIZE:.*]] = getelementptr i8, i8* %[[BUF]], i64 3 // CHECK: store i8 0, i8* %[[ARGSIZE]], align 1 // CHECK-NEXT: ret void Index: clang/lib/CodeGen/CGBuiltin.cpp === --- clang/lib/CodeGen/CGBuiltin.cpp +++ clang/lib/CodeGen/CGBuiltin.cpp @@ -3594,13 +3594,6 @@ case Builtin::BI__builtin_os_log_format: return emitBuiltinOSLogFormat(*E); - case Builtin::BI__builtin_os_log_format_buffer_size: { -analyze_os_log::OSLogBufferLayout Layout; -analyze_os_log::computeOSLogBufferLayout(CGM.getContext(), E, Layout); -return RValue::get(ConstantInt::get(ConvertType(E->getType()), -Layout.size().getQuantity())); - } - case Builtin::BI__xray_customevent: { if (!ShouldXRayInstrumentFunction()) return RValue::getIgnored(); Index: clang/lib/AST/ExprConstant.cpp === --- clang/lib/AST/ExprConstant.cpp +++ clang/lib/AST/ExprConstant.cpp @@ -33,6 +33,7 @@ // //===--===// +#include "clang/Analysis/Analyses/OSLog.h" #include "clang/AST/APValue.h" #include "clang/AST/ASTContext.h" #include "clang/AST/ASTDiagnostic.h" @@ -8112,6 +8113,12 @@ llvm_unreachable("unexpected EvalMode"); } + case Builtin::BI__builtin_os_log_format_buffer_size: { +analyze_os_log::OSLogBufferLayout Layout; +analyze_os_log::computeOSLogBufferLayout(Info.Ctx, E, Layout); +return Success(Layout.size().getQuantity(), E); + } + case Builtin::BI__builtin_bswap16: case Builtin::BI__builtin_bswap32: case Builtin::BI__builtin_bswap64: { Index: clang/test/CodeGen/builtins.c === --- clang/test/CodeGen/builtins.c +++ clang/test/CodeGen/builtins.c @@ -729,25 +729,28 @@ // CHECK-LABEL: define void @test_builtin_os_log_errno void test_builtin_os_log_errno() { - // CHECK: %[[VLA:.*]] = alloca i8, i64 4, align 16 - // CHECK: call void @__os_log_helper_16_2_1_0_96(i8* %[[VLA]]) + // CHECK-NOT: @stacksave + // CHECK: %[[BUF:.*]] = alloca [4 x i8], align 1 + // CHECK: %[[DECAY:.*]] = getelementptr inbounds [4 x i8], [4 x i8]* %[[BUF]], i32 0, i32 0 + // CHECK: call void @__os_log_helper_1_2_1_0_96(i8* %[[DECAY]]) + // CHECK-NOT: @stackrestore char buf[__builtin_os_log_format_buffer_size("%m")]; __builtin_os_log_format(buf, "%m"); } -// CHECK-LABEL: define linkonce_odr hidden void @__os_log_helper_16_2_1_0_96 +// CHECK-LABEL: define linkonce_odr hidden void @__os_log_helper_1_2_1_0_96 // CHECK: (i8* %[[BUFFER:.*]]) // CHECK: %[[BUFFER_ADDR:.*]
[PATCH] D38061: Set AnonymousTagLocations false for ASTContext if column info is expected not to be used
twoh added a comment. @aprantl It is a debug info. If you compile test/CodeGenCXX/debug-info-anonymous.cpp file with `clang -g2 -emit-llvm -S `, you will find debug metadata something like `distinct !DISubprogram(name: "foo", linkageName: "_Z3fooIN1XUt_EEiT_" ...`, which will eventually be included in .debug_info section. Repository: rC Clang https://reviews.llvm.org/D38061 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53513: [OPENMP] Add support for 'atomic_default_mem_order' clause on requires directive
ABataev added a comment. Check the code formatting, please. There should be lines longer than 80 symbols. Comment at: clang/include/clang/AST/OpenMPClause.h:886 + /// \param K Kind of clause. + void setAtomicDefaultMemOrderKind(OpenMPAtomicDefaultMemOrderClauseKind K) { +Kind = K; Check formatting here Comment at: clang/include/clang/AST/OpenMPClause.h:906 + /// \param EndLoc Ending location of the clause. + OMPAtomicDefaultMemOrderClause(OpenMPAtomicDefaultMemOrderClauseKind A, + SourceLocation ALoc, SourceLocation StartLoc, Also, formatting Comment at: clang/include/clang/AST/OpenMPClause.h:930 + /// Returns location of clause kind. + SourceLocation getAtomicDefaultMemOrderKindKwLoc() const { return KindKwLoc; } + Again, probably too long line. Repository: rC Clang https://reviews.llvm.org/D53513 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53296: [analyzer] New flag to print all -analyzer-config options
george.karpenkov accepted this revision. george.karpenkov added a comment. This revision is now accepted and ready to land. Good to go, with minor nits inline. Comment at: lib/FrontendTool/ExecuteCompilerInvocation.cpp:255 +ento::printAnalyzerConfigList(llvm::outs()); +return true; + } Hm, should we return here? If there are errors, which are only printed in the next part, should they still be printed? Comment at: test/Analysis/analyzer-list-configs.c:13 +// +// CHECK: OPTIONS: Just to be sure, I would hardcode checking for at least the first option here. https://reviews.llvm.org/D53296 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38061: Set AnonymousTagLocations false for ASTContext if column info is expected not to be used
dblaikie added a comment. In https://reviews.llvm.org/D38061#1271021, @twoh wrote: > @aprantl It is a debug info. If you compile > test/CodeGenCXX/debug-info-anonymous.cpp file with `clang -g2 -emit-llvm -S > `, you will find debug metadata something like `distinct !DISubprogram(name: > "foo /home/twoh/llvms/llvm/tools/clang/test/CodeGenCXX/debug-info-anonymous.cpp:9:3)>", > linkageName: "_Z3fooIN1XUt_EEiT_" ...`, which will eventually be included in > .debug_info section. For comparison, GCC names these "foo >" - this is somewhat of a compatibility problem, since the template function definition's names won't match between GCC and Clang, but I guess this is by far not the only instance of that. GCC keeps that naming scheme even when it's clearly ambiguous (ie: it's not just making a short name when there's no other X::anonymous enum, it does it even when there's two of them, etc) Repository: rC Clang https://reviews.llvm.org/D38061 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r344929 - [X86] Add new features to the priority list for target attribute multiversioning.
Author: ctopper Date: Mon Oct 22 10:59:58 2018 New Revision: 344929 URL: http://llvm.org/viewvc/llvm-project?rev=344929&view=rev Log: [X86] Add new features to the priority list for target attribute multiversioning. Modified: cfe/trunk/include/clang/Basic/X86Target.def Modified: cfe/trunk/include/clang/Basic/X86Target.def URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/X86Target.def?rev=344929&r1=344928&r2=344929&view=diff == --- cfe/trunk/include/clang/Basic/X86Target.def (original) +++ cfe/trunk/include/clang/Basic/X86Target.def Mon Oct 22 10:59:58 2018 @@ -283,6 +283,11 @@ FEATURE(FEATURE_AVX512IFMA) FEATURE(FEATURE_AVX5124VNNIW) FEATURE(FEATURE_AVX5124FMAPS) FEATURE(FEATURE_AVX512VPOPCNTDQ) +FEATURE(FEATURE_AVX512VBMI2) +FEATURE(FEATURE_GFNI) +FEATURE(FEATURE_VPCLMULQDQ) +FEATURE(FEATURE_AVX512VNNI) +FEATURE(FEATURE_AVX512BITALG) // FIXME: When commented out features are supported in LLVM, enable them here. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53457: clang-cl: Add "/Xdriver:" pass-through arg support.
neerajksingh added a comment. In https://reviews.llvm.org/D53457#1269769, @hans wrote: > I'm not completely convinced that we want this. So far we've used the > strategy of promoting clang options that are also useful in clang-cl to core > options, and if someone wants to use more clang than that, maybe clang-cl > isn't the right driver for that use-case. > > But I suppose an argument could be made for having an escape hatch from > clang-cl if it doesn't add too much complexity to the code. This is a good point. However, having this escape hatch gets you and Reid and others out of the business of having to promote options. Also, as new flags are added to the compiler people might need one revision of the official builds to realize they need a flag and one revision to get the flag added to the binary release. This obviously isn't a problem for people building Clang from source, but it does add unnecessary friction as I found myself. > I'm not sure I'm a fan of calling it /Xdriver: though, because what does it > mean - clang-cl is the driver, but the option refers to the clang driver. The > natural name would of course be -Xclang but that already means something > else. Maybe we could just call it /clang: At the conference last week I discussed this with Reid Kleckner. One of the options we discussed was trying to make things work such that -Xclang serves both purposes. We quickly decided that this wouldn't work. /clang: would be fine, but it might be more confusing since people will wonder what's the difference between /Xclang and /clang:. We could use something more verbose like /Xclang-driver:. I'd be happy to change the flag to whatever spelling will build consensus. Repository: rC Clang https://reviews.llvm.org/D53457 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53069: [analyzer][www] Update avaible_checks.html
george.karpenkov requested changes to this revision. george.karpenkov added inline comments. This revision now requires changes to proceed. Comment at: www/analyzer/available_checks.html:459 + Spurious newline Comment at: www/analyzer/available_checks.html:496 + + + If we don't have a description, let's just drop it. Comment at: www/analyzer/available_checks.html:677 + +void use_semaphor_antipattern() { + dispatch_semaphore_t sema = dispatch_semaphore_create(0); I have a longer description: This checker finds a common performance anti-pattern in a code that uses Grand Central dispatch. The anti-pattern involves emulating a synchronous call from an asynchronous API using semaphores, as in the snippet below, where the `requestCurrentTaskName` function makes an XPC call and then uses the semaphore to block until the XPC call returns: ``` + (NSString *)requestCurrentTaskName { __block NSString *taskName = nil; dispatch_semaphore_t sema = dispatch_semaphore_create(0); NSXPCConnection *connection = [[NSXPCConnection alloc] initWithServiceName:@"MyConnection"]; id remoteObjectProxy = connection.remoteObjectProxy; [remoteObjectProxy requestCurrentTaskName:^(NSString *task) { taskName = task; dispatch_semaphore_signal(sema); }]; dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); return taskName; } ``` Usage of such a pattern in production code running on the main thread is discouraged, as the main queue gets blocked waiting for the background queue, which could be running at a lower priority, and unnecessary threads are spawned in the process. In order to avoid the anti-pattern, the available alternatives are: - Use the synchronous version of the API, if available. In the example above, the synchronous XPC proxy object can be used: ``` + (NSString *)requestCurrentTaskName { __block NSString *taskName = nil; NSXPCConnection *connection = [[NSXPCConnection alloc] initWithServiceName:@"MyConnection"]; id remoteObjectProxy = [connection synchronousRemoteObjectProxyWithErrorHandler:^(NSError *error) { NSLog(@"Error = %@", error); }]; [remoteObjectProxy requestCurrentTaskName:^(NSString *task) { taskName = task; }]; return taskName; } ``` - Alternatively, the API can be used in the asynchronous way. Comment at: www/analyzer/available_checks.html:768 +Check for proper uses of Objective-C properties + + If we don't have proper description, let's drop. Comment at: www/analyzer/available_checks.html:877 +(ObjC) +Warn about potentially crashing writes to autoreleasing objects from different +autoreleasing pools in Objective-C. I have a longer description: Under ARC, function parameters which are pointers to pointers (e.g. NSError**) are `__autoreleasing`. Writing to such parameters inside autoreleasing pools might crash whenever the parameter outlives the pool. Detecting such crashes may be difficult, as usage of autorelease pool is usually hidden inside the called functions implementation. Examples include: ``` BOOL writeToErrorWithIterator(NSError *__autoreleasing* error, NSArray *a) { [a enumerateObjectsUsingBlock:^{ *error = [NSError errorWithDomain:1]; }]; } ``` and ``` BOOL writeToErrorInBlockFromCFunc(NSError *__autoreleasing* error) { dispatch_semaphore_t sem = dispatch_semaphore_create(0l); dispatch_async(queue, ^{ if (error) { *error = [NSError errorWithDomain:1]; } dispatch_semaphore_signal(sem); }); dispatch_semaphore_wait(sem, 100); return 0; } ``` Comment at: www/analyzer/available_checks.html:1071 +(ObjC) +Model the APIs that are guaranteed to return a non-nil value. + Probably should be dropped. Comment at: www/analyzer/available_checks.html:1119 + + + Top of the checker file has a somewhat reasonable description: // A checker for detecting leaks resulting from allocating temporary // autoreleased objects before starting the main run loop. // // Checks for two antipatterns: // 1. ObjCMessageExpr followed by [[NSRunLoop mainRunLoop] run] in the same // autorelease pool. // 2. ObjCMessageExpr followed by [[NSRunLoop mainRunLoop] run] in no // autorelease pool. // // Any temporary objects autoreleased in code called in those expressions // will not be deallocated until the program exits, and are effectively leaks. https://reviews.llvm.org/D53069 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like elements
george.karpenkov added a comment. Herald added subscribers: dkrupp, donat.nagy. I'm marking it as "needs changes" for now -- the idea seems reasonable, but it's hard to tell without a thorough evaluation on at least a few codebases. Additionally, we should figure out a checker group for this - if "alpha" means "work in progress", then it should be under something else, like "linting" or similar. https://reviews.llvm.org/D50488 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52949: [Diagnostics] Implement -Wsizeof-pointer-div
xbolva00 added a comment. Ping https://reviews.llvm.org/D52949 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52835: [Diagnostics] Check integer to floating point number implicit conversions
xbolva00 added a comment. Ping https://reviews.llvm.org/D52835 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53483: [analyzer] Restrict AnalyzerOptions' interface so that non-checker objects have to be registered
george.karpenkov added a comment. OK, so the overall direction makes sense: unregistered options are restricted to checkers, and for others, an explicit getter must be maintained. (though I would also prefer if even checkers could pre-register their options somehow) @NoQ does this make sense to you? Comment at: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h:243 + /// specified. + StringRef getStringOption(StringRef Name, StringRef DefaultVal); xazax.hun wrote: > If you want the devs to maintain an explicit getter for each analyzer option > rather than making this one public at some point, please document expectation > this somewhere. +1 Repository: rC Clang https://reviews.llvm.org/D53483 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53206: Allow padding checker to traverse simple class hierarchies
george.karpenkov added a comment. @bcraig comments look valid, marking as "Needs Changes" Repository: rC Clang https://reviews.llvm.org/D53206 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53206: Allow padding checker to traverse simple class hierarchies
tekknolagi added inline comments. Comment at: test/Analysis/padding_cpp.cpp:204-212 +// expected-warning@+1{{Excessive padding in 'struct FakeIntSandwich'}} +struct FakeIntSandwich { + char c1; + int i; + char c2; +}; + bcraig wrote: > Looking at this again... what new cases does this catch? FakeIntSandwich was > caught before (it is identical to 'PaddedA', and AnotherIntSandwich generated > no warning before. So what is different? > > EBO1 and EBO2 are cases above that would be nice to catch, but aren't being > caught right now. Ah, you're right. I'll just keep the one in `padding_inherit`. Repository: rC Clang https://reviews.llvm.org/D53206 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53206: Allow padding checker to traverse simple class hierarchies
tekknolagi updated this revision to Diff 170464. tekknolagi edited the summary of this revision. tekknolagi added a comment. Remove useless test case in `padding_cpp.cpp` Repository: rC Clang https://reviews.llvm.org/D53206 Files: lib/StaticAnalyzer/Checkers/PaddingChecker.cpp test/Analysis/padding_inherit.cpp Index: test/Analysis/padding_inherit.cpp === --- /dev/null +++ test/Analysis/padding_inherit.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_analyze_cc1 -std=c++14 -analyzer-checker=optin.performance -analyzer-config optin.performance.Padding:AllowedPad=20 -verify %s + +// A class that has no fields and one base class should visit that base class +// instead. +// expected-warning@+1{{Excessive padding in 'struct FakeIntSandwich'}} +struct FakeIntSandwich { + char c1; + int i; + char c2; +}; + +struct AnotherIntSandwich : FakeIntSandwich { // no-warning +}; + +struct IntSandwich {}; + +// But we don't yet support multiple base classes. +struct TooManyBaseClasses : FakeIntSandwich, IntSandwich { // no-warning +}; + +AnotherIntSandwich ais[100]; + +struct Empty {}; +struct DoubleEmpty : Empty { // no-warning +Empty e; +}; Index: lib/StaticAnalyzer/Checkers/PaddingChecker.cpp === --- lib/StaticAnalyzer/Checkers/PaddingChecker.cpp +++ lib/StaticAnalyzer/Checkers/PaddingChecker.cpp @@ -75,6 +75,19 @@ if (shouldSkipDecl(RD)) return; +// We need to be looking at a definition, not just any pointer to the +// declaration. +if (!(RD = RD->getDefinition())) + return; + +// This is the simplest correct case: a class with no fields and one base +// class. Other cases are more complicated because of how the base classes +// & fields might interact, so we don't bother dealing with them. +if (auto *CXXRD = dyn_cast(RD)) + if (CXXRD->field_empty() && CXXRD->getNumBases() == 1) +return visitRecord(CXXRD->bases().begin()->getType()->getAsRecordDecl(), + PadMultiplier); + auto &ASTContext = RD->getASTContext(); const ASTRecordLayout &RL = ASTContext.getASTRecordLayout(RD); assert(llvm::isPowerOf2_64(RL.getAlignment().getQuantity())); @@ -112,8 +125,7 @@ if (RT == nullptr) return; -// TODO: Recurse into the fields and base classes to see if any -// of those have excess padding. +// TODO: Recurse into the fields to see if they have excess padding. visitRecord(RT->getDecl(), Elts); } @@ -132,13 +144,17 @@ // Not going to attempt to optimize unions. if (RD->isUnion()) return true; -// How do you reorder fields if you haven't got any? -if (RD->field_empty()) - return true; if (auto *CXXRD = dyn_cast(RD)) { + // TODO: Figure out why we are going through declarations and not only + // definitions. + if (!(CXXRD = CXXRD->getDefinition())) +return true; // Tail padding with base classes ends up being very complicated. - // We will skip objects with base classes for now. - if (CXXRD->getNumBases() != 0) + // We will skip objects with base classes for now, unless they do not + // have fields. + if (!CXXRD->field_empty() && CXXRD->getNumBases() != 0) +return true; + if (CXXRD->field_empty() && CXXRD->getNumBases() != 1) return true; // Virtual bases are complicated, skipping those for now. if (CXXRD->getNumVBases() != 0) @@ -150,6 +166,10 @@ if (CXXRD->getTypeForDecl()->isInstantiationDependentType()) return true; } +// How do you reorder fields if you haven't got any? +else if (RD->field_empty()) + return true; + auto IsTrickyField = [](const FieldDecl *FD) -> bool { // Bitfield layout is hard. if (FD->isBitField()) @@ -323,7 +343,7 @@ BR->emitReport(std::move(Report)); } }; -} +} // namespace void ento::registerPaddingChecker(CheckerManager &Mgr) { Mgr.registerChecker(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r344934 - Generate ClangFormatStyleOptions.rst from Format.h (using docs/tools/dump_format_style.py)
Author: sylvestre Date: Mon Oct 22 11:48:58 2018 New Revision: 344934 URL: http://llvm.org/viewvc/llvm-project?rev=344934&view=rev Log: Generate ClangFormatStyleOptions.rst from Format.h (using docs/tools/dump_format_style.py) Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=344934&r1=344933&r2=344934&view=diff == --- cfe/trunk/docs/ClangFormatStyleOptions.rst (original) +++ cfe/trunk/docs/ClangFormatStyleOptions.rst Mon Oct 22 11:48:58 2018 @@ -1134,21 +1134,17 @@ the configuration (without a prefix: ``A .. code-block:: c++ true: -FitsOnOneLine::Constructor() -: a(aa), a(aa) {} - -DoesntFit::Constructor() -: a(aa), - a(aa), - a(aa) {} +SomeClass::Constructor() +: (), (), (a) { + return 0; +} false: -FitsOnOneLine::Constructor() -: a(aa), a(aa) {} - -DoesntFit::Constructor() -: a(aa), a(aa), - a(aa) {} +SomeClass::Constructor() +: (), (), + (a) { + return 0; +} **ConstructorInitializerIndentWidth** (``unsigned``) The number of characters to use for indentation of constructor @@ -1402,6 +1398,37 @@ the configuration (without a prefix: ``A LngReturnType LngFunctionDeclaration(); +**JavaImportGroups** (``std::vector``) + A vector of prefixes ordered by the desired groups for Java imports. + + Each group is seperated by a newline. Static imports will also follow the + same grouping convention above all non-static imports. One group's prefix + can be a subset of another - the longest prefix is always matched. Within + a group, the imports are ordered lexicographically. + + In the .clang-format configuration file, this can be configured like: + + .. code-block:: yaml + +JavaImportGroups: ['com.example', 'com', 'org'] + Which will result in imports being formatted as so: + + .. code-block:: java + + import static com.example.function1; + + import static com.test.function2; + + import static org.example.function3; + + import com.example.ClassA; + import com.example.Test; + import com.example.a.ClassB; + + import com.test.ClassC; + + import org.example.ClassD; + **JavaScriptQuotes** (``JavaScriptQuoteStyle``) The JavaScriptQuoteStyle to use for JavaScript strings. @@ -1980,7 +2007,8 @@ the configuration (without a prefix: ``A **StatementMacros** (``std::vector``) - A vector of macros that should be interpreted as complete statements. + A vector of macros that should be interpreted as complete + statements. Typical macros are expressions, and require a semi-colon to be added; sometimes this is not the case, and this allows to make ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53066: [RFC] [Driver] Use forward slashes in most linker arguments
mstorsjo added a comment. Ping @rnk https://reviews.llvm.org/D53066 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51531: [analyzer][UninitializedObjectChecker] Uninit regions are only reported once
NoQ added a comment. I think `RetainCountChecker` is the only checker that maintains such maps and does such cleanup: https://github.com/llvm-mirror/clang/blob/efe41bf98/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h#L288 I didn't know it does that until today. https://reviews.llvm.org/D51531 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52857: [clang-query] Add non-exclusive output API
pcc added a comment. I'm not really involved in clang-query development these days, so this is more of a drive-by comment. It wasn't really obvious to me what the wording of the help text for `set enable-output` meant: > Set whether to enable content non-exclusively. I figured out from the name of the option and from reading the source code that it just means "Enable output in format ." This seems confusing to me because I would expect `set foo bar` to set the value of a variable `foo` to `bar`, which doesn't match what this command does. What do you think about spelling it as something like `enable output `? Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D52857 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53308: [Fixed Point Arithmetic] Fixed Point to Boolean Cast
leonardchan added inline comments. Comment at: clang/lib/CodeGen/CGExprScalar.cpp:2026 +return EmitScalarConversion(Visit(E), E->getType(), DestTy, +CE->getExprLoc()); ebevhan wrote: > rjmccall wrote: > > Why are you pushing these casts through `EmitScalarConversion` when the > > cast kind already tells you which operation you're doing? > It could be useful to enable EmitScalarConversion to handle any of the > conversions so it can be used in other contexts than expanding a cast. > It could be useful to enable EmitScalarConversion to handle any of the > conversions so it can be used in other contexts than expanding a cast. This was also the reason I did this since `EmitScalarConversion` seems to get called in many places as a generic dispatch for different conversions. Repository: rC Clang https://reviews.llvm.org/D53308 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r344939 - Hopefully fix the documentation generation issue
Author: sylvestre Date: Mon Oct 22 12:07:29 2018 New Revision: 344939 URL: http://llvm.org/viewvc/llvm-project?rev=344939&view=rev Log: Hopefully fix the documentation generation issue Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst cfe/trunk/include/clang/Format/Format.h Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=344939&r1=344938&r2=344939&view=diff == --- cfe/trunk/docs/ClangFormatStyleOptions.rst (original) +++ cfe/trunk/docs/ClangFormatStyleOptions.rst Mon Oct 22 12:07:29 2018 @@ -1406,12 +1406,14 @@ the configuration (without a prefix: ``A can be a subset of another - the longest prefix is always matched. Within a group, the imports are ordered lexicographically. - In the .clang-format configuration file, this can be configured like: + In the .clang-format configuration file, this can be configured like + in the following yaml example. This will result in imports being + formatted as in the Java example below. .. code-block:: yaml JavaImportGroups: ['com.example', 'com', 'org'] - Which will result in imports being formatted as so: + .. code-block:: java Modified: cfe/trunk/include/clang/Format/Format.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=344939&r1=344938&r2=344939&view=diff == --- cfe/trunk/include/clang/Format/Format.h (original) +++ cfe/trunk/include/clang/Format/Format.h Mon Oct 22 12:07:29 2018 @@ -1139,11 +1139,13 @@ struct FormatStyle { /// can be a subset of another - the longest prefix is always matched. Within /// a group, the imports are ordered lexicographically. /// - /// In the .clang-format configuration file, this can be configured like: + /// In the .clang-format configuration file, this can be configured like + /// in the following yaml example. This will result in imports being + /// formatted as in the Java example below. /// \code{.yaml} /// JavaImportGroups: ['com.example', 'com', 'org'] /// \endcode - /// Which will result in imports being formatted as so: + /// /// \code{.java} ///import static com.example.function1; /// ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules
JonasToth added inline comments. Comment at: clang-tidy/cppcoreguidelines/MacroUsageCheck.h:34-35 + void registerPPCallbacks(CompilerInstance &Compiler) override; + void warnMacro(const MacroDirective *MD); + void warnNaming(const MacroDirective *MD); + aaron.ballman wrote: > Nit: these can be private functions instead. They are used by the PPCallbacks. I think adding a `friend` is not worth it. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D41648 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules
JonasToth updated this revision to Diff 170470. JonasToth marked 4 inline comments as done. JonasToth added a comment. - address review nits Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D41648 Files: clang-tidy/cppcoreguidelines/CMakeLists.txt clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp clang-tidy/cppcoreguidelines/MacroUsageCheck.h docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst docs/clang-tidy/checks/list.rst test/clang-tidy/cppcoreguidelines-macro-usage-caps-only.cpp test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp test/clang-tidy/cppcoreguidelines-macro-usage.cpp Index: test/clang-tidy/cppcoreguidelines-macro-usage.cpp === --- /dev/null +++ test/clang-tidy/cppcoreguidelines-macro-usage.cpp @@ -0,0 +1,18 @@ +// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t + +#ifndef INCLUDE_GUARD +#define INCLUDE_GUARD + +#define PROBLEMATIC_CONSTANT 0 +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro used to declare a constant; consider using a 'constexpr' constant + +#define PROBLEMATIC_FUNCTION(x, y) ((a) > (b) ? (a) : (b)) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: function-like macro used; consider a 'constexpr' template function + +#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro used; consider using a 'constexpr' variadic template function + +#define PROBLEMATIC_VARIADIC2(x, ...) (__VA_ARGS__) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro used; consider using a 'constexpr' variadic template function + +#endif Index: test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp === --- /dev/null +++ test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp @@ -0,0 +1,28 @@ +// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t \ +// RUN: -config='{CheckOptions: \ +// RUN: [{key: cppcoreguidelines-macro-usage.AllowedRegexp, value: "DEBUG_*|TEST_*"}]}' -- + +#ifndef INCLUDE_GUARD +#define INCLUDE_GUARD + +#define PROBLEMATIC_CONSTANT 0 +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro used to declare a constant; consider using a 'constexpr' constant + +#define PROBLEMATIC_FUNCTION(x, y) ((a) > (b) ? (a) : (b)) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: function-like macro used; consider a 'constexpr' template function + +#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro used; consider using a 'constexpr' variadic template function + +#define PROBLEMATIC_VARIADIC2(x, ...) (__VA_ARGS__) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro used; consider using a 'constexpr' variadic template function + +#define DEBUG_CONSTANT 0 +#define DEBUG_FUNCTION(x, y) ((a) > (b) ? (a) : (b)) +#define DEBUG_VARIADIC(...) (__VA_ARGS__) +#define TEST_CONSTANT 0 +#define TEST_FUNCTION(x, y) ((a) > (b) ? (a) : (b)) +#define TEST_VARIADIC(...) (__VA_ARGS__) +#define TEST_VARIADIC2(x, ...) (__VA_ARGS__) + +#endif Index: test/clang-tidy/cppcoreguidelines-macro-usage-caps-only.cpp === --- /dev/null +++ test/clang-tidy/cppcoreguidelines-macro-usage-caps-only.cpp @@ -0,0 +1,24 @@ +// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t \ +// RUN: -config='{CheckOptions: \ +// RUN: [{key: cppcoreguidelines-macro-usage.CheckCapsOnly, value: 1}]}' -- + +#ifndef INCLUDE_GUARD +#define INCLUDE_GUARD + +#define problematic_constant 0 +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro definition does not define the macro name using all uppercase characters + +#define problematic_function(x, y) ((a) > (b) ? (a) : (b)) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro definition does not define the macro name using all uppercase characters + +#define problematic_variadic(...) (__VA_ARGS__) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro definition does not define the macro name using all uppercase characters +// +#define problematic_variadic2(x, ...) (__VA_ARGS__) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro definition does not define the macro name using all uppercase characters + +#define OKISH_CONSTANT 42 +#define OKISH_FUNCTION(x, y) ((a) > (b) ? (a) : (b)) +#define OKISH_VARIADIC(...) (__VA_ARGS__) + +#endif Index: docs/clang-tidy/checks/list.rst === --- docs/clang-tidy/checks/list.rst +++ docs/clang-tidy/checks/list.rst @@ -89,6 +89,7 @@ cppcoreguidelines-avoid-magic-numbers (redirects to readability-magic-numbers) cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) cppcoreguidelines-interfaces-global-init + cppcoreguidelines-macro-usage cppcoreguidelines-narrowing-conversions cppcoreguidelines-no-malloc cppcoreguidelines-non-private-me
[PATCH] D53513: [OPENMP] Add support for 'atomic_default_mem_order' clause on requires directive
patricklyster added inline comments. Comment at: clang/include/clang/AST/OpenMPClause.h:930 + /// Returns location of clause kind. + SourceLocation getAtomicDefaultMemOrderKindKwLoc() const { return KindKwLoc; } + ABataev wrote: > Again, probably too long line. None of these lines are longer than 80 symbols - hard to see this on Phabricator though. All this code was formatted using the clang-format tool. Would you still like me to change it? Repository: rC Clang https://reviews.llvm.org/D53513 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules
JonasToth updated this revision to Diff 170471. JonasToth added a comment. - add missing private Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D41648 Files: clang-tidy/cppcoreguidelines/CMakeLists.txt clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp clang-tidy/cppcoreguidelines/MacroUsageCheck.h docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst docs/clang-tidy/checks/list.rst test/clang-tidy/cppcoreguidelines-macro-usage-caps-only.cpp test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp test/clang-tidy/cppcoreguidelines-macro-usage.cpp Index: test/clang-tidy/cppcoreguidelines-macro-usage.cpp === --- /dev/null +++ test/clang-tidy/cppcoreguidelines-macro-usage.cpp @@ -0,0 +1,18 @@ +// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t + +#ifndef INCLUDE_GUARD +#define INCLUDE_GUARD + +#define PROBLEMATIC_CONSTANT 0 +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro used to declare a constant; consider using a 'constexpr' constant + +#define PROBLEMATIC_FUNCTION(x, y) ((a) > (b) ? (a) : (b)) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: function-like macro used; consider a 'constexpr' template function + +#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro used; consider using a 'constexpr' variadic template function + +#define PROBLEMATIC_VARIADIC2(x, ...) (__VA_ARGS__) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro used; consider using a 'constexpr' variadic template function + +#endif Index: test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp === --- /dev/null +++ test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp @@ -0,0 +1,28 @@ +// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t \ +// RUN: -config='{CheckOptions: \ +// RUN: [{key: cppcoreguidelines-macro-usage.AllowedRegexp, value: "DEBUG_*|TEST_*"}]}' -- + +#ifndef INCLUDE_GUARD +#define INCLUDE_GUARD + +#define PROBLEMATIC_CONSTANT 0 +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro used to declare a constant; consider using a 'constexpr' constant + +#define PROBLEMATIC_FUNCTION(x, y) ((a) > (b) ? (a) : (b)) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: function-like macro used; consider a 'constexpr' template function + +#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro used; consider using a 'constexpr' variadic template function + +#define PROBLEMATIC_VARIADIC2(x, ...) (__VA_ARGS__) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro used; consider using a 'constexpr' variadic template function + +#define DEBUG_CONSTANT 0 +#define DEBUG_FUNCTION(x, y) ((a) > (b) ? (a) : (b)) +#define DEBUG_VARIADIC(...) (__VA_ARGS__) +#define TEST_CONSTANT 0 +#define TEST_FUNCTION(x, y) ((a) > (b) ? (a) : (b)) +#define TEST_VARIADIC(...) (__VA_ARGS__) +#define TEST_VARIADIC2(x, ...) (__VA_ARGS__) + +#endif Index: test/clang-tidy/cppcoreguidelines-macro-usage-caps-only.cpp === --- /dev/null +++ test/clang-tidy/cppcoreguidelines-macro-usage-caps-only.cpp @@ -0,0 +1,24 @@ +// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t \ +// RUN: -config='{CheckOptions: \ +// RUN: [{key: cppcoreguidelines-macro-usage.CheckCapsOnly, value: 1}]}' -- + +#ifndef INCLUDE_GUARD +#define INCLUDE_GUARD + +#define problematic_constant 0 +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro definition does not define the macro name using all uppercase characters + +#define problematic_function(x, y) ((a) > (b) ? (a) : (b)) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro definition does not define the macro name using all uppercase characters + +#define problematic_variadic(...) (__VA_ARGS__) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro definition does not define the macro name using all uppercase characters +// +#define problematic_variadic2(x, ...) (__VA_ARGS__) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro definition does not define the macro name using all uppercase characters + +#define OKISH_CONSTANT 42 +#define OKISH_FUNCTION(x, y) ((a) > (b) ? (a) : (b)) +#define OKISH_VARIADIC(...) (__VA_ARGS__) + +#endif Index: docs/clang-tidy/checks/list.rst === --- docs/clang-tidy/checks/list.rst +++ docs/clang-tidy/checks/list.rst @@ -89,6 +89,7 @@ cppcoreguidelines-avoid-magic-numbers (redirects to readability-magic-numbers) cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) cppcoreguidelines-interfaces-global-init + cppcoreguidelines-macro-usage cppcoreguidelines-narrowing-conversions cppcoreguidelines-no-malloc cppcoreguidelines-non-private-member-variables-in-classes (redirects to misc
[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules
JonasToth updated this revision to Diff 170472. JonasToth added a comment. - [Doc] add missing release notes Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D41648 Files: clang-tidy/cppcoreguidelines/CMakeLists.txt clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp clang-tidy/cppcoreguidelines/MacroUsageCheck.h docs/ReleaseNotes.rst docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst docs/clang-tidy/checks/list.rst test/clang-tidy/cppcoreguidelines-macro-usage-caps-only.cpp test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp test/clang-tidy/cppcoreguidelines-macro-usage.cpp Index: test/clang-tidy/cppcoreguidelines-macro-usage.cpp === --- /dev/null +++ test/clang-tidy/cppcoreguidelines-macro-usage.cpp @@ -0,0 +1,18 @@ +// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t + +#ifndef INCLUDE_GUARD +#define INCLUDE_GUARD + +#define PROBLEMATIC_CONSTANT 0 +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro used to declare a constant; consider using a 'constexpr' constant + +#define PROBLEMATIC_FUNCTION(x, y) ((a) > (b) ? (a) : (b)) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: function-like macro used; consider a 'constexpr' template function + +#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro used; consider using a 'constexpr' variadic template function + +#define PROBLEMATIC_VARIADIC2(x, ...) (__VA_ARGS__) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro used; consider using a 'constexpr' variadic template function + +#endif Index: test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp === --- /dev/null +++ test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp @@ -0,0 +1,28 @@ +// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t \ +// RUN: -config='{CheckOptions: \ +// RUN: [{key: cppcoreguidelines-macro-usage.AllowedRegexp, value: "DEBUG_*|TEST_*"}]}' -- + +#ifndef INCLUDE_GUARD +#define INCLUDE_GUARD + +#define PROBLEMATIC_CONSTANT 0 +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro used to declare a constant; consider using a 'constexpr' constant + +#define PROBLEMATIC_FUNCTION(x, y) ((a) > (b) ? (a) : (b)) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: function-like macro used; consider a 'constexpr' template function + +#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro used; consider using a 'constexpr' variadic template function + +#define PROBLEMATIC_VARIADIC2(x, ...) (__VA_ARGS__) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro used; consider using a 'constexpr' variadic template function + +#define DEBUG_CONSTANT 0 +#define DEBUG_FUNCTION(x, y) ((a) > (b) ? (a) : (b)) +#define DEBUG_VARIADIC(...) (__VA_ARGS__) +#define TEST_CONSTANT 0 +#define TEST_FUNCTION(x, y) ((a) > (b) ? (a) : (b)) +#define TEST_VARIADIC(...) (__VA_ARGS__) +#define TEST_VARIADIC2(x, ...) (__VA_ARGS__) + +#endif Index: test/clang-tidy/cppcoreguidelines-macro-usage-caps-only.cpp === --- /dev/null +++ test/clang-tidy/cppcoreguidelines-macro-usage-caps-only.cpp @@ -0,0 +1,24 @@ +// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t \ +// RUN: -config='{CheckOptions: \ +// RUN: [{key: cppcoreguidelines-macro-usage.CheckCapsOnly, value: 1}]}' -- + +#ifndef INCLUDE_GUARD +#define INCLUDE_GUARD + +#define problematic_constant 0 +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro definition does not define the macro name using all uppercase characters + +#define problematic_function(x, y) ((a) > (b) ? (a) : (b)) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro definition does not define the macro name using all uppercase characters + +#define problematic_variadic(...) (__VA_ARGS__) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro definition does not define the macro name using all uppercase characters +// +#define problematic_variadic2(x, ...) (__VA_ARGS__) +// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro definition does not define the macro name using all uppercase characters + +#define OKISH_CONSTANT 42 +#define OKISH_FUNCTION(x, y) ((a) > (b) ? (a) : (b)) +#define OKISH_VARIADIC(...) (__VA_ARGS__) + +#endif Index: docs/clang-tidy/checks/list.rst === --- docs/clang-tidy/checks/list.rst +++ docs/clang-tidy/checks/list.rst @@ -89,6 +89,7 @@ cppcoreguidelines-avoid-magic-numbers (redirects to readability-magic-numbers) cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) cppcoreguidelines-interfaces-global-init + cppcoreguidelines-macro-usage cppcoreguidelines-narrowing-conversions cppcoreguidelines-no-malloc cppcoreguidelines-non-private-member-var
[clang-tools-extra] r344940 - [clang-tidy] implement cppcoreguidelines macro rules
Author: jonastoth Date: Mon Oct 22 12:20:01 2018 New Revision: 344940 URL: http://llvm.org/viewvc/llvm-project?rev=344940&view=rev Log: [clang-tidy] implement cppcoreguidelines macro rules Summary: In short macros are discouraged by multiple rules (and sometimes reference randomly). [Enum.1], [ES.30], [ES.31] This check allows only headerguards and empty macros for annotation. Reviewers: aaron.ballman, hokein Reviewed By: aaron.ballman Subscribers: jbcoe, Eugene.Zelenko, klimek, nemanjai, mgorny, xazax.hun, kbarton, cfe-commits Differential Revision: https://reviews.llvm.org/D41648 Added: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.h clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage-caps-only.cpp clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage.cpp Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp clang-tools-extra/trunk/docs/ReleaseNotes.rst clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt?rev=344940&r1=344939&r2=344940&view=diff == --- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt (original) +++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt Mon Oct 22 12:20:01 2018 @@ -4,6 +4,7 @@ add_clang_library(clangTidyCppCoreGuidel AvoidGotoCheck.cpp CppCoreGuidelinesTidyModule.cpp InterfacesGlobalInitCheck.cpp + MacroUsageCheck.cpp NarrowingConversionsCheck.cpp NoMallocCheck.cpp OwningMemoryCheck.cpp Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp?rev=344940&r1=344939&r2=344940&view=diff == --- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp Mon Oct 22 12:20:01 2018 @@ -15,6 +15,7 @@ #include "../readability/MagicNumbersCheck.h" #include "AvoidGotoCheck.h" #include "InterfacesGlobalInitCheck.h" +#include "MacroUsageCheck.h" #include "NarrowingConversionsCheck.h" #include "NoMallocCheck.h" #include "OwningMemoryCheck.h" @@ -45,6 +46,8 @@ public: "cppcoreguidelines-avoid-magic-numbers"); CheckFactories.registerCheck( "cppcoreguidelines-interfaces-global-init"); +CheckFactories.registerCheck( +"cppcoreguidelines-macro-usage"); CheckFactories.registerCheck( "cppcoreguidelines-narrowing-conversions"); CheckFactories.registerCheck("cppcoreguidelines-no-malloc"); Added: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp?rev=344940&view=auto == --- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp (added) +++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp Mon Oct 22 12:20:01 2018 @@ -0,0 +1,95 @@ +//===--- MacroUsageCheck.cpp - clang-tidy--===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "MacroUsageCheck.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Lex/PPCallbacks.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/Support/Regex.h" +#include + +namespace clang { +namespace tidy { +namespace cppcoreguidelines { + +namespace { + +bool isCapsOnly(StringRef Name) { + return std::all_of(Name.begin(), Name.end(), [](const char c) { +if (std::isupper(c) || std::isdigit(c) || c == '_') + return true; +return false; + }); +} + +class MacroUsageCallbacks : public PPCallbacks { +public: + MacroUsageCallbacks(MacroUsageCheck *Check, StringRef RegExp, bool CapsOnly) + : Check(Check), RegExp(RegExp), CheckCapsOnly(CapsOnly) {} + void MacroDefined(const Token &MacroNameTok, +const MacroDirective *MD) override { +i
[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules
This revision was automatically updated to reflect the committed changes. Closed by commit rCTE344940: [clang-tidy] implement cppcoreguidelines macro rules (authored by JonasToth, committed by ). Changed prior to commit: https://reviews.llvm.org/D41648?vs=170472&id=170473#toc Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D41648 Files: clang-tidy/cppcoreguidelines/CMakeLists.txt clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp clang-tidy/cppcoreguidelines/MacroUsageCheck.h docs/ReleaseNotes.rst docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst docs/clang-tidy/checks/list.rst test/clang-tidy/cppcoreguidelines-macro-usage-caps-only.cpp test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp test/clang-tidy/cppcoreguidelines-macro-usage.cpp Index: clang-tidy/cppcoreguidelines/MacroUsageCheck.h === --- clang-tidy/cppcoreguidelines/MacroUsageCheck.h +++ clang-tidy/cppcoreguidelines/MacroUsageCheck.h @@ -0,0 +1,48 @@ +//===--- MacroUsageCheck.h - clang-tidy--*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H + +#include "../ClangTidy.h" +#include "clang/Lex/Preprocessor.h" +#include + +namespace clang { +namespace tidy { +namespace cppcoreguidelines { + +/// Find macro usage that is considered problematic because better language +/// constructs exist for the task. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-macro-usage.html +class MacroUsageCheck : public ClangTidyCheck { +public: + MacroUsageCheck(StringRef Name, ClangTidyContext *Context) + : ClangTidyCheck(Name, Context), +AllowedRegexp(Options.get("AllowedRegexp", "^DEBUG_*")), +CheckCapsOnly(Options.get("CheckCapsOnly", 0)) {} + void storeOptions(ClangTidyOptions::OptionMap &Opts) override; + void registerPPCallbacks(CompilerInstance &Compiler) override; + void warnMacro(const MacroDirective *MD); + void warnNaming(const MacroDirective *MD); + +private: + /// A regular expression that defines how allowed macros must look like. + std::string AllowedRegexp; + /// Control if only the check shall only test on CAPS_ONLY macros. + bool CheckCapsOnly; +}; + +} // namespace cppcoreguidelines +} // namespace tidy +} // namespace clang + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H Index: clang-tidy/cppcoreguidelines/CMakeLists.txt === --- clang-tidy/cppcoreguidelines/CMakeLists.txt +++ clang-tidy/cppcoreguidelines/CMakeLists.txt @@ -4,6 +4,7 @@ AvoidGotoCheck.cpp CppCoreGuidelinesTidyModule.cpp InterfacesGlobalInitCheck.cpp + MacroUsageCheck.cpp NarrowingConversionsCheck.cpp NoMallocCheck.cpp OwningMemoryCheck.cpp Index: clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp === --- clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp +++ clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp @@ -0,0 +1,95 @@ +//===--- MacroUsageCheck.cpp - clang-tidy--===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "MacroUsageCheck.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Lex/PPCallbacks.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/Support/Regex.h" +#include + +namespace clang { +namespace tidy { +namespace cppcoreguidelines { + +namespace { + +bool isCapsOnly(StringRef Name) { + return std::all_of(Name.begin(), Name.end(), [](const char c) { +if (std::isupper(c) || std::isdigit(c) || c == '_') + return true; +return false; + }); +} + +class MacroUsageCallbacks : public PPCallbacks { +public: + MacroUsageCallbacks(MacroUsageCheck *Check, StringRef RegExp, bool CapsOnly) + : Check(Check), RegExp(RegExp), CheckCapsOnly(CapsOnly) {} + void MacroDefined(const Token &MacroNameTok, +const MacroDirective *MD) override { +if (MD->getMacroInfo()->isUsedForHeaderGuard() || +MD->getMacroInfo()->getNumTokens() == 0) + return; + +StringRef MacroName = MacroNameTok.getIdentifierInfo()->getName(); +if (!CheckCapsOnly && !llvm::Regex(RegExp).match(MacroName)) + Check->warnMacro(MD);
[PATCH] D53520: Update the example of BS_Stroustrup to match what is done by clang-format
sylvestre.ledru created this revision. sylvestre.ledru added a reviewer: krasimir. reported here https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=911561 clang-format-7 -style="{BreakBeforeBraces: Stroustrup}" wasn't doing the same as the doc Repository: rC Clang https://reviews.llvm.org/D53520 Files: docs/ClangFormatStyleOptions.rst include/clang/Format/Format.h Index: include/clang/Format/Format.h === --- include/clang/Format/Format.h +++ include/clang/Format/Format.h @@ -528,25 +528,21 @@ /// enum X : int { A, B }; /// \endcode BS_Mozilla, -/// Like ``Attach``, but break before function definitions, ``catch``, and -/// ``else``. +/// Always break before braces. /// \code /// try { /// foo(); -/// } catch () { +/// } +/// catch () { /// } /// void foo() { bar(); } -/// class foo -/// { +/// class foo { /// }; /// if (foo()) { -/// } else { /// } -/// enum X : int -/// { -/// A, -/// B -/// }; +/// else { +/// } +/// enum X : int { A, B }; /// \endcode BS_Stroustrup, /// Always break before braces. Index: docs/ClangFormatStyleOptions.rst === --- docs/ClangFormatStyleOptions.rst +++ docs/ClangFormatStyleOptions.rst @@ -901,27 +901,23 @@ enum X : int { A, B }; * ``BS_Stroustrup`` (in configuration: ``Stroustrup``) -Like ``Attach``, but break before function definitions, ``catch``, and -``else``. +Always break before braces. .. code-block:: c++ try { foo(); - } catch () { + } + catch () { } void foo() { bar(); } - class foo - { + class foo { }; if (foo()) { - } else { } - enum X : int - { -A, -B - }; + else { + } + enum X : int { A, B }; * ``BS_Allman`` (in configuration: ``Allman``) Always break before braces. Index: include/clang/Format/Format.h === --- include/clang/Format/Format.h +++ include/clang/Format/Format.h @@ -528,25 +528,21 @@ /// enum X : int { A, B }; /// \endcode BS_Mozilla, -/// Like ``Attach``, but break before function definitions, ``catch``, and -/// ``else``. +/// Always break before braces. /// \code /// try { /// foo(); -/// } catch () { +/// } +/// catch () { /// } /// void foo() { bar(); } -/// class foo -/// { +/// class foo { /// }; /// if (foo()) { -/// } else { /// } -/// enum X : int -/// { -/// A, -/// B -/// }; +/// else { +/// } +/// enum X : int { A, B }; /// \endcode BS_Stroustrup, /// Always break before braces. Index: docs/ClangFormatStyleOptions.rst === --- docs/ClangFormatStyleOptions.rst +++ docs/ClangFormatStyleOptions.rst @@ -901,27 +901,23 @@ enum X : int { A, B }; * ``BS_Stroustrup`` (in configuration: ``Stroustrup``) -Like ``Attach``, but break before function definitions, ``catch``, and -``else``. +Always break before braces. .. code-block:: c++ try { foo(); - } catch () { + } + catch () { } void foo() { bar(); } - class foo - { + class foo { }; if (foo()) { - } else { } - enum X : int - { -A, -B - }; + else { + } + enum X : int { A, B }; * ``BS_Allman`` (in configuration: ``Allman``) Always break before braces. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53206: Allow padding checker to traverse simple class hierarchies
tekknolagi added inline comments. Comment at: test/Analysis/padding_cpp.cpp:204-212 +// expected-warning@+1{{Excessive padding in 'struct FakeIntSandwich'}} +struct FakeIntSandwich { + char c1; + int i; + char c2; +}; + tekknolagi wrote: > bcraig wrote: > > Looking at this again... what new cases does this catch? FakeIntSandwich > > was caught before (it is identical to 'PaddedA', and AnotherIntSandwich > > generated no warning before. So what is different? > > > > EBO1 and EBO2 are cases above that would be nice to catch, but aren't being > > caught right now. > Ah, you're right. I'll just keep the one in `padding_inherit`. @bcraig I updated the description of the diff to be more informative about the particular cases this change catches. Repository: rC Clang https://reviews.llvm.org/D53206 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53463: [Driver] allow Android triples to alias for non Android targets
danalbert accepted this revision. danalbert added a comment. LGTM Repository: rC Clang https://reviews.llvm.org/D53463 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53206: Allow padding checker to traverse simple class hierarchies
tekknolagi updated this revision to Diff 170475. tekknolagi added a comment. Make the test case a little easier to read Repository: rC Clang https://reviews.llvm.org/D53206 Files: lib/StaticAnalyzer/Checkers/PaddingChecker.cpp test/Analysis/padding_inherit.cpp Index: test/Analysis/padding_inherit.cpp === --- /dev/null +++ test/Analysis/padding_inherit.cpp @@ -0,0 +1,25 @@ +// RUN: %clang_analyze_cc1 -std=c++14 -analyzer-checker=optin.performance -analyzer-config optin.performance.Padding:AllowedPad=20 -verify %s + +// A class that has no fields and one base class should visit that base class +// instead. +// expected-warning@+1{{Excessive padding in 'struct FakeIntSandwich'}} +struct FakeIntSandwich { + char c1; + int i; + char c2; +}; + +struct AnotherIntSandwich : FakeIntSandwich { // no-warning +}; + +// But we don't yet support multiple base classes. +struct IntSandwich {}; +struct TooManyBaseClasses : FakeIntSandwich, IntSandwich { // no-warning +}; + +AnotherIntSandwich ais[100]; + +struct Empty {}; +struct DoubleEmpty : Empty { // no-warning +Empty e; +}; Index: lib/StaticAnalyzer/Checkers/PaddingChecker.cpp === --- lib/StaticAnalyzer/Checkers/PaddingChecker.cpp +++ lib/StaticAnalyzer/Checkers/PaddingChecker.cpp @@ -75,6 +75,19 @@ if (shouldSkipDecl(RD)) return; +// We need to be looking at a definition, not just any pointer to the +// declaration. +if (!(RD = RD->getDefinition())) + return; + +// This is the simplest correct case: a class with no fields and one base +// class. Other cases are more complicated because of how the base classes +// & fields might interact, so we don't bother dealing with them. +if (auto *CXXRD = dyn_cast(RD)) + if (CXXRD->field_empty() && CXXRD->getNumBases() == 1) +return visitRecord(CXXRD->bases().begin()->getType()->getAsRecordDecl(), + PadMultiplier); + auto &ASTContext = RD->getASTContext(); const ASTRecordLayout &RL = ASTContext.getASTRecordLayout(RD); assert(llvm::isPowerOf2_64(RL.getAlignment().getQuantity())); @@ -112,8 +125,7 @@ if (RT == nullptr) return; -// TODO: Recurse into the fields and base classes to see if any -// of those have excess padding. +// TODO: Recurse into the fields to see if they have excess padding. visitRecord(RT->getDecl(), Elts); } @@ -132,13 +144,17 @@ // Not going to attempt to optimize unions. if (RD->isUnion()) return true; -// How do you reorder fields if you haven't got any? -if (RD->field_empty()) - return true; if (auto *CXXRD = dyn_cast(RD)) { + // TODO: Figure out why we are going through declarations and not only + // definitions. + if (!(CXXRD = CXXRD->getDefinition())) +return true; // Tail padding with base classes ends up being very complicated. - // We will skip objects with base classes for now. - if (CXXRD->getNumBases() != 0) + // We will skip objects with base classes for now, unless they do not + // have fields. + if (!CXXRD->field_empty() && CXXRD->getNumBases() != 0) +return true; + if (CXXRD->field_empty() && CXXRD->getNumBases() != 1) return true; // Virtual bases are complicated, skipping those for now. if (CXXRD->getNumVBases() != 0) @@ -150,6 +166,10 @@ if (CXXRD->getTypeForDecl()->isInstantiationDependentType()) return true; } +// How do you reorder fields if you haven't got any? +else if (RD->field_empty()) + return true; + auto IsTrickyField = [](const FieldDecl *FD) -> bool { // Bitfield layout is hard. if (FD->isBitField()) @@ -323,7 +343,7 @@ BR->emitReport(std::move(Report)); } }; -} +} // namespace void ento::registerPaddingChecker(CheckerManager &Mgr) { Mgr.registerChecker(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52857: [clang-query] Add non-exclusive output API
steveire added a comment. > This seems confusing to me because I would expect set foo bar to set the > value of a variable foo to bar, This is already not the case with `set output diag` etc. That said, I don't mind spelling this ` output foo`. It's not my decision. It's up to the reviewers. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D52857 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53513: [OPENMP] Add support for 'atomic_default_mem_order' clause on requires directive
ABataev accepted this revision. ABataev added a comment. This revision is now accepted and ready to land. LG Repository: rC Clang https://reviews.llvm.org/D53513 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits