[PATCH] D32199: [TySan] A Type Sanitizer (Clang)

2020-07-16 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added a comment.

Hello to everyone following along! My apologies for the lack of activity; I 
should have made a comment sooner.

Back in December/January I was exploring working on TySan (met with Hal and 
Richard, in addition to rebasing the diffs). After digging into the problem 
space, it became clear that it's not something I could prioritize over other 
works. Since that time, nothing has changed on my end, so I don't expect to 
continue working on this.

If anyone is interested in picking this up, I would be thrilled! - CJ


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D32199/new/

https://reviews.llvm.org/D32199



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124164: [include-cleaner] Include-cleaner library structure, and simplistic AST walking.

2022-04-28 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson accepted this revision.
CJ-Johnson added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:18
+class ASTWalker : public RecursiveASTVisitor {
+  DeclCallback Callback;
+

Apologies for my ignorance of LLVM style. Should this be named with a trailing 
underscore? And should it be a private field?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124164/new/

https://reviews.llvm.org/D124164

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32199: [TySan] A Type Sanitizer (Clang)

2020-01-02 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson commandeered this revision.
CJ-Johnson added a reviewer: hfinkel.
CJ-Johnson added a comment.

After discussing things with Hal, I'm going to take over these diffs and try to 
update them to the new pass manager :)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D32199/new/

https://reviews.llvm.org/D32199



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32199: [TySan] A Type Sanitizer (Clang)

2020-01-02 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 235944.
CJ-Johnson added a comment.

Rebase on head


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D32199/new/

https://reviews.llvm.org/D32199

Files:
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Sanitizers.def
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenTBAA.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/CodeGen/sanitize-type-attr.cpp
  clang/test/Driver/sanitizer-ld.c

Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -228,6 +228,18 @@
 // CHECK-ASAN-MYRIAD-NOT: "-lc"
 // CHECK-ASAN-MYRIAD: libclang_rt.asan-sparcel.a"
 
+// RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target x86_64-unknown-linux -fuse-ld=ld -stdlib=platform -lstdc++ \
+// RUN: -fsanitize=type \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-TYSAN-LINUX-CXX %s
+//
+// CHECK-TYSAN-LINUX-CXX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-TYSAN-LINUX-CXX-NOT: stdc++
+// CHECK-TYSAN-LINUX-CXX: "-whole-archive" "{{.*}}libclang_rt.tysan-x86_64.a" "-no-whole-archive"
+// CHECK-TYSAN-LINUX-CXX: stdc++
+
 // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-unknown-linux -fuse-ld=ld -stdlib=platform -lstdc++ \
 // RUN: -fsanitize=thread \
Index: clang/test/CodeGen/sanitize-type-attr.cpp
===
--- /dev/null
+++ clang/test/CodeGen/sanitize-type-attr.cpp
@@ -0,0 +1,74 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefix=WITHOUT %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s -fsanitize=type | FileCheck -check-prefix=TYSAN %s
+// RUN: echo "src:%s" | sed -e 's/\\//g' > %t
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s -fsanitize=type -fsanitize-blacklist=%t | FileCheck -check-prefix=BL %s
+
+// The sanitize_type attribute should be attached to functions
+// when TypeSanitizer is enabled, unless no_sanitize("type") attribute
+// is present.
+
+// WITHOUT:  NoTYSAN1{{.*}}) [[NOATTR:#[0-9]+]]
+// BL:  NoTYSAN1{{.*}}) [[NOATTR:#[0-9]+]]
+// TYSAN:  NoTYSAN1{{.*}}) [[NOATTR:#[0-9]+]]
+__attribute__((no_sanitize("type")))
+int NoTYSAN1(int *a) { return *a; }
+
+// WITHOUT:  NoTYSAN2{{.*}}) [[NOATTR]]
+// BL:  NoTYSAN2{{.*}}) [[NOATTR]]
+// TYSAN:  NoTYSAN2{{.*}}) [[NOATTR]]
+__attribute__((no_sanitize("type")))
+int NoTYSAN2(int *a);
+int NoTYSAN2(int *a) { return *a; }
+
+// WITHOUT:  NoTYSAN3{{.*}}) [[NOATTR:#[0-9]+]]
+// BL:  NoTYSAN3{{.*}}) [[NOATTR:#[0-9]+]]
+// TYSAN:  NoTYSAN3{{.*}}) [[NOATTR:#[0-9]+]]
+__attribute__((no_sanitize("type")))
+int NoTYSAN3(int *a) { return *a; }
+
+// WITHOUT:  TYSANOk{{.*}}) [[NOATTR]]
+// BL:  TYSANOk{{.*}}) [[NOATTR]]
+// TYSAN: TYSANOk{{.*}}) [[WITH:#[0-9]+]]
+int TYSANOk(int *a) { return *a; }
+
+// WITHOUT:  TemplateTYSANOk{{.*}}) [[NOATTR]]
+// BL:  TemplateTYSANOk{{.*}}) [[NOATTR]]
+// TYSAN: TemplateTYSANOk{{.*}}) [[WITH]]
+template
+int TemplateTYSANOk() { return i; }
+
+// WITHOUT:  TemplateNoTYSAN{{.*}}) [[NOATTR]]
+// BL:  TemplateNoTYSAN{{.*}}) [[NOATTR]]
+// TYSAN: TemplateNoTYSAN{{.*}}) [[NOATTR]]
+template
+__attribute__((no_sanitize("type")))
+int TemplateNoTYSAN() { return i; }
+
+int force_instance = TemplateTYSANOk<42>()
+   + TemplateNoTYSAN<42>();
+
+// Check that __cxx_global_var_init* get the sanitize_type attribute.
+int global1 = 0;
+int global2 = *(int*)((char*)&global1+1);
+// WITHOUT: @__cxx_global_var_init{{.*}}[[NOATTR:#[0-9]+]]
+// BL: @__cxx_global_var_init{{.*}}[[NOATTR:#[0-9]+]]
+// TYSAN: @__cxx_global_var_init{{.*}}[[WITH:#[0-9]+]]
+
+// Make sure that we don't add globals to the list for which we don't have a
+// specific type description.
+struct SX { int a, b; };
+SX sx;
+
+// WITHOUT: attributes [[NOATTR]] = { noinline nounwind{{.*}} }
+
+// BL: attributes [[NOATTR]] = { noinline nounwind{{.*}} }
+
+// TYSAN: attributes [[NOATTR]] = { noinline nounwind{{.*}} }
+// TYSAN: attributes [[WITH]] = { noinline nounwind sanitize_type{{.*}} }
+
+// TYSAN-DAG: !llvm.tysan.globals = !{[[G1MD:![0-9]+]], [[G2MD:![0-9]+]], [[G3MD:![0-9]+]]}
+// TYSAN-DAG: [[G1MD]] = !{i32* @force_instance, [[INTMD:![0-9]+]]}
+// TYSAN-DAG: [[INTMD]] = !{!"int",
+// TYSAN-DAG: [[G2MD]] = !{i32* @global1, [[INTMD]]}
+// TYSAN-DAG: [[G3MD]] = !{i32* @global2, [[INTMD]]}
+// TYSAN-DAG: Simple C++ TBAA
\

[PATCH] D32199: [TySan] A Type Sanitizer (Clang)

2020-01-02 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 235948.
CJ-Johnson edited the summary of this revision.
CJ-Johnson added a comment.
Herald added a project: clang.

Fixing rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D32199/new/

https://reviews.llvm.org/D32199

Files:
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Sanitizers.def
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenTBAA.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/CodeGen/sanitize-type-attr.cpp
  clang/test/Driver/sanitizer-ld.c

Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -228,6 +228,18 @@
 // CHECK-ASAN-MYRIAD-NOT: "-lc"
 // CHECK-ASAN-MYRIAD: libclang_rt.asan-sparcel.a"
 
+// RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target x86_64-unknown-linux -fuse-ld=ld -stdlib=platform -lstdc++ \
+// RUN: -fsanitize=type \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-TYSAN-LINUX-CXX %s
+//
+// CHECK-TYSAN-LINUX-CXX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-TYSAN-LINUX-CXX-NOT: stdc++
+// CHECK-TYSAN-LINUX-CXX: "-whole-archive" "{{.*}}libclang_rt.tysan-x86_64.a" "-no-whole-archive"
+// CHECK-TYSAN-LINUX-CXX: stdc++
+
 // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-unknown-linux -fuse-ld=ld -stdlib=platform -lstdc++ \
 // RUN: -fsanitize=thread \
Index: clang/test/CodeGen/sanitize-type-attr.cpp
===
--- /dev/null
+++ clang/test/CodeGen/sanitize-type-attr.cpp
@@ -0,0 +1,74 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefix=WITHOUT %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s -fsanitize=type | FileCheck -check-prefix=TYSAN %s
+// RUN: echo "src:%s" | sed -e 's/\\//g' > %t
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s -fsanitize=type -fsanitize-blacklist=%t | FileCheck -check-prefix=BL %s
+
+// The sanitize_type attribute should be attached to functions
+// when TypeSanitizer is enabled, unless no_sanitize("type") attribute
+// is present.
+
+// WITHOUT:  NoTYSAN1{{.*}}) [[NOATTR:#[0-9]+]]
+// BL:  NoTYSAN1{{.*}}) [[NOATTR:#[0-9]+]]
+// TYSAN:  NoTYSAN1{{.*}}) [[NOATTR:#[0-9]+]]
+__attribute__((no_sanitize("type")))
+int NoTYSAN1(int *a) { return *a; }
+
+// WITHOUT:  NoTYSAN2{{.*}}) [[NOATTR]]
+// BL:  NoTYSAN2{{.*}}) [[NOATTR]]
+// TYSAN:  NoTYSAN2{{.*}}) [[NOATTR]]
+__attribute__((no_sanitize("type")))
+int NoTYSAN2(int *a);
+int NoTYSAN2(int *a) { return *a; }
+
+// WITHOUT:  NoTYSAN3{{.*}}) [[NOATTR:#[0-9]+]]
+// BL:  NoTYSAN3{{.*}}) [[NOATTR:#[0-9]+]]
+// TYSAN:  NoTYSAN3{{.*}}) [[NOATTR:#[0-9]+]]
+__attribute__((no_sanitize("type")))
+int NoTYSAN3(int *a) { return *a; }
+
+// WITHOUT:  TYSANOk{{.*}}) [[NOATTR]]
+// BL:  TYSANOk{{.*}}) [[NOATTR]]
+// TYSAN: TYSANOk{{.*}}) [[WITH:#[0-9]+]]
+int TYSANOk(int *a) { return *a; }
+
+// WITHOUT:  TemplateTYSANOk{{.*}}) [[NOATTR]]
+// BL:  TemplateTYSANOk{{.*}}) [[NOATTR]]
+// TYSAN: TemplateTYSANOk{{.*}}) [[WITH]]
+template
+int TemplateTYSANOk() { return i; }
+
+// WITHOUT:  TemplateNoTYSAN{{.*}}) [[NOATTR]]
+// BL:  TemplateNoTYSAN{{.*}}) [[NOATTR]]
+// TYSAN: TemplateNoTYSAN{{.*}}) [[NOATTR]]
+template
+__attribute__((no_sanitize("type")))
+int TemplateNoTYSAN() { return i; }
+
+int force_instance = TemplateTYSANOk<42>()
+   + TemplateNoTYSAN<42>();
+
+// Check that __cxx_global_var_init* get the sanitize_type attribute.
+int global1 = 0;
+int global2 = *(int*)((char*)&global1+1);
+// WITHOUT: @__cxx_global_var_init{{.*}}[[NOATTR:#[0-9]+]]
+// BL: @__cxx_global_var_init{{.*}}[[NOATTR:#[0-9]+]]
+// TYSAN: @__cxx_global_var_init{{.*}}[[WITH:#[0-9]+]]
+
+// Make sure that we don't add globals to the list for which we don't have a
+// specific type description.
+struct SX { int a, b; };
+SX sx;
+
+// WITHOUT: attributes [[NOATTR]] = { noinline nounwind{{.*}} }
+
+// BL: attributes [[NOATTR]] = { noinline nounwind{{.*}} }
+
+// TYSAN: attributes [[NOATTR]] = { noinline nounwind{{.*}} }
+// TYSAN: attributes [[WITH]] = { noinline nounwind sanitize_type{{.*}} }
+
+// TYSAN-DAG: !llvm.tysan.globals = !{[[G1MD:![0-9]+]], [[G2MD:![0-9]+]], [[G3MD:![0-9]+]]}
+// TYSAN-DAG: [[G1MD]] = !{i32* @force_instance, [[INTMD:![0-9]+]]}
+// TYSAN-DAG: [[INTMD]] = !{!"int",
+// TYSAN-DAG: [[G2MD]]

[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-11-07 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 303648.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CXX/except/except.spec/p14-ir.cpp
  clang/test/CodeGen/arm64-microsoft-arguments.cpp
  clang/test/CodeGen/attr-nomerge.cpp
  clang/test/CodeGen/no-builtin.cpp
  clang/test/CodeGen/temporary-lifetime.cpp
  clang/test/CodeGenCUDA/device-var-init.cu
  clang/test/CodeGenCXX/2011-12-19-init-list-ctor.cpp
  
clang/test/CodeGenCXX/RelativeVTablesABI/child-inheritted-from-parent-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/child-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-1.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-2.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/diamond-virtual-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/member-function-pointer.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/multiple-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-and-child-in-comdats.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/pass-byval-attributes.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/simple-vtable-definition.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/vbase-offset.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/virtual-function-call.cpp
  clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
  clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
  clang/test/CodeGenCXX/aix-static-init.cpp
  clang/test/CodeGenCXX/amdgcn-automatic-variable.cpp
  clang/test/CodeGenCXX/amdgcn-func-arg.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-call.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-virtual-dtor-call.cpp
  clang/test/CodeGenCXX/apple-kext.cpp
  clang/test/CodeGenCXX/arm.cpp
  clang/test/CodeGenCXX/arm64-constructor-return.cpp
  clang/test/CodeGenCXX/array-default-argument.cpp
  clang/test/CodeGenCXX/atomicinit.cpp
  clang/test/CodeGenCXX/attr-disable-tail-calls.cpp
  clang/test/CodeGenCXX/attr-target-mv-member-funcs.cpp
  clang/test/CodeGenCXX/attr-target-mv-out-of-line-defs.cpp
  clang/test/CodeGenCXX/attr.cpp
  clang/test/CodeGenCXX/auto-variable-template.cpp
  clang/test/CodeGenCXX/blocks-cxx11.cpp
  clang/test/CodeGenCXX/blocks.cpp
  clang/test/CodeGenCXX/builtin-source-location.cpp
  clang/test/CodeGenCXX/builtin_LINE.cpp
  clang/test/CodeGenCXX/catch-undef-behavior.cpp
  clang/test/CodeGenCXX/cfi-cross-dso.cpp
  clang/test/CodeGenCXX/conditional-gnu-ext.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
  clang/test/CodeGenCXX/constructor-direct-call.cpp
  clang/test/CodeGenCXX/constructor-init.cpp
  clang/test/CodeGenCXX/constructors.cpp
  clang/test/CodeGenCXX/copy-constructor-elim-2.cpp
  clang/test/CodeGenCXX/copy-constructor-synthesis.cpp
  clang/test/CodeGenCXX/cxx0x-delegating-ctors.cpp
  clang/test/CodeGenCXX/cxx0x-initializer-constructors.cpp
  clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
  clang/test/CodeGenCXX/cxx11-initializer-aggregate.cpp
  clang/test/CodeGenCXX/cxx11-initializer-array-new.cpp
  clang/test/CodeGenCXX/cxx11-thread-local.cpp
  clang/test/CodeGenCXX/cxx1y-init-captures.cpp
  clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
  clang/test/CodeGenCXX/cxx1z-copy-omission.cpp
  clang/test/CodeGenCXX/cxx1z-decomposition.cpp
  clang/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp
  clang/test/CodeGenCXX/cxx1z-lambda-star-this.cpp
  clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp
  clang/test/CodeGenCXX/debug-info-class.cpp
  clang/test/CodeGenCXX/debug-info-ms-dtor-thunks.cpp
  clang/test/CodeGenCXX/default-arg-temps.cpp
  clang/test/CodeGenCXX/default-arguments.cpp
  clang/test/CodeGenCXX/delete.cpp
  clang/test/CodeGenCXX/derived-to-base-conv.cpp
  clang/test/CodeGenCXX/destructors.cpp
  clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
  clang/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp
  clang/test/CodeGenCXX/dllexport-ctor-closure.cpp
  clang/test/CodeGenCXX/dllexport-members.cpp
  clang/test/CodeGenCXX/dllexport.cpp
  clang/test/CodeGenCXX/dllimport-dtor-thunks.cpp
  clang/test/CodeGenCXX/dllimport-members.cpp
  clang/test/CodeGenCXX/dllimport.cpp
  clang/test/CodeGenCXX/duplicate-mangled-name.cpp
  clang/test/CodeGenCXX/eh.cpp
  clang/test/CodeGenCXX/empty-nontrivially-copyable.cpp
  clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
  clang/test/CodeGenCXX/exceptions-seh.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/ext-int.cpp
  clang/test/CodeGenCXX/float128-declarations.cpp
  clang/test/CodeGenCXX/float16-declarations.cpp
  clang/test/CodeGenCXX/global-dtor-no-atexit.cpp
  clang/test/CodeGenCXX/global-init.cpp
  clang/test/CodeGenCXX/goto.cpp
  clang/test/CodeGenCXX/hidden-dllimport.cpp
  clang/test/CodeGenCXX/implicit-co

[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-11-07 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added inline comments.



Comment at: clang/test/CodeGenCXX/this-nonnull.cpp:1-2
+// RUN: %clang_cc1 -S -emit-llvm -o - -triple %itanium_abi_triple %s | 
FileCheck %s -check-prefix=CHECK-YES
+// RUN: %clang_cc1 -S -emit-llvm -o - -fno-delete-null-pointer-checks -triple 
%itanium_abi_triple %s | FileCheck %s -check-prefix=CHECK-NO
+

rsmith wrote:
> Please use a specific triple here (eg `x86_64-linux-gnu`); right now this 
> test would fail on Itanium targets where `sizeof(Struct)` is not exactly 12 
> (which is not guaranteed -- `int` might not be 32 bits wide on all Itanium 
> targets).
This has now been switched to `-triple=x86_64-linux-gnu` :)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-11-16 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 305603.
Herald added a subscriber: lxfind.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CXX/except/except.spec/p14-ir.cpp
  clang/test/CodeGen/aix-ignore-xcoff-visibility.cpp
  clang/test/CodeGen/arm64-microsoft-arguments.cpp
  clang/test/CodeGen/attr-nomerge.cpp
  clang/test/CodeGen/no-builtin.cpp
  clang/test/CodeGen/temporary-lifetime.cpp
  clang/test/CodeGenCUDA/device-var-init.cu
  clang/test/CodeGenCXX/2011-12-19-init-list-ctor.cpp
  
clang/test/CodeGenCXX/RelativeVTablesABI/child-inheritted-from-parent-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/child-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-1.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-2.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/diamond-virtual-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/member-function-pointer.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/multiple-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-and-child-in-comdats.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/pass-byval-attributes.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/simple-vtable-definition.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/vbase-offset.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/virtual-function-call.cpp
  clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
  clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
  clang/test/CodeGenCXX/aix-static-init.cpp
  clang/test/CodeGenCXX/amdgcn-automatic-variable.cpp
  clang/test/CodeGenCXX/amdgcn-func-arg.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-call.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-virtual-dtor-call.cpp
  clang/test/CodeGenCXX/apple-kext.cpp
  clang/test/CodeGenCXX/arm.cpp
  clang/test/CodeGenCXX/arm64-constructor-return.cpp
  clang/test/CodeGenCXX/array-default-argument.cpp
  clang/test/CodeGenCXX/atomicinit.cpp
  clang/test/CodeGenCXX/attr-disable-tail-calls.cpp
  clang/test/CodeGenCXX/attr-target-mv-member-funcs.cpp
  clang/test/CodeGenCXX/attr-target-mv-out-of-line-defs.cpp
  clang/test/CodeGenCXX/attr.cpp
  clang/test/CodeGenCXX/auto-variable-template.cpp
  clang/test/CodeGenCXX/blocks-cxx11.cpp
  clang/test/CodeGenCXX/blocks.cpp
  clang/test/CodeGenCXX/builtin-source-location.cpp
  clang/test/CodeGenCXX/builtin_LINE.cpp
  clang/test/CodeGenCXX/catch-undef-behavior.cpp
  clang/test/CodeGenCXX/cfi-cross-dso.cpp
  clang/test/CodeGenCXX/conditional-gnu-ext.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
  clang/test/CodeGenCXX/constructor-direct-call.cpp
  clang/test/CodeGenCXX/constructor-init.cpp
  clang/test/CodeGenCXX/constructors.cpp
  clang/test/CodeGenCXX/copy-constructor-elim-2.cpp
  clang/test/CodeGenCXX/copy-constructor-synthesis.cpp
  clang/test/CodeGenCXX/cxx0x-delegating-ctors.cpp
  clang/test/CodeGenCXX/cxx0x-initializer-constructors.cpp
  clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
  clang/test/CodeGenCXX/cxx11-initializer-aggregate.cpp
  clang/test/CodeGenCXX/cxx11-initializer-array-new.cpp
  clang/test/CodeGenCXX/cxx11-thread-local.cpp
  clang/test/CodeGenCXX/cxx1y-init-captures.cpp
  clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
  clang/test/CodeGenCXX/cxx1z-copy-omission.cpp
  clang/test/CodeGenCXX/cxx1z-decomposition.cpp
  clang/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp
  clang/test/CodeGenCXX/cxx1z-lambda-star-this.cpp
  clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp
  clang/test/CodeGenCXX/debug-info-class.cpp
  clang/test/CodeGenCXX/debug-info-destroy-helper.cpp
  clang/test/CodeGenCXX/debug-info-ms-dtor-thunks.cpp
  clang/test/CodeGenCXX/default-arg-temps.cpp
  clang/test/CodeGenCXX/default-arguments.cpp
  clang/test/CodeGenCXX/delete.cpp
  clang/test/CodeGenCXX/derived-to-base-conv.cpp
  clang/test/CodeGenCXX/destructors.cpp
  clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
  clang/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp
  clang/test/CodeGenCXX/dllexport-ctor-closure.cpp
  clang/test/CodeGenCXX/dllexport-members.cpp
  clang/test/CodeGenCXX/dllexport.cpp
  clang/test/CodeGenCXX/dllimport-dtor-thunks.cpp
  clang/test/CodeGenCXX/dllimport-members.cpp
  clang/test/CodeGenCXX/dllimport.cpp
  clang/test/CodeGenCXX/duplicate-mangled-name.cpp
  clang/test/CodeGenCXX/eh.cpp
  clang/test/CodeGenCXX/empty-nontrivially-copyable.cpp
  clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
  clang/test/CodeGenCXX/exceptions-seh.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/ext-int.cpp
  clang/test/CodeGenCXX/float128-declarations.cpp
  clang/test/CodeGenCXX/float16-declarations.cpp
  clang/test/CodeGenCXX/global-dtor-no-atexit.cpp
  clang/tes

[PATCH] D17993: [CodeGen] Apply 'nonnull' and 'dereferenceable(N)' to 'this' pointer arguments.

2020-11-16 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added a comment.

In D17993#2398337 , @jdoerfert wrote:

> Please modify the commit subject and add a proper message.

Thank you for the reminder! It slipped my mind.

Fixed :)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-10-09 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added inline comments.



Comment at: include/clang/Driver/Options.td:1157
+def fno_delete_null_pointer_checks : Flag<["-"], 
"fno-delete-null-pointer-checks">,
+  Group, Flags<[CC1Option]>;
 

rjmccall wrote:
> Please include HelpText, and it's probably worth talking about this in the 
> actual docs.
This flag has since been added via D47894 😃


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-10-09 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added a comment.

After chatting with bkramer , I'm working 
on rebasing this diff so that it can be landed.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-10-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson commandeered this revision.
CJ-Johnson added a reviewer: bkramer.
CJ-Johnson added a comment.

The patch is ready! Commandeering this change :)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-10-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 297640.
CJ-Johnson edited the summary of this revision.
CJ-Johnson added a comment.
Herald added subscribers: jdoerfert, aheejin, sbc100, jvesely, dschuff.

Rebasing on head, removing flag changes since that was added in 
https://reviews.llvm.org/D47894 and fixing broken tests


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CXX/except/except.spec/p14-ir.cpp
  clang/test/CodeGen/arm64-microsoft-arguments.cpp
  clang/test/CodeGen/attr-nomerge.cpp
  clang/test/CodeGen/no-builtin.cpp
  clang/test/CodeGen/temporary-lifetime.cpp
  clang/test/CodeGenCUDA/device-var-init.cu
  clang/test/CodeGenCXX/2011-12-19-init-list-ctor.cpp
  
clang/test/CodeGenCXX/RelativeVTablesABI/child-inheritted-from-parent-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/child-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-1.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-2.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/diamond-virtual-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/member-function-pointer.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/multiple-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-and-child-in-comdats.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/pass-byval-attributes.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/simple-vtable-definition.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/vbase-offset.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/virtual-function-call.cpp
  clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
  clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
  clang/test/CodeGenCXX/aix-static-init.cpp
  clang/test/CodeGenCXX/amdgcn-automatic-variable.cpp
  clang/test/CodeGenCXX/amdgcn-func-arg.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-call.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-virtual-dtor-call.cpp
  clang/test/CodeGenCXX/apple-kext.cpp
  clang/test/CodeGenCXX/arm.cpp
  clang/test/CodeGenCXX/arm64-constructor-return.cpp
  clang/test/CodeGenCXX/array-default-argument.cpp
  clang/test/CodeGenCXX/atomicinit.cpp
  clang/test/CodeGenCXX/attr-disable-tail-calls.cpp
  clang/test/CodeGenCXX/attr-target-mv-member-funcs.cpp
  clang/test/CodeGenCXX/attr-target-mv-out-of-line-defs.cpp
  clang/test/CodeGenCXX/attr.cpp
  clang/test/CodeGenCXX/auto-variable-template.cpp
  clang/test/CodeGenCXX/blocks-cxx11.cpp
  clang/test/CodeGenCXX/blocks.cpp
  clang/test/CodeGenCXX/builtin-source-location.cpp
  clang/test/CodeGenCXX/builtin_LINE.cpp
  clang/test/CodeGenCXX/catch-undef-behavior.cpp
  clang/test/CodeGenCXX/cfi-cross-dso.cpp
  clang/test/CodeGenCXX/conditional-gnu-ext.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
  clang/test/CodeGenCXX/constructor-direct-call.cpp
  clang/test/CodeGenCXX/constructor-init.cpp
  clang/test/CodeGenCXX/constructors.cpp
  clang/test/CodeGenCXX/copy-constructor-elim-2.cpp
  clang/test/CodeGenCXX/copy-constructor-synthesis.cpp
  clang/test/CodeGenCXX/cxx0x-delegating-ctors.cpp
  clang/test/CodeGenCXX/cxx0x-initializer-constructors.cpp
  clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
  clang/test/CodeGenCXX/cxx11-initializer-aggregate.cpp
  clang/test/CodeGenCXX/cxx11-initializer-array-new.cpp
  clang/test/CodeGenCXX/cxx11-thread-local.cpp
  clang/test/CodeGenCXX/cxx1y-init-captures.cpp
  clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
  clang/test/CodeGenCXX/cxx1z-copy-omission.cpp
  clang/test/CodeGenCXX/cxx1z-decomposition.cpp
  clang/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp
  clang/test/CodeGenCXX/cxx1z-lambda-star-this.cpp
  clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp
  clang/test/CodeGenCXX/debug-info-class.cpp
  clang/test/CodeGenCXX/debug-info-ms-dtor-thunks.cpp
  clang/test/CodeGenCXX/default-arg-temps.cpp
  clang/test/CodeGenCXX/default-arguments.cpp
  clang/test/CodeGenCXX/delete.cpp
  clang/test/CodeGenCXX/derived-to-base-conv.cpp
  clang/test/CodeGenCXX/destructors.cpp
  clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
  clang/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp
  clang/test/CodeGenCXX/dllexport-ctor-closure.cpp
  clang/test/CodeGenCXX/dllexport-members.cpp
  clang/test/CodeGenCXX/dllexport.cpp
  clang/test/CodeGenCXX/dllimport-dtor-thunks.cpp
  clang/test/CodeGenCXX/dllimport-members.cpp
  clang/test/CodeGenCXX/dllimport.cpp
  clang/test/CodeGenCXX/duplicate-mangled-name.cpp
  clang/test/CodeGenCXX/eh.cpp
  clang/test/CodeGenCXX/empty-nontrivially-copyable.cpp
  clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
  clang/test/CodeGenCXX/exceptions-seh.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/ext-int.cpp
  clang/test/CodeGenCXX/float128-declarations.cpp
  clang/tes

[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-10-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added a comment.

In D17993#2325610 , @jdoerfert wrote:

> Can you please upload again with full context?

My apologies, I am new to LLVM contribution. What is the best way to do that 
such that it squashes all of my local git commits?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-10-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 297645.
CJ-Johnson added a comment.
Herald added subscribers: llvm-commits, kerbowa, hiraditya, nhaehnle, arsenm.
Herald added a project: LLVM.

Update diff with full context


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

Files:
  llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
  llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
  llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h


Index: llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
===
--- llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
+++ llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
@@ -591,6 +591,7 @@
 bool isCI(const MCSubtargetInfo &STI);
 bool isVI(const MCSubtargetInfo &STI);
 bool isGFX9(const MCSubtargetInfo &STI);
+bool isGFX9Plus(const MCSubtargetInfo &STI);
 bool isGFX10(const MCSubtargetInfo &STI);
 bool isGCN3Encoding(const MCSubtargetInfo &STI);
 bool isGFX10_BEncoding(const MCSubtargetInfo &STI);
Index: llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
===
--- llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
+++ llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
@@ -1078,6 +1078,10 @@
   return STI.getFeatureBits()[AMDGPU::FeatureGFX9];
 }
 
+bool isGFX9Plus(const MCSubtargetInfo &STI) {
+  return isGFX9(STI) || isGFX10(STI);
+}
+
 bool isGFX10(const MCSubtargetInfo &STI) {
   return STI.getFeatureBits()[AMDGPU::FeatureGFX10];
 }
Index: llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
===
--- llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -1190,6 +1190,10 @@
 return AMDGPU::isGFX9(getSTI());
   }
 
+  bool isGFX9Plus() const {
+return AMDGPU::isGFX9Plus(getSTI());
+  }
+
   bool isGFX10() const {
 return AMDGPU::isGFX10(getSTI());
   }
@@ -4699,7 +4703,7 @@
   for (MCRegAliasIterator R(AMDGPU::TTMP12_TTMP13_TTMP14_TTMP15, &MRI, true);
R.isValid(); ++R) {
 if (*R == RegNo)
-  return isGFX9() || isGFX10();
+  return isGFX9Plus();
   }
 
   // GFX10 has 2 more SGPRs 104 and 105.


Index: llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
===
--- llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
+++ llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
@@ -591,6 +591,7 @@
 bool isCI(const MCSubtargetInfo &STI);
 bool isVI(const MCSubtargetInfo &STI);
 bool isGFX9(const MCSubtargetInfo &STI);
+bool isGFX9Plus(const MCSubtargetInfo &STI);
 bool isGFX10(const MCSubtargetInfo &STI);
 bool isGCN3Encoding(const MCSubtargetInfo &STI);
 bool isGFX10_BEncoding(const MCSubtargetInfo &STI);
Index: llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
===
--- llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
+++ llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
@@ -1078,6 +1078,10 @@
   return STI.getFeatureBits()[AMDGPU::FeatureGFX9];
 }
 
+bool isGFX9Plus(const MCSubtargetInfo &STI) {
+  return isGFX9(STI) || isGFX10(STI);
+}
+
 bool isGFX10(const MCSubtargetInfo &STI) {
   return STI.getFeatureBits()[AMDGPU::FeatureGFX10];
 }
Index: llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
===
--- llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -1190,6 +1190,10 @@
 return AMDGPU::isGFX9(getSTI());
   }
 
+  bool isGFX9Plus() const {
+return AMDGPU::isGFX9Plus(getSTI());
+  }
+
   bool isGFX10() const {
 return AMDGPU::isGFX10(getSTI());
   }
@@ -4699,7 +4703,7 @@
   for (MCRegAliasIterator R(AMDGPU::TTMP12_TTMP13_TTMP14_TTMP15, &MRI, true);
R.isValid(); ++R) {
 if (*R == RegNo)
-  return isGFX9() || isGFX10();
+  return isGFX9Plus();
   }
 
   // GFX10 has 2 more SGPRs 104 and 105.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-10-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 297647.
CJ-Johnson added a comment.

Update with full diff context


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CXX/except/except.spec/p14-ir.cpp
  clang/test/CodeGen/arm64-microsoft-arguments.cpp
  clang/test/CodeGen/attr-nomerge.cpp
  clang/test/CodeGen/no-builtin.cpp
  clang/test/CodeGen/temporary-lifetime.cpp
  clang/test/CodeGenCUDA/device-var-init.cu
  clang/test/CodeGenCXX/2011-12-19-init-list-ctor.cpp
  
clang/test/CodeGenCXX/RelativeVTablesABI/child-inheritted-from-parent-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/child-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-1.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-2.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/diamond-virtual-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/member-function-pointer.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/multiple-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-and-child-in-comdats.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/pass-byval-attributes.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/simple-vtable-definition.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/vbase-offset.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/virtual-function-call.cpp
  clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
  clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
  clang/test/CodeGenCXX/aix-static-init.cpp
  clang/test/CodeGenCXX/amdgcn-automatic-variable.cpp
  clang/test/CodeGenCXX/amdgcn-func-arg.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-call.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-virtual-dtor-call.cpp
  clang/test/CodeGenCXX/apple-kext.cpp
  clang/test/CodeGenCXX/arm.cpp
  clang/test/CodeGenCXX/arm64-constructor-return.cpp
  clang/test/CodeGenCXX/array-default-argument.cpp
  clang/test/CodeGenCXX/atomicinit.cpp
  clang/test/CodeGenCXX/attr-disable-tail-calls.cpp
  clang/test/CodeGenCXX/attr-target-mv-member-funcs.cpp
  clang/test/CodeGenCXX/attr-target-mv-out-of-line-defs.cpp
  clang/test/CodeGenCXX/attr.cpp
  clang/test/CodeGenCXX/auto-variable-template.cpp
  clang/test/CodeGenCXX/blocks-cxx11.cpp
  clang/test/CodeGenCXX/blocks.cpp
  clang/test/CodeGenCXX/builtin-source-location.cpp
  clang/test/CodeGenCXX/builtin_LINE.cpp
  clang/test/CodeGenCXX/catch-undef-behavior.cpp
  clang/test/CodeGenCXX/cfi-cross-dso.cpp
  clang/test/CodeGenCXX/conditional-gnu-ext.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
  clang/test/CodeGenCXX/constructor-direct-call.cpp
  clang/test/CodeGenCXX/constructor-init.cpp
  clang/test/CodeGenCXX/constructors.cpp
  clang/test/CodeGenCXX/copy-constructor-elim-2.cpp
  clang/test/CodeGenCXX/copy-constructor-synthesis.cpp
  clang/test/CodeGenCXX/cxx0x-delegating-ctors.cpp
  clang/test/CodeGenCXX/cxx0x-initializer-constructors.cpp
  clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
  clang/test/CodeGenCXX/cxx11-initializer-aggregate.cpp
  clang/test/CodeGenCXX/cxx11-initializer-array-new.cpp
  clang/test/CodeGenCXX/cxx11-thread-local.cpp
  clang/test/CodeGenCXX/cxx1y-init-captures.cpp
  clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
  clang/test/CodeGenCXX/cxx1z-copy-omission.cpp
  clang/test/CodeGenCXX/cxx1z-decomposition.cpp
  clang/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp
  clang/test/CodeGenCXX/cxx1z-lambda-star-this.cpp
  clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp
  clang/test/CodeGenCXX/debug-info-class.cpp
  clang/test/CodeGenCXX/debug-info-ms-dtor-thunks.cpp
  clang/test/CodeGenCXX/default-arg-temps.cpp
  clang/test/CodeGenCXX/default-arguments.cpp
  clang/test/CodeGenCXX/delete.cpp
  clang/test/CodeGenCXX/derived-to-base-conv.cpp
  clang/test/CodeGenCXX/destructors.cpp
  clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
  clang/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp
  clang/test/CodeGenCXX/dllexport-ctor-closure.cpp
  clang/test/CodeGenCXX/dllexport-members.cpp
  clang/test/CodeGenCXX/dllexport.cpp
  clang/test/CodeGenCXX/dllimport-dtor-thunks.cpp
  clang/test/CodeGenCXX/dllimport-members.cpp
  clang/test/CodeGenCXX/dllimport.cpp
  clang/test/CodeGenCXX/duplicate-mangled-name.cpp
  clang/test/CodeGenCXX/eh.cpp
  clang/test/CodeGenCXX/empty-nontrivially-copyable.cpp
  clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
  clang/test/CodeGenCXX/exceptions-seh.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/ext-int.cpp
  clang/test/CodeGenCXX/float128-declarations.cpp
  clang/test/CodeGenCXX/float16-declarations.cpp
  clang/test/CodeGenCXX/global-dtor-no-atexit.cpp
  clang/test/CodeGenCXX/global-init.cpp
  clang/test/CodeGenCXX/goto.cpp
  clang/test/CodeGenCXX/hidden-dllimport.cpp
  cla

[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-10-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added inline comments.



Comment at: llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp:1082
+bool isGFX9Plus(const MCSubtargetInfo &STI) {
+  return isGFX9(STI) || isGFX10(STI);
+}

arsenm wrote:
> How are these changes related?
This is a mistake. I did not add this and I'm not sure why it is being included 
in the change.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-10-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added inline comments.



Comment at: llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp:1082
+bool isGFX9Plus(const MCSubtargetInfo &STI) {
+  return isGFX9(STI) || isGFX10(STI);
+}

CJ-Johnson wrote:
> arsenm wrote:
> > How are these changes related?
> This is a mistake. I did not add this and I'm not sure why it is being 
> included in the change.
I believe this has been fixed now. Can you confirm?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-10-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 297655.
CJ-Johnson added a comment.

Apply dereferenceable even if null is a valid address


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CXX/except/except.spec/p14-ir.cpp
  clang/test/CodeGen/arm64-microsoft-arguments.cpp
  clang/test/CodeGen/attr-nomerge.cpp
  clang/test/CodeGen/no-builtin.cpp
  clang/test/CodeGen/temporary-lifetime.cpp
  clang/test/CodeGenCUDA/device-var-init.cu
  clang/test/CodeGenCXX/2011-12-19-init-list-ctor.cpp
  
clang/test/CodeGenCXX/RelativeVTablesABI/child-inheritted-from-parent-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/child-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-1.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-2.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/diamond-virtual-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/member-function-pointer.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/multiple-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-and-child-in-comdats.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/pass-byval-attributes.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/simple-vtable-definition.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/vbase-offset.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/virtual-function-call.cpp
  clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
  clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
  clang/test/CodeGenCXX/aix-static-init.cpp
  clang/test/CodeGenCXX/amdgcn-automatic-variable.cpp
  clang/test/CodeGenCXX/amdgcn-func-arg.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-call.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-virtual-dtor-call.cpp
  clang/test/CodeGenCXX/apple-kext.cpp
  clang/test/CodeGenCXX/arm.cpp
  clang/test/CodeGenCXX/arm64-constructor-return.cpp
  clang/test/CodeGenCXX/array-default-argument.cpp
  clang/test/CodeGenCXX/atomicinit.cpp
  clang/test/CodeGenCXX/attr-disable-tail-calls.cpp
  clang/test/CodeGenCXX/attr-target-mv-member-funcs.cpp
  clang/test/CodeGenCXX/attr-target-mv-out-of-line-defs.cpp
  clang/test/CodeGenCXX/attr.cpp
  clang/test/CodeGenCXX/auto-variable-template.cpp
  clang/test/CodeGenCXX/blocks-cxx11.cpp
  clang/test/CodeGenCXX/blocks.cpp
  clang/test/CodeGenCXX/builtin-source-location.cpp
  clang/test/CodeGenCXX/builtin_LINE.cpp
  clang/test/CodeGenCXX/catch-undef-behavior.cpp
  clang/test/CodeGenCXX/cfi-cross-dso.cpp
  clang/test/CodeGenCXX/conditional-gnu-ext.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
  clang/test/CodeGenCXX/constructor-direct-call.cpp
  clang/test/CodeGenCXX/constructor-init.cpp
  clang/test/CodeGenCXX/constructors.cpp
  clang/test/CodeGenCXX/copy-constructor-elim-2.cpp
  clang/test/CodeGenCXX/copy-constructor-synthesis.cpp
  clang/test/CodeGenCXX/cxx0x-delegating-ctors.cpp
  clang/test/CodeGenCXX/cxx0x-initializer-constructors.cpp
  clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
  clang/test/CodeGenCXX/cxx11-initializer-aggregate.cpp
  clang/test/CodeGenCXX/cxx11-initializer-array-new.cpp
  clang/test/CodeGenCXX/cxx11-thread-local.cpp
  clang/test/CodeGenCXX/cxx1y-init-captures.cpp
  clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
  clang/test/CodeGenCXX/cxx1z-copy-omission.cpp
  clang/test/CodeGenCXX/cxx1z-decomposition.cpp
  clang/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp
  clang/test/CodeGenCXX/cxx1z-lambda-star-this.cpp
  clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp
  clang/test/CodeGenCXX/debug-info-class.cpp
  clang/test/CodeGenCXX/debug-info-ms-dtor-thunks.cpp
  clang/test/CodeGenCXX/default-arg-temps.cpp
  clang/test/CodeGenCXX/default-arguments.cpp
  clang/test/CodeGenCXX/delete.cpp
  clang/test/CodeGenCXX/derived-to-base-conv.cpp
  clang/test/CodeGenCXX/destructors.cpp
  clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
  clang/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp
  clang/test/CodeGenCXX/dllexport-ctor-closure.cpp
  clang/test/CodeGenCXX/dllexport-members.cpp
  clang/test/CodeGenCXX/dllexport.cpp
  clang/test/CodeGenCXX/dllimport-dtor-thunks.cpp
  clang/test/CodeGenCXX/dllimport-members.cpp
  clang/test/CodeGenCXX/dllimport.cpp
  clang/test/CodeGenCXX/duplicate-mangled-name.cpp
  clang/test/CodeGenCXX/eh.cpp
  clang/test/CodeGenCXX/empty-nontrivially-copyable.cpp
  clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
  clang/test/CodeGenCXX/exceptions-seh.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/ext-int.cpp
  clang/test/CodeGenCXX/float128-declarations.cpp
  clang/test/CodeGenCXX/float16-declarations.cpp
  clang/test/CodeGenCXX/global-dtor-no-atexit.cpp
  clang/test/CodeGenCXX/global-init.cpp
  clang/test/CodeGenCXX/goto.cpp
  clang/test/CodeGenCXX/hi

[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-10-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:2174
+  }
+
   unsigned ArgNo = 0;

jdoerfert wrote:
> Even if null pointer is valid we should place dereferenceable.
> 
> We also could never place nonnull and let the middle-end make the 
> dereferenceable -> nonnull deduction, though I don't see why we can't just 
> add nonnull here.
I re-ran ninja check after making this fix and addressed the newly-affected 
tests. So the patch is fully up to date :)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-10-31 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson marked an inline comment as done.
CJ-Johnson added inline comments.



Comment at: 
clang/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual-inheritance.cpp:126
 //
-// CHECK: call x86_thiscallcc void %[[VFUN_VALUE]](i8* %[[RIGHT]])
+// CHECK: call x86_thiscallcc void %[[VFUN_VALUE]](i8* nonnull %[[RIGHT]])
 // CHECK: ret

rsmith wrote:
> Why does this call get `nonnull` but not `dereferenceable`? Seems like we 
> should be able to use at least `dereferenceable(sizeof(Right))` here -- but I 
> think we could actually be more aggressive and pass 
> `dereferenceable(sizeof(ChildOverride) - offsetof(ChildOverride,  class>))`.
Fixed! Added a check for `isVoidPointerType()` :)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-10-31 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 302107.
CJ-Johnson marked an inline comment as done.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CXX/except/except.spec/p14-ir.cpp
  clang/test/CodeGen/arm64-microsoft-arguments.cpp
  clang/test/CodeGen/attr-nomerge.cpp
  clang/test/CodeGen/no-builtin.cpp
  clang/test/CodeGen/temporary-lifetime.cpp
  clang/test/CodeGenCUDA/device-var-init.cu
  clang/test/CodeGenCXX/2011-12-19-init-list-ctor.cpp
  
clang/test/CodeGenCXX/RelativeVTablesABI/child-inheritted-from-parent-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/child-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-1.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-2.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/diamond-virtual-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/member-function-pointer.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/multiple-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-and-child-in-comdats.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/pass-byval-attributes.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/simple-vtable-definition.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/vbase-offset.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/virtual-function-call.cpp
  clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
  clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
  clang/test/CodeGenCXX/aix-static-init.cpp
  clang/test/CodeGenCXX/amdgcn-automatic-variable.cpp
  clang/test/CodeGenCXX/amdgcn-func-arg.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-call.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-virtual-dtor-call.cpp
  clang/test/CodeGenCXX/apple-kext.cpp
  clang/test/CodeGenCXX/arm.cpp
  clang/test/CodeGenCXX/arm64-constructor-return.cpp
  clang/test/CodeGenCXX/array-default-argument.cpp
  clang/test/CodeGenCXX/atomicinit.cpp
  clang/test/CodeGenCXX/attr-disable-tail-calls.cpp
  clang/test/CodeGenCXX/attr-target-mv-member-funcs.cpp
  clang/test/CodeGenCXX/attr-target-mv-out-of-line-defs.cpp
  clang/test/CodeGenCXX/attr.cpp
  clang/test/CodeGenCXX/auto-variable-template.cpp
  clang/test/CodeGenCXX/blocks-cxx11.cpp
  clang/test/CodeGenCXX/blocks.cpp
  clang/test/CodeGenCXX/builtin-source-location.cpp
  clang/test/CodeGenCXX/builtin_LINE.cpp
  clang/test/CodeGenCXX/catch-undef-behavior.cpp
  clang/test/CodeGenCXX/cfi-cross-dso.cpp
  clang/test/CodeGenCXX/conditional-gnu-ext.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
  clang/test/CodeGenCXX/constructor-direct-call.cpp
  clang/test/CodeGenCXX/constructor-init.cpp
  clang/test/CodeGenCXX/constructors.cpp
  clang/test/CodeGenCXX/copy-constructor-elim-2.cpp
  clang/test/CodeGenCXX/copy-constructor-synthesis.cpp
  clang/test/CodeGenCXX/cxx0x-delegating-ctors.cpp
  clang/test/CodeGenCXX/cxx0x-initializer-constructors.cpp
  clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
  clang/test/CodeGenCXX/cxx11-initializer-aggregate.cpp
  clang/test/CodeGenCXX/cxx11-initializer-array-new.cpp
  clang/test/CodeGenCXX/cxx11-thread-local.cpp
  clang/test/CodeGenCXX/cxx1y-init-captures.cpp
  clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
  clang/test/CodeGenCXX/cxx1z-copy-omission.cpp
  clang/test/CodeGenCXX/cxx1z-decomposition.cpp
  clang/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp
  clang/test/CodeGenCXX/cxx1z-lambda-star-this.cpp
  clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp
  clang/test/CodeGenCXX/debug-info-class.cpp
  clang/test/CodeGenCXX/debug-info-ms-dtor-thunks.cpp
  clang/test/CodeGenCXX/default-arg-temps.cpp
  clang/test/CodeGenCXX/default-arguments.cpp
  clang/test/CodeGenCXX/delete.cpp
  clang/test/CodeGenCXX/derived-to-base-conv.cpp
  clang/test/CodeGenCXX/destructors.cpp
  clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
  clang/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp
  clang/test/CodeGenCXX/dllexport-ctor-closure.cpp
  clang/test/CodeGenCXX/dllexport-members.cpp
  clang/test/CodeGenCXX/dllexport.cpp
  clang/test/CodeGenCXX/dllimport-dtor-thunks.cpp
  clang/test/CodeGenCXX/dllimport-members.cpp
  clang/test/CodeGenCXX/dllimport.cpp
  clang/test/CodeGenCXX/duplicate-mangled-name.cpp
  clang/test/CodeGenCXX/eh.cpp
  clang/test/CodeGenCXX/empty-nontrivially-copyable.cpp
  clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
  clang/test/CodeGenCXX/exceptions-seh.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/ext-int.cpp
  clang/test/CodeGenCXX/float128-declarations.cpp
  clang/test/CodeGenCXX/float16-declarations.cpp
  clang/test/CodeGenCXX/global-dtor-no-atexit.cpp
  clang/test/CodeGenCXX/global-init.cpp
  clang/test/CodeGenCXX/goto.cpp
  clang/test/CodeGenCXX/hidden-dllimport.cpp
  clang/test/CodeGen

[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-10-31 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added a comment.

The new tests can be found in this-nonnull.cpp: 
https://reviews.llvm.org/differential/changeset/?ref=2242268


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-11-02 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 302236.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CXX/except/except.spec/p14-ir.cpp
  clang/test/CodeGen/arm64-microsoft-arguments.cpp
  clang/test/CodeGen/attr-nomerge.cpp
  clang/test/CodeGen/no-builtin.cpp
  clang/test/CodeGen/temporary-lifetime.cpp
  clang/test/CodeGenCUDA/device-var-init.cu
  clang/test/CodeGenCXX/2011-12-19-init-list-ctor.cpp
  
clang/test/CodeGenCXX/RelativeVTablesABI/child-inheritted-from-parent-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/child-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-1.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-2.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/diamond-virtual-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/member-function-pointer.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/multiple-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-and-child-in-comdats.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/pass-byval-attributes.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/simple-vtable-definition.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/vbase-offset.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/virtual-function-call.cpp
  clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
  clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
  clang/test/CodeGenCXX/aix-static-init.cpp
  clang/test/CodeGenCXX/amdgcn-automatic-variable.cpp
  clang/test/CodeGenCXX/amdgcn-func-arg.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-call.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-virtual-dtor-call.cpp
  clang/test/CodeGenCXX/apple-kext.cpp
  clang/test/CodeGenCXX/arm.cpp
  clang/test/CodeGenCXX/arm64-constructor-return.cpp
  clang/test/CodeGenCXX/array-default-argument.cpp
  clang/test/CodeGenCXX/atomicinit.cpp
  clang/test/CodeGenCXX/attr-disable-tail-calls.cpp
  clang/test/CodeGenCXX/attr-target-mv-member-funcs.cpp
  clang/test/CodeGenCXX/attr-target-mv-out-of-line-defs.cpp
  clang/test/CodeGenCXX/attr.cpp
  clang/test/CodeGenCXX/auto-variable-template.cpp
  clang/test/CodeGenCXX/blocks-cxx11.cpp
  clang/test/CodeGenCXX/blocks.cpp
  clang/test/CodeGenCXX/builtin-source-location.cpp
  clang/test/CodeGenCXX/builtin_LINE.cpp
  clang/test/CodeGenCXX/catch-undef-behavior.cpp
  clang/test/CodeGenCXX/cfi-cross-dso.cpp
  clang/test/CodeGenCXX/conditional-gnu-ext.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
  clang/test/CodeGenCXX/constructor-direct-call.cpp
  clang/test/CodeGenCXX/constructor-init.cpp
  clang/test/CodeGenCXX/constructors.cpp
  clang/test/CodeGenCXX/copy-constructor-elim-2.cpp
  clang/test/CodeGenCXX/copy-constructor-synthesis.cpp
  clang/test/CodeGenCXX/cxx0x-delegating-ctors.cpp
  clang/test/CodeGenCXX/cxx0x-initializer-constructors.cpp
  clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
  clang/test/CodeGenCXX/cxx11-initializer-aggregate.cpp
  clang/test/CodeGenCXX/cxx11-initializer-array-new.cpp
  clang/test/CodeGenCXX/cxx11-thread-local.cpp
  clang/test/CodeGenCXX/cxx1y-init-captures.cpp
  clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
  clang/test/CodeGenCXX/cxx1z-copy-omission.cpp
  clang/test/CodeGenCXX/cxx1z-decomposition.cpp
  clang/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp
  clang/test/CodeGenCXX/cxx1z-lambda-star-this.cpp
  clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp
  clang/test/CodeGenCXX/debug-info-class.cpp
  clang/test/CodeGenCXX/debug-info-ms-dtor-thunks.cpp
  clang/test/CodeGenCXX/default-arg-temps.cpp
  clang/test/CodeGenCXX/default-arguments.cpp
  clang/test/CodeGenCXX/delete.cpp
  clang/test/CodeGenCXX/derived-to-base-conv.cpp
  clang/test/CodeGenCXX/destructors.cpp
  clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
  clang/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp
  clang/test/CodeGenCXX/dllexport-ctor-closure.cpp
  clang/test/CodeGenCXX/dllexport-members.cpp
  clang/test/CodeGenCXX/dllexport.cpp
  clang/test/CodeGenCXX/dllimport-dtor-thunks.cpp
  clang/test/CodeGenCXX/dllimport-members.cpp
  clang/test/CodeGenCXX/dllimport.cpp
  clang/test/CodeGenCXX/duplicate-mangled-name.cpp
  clang/test/CodeGenCXX/eh.cpp
  clang/test/CodeGenCXX/empty-nontrivially-copyable.cpp
  clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
  clang/test/CodeGenCXX/exceptions-seh.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/ext-int.cpp
  clang/test/CodeGenCXX/float128-declarations.cpp
  clang/test/CodeGenCXX/float16-declarations.cpp
  clang/test/CodeGenCXX/global-dtor-no-atexit.cpp
  clang/test/CodeGenCXX/global-init.cpp
  clang/test/CodeGenCXX/goto.cpp
  clang/test/CodeGenCXX/hidden-dllimport.cpp
  clang/test/CodeGenCXX/implicit-co

[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-11-02 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson marked an inline comment as done.
CJ-Johnson added a comment.

In D17993#2367447 , @rsmith wrote:

> Thanks! We should also have a test for the behavior when targeting the MS 
> ABI, where we sometimes don't emit the `nonnull dereferenceable` because the 
> "`this`" pointer might actually point outside the object, but otherwise I 
> think this is ready to go.
>
> Please can you also put together a patch for the release notes? This seems 
> worth mentioning there.

Done and done. Thanks!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D17993/new/

https://reviews.llvm.org/D17993

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-03 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 384597.
CJ-Johnson added a comment.

Remove mistaken changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1030 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const C *);
+  basic_string_view(const basic_string_view &);
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>, basic_string_view);
+template 
+bool operator<(basic_string_view, type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>, basic_string_view);
+template 
+bool operator<=(basic_string_view, type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>, basic_string_view);
+template 
+bool operator>(basic_string_view, type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>, basic_string_view);
+template 
+bool operator>=(basic_string_view, type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>, basic_string_view);
+template 
+bool operator==(basic_string_view, type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>, basic_string_view);
+template 
+bool operator!=(basic_string_view, type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;{{$}}
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;{{$}}
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;{{$}}
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;{{$}}
+
+// (void)(const std::string_view(nullptr)) /* a5 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a8 */;
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::string_view{nullptr}) /* a9 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a9 */;{{$}}
+
+(void)(std::string_view{(nullptr)}) /* a10 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::stri

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-03 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 384598.
CJ-Johnson added a comment.

Remove mistaken changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1030 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const C *);
+  basic_string_view(const basic_string_view &);
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>, basic_string_view);
+template 
+bool operator<(basic_string_view, type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>, basic_string_view);
+template 
+bool operator<=(basic_string_view, type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>, basic_string_view);
+template 
+bool operator>(basic_string_view, type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>, basic_string_view);
+template 
+bool operator>=(basic_string_view, type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>, basic_string_view);
+template 
+bool operator==(basic_string_view, type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>, basic_string_view);
+template 
+bool operator!=(basic_string_view, type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;{{$}}
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;{{$}}
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;{{$}}
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;{{$}}
+
+// (void)(const std::string_view(nullptr)) /* a5 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a8 */;
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::string_view{nullptr}) /* a9 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a9 */;{{$}}
+
+(void)(std::string_view{(nullptr)}) /* a10 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::stri

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-03 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 384599.
CJ-Johnson added a comment.

Add missing newline


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1030 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const C *);
+  basic_string_view(const basic_string_view &);
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>, basic_string_view);
+template 
+bool operator<(basic_string_view, type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>, basic_string_view);
+template 
+bool operator<=(basic_string_view, type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>, basic_string_view);
+template 
+bool operator>(basic_string_view, type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>, basic_string_view);
+template 
+bool operator>=(basic_string_view, type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>, basic_string_view);
+template 
+bool operator==(basic_string_view, type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>, basic_string_view);
+template 
+bool operator!=(basic_string_view, type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;{{$}}
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;{{$}}
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;{{$}}
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;{{$}}
+
+// (void)(const std::string_view(nullptr)) /* a5 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a8 */;
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::string_view{nullptr}) /* a9 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a9 */;{{$}}
+
+(void)(std::string_view{(nullptr)}) /* a10 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_v

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-04 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added a comment.

In D113148#3107897 , @Sockke wrote:

> This seems to be an existing check. Have you compared it with 
> **bugprone-string-constructor**?

Thanks for the suggestion! From what I can tell, bugprone-string-constructor 
check only has warnings and does not provide fixes in most cases. The goal of 
bugprone-stringview-nullptr is to robustly enumerate the many cases that it 
cares about and provide fixes. For that reason, I think making it a separate 
check is best.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113195: Suggests switching the initialization pattern of absl::Cleanup instances from the factory function to class template argument deduction (CTAD) in C++17 and higher.

2021-11-04 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson created this revision.
CJ-Johnson added a reviewer: ymandel.
Herald added subscribers: carlosgalvezp, mgorny.
CJ-Johnson requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Suggests switching the initialization pattern of absl::Cleanup instances from 
the factory function to class template argument deduction (CTAD) in C++17 and 
higher.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113195

Files:
  clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp
  clang-tools-extra/clang-tidy/abseil/CMakeLists.txt
  clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
  clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/abseil-cleanup-ctad.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
@@ -0,0 +1,68 @@
+// RUN: %check_clang_tidy %s abseil-cleanup-ctad -std=c++17 %t
+
+namespace absl {
+
+struct Tag {};
+
+template 
+class Cleanup {
+public:
+  Cleanup(T) {}
+  Cleanup(Cleanup &&) {}
+};
+
+template 
+Cleanup(Callback callback) -> Cleanup;
+
+template 
+absl::Cleanup MakeCleanup(T t) {
+  return absl::Cleanup(t);
+}
+
+} // namespace absl
+
+namespace std {
+
+template 
+class function {
+public:
+  template 
+  function(T) {}
+  function(const function &) {}
+};
+
+} // namespace std
+
+void test() {
+  auto a = absl::MakeCleanup([] {});
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup a = [] {};{{$}}
+
+  auto b = absl::MakeCleanup(([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup b = [] {};{{$}}
+
+  const auto c = absl::MakeCleanup([] {});
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup c = [] {};{{$}}
+
+  const auto d = absl::MakeCleanup(([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup d = [] {};{{$}}
+
+  auto e = absl::MakeCleanup(std::function([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup e = std::function([] {});{{$}}
+
+  auto f = absl::MakeCleanup((std::function([] {})));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup f = std::function([] {});{{$}}
+
+  const auto g = absl::MakeCleanup(std::function([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup g = std::function([] {});{{$}}
+
+  const auto h = absl::MakeCleanup((std::function([] {})));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup h = std::function([] {});{{$}}
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -12,6 +12,7 @@
 .. csv-table::
:header: "Name", "Offers fixes"
 
+   `abseil-cleanup-ctad `_, "Yes"
`abseil-duration-addition `_, "Yes"
`abseil-duration-comparison `_, "Yes"
`abseil-duration-conversion-cast `_, "Yes"
@@ -114,13 +115,12 @@
`cert-dcl50-cpp `_,
`cert-dcl58-cpp `_,
`cert-env33-c `_,
+   `cert-err33-c `_,
`cert-err34-c `_,
`cert-err52-cpp `_,
`cert-err58-cpp `_,
`cert-err60-cpp `_,
-   `cert-exp42-c `_,
`cert-flp30-c `_,
-   `cert-flp37-c `_,
`cert-mem57-cpp `_,
`cert-msc50-cpp `_,
`cert-msc51-cpp `_,
@@ -288,6 +288,7 @@
`readability-const-return-type `_, "Yes"
`readability-container-size-empty `_, "Yes"
`readability-convert-member-functions-to-static `_,
+   `readability-data-pointer `_,
`readability-delete-null-pointer `_, "Yes"
`readability-else-after-return `_, "Yes"
`readability-function-cognitive-complexity `_,
@@ -333,13 +334,14 @@
`cert-dcl03-c `_, `misc-static-assert `_, "Yes"
`cert-dcl16-c `_, `readability-uppercase-literal-

[PATCH] D113195: Suggests switching the initialization pattern of absl::Cleanup instances from the factory function to class template argument deduction (CTAD) in C++17 and higher.

2021-11-04 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 384773.
CJ-Johnson added a comment.

Remove unwanted changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113195/new/

https://reviews.llvm.org/D113195

Files:
  clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp
  clang-tools-extra/clang-tidy/abseil/CMakeLists.txt
  clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
  clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/abseil-cleanup-ctad.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
@@ -0,0 +1,68 @@
+// RUN: %check_clang_tidy %s abseil-cleanup-ctad -std=c++17 %t
+
+namespace absl {
+
+struct Tag {};
+
+template 
+class Cleanup {
+public:
+  Cleanup(T) {}
+  Cleanup(Cleanup &&) {}
+};
+
+template 
+Cleanup(Callback callback) -> Cleanup;
+
+template 
+absl::Cleanup MakeCleanup(T t) {
+  return absl::Cleanup(t);
+}
+
+} // namespace absl
+
+namespace std {
+
+template 
+class function {
+public:
+  template 
+  function(T) {}
+  function(const function &) {}
+};
+
+} // namespace std
+
+void test() {
+  auto a = absl::MakeCleanup([] {});
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup a = [] {};{{$}}
+
+  auto b = absl::MakeCleanup(([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup b = [] {};{{$}}
+
+  const auto c = absl::MakeCleanup([] {});
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup c = [] {};{{$}}
+
+  const auto d = absl::MakeCleanup(([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup d = [] {};{{$}}
+
+  auto e = absl::MakeCleanup(std::function([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup e = std::function([] {});{{$}}
+
+  auto f = absl::MakeCleanup((std::function([] {})));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup f = std::function([] {});{{$}}
+
+  const auto g = absl::MakeCleanup(std::function([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup g = std::function([] {});{{$}}
+
+  const auto h = absl::MakeCleanup((std::function([] {})));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup h = std::function([] {});{{$}}
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -12,6 +12,7 @@
 .. csv-table::
:header: "Name", "Offers fixes"
 
+   `abseil-cleanup-ctad `_, "Yes"
`abseil-duration-addition `_, "Yes"
`abseil-duration-comparison `_, "Yes"
`abseil-duration-conversion-cast `_, "Yes"
@@ -447,4 +448,4 @@
`hicpp-use-override `_, `modernize-use-override `_, "Yes"
`hicpp-vararg `_, `cppcoreguidelines-pro-type-vararg `_,
`llvm-else-after-return `_, `readability-else-after-return `_, "Yes"
-   `llvm-qualified-auto `_, `readability-qualified-auto `_, "Yes"
+   `llvm-qualified-auto `_, `readability-qualified-auto `_, "Yes"
\ No newline at end of file
Index: clang-tools-extra/docs/clang-tidy/checks/abseil-cleanup-ctad.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/abseil-cleanup-ctad.rst
@@ -0,0 +1,22 @@
+.. title:: clang-tidy - abseil-cleanup-ctad
+
+abseil-cleanup-ctad
+===
+
+Suggests switching the initialization pattern of ``absl::Cleanup``
+instances from the factory function to class template argument
+deduction (CTAD) in C++17 and higher.
+
+.. code-block:: c++
+
+  auto c1 = absl::MakeCleanup([] {});
+
+  const auto c2 = absl::MakeCleanup(std::function([] {}));
+
+becomes
+
+.. code-block:: c++
+
+  absl::Cleanup c1 = [] 

[PATCH] D113195: Suggests switching the initialization pattern of absl::Cleanup instances from the factory function to class template argument deduction (CTAD) in C++17 and higher.

2021-11-04 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 384774.
CJ-Johnson added a comment.

Add trailing newline


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113195/new/

https://reviews.llvm.org/D113195

Files:
  clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp
  clang-tools-extra/clang-tidy/abseil/CMakeLists.txt
  clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
  clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/abseil-cleanup-ctad.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
@@ -0,0 +1,68 @@
+// RUN: %check_clang_tidy %s abseil-cleanup-ctad -std=c++17 %t
+
+namespace absl {
+
+struct Tag {};
+
+template 
+class Cleanup {
+public:
+  Cleanup(T) {}
+  Cleanup(Cleanup &&) {}
+};
+
+template 
+Cleanup(Callback callback) -> Cleanup;
+
+template 
+absl::Cleanup MakeCleanup(T t) {
+  return absl::Cleanup(t);
+}
+
+} // namespace absl
+
+namespace std {
+
+template 
+class function {
+public:
+  template 
+  function(T) {}
+  function(const function &) {}
+};
+
+} // namespace std
+
+void test() {
+  auto a = absl::MakeCleanup([] {});
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup a = [] {};{{$}}
+
+  auto b = absl::MakeCleanup(([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup b = [] {};{{$}}
+
+  const auto c = absl::MakeCleanup([] {});
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup c = [] {};{{$}}
+
+  const auto d = absl::MakeCleanup(([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup d = [] {};{{$}}
+
+  auto e = absl::MakeCleanup(std::function([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup e = std::function([] {});{{$}}
+
+  auto f = absl::MakeCleanup((std::function([] {})));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup f = std::function([] {});{{$}}
+
+  const auto g = absl::MakeCleanup(std::function([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup g = std::function([] {});{{$}}
+
+  const auto h = absl::MakeCleanup((std::function([] {})));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup h = std::function([] {});{{$}}
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -12,6 +12,7 @@
 .. csv-table::
:header: "Name", "Offers fixes"
 
+   `abseil-cleanup-ctad `_, "Yes"
`abseil-duration-addition `_, "Yes"
`abseil-duration-comparison `_, "Yes"
`abseil-duration-conversion-cast `_, "Yes"
@@ -448,3 +449,4 @@
`hicpp-vararg `_, `cppcoreguidelines-pro-type-vararg `_,
`llvm-else-after-return `_, `readability-else-after-return `_, "Yes"
`llvm-qualified-auto `_, `readability-qualified-auto `_, "Yes"
+   
\ No newline at end of file
Index: clang-tools-extra/docs/clang-tidy/checks/abseil-cleanup-ctad.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/abseil-cleanup-ctad.rst
@@ -0,0 +1,22 @@
+.. title:: clang-tidy - abseil-cleanup-ctad
+
+abseil-cleanup-ctad
+===
+
+Suggests switching the initialization pattern of ``absl::Cleanup``
+instances from the factory function to class template argument
+deduction (CTAD) in C++17 and higher.
+
+.. code-block:: c++
+
+  auto c1 = absl::MakeCleanup([] {});
+
+  const auto c2 = absl::MakeCleanup(std::function([] {}));
+
+becomes
+
+.. code-block:: c++
+
+  absl::Cleanup c1 = [] {};
+
+  const absl::Cleanup c2 = std::function([] {});
Index: clang-tools-extra/docs/ReleaseNotes.rst

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-04 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 384775.
CJ-Johnson added a comment.

Remove trailing whitespace


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1030 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const C *);
+  basic_string_view(const basic_string_view &);
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>, basic_string_view);
+template 
+bool operator<(basic_string_view, type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>, basic_string_view);
+template 
+bool operator<=(basic_string_view, type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>, basic_string_view);
+template 
+bool operator>(basic_string_view, type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>, basic_string_view);
+template 
+bool operator>=(basic_string_view, type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>, basic_string_view);
+template 
+bool operator==(basic_string_view, type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>, basic_string_view);
+template 
+bool operator!=(basic_string_view, type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;{{$}}
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;{{$}}
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;{{$}}
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;{{$}}
+
+// (void)(const std::string_view(nullptr)) /* a5 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a8 */;
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::string_view{nullptr}) /* a9 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a9 */;{{$}}
+
+(void)(std::string_view{(nullptr)}) /* a10 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::s

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-04 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added a comment.

In D113148#3108993 , @aaron.ballman 
wrote:

> Generally speaking, we prefer to improve the existing checks. I think 
> `bugprone-string-constructor` would probably be a better place for the 
> constructor-related functionality. But that still means we don't have a good 
> place for things like the assignment and comparison functionality, and it 
> seems more useful to keep all of the `string_view`-with-`nullptr` logic in 
> one place. That said, we should be careful we're not too onerous when users 
> enable all `bugprone` checks together.

I agree with the statement "it seems more useful to keep all of the 
`string_view`-with-`nullptr` logic in one place". To me, these are very 
logically related. The fact that some of it is constructor based is not as 
useful from a user perspective. The relationship between `nullptr` and 
`string_view` is more important, in my view.

As for "we should be careful we're not too onerous when users enable all 
`bugprone` checks together.", these fixes are about preventing UB. While I did 
put this in the "bugprone" module, perhaps "prone" is the wrong way to think 
about it. It's unconditionally UB in all cases, not just a potential bug. The 
suggested fixes are important for preventing crashes in the short term, but 
more importantly for allowing the code to build in the future, since the 
constructor overload `basic_string_view(nullptr_t) = delete;` is being added.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-04 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson marked an inline comment as done.
CJ-Johnson added a comment.

Thanks for the additional info, @aaron.ballman! I had not considered the issues 
with duplicate warnings. I agree that it would be annoying for users. That 
being the case, the second option ("remove the string_view nullptr checking 
functionality from bugprone-string-constructor so it only lives in the new 
check") sounds the most appealing to me, personally.




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp:84
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing 
basic_string_view from null is undefined; replace with the default constructor

aaron.ballman wrote:
> This (and many others) also generates `-Wbraced-scalar-init`, is that 
> intentional?
My goal was just to be thorough in the cases tested. It's not an endorsement of 
the source patterns. :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-04 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 384881.
CJ-Johnson marked an inline comment as done.
CJ-Johnson added a comment.

Fix spelling error


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1030 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const C *);
+  basic_string_view(const basic_string_view &);
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>, basic_string_view);
+template 
+bool operator<(basic_string_view, type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>, basic_string_view);
+template 
+bool operator<=(basic_string_view, type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>, basic_string_view);
+template 
+bool operator>(basic_string_view, type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>, basic_string_view);
+template 
+bool operator>=(basic_string_view, type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>, basic_string_view);
+template 
+bool operator==(basic_string_view, type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>, basic_string_view);
+template 
+bool operator!=(basic_string_view, type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;{{$}}
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;{{$}}
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;{{$}}
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;{{$}}
+
+// (void)(const std::string_view(nullptr)) /* a5 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a8 */;
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::string_view{nullptr}) /* a9 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a9 */;{{$}}
+
+(void)(std::string_view{(nullptr)}) /* a10 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+/

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-04 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 384890.
CJ-Johnson added a comment.

Change static_cast suggested edit to use parens instead of braces


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1030 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const C *);
+  basic_string_view(const basic_string_view &);
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>, basic_string_view);
+template 
+bool operator<(basic_string_view, type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>, basic_string_view);
+template 
+bool operator<=(basic_string_view, type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>, basic_string_view);
+template 
+bool operator>(basic_string_view, type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>, basic_string_view);
+template 
+bool operator>=(basic_string_view, type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>, basic_string_view);
+template 
+bool operator==(basic_string_view, type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>, basic_string_view);
+template 
+bool operator!=(basic_string_view, type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;{{$}}
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;{{$}}
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;{{$}}
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;{{$}}
+
+// (void)(const std::string_view(nullptr)) /* a5 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a8 */;
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::string_view{nullptr}) /* a9 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a9 */;{{$}}
+
+(void)(std::string_view{(nullptr)}) /* a10 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+   

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-05 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 385130.
CJ-Johnson added a comment.

Remove double brackets for list initialization and use default initialization 
to avoid most vexing parse


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1030 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const C *);
+  basic_string_view(const basic_string_view &);
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>, basic_string_view);
+template 
+bool operator<(basic_string_view, type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>, basic_string_view);
+template 
+bool operator<=(basic_string_view, type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>, basic_string_view);
+template 
+bool operator>(basic_string_view, type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>, basic_string_view);
+template 
+bool operator>=(basic_string_view, type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>, basic_string_view);
+template 
+bool operator==(basic_string_view, type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>, basic_string_view);
+template 
+bool operator!=(basic_string_view, type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;{{$}}
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;{{$}}
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;{{$}}
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;{{$}}
+
+// (void)(const std::string_view(nullptr)) /* a5 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a8 */;
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::string_view{nullptr}) /* a9 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a9 */;{{$}}
+
+(void)(std::string_view{(nullptr)}) /* a10 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; r

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-05 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 385133.
CJ-Johnson added a comment.

nits


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1030 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const C *);
+  basic_string_view(const basic_string_view &);
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>, basic_string_view);
+template 
+bool operator<(basic_string_view, type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>, basic_string_view);
+template 
+bool operator<=(basic_string_view, type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>, basic_string_view);
+template 
+bool operator>(basic_string_view, type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>, basic_string_view);
+template 
+bool operator>=(basic_string_view, type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>, basic_string_view);
+template 
+bool operator==(basic_string_view, type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>, basic_string_view);
+template 
+bool operator!=(basic_string_view, type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;{{$}}
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;{{$}}
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;{{$}}
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;{{$}}
+
+// (void)(const std::string_view(nullptr)) /* a5 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a8 */;
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::string_view{nullptr}) /* a9 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a9 */;{{$}}
+
+(void)(std::string_view{(nullptr)}) /* a10 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a10 *

[PATCH] D113195: [clang-tidy] Add check for initialization of `absl::Cleanup`.

2021-11-08 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson marked 4 inline comments as done.
CJ-Johnson added a comment.

Thanks for the review! I'll apply the same fixes to the string_view diff as well


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113195/new/

https://reviews.llvm.org/D113195

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113195: [clang-tidy] Add check for initialization of `absl::Cleanup`.

2021-11-08 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 385487.
CJ-Johnson added a comment.

Address nits and update the absl::Cleanup stub to be accurate with the real 
interface (with associated changes to the AST matcher)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113195/new/

https://reviews.llvm.org/D113195

Files:
  clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp
  clang-tools-extra/clang-tidy/abseil/CMakeLists.txt
  clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
  clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/abseil-cleanup-ctad.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
@@ -0,0 +1,115 @@
+// RUN: %check_clang_tidy %s abseil-cleanup-ctad -std=c++17 %t
+
+namespace std {
+
+template 
+struct is_same {
+  static const bool value = false;
+};
+
+template 
+struct is_same { static const bool value = true; };
+
+template 
+class function {
+public:
+  template 
+  function(T) {}
+  function(const function &) {}
+};
+
+} // namespace std
+
+namespace absl {
+
+namespace cleanup_internal {
+
+struct Tag {};
+
+template 
+class Storage {
+public:
+  Storage() = delete;
+
+  explicit Storage(Callback callback) {}
+
+  Storage(Storage &&other) {}
+
+  Storage(const Storage &other) = delete;
+
+  Storage &operator=(Storage &&other) = delete;
+
+  Storage &operator=(const Storage &other) = delete;
+
+private:
+  bool is_callback_engaged_;
+  alignas(Callback) char callback_buffer_[sizeof(Callback)];
+};
+
+} // namespace cleanup_internal
+
+template 
+class Cleanup final {
+public:
+  Cleanup(Callback callback) // NOLINT
+  : storage_(static_cast(callback)) {}
+
+  Cleanup(Cleanup &&other) = default;
+
+  void Cancel() &&;
+
+  void Invoke() &&;
+
+  ~Cleanup();
+
+private:
+  cleanup_internal::Storage storage_;
+};
+
+template 
+Cleanup(Callback callback) -> Cleanup;
+
+template 
+absl::Cleanup MakeCleanup(Callback callback) {
+  return {static_cast(callback)};
+}
+
+} // namespace absl
+
+void test() {
+  auto a = absl::MakeCleanup([] {});
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup a = [] {};{{$}}
+
+  // Removes extra parens
+  auto b = absl::MakeCleanup(([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup b = [] {};{{$}}
+
+  auto c = absl::MakeCleanup(std::function([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup c = std::function([] {});{{$}}
+
+  // Removes extra parens
+  auto d = absl::MakeCleanup((std::function([] {})));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup d = std::function([] {});{{$}}
+
+  const auto e = absl::MakeCleanup([] {});
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup e = [] {};{{$}}
+
+  // Removes extra parens
+  const auto f = absl::MakeCleanup(([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup f = [] {};{{$}}
+
+  const auto g = absl::MakeCleanup(std::function([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup g = std::function([] {});{{$}}
+
+  // Removes extra parens
+  const auto h = absl::MakeCleanup((std::function([] {})));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup h = std::function([] {});{{$}}
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -12,6 +12,7 @@
 .. csv-table::
:header: "Name", "Offers fixes"
 
+   `abseil-cleanup-ctad `_, "Yes"
`abseil-duration-addition `_, "Yes"
`abseil-duration-comparison `_, "Yes"
`abseil-duration-conversion-cast `_, "Yes"
@@ -448,3 +449,4 @@
`hicpp-vararg `_, `cppcoreguidelines-pro-type-vararg `_,
`llvm-else-after-return `_, `readability-else-after-return `_, "Yes"
`llvm-qualified-auto `_, `readability-qualified-auto `_, "Yes"
+   
\ No newline at end of file
Index: clang-tools-extra/docs/clang-tidy/checks/abseil-cleanup-c

[PATCH] D113195: [clang-tidy] Add check for initialization of `absl::Cleanup`.

2021-11-08 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 385489.
CJ-Johnson added a comment.

Fix documentation nit


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113195/new/

https://reviews.llvm.org/D113195

Files:
  clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp
  clang-tools-extra/clang-tidy/abseil/CMakeLists.txt
  clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
  clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/abseil-cleanup-ctad.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
@@ -0,0 +1,115 @@
+// RUN: %check_clang_tidy %s abseil-cleanup-ctad -std=c++17 %t
+
+namespace std {
+
+template 
+struct is_same {
+  static const bool value = false;
+};
+
+template 
+struct is_same { static const bool value = true; };
+
+template 
+class function {
+public:
+  template 
+  function(T) {}
+  function(const function &) {}
+};
+
+} // namespace std
+
+namespace absl {
+
+namespace cleanup_internal {
+
+struct Tag {};
+
+template 
+class Storage {
+public:
+  Storage() = delete;
+
+  explicit Storage(Callback callback) {}
+
+  Storage(Storage &&other) {}
+
+  Storage(const Storage &other) = delete;
+
+  Storage &operator=(Storage &&other) = delete;
+
+  Storage &operator=(const Storage &other) = delete;
+
+private:
+  bool is_callback_engaged_;
+  alignas(Callback) char callback_buffer_[sizeof(Callback)];
+};
+
+} // namespace cleanup_internal
+
+template 
+class Cleanup final {
+public:
+  Cleanup(Callback callback) // NOLINT
+  : storage_(static_cast(callback)) {}
+
+  Cleanup(Cleanup &&other) = default;
+
+  void Cancel() &&;
+
+  void Invoke() &&;
+
+  ~Cleanup();
+
+private:
+  cleanup_internal::Storage storage_;
+};
+
+template 
+Cleanup(Callback callback) -> Cleanup;
+
+template 
+absl::Cleanup MakeCleanup(Callback callback) {
+  return {static_cast(callback)};
+}
+
+} // namespace absl
+
+void test() {
+  auto a = absl::MakeCleanup([] {});
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup a = [] {};{{$}}
+
+  // Removes extra parens
+  auto b = absl::MakeCleanup(([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup b = [] {};{{$}}
+
+  auto c = absl::MakeCleanup(std::function([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup c = std::function([] {});{{$}}
+
+  // Removes extra parens
+  auto d = absl::MakeCleanup((std::function([] {})));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup d = std::function([] {});{{$}}
+
+  const auto e = absl::MakeCleanup([] {});
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup e = [] {};{{$}}
+
+  // Removes extra parens
+  const auto f = absl::MakeCleanup(([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup f = [] {};{{$}}
+
+  const auto g = absl::MakeCleanup(std::function([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup g = std::function([] {});{{$}}
+
+  // Removes extra parens
+  const auto h = absl::MakeCleanup((std::function([] {})));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 and higher
+  // CHECK-FIXES: {{^}}  const absl::Cleanup h = std::function([] {});{{$}}
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -12,6 +12,7 @@
 .. csv-table::
:header: "Name", "Offers fixes"
 
+   `abseil-cleanup-ctad `_, "Yes"
`abseil-duration-addition `_, "Yes"
`abseil-duration-comparison `_, "Yes"
`abseil-duration-conversion-cast `_, "Yes"
@@ -448,3 +449,4 @@
`hicpp-vararg `_, `cppcoreguidelines-pro-type-vararg `_,
`llvm-else-after-return `_, `readability-else-after-return `_, "Yes"
`llvm-qualified-auto `_, `readability-qualified-auto `_, "Yes"
+   
\ No newline at end of file
Index: clang-tools-extra/docs/clang-tidy/checks/abseil-cleanup-ctad.rst
===
--- /dev/null
+++ clang-tools-extr

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-08 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 385495.
CJ-Johnson added a comment.

Update test file to use truncated messages


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1030 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const C *);
+  basic_string_view(const basic_string_view &);
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>, basic_string_view);
+template 
+bool operator<(basic_string_view, type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>, basic_string_view);
+template 
+bool operator<=(basic_string_view, type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>, basic_string_view);
+template 
+bool operator>(basic_string_view, type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>, basic_string_view);
+template 
+bool operator>=(basic_string_view, type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>, basic_string_view);
+template 
+bool operator==(basic_string_view, type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>, basic_string_view);
+template 
+bool operator!=(basic_string_view, type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;{{$}}
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;{{$}}
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;{{$}}
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;{{$}}
+
+// (void)(const std::string_view(nullptr)) /* a5 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a8 */;
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::string_view{nullptr}) /* a9 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a9 */;{{$}}
+
+(void)(std::string_view{(nullptr)}) /* a10 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a10 */;{{$}}
+
+(void)(std::string_view{{nullptr}}) /* a11 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a11 */;{{$}}
+
+(void)(std::string_view{{(nullptr)}}) /* a12 */;
+// CHECK-MESSAGES: :

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-08 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp:84
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing 
basic_string_view from null is undefined; replace with the default constructor

CJ-Johnson wrote:
> aaron.ballman wrote:
> > This (and many others) also generates `-Wbraced-scalar-init`, is that 
> > intentional?
> My goal was just to be thorough in the cases tested. It's not an endorsement 
> of the source patterns. :)
As a followup to this: I've added additional test cases and a minor change to 
the AST matchers to catch another form of the `-Wbraced-scalar-init` pattern.

This: `accepts_string_view({{}});`

This pattern will select the `const CharT*` constructor overload and then 
value-initialize the argument, causing a null deref. It happens to not include 
the `nullptr` literal but it has the exact same effect as 
`accepts_string_view(nullptr);` and `accepts_string_view({nullptr});`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-08 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 385530.
CJ-Johnson added a comment.

Add AST matcher support and tests for {{}} case where a null pointer is 
implicitly created


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1221 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const C *);
+  basic_string_view(const basic_string_view &);
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>, basic_string_view);
+template 
+bool operator<(basic_string_view, type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>, basic_string_view);
+template 
+bool operator<=(basic_string_view, type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>, basic_string_view);
+template 
+bool operator>(basic_string_view, type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>, basic_string_view);
+template 
+bool operator>=(basic_string_view, type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>, basic_string_view);
+template 
+bool operator==(basic_string_view, type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>, basic_string_view);
+template 
+bool operator!=(basic_string_view, type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;
+
+(void)(std::string_view({})) /* a5 */; // Default `const CharT*`
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a5 */;
+
+// (void)(const std::string_view(nullptr)) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a8 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a9 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({})) /* a10 */; // Default `const CharT*`
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::string_view{nullptr}) /* a11 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a11 */;
+
+(void)(std::string_view{(nullptr)}) /* a12 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constru

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-08 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 385531.
CJ-Johnson added a comment.

Add missing newline


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1221 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const C *);
+  basic_string_view(const basic_string_view &);
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>, basic_string_view);
+template 
+bool operator<(basic_string_view, type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>, basic_string_view);
+template 
+bool operator<=(basic_string_view, type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>, basic_string_view);
+template 
+bool operator>(basic_string_view, type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>, basic_string_view);
+template 
+bool operator>=(basic_string_view, type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>, basic_string_view);
+template 
+bool operator==(basic_string_view, type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>, basic_string_view);
+template 
+bool operator!=(basic_string_view, type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;
+
+(void)(std::string_view({})) /* a5 */; // Default `const CharT*`
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a5 */;
+
+// (void)(const std::string_view(nullptr)) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a8 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a9 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({})) /* a10 */; // Default `const CharT*`
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::string_view{nullptr}) /* a11 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a11 */;
+
+(void)(std::string_view{(nullptr)}) /* a12 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-08 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 385532.
CJ-Johnson added a comment.

Rebase on head


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1221 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const C *);
+  basic_string_view(const basic_string_view &);
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>, basic_string_view);
+template 
+bool operator<(basic_string_view, type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>, basic_string_view);
+template 
+bool operator<=(basic_string_view, type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>, basic_string_view);
+template 
+bool operator>(basic_string_view, type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>, basic_string_view);
+template 
+bool operator>=(basic_string_view, type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>, basic_string_view);
+template 
+bool operator==(basic_string_view, type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>, basic_string_view);
+template 
+bool operator!=(basic_string_view, type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;
+
+(void)(std::string_view({})) /* a5 */; // Default `const CharT*`
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a5 */;
+
+// (void)(const std::string_view(nullptr)) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a8 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a9 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({})) /* a10 */; // Default `const CharT*`
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::string_view{nullptr}) /* a11 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a11 */;
+
+(void)(std::string_view{(nullptr)}) /* a12 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-08 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 385575.
CJ-Johnson added a comment.

Add additional tests for sv.empty() cases to ensure parens are removed where 
appropriate


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1369 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const C *);
+  basic_string_view(const basic_string_view &);
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>, basic_string_view);
+template 
+bool operator<(basic_string_view, type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>, basic_string_view);
+template 
+bool operator<=(basic_string_view, type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>, basic_string_view);
+template 
+bool operator>(basic_string_view, type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>, basic_string_view);
+template 
+bool operator>=(basic_string_view, type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>, basic_string_view);
+template 
+bool operator==(basic_string_view, type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>, basic_string_view);
+template 
+bool operator!=(basic_string_view, type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;
+
+(void)(std::string_view({})) /* a5 */; // Default `const CharT*`
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a5 */;
+
+// (void)(const std::string_view(nullptr)) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a8 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a9 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({})) /* a10 */; // Default `const CharT*`
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::string_view{nullptr}) /* a11 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a11 */;
+
+(void)(std::string_view{(nullptr)}) /* a12 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: construct

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-08 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 385635.
CJ-Johnson added a comment.

Add missing test cases


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1417 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const C *);
+  basic_string_view(const basic_string_view &);
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>, basic_string_view);
+template 
+bool operator<(basic_string_view, type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>, basic_string_view);
+template 
+bool operator<=(basic_string_view, type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>, basic_string_view);
+template 
+bool operator>(basic_string_view, type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>, basic_string_view);
+template 
+bool operator>=(basic_string_view, type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>, basic_string_view);
+template 
+bool operator==(basic_string_view, type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>, basic_string_view);
+template 
+bool operator!=(basic_string_view, type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;
+
+(void)(std::string_view({})) /* a5 */; // Default `const CharT*`
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a5 */;
+
+// (void)(const std::string_view(nullptr)) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a8 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a9 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({})) /* a10 */; // Default `const CharT*`
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::string_view{nullptr}) /* a11 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a11 */;
+
+(void)(std::string_view{(nullptr)}) /* a12 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_v

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson marked 5 inline comments as done.
CJ-Johnson added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp:75
+  compoundLiteralExpr(has(StringViewConstructingFromNullExpr)),
+  changeTo(node("null_argument_expr"), cat("")), construction_warning);
+

ymandel wrote:
> And more below...
Updated all 9 of them. Thanks!



Comment at: clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp:90
+  declStmt(
+  has(varDecl(has(StringViewConstructingFromNullExpr),
+  unless(has(cxxConstructExpr(isListInitialization()

ymandel wrote:
> Here and throughout the matchers: in general, `has` is a fallback when you 
> don't have a more specific matcher. In this case, It think you mean to be 
> testing the initialization expression, in which case you should query that 
> directly: `hasInitializer`.  I'd recommend you revisit the uses of `has` and 
> check in each case if there's a more specific query. That's both cheaper 
> (doesn't need to iterate through all children) and more readable (because it 
> expresses the intent).
Thanks for the suggestion! I went back through all of the has calls and 
replaced the ones I could with something more specific.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp:134-147
+// (void)(const std::string_view{nullptr}) /* a16 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view{(nullptr)}) /* a17 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view{{nullptr}}) /* a18 */;

ymandel wrote:
> what are these lines doing?
These lines are not "tests" themselves but they clearly document that all of 
the various permutations have been considered. If someone reads the test file 
and thinks "what about this other case?", these demonstrate that such other 
cases have been considered but are not valid :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 386904.
CJ-Johnson marked 3 inline comments as done.
CJ-Johnson added a comment.

Address review comments from Yitzie


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1417 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const C *);
+  basic_string_view(const basic_string_view &);
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>, basic_string_view);
+template 
+bool operator<(basic_string_view, type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>, basic_string_view);
+template 
+bool operator<=(basic_string_view, type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>, basic_string_view);
+template 
+bool operator>(basic_string_view, type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>, basic_string_view);
+template 
+bool operator>=(basic_string_view, type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>, basic_string_view);
+template 
+bool operator==(basic_string_view, type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>, basic_string_view);
+template 
+bool operator!=(basic_string_view, type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;
+
+(void)(std::string_view({})) /* a5 */; // Default `const CharT*`
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a5 */;
+
+// (void)(const std::string_view(nullptr)) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a8 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a9 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({})) /* a10 */; // Default `const CharT*`
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::string_view{nullptr}) /* a11 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a11 */;
+
+(void)(std::string_view{(nullptr)}) /* a12 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-22 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 388972.
CJ-Johnson marked 6 inline comments as done.
CJ-Johnson added a comment.

Address reviewer comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1417 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const C *);
+  basic_string_view(const basic_string_view &);
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>, basic_string_view);
+template 
+bool operator<(basic_string_view, type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>, basic_string_view);
+template 
+bool operator<=(basic_string_view, type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>, basic_string_view);
+template 
+bool operator>(basic_string_view, type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>, basic_string_view);
+template 
+bool operator>=(basic_string_view, type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>, basic_string_view);
+template 
+bool operator==(basic_string_view, type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>, basic_string_view);
+template 
+bool operator!=(basic_string_view, type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;
+
+(void)(std::string_view({})) /* a5 */; // Default `const CharT*`
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a5 */;
+
+// (void)(const std::string_view(nullptr)) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a8 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a9 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({})) /* a10 */; // Default `const CharT*`
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::string_view{nullptr}) /* a11 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a11 */;
+
+(void)(std::string_view{(nullptr)}) /* a12 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+ 

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-22 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 388973.
CJ-Johnson added a comment.

Rebase on head


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1417 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const C *);
+  basic_string_view(const basic_string_view &);
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>, basic_string_view);
+template 
+bool operator<(basic_string_view, type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>, basic_string_view);
+template 
+bool operator<=(basic_string_view, type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>, basic_string_view);
+template 
+bool operator>(basic_string_view, type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>, basic_string_view);
+template 
+bool operator>=(basic_string_view, type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>, basic_string_view);
+template 
+bool operator==(basic_string_view, type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>, basic_string_view);
+template 
+bool operator!=(basic_string_view, type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;
+
+(void)(std::string_view({})) /* a5 */; // Default `const CharT*`
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a5 */;
+
+// (void)(const std::string_view(nullptr)) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a8 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a9 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({})) /* a10 */; // Default `const CharT*`
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::string_view{nullptr}) /* a11 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a11 */;
+
+(void)(std::string_view{(nullptr)}) /* a12 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-22 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added a comment.

Thank you all for the feedback! Would it be ok to proceed with removing the 
`nullptr` checking for `basic_string_view` in `bugprone-string-constructor`, as 
Alex indicated?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-30 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 390820.
CJ-Johnson added a comment.

Address nits


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1438 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using size_t = long long;
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+
+  basic_string_view(const CharT *);
+
+  // Not present in C++17 and C++20:
+  // basic_string_view(std::nullptr_t);
+
+  basic_string_view(const CharT *, size_t);
+
+  basic_string_view(const basic_string_view &);
+
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>,
+   basic_string_view);
+template 
+bool operator<(basic_string_view,
+   type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>,
+basic_string_view);
+template 
+bool operator<=(basic_string_view,
+type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>,
+   basic_string_view);
+template 
+bool operator>(basic_string_view,
+   type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>,
+basic_string_view);
+template 
+bool operator>=(basic_string_view,
+type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>,
+basic_string_view);
+template 
+bool operator==(basic_string_view,
+type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>,
+basic_string_view);
+template 
+bool operator!=(basic_string_view,
+type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;
+
+(void)(std::string_view({})) /* a5 */; // Default `const CharT*`
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a5 */;
+
+// (void)(const std::string_view(nullptr)) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a8 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a9 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({})) /* a10 */; // Default `const CharT*`
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::st

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-30 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 390822.
CJ-Johnson added a comment.

Rebase on head


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1438 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using size_t = long long;
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+
+  basic_string_view(const CharT *);
+
+  // Not present in C++17 and C++20:
+  // basic_string_view(std::nullptr_t);
+
+  basic_string_view(const CharT *, size_t);
+
+  basic_string_view(const basic_string_view &);
+
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>,
+   basic_string_view);
+template 
+bool operator<(basic_string_view,
+   type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>,
+basic_string_view);
+template 
+bool operator<=(basic_string_view,
+type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>,
+   basic_string_view);
+template 
+bool operator>(basic_string_view,
+   type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>,
+basic_string_view);
+template 
+bool operator>=(basic_string_view,
+type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>,
+basic_string_view);
+template 
+bool operator==(basic_string_view,
+type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>,
+basic_string_view);
+template 
+bool operator!=(basic_string_view,
+type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;
+
+(void)(std::string_view({})) /* a5 */; // Default `const CharT*`
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a5 */;
+
+// (void)(const std::string_view(nullptr)) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a8 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a9 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({})) /* a10 */; // Default `const CharT*`
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(void)(std::

[PATCH] D114823: Filter string_view from the nullptr diagnosis of bugprone-string-constructor to prevent duplicate warnings with bugprone-stringview-nullptr

2021-11-30 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson created this revision.
CJ-Johnson added reviewers: ymandel, alexfh, njames93, hokein, whisperity.
Herald added subscribers: carlosgalvezp, rnkovacs.
CJ-Johnson requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Updates the check and tests to not diagnose null for string_view (but retains 
null for string)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114823

Files:
  clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-string-constructor.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-string-constructor.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-string-constructor.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-string-constructor.cpp
@@ -74,10 +74,6 @@
   // CHECK-MESSAGES: [[@LINE-1]]:20: warning: length is bigger than string 
literal size
   std::string_view q5(kText3, 0x100);
   // CHECK-MESSAGES: [[@LINE-1]]:20: warning: suspicious large length parameter
-  std::string_view q6(nullptr);
-  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: constructing string from nullptr 
is undefined behaviour
-  std::string_view q7 = 0;
-  // CHECK-MESSAGES: [[@LINE-1]]:25: warning: constructing string from nullptr 
is undefined behaviour
 }
 
 std::string StringFromZero() {
@@ -85,11 +81,6 @@
   // CHECK-MESSAGES: [[@LINE-1]]:10: warning: constructing string from nullptr 
is undefined behaviour
 }
 
-std::string_view StringViewFromZero() {
-  return 0;
-  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: constructing string from nullptr 
is undefined behaviour
-}
-
 void Valid() {
   std::string empty();
   std::string str(4, 'x');
Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
@@ -121,17 +121,20 @@
   // Check the literal string constructor with char pointer.
   // [i.e. string (const char* s);]
   Finder->addMatcher(
-  traverse(TK_AsIs,
-   cxxConstructExpr(
-   hasDeclaration(cxxConstructorDecl(ofClass(cxxRecordDecl(
-   hasAnyName(removeNamespaces(StringNames)),
-   hasArgument(0, expr().bind("from-ptr")),
-   // do not match std::string(ptr, int)
-   // match std::string(ptr, alloc)
-   // match std::string(ptr)
-   anyOf(hasArgument(1, unless(hasType(isInteger(,
- argumentCountIs(1)))
-   .bind("constructor")),
+  traverse(
+  TK_AsIs,
+  cxxConstructExpr(
+  hasDeclaration(cxxConstructorDecl(ofClass(anyOf(
+  cxxRecordDecl(hasName("basic_string_view"))
+  .bind("basic_string_view_decl"),
+  cxxRecordDecl(hasAnyName(removeNamespaces(StringNames))),
+  hasArgument(0, expr().bind("from-ptr")),
+  // do not match std::string(ptr, int)
+  // match std::string(ptr, alloc)
+  // match std::string(ptr)
+  anyOf(hasArgument(1, unless(hasType(isInteger(,
+argumentCountIs(1)))
+  .bind("constructor")),
   this);
 }
 
@@ -167,7 +170,13 @@
 Ptr->EvaluateAsRValue(ConstPtr, Ctx) &&
 ((ConstPtr.Val.isInt() && ConstPtr.Val.getInt().isZero()) ||
  (ConstPtr.Val.isLValue() && ConstPtr.Val.isNullPointer( {
-  diag(Loc, "constructing string from nullptr is undefined behaviour");
+  const auto *StringViewType =
+  Result.Nodes.getNodeAs("basic_string_view_decl");
+  // Filter out basic_string_view to avoid conflicts with
+  // bugprone-stringview-nullptr
+  if (StringViewType == nullptr) {
+diag(Loc, "constructing string from nullptr is undefined behaviour");
+  }
 }
   }
 }


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-string-constructor.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-string-constructor.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-string-constructor.cpp
@@ -74,10 +74,6 @@
   // CHECK-MESSAGES: [[@LINE-1]]:20: warning: length is bigger than string literal size
   std::string_view q5(kText3, 0x100);
   // CHECK-MESSAGES: [[@LINE-1]]:20: warning: suspicious large length parameter
-  std::string_view q6(nullptr);
-  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: constructing string from nullptr is undefined behaviour
-  std::string_view q7 = 0;
-  // CHECK-MESSAGES: [[@LINE-1]]:25: warning: constructing string from nullptr is undefined behaviour
 }
 
 std::string StringFromZero() {

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-11-30 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added a comment.

Pinging this thread with https://reviews.llvm.org/D113148

If we land both this revision and that one, then duplicate warnings won't be a 
problem. :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114823: Filter string_view from the nullptr diagnosis of bugprone-string-constructor to prevent duplicate warnings with bugprone-stringview-nullptr

2021-12-01 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 391040.
CJ-Johnson marked an inline comment as done.
CJ-Johnson added a comment.

Switch to early return for the filter


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114823/new/

https://reviews.llvm.org/D114823

Files:
  clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-string-constructor.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-string-constructor.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-string-constructor.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-string-constructor.cpp
@@ -74,10 +74,6 @@
   // CHECK-MESSAGES: [[@LINE-1]]:20: warning: length is bigger than string 
literal size
   std::string_view q5(kText3, 0x100);
   // CHECK-MESSAGES: [[@LINE-1]]:20: warning: suspicious large length parameter
-  std::string_view q6(nullptr);
-  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: constructing string from nullptr 
is undefined behaviour
-  std::string_view q7 = 0;
-  // CHECK-MESSAGES: [[@LINE-1]]:25: warning: constructing string from nullptr 
is undefined behaviour
 }
 
 std::string StringFromZero() {
@@ -85,11 +81,6 @@
   // CHECK-MESSAGES: [[@LINE-1]]:10: warning: constructing string from nullptr 
is undefined behaviour
 }
 
-std::string_view StringViewFromZero() {
-  return 0;
-  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: constructing string from nullptr 
is undefined behaviour
-}
-
 void Valid() {
   std::string empty();
   std::string str(4, 'x');
Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
@@ -121,17 +121,20 @@
   // Check the literal string constructor with char pointer.
   // [i.e. string (const char* s);]
   Finder->addMatcher(
-  traverse(TK_AsIs,
-   cxxConstructExpr(
-   hasDeclaration(cxxConstructorDecl(ofClass(cxxRecordDecl(
-   hasAnyName(removeNamespaces(StringNames)),
-   hasArgument(0, expr().bind("from-ptr")),
-   // do not match std::string(ptr, int)
-   // match std::string(ptr, alloc)
-   // match std::string(ptr)
-   anyOf(hasArgument(1, unless(hasType(isInteger(,
- argumentCountIs(1)))
-   .bind("constructor")),
+  traverse(
+  TK_AsIs,
+  cxxConstructExpr(
+  hasDeclaration(cxxConstructorDecl(ofClass(anyOf(
+  cxxRecordDecl(hasName("basic_string_view"))
+  .bind("basic_string_view_decl"),
+  cxxRecordDecl(hasAnyName(removeNamespaces(StringNames))),
+  hasArgument(0, expr().bind("from-ptr")),
+  // do not match std::string(ptr, int)
+  // match std::string(ptr, alloc)
+  // match std::string(ptr)
+  anyOf(hasArgument(1, unless(hasType(isInteger(,
+argumentCountIs(1)))
+  .bind("constructor")),
   this);
 }
 
@@ -167,6 +170,11 @@
 Ptr->EvaluateAsRValue(ConstPtr, Ctx) &&
 ((ConstPtr.Val.isInt() && ConstPtr.Val.getInt().isZero()) ||
  (ConstPtr.Val.isLValue() && ConstPtr.Val.isNullPointer( {
+  if (Result.Nodes.getNodeAs("basic_string_view_decl")) {
+// Filter out basic_string_view to avoid conflicts with
+// bugprone-stringview-nullptr
+return;
+  }
   diag(Loc, "constructing string from nullptr is undefined behaviour");
 }
   }


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-string-constructor.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-string-constructor.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-string-constructor.cpp
@@ -74,10 +74,6 @@
   // CHECK-MESSAGES: [[@LINE-1]]:20: warning: length is bigger than string literal size
   std::string_view q5(kText3, 0x100);
   // CHECK-MESSAGES: [[@LINE-1]]:20: warning: suspicious large length parameter
-  std::string_view q6(nullptr);
-  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: constructing string from nullptr is undefined behaviour
-  std::string_view q7 = 0;
-  // CHECK-MESSAGES: [[@LINE-1]]:25: warning: constructing string from nullptr is undefined behaviour
 }
 
 std::string StringFromZero() {
@@ -85,11 +81,6 @@
   // CHECK-MESSAGES: [[@LINE-1]]:10: warning: constructing string from nullptr is undefined behaviour
 }
 
-std::string_view StringViewFromZero() {
-  return 0;
-  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: constructing string from nullptr is undefined behaviour
-}
-
 vo

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-12-01 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 391068.
CJ-Johnson added a comment.

Add missing comment lines


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1438 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using size_t = long long;
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+
+  basic_string_view(const CharT *);
+
+  // Not present in C++17 and C++20:
+  // basic_string_view(std::nullptr_t);
+
+  basic_string_view(const CharT *, size_t);
+
+  basic_string_view(const basic_string_view &);
+
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>,
+   basic_string_view);
+template 
+bool operator<(basic_string_view,
+   type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>,
+basic_string_view);
+template 
+bool operator<=(basic_string_view,
+type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>,
+   basic_string_view);
+template 
+bool operator>(basic_string_view,
+   type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>,
+basic_string_view);
+template 
+bool operator>=(basic_string_view,
+type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>,
+basic_string_view);
+template 
+bool operator==(basic_string_view,
+type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>,
+basic_string_view);
+template 
+bool operator!=(basic_string_view,
+type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;
+
+(void)(std::string_view({})) /* a5 */; // Default `const CharT*`
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a5 */;
+
+// (void)(const std::string_view(nullptr)) /* a6 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view((nullptr))) /* a7 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({nullptr})) /* a8 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({(nullptr)})) /* a9 */;
+// CV qualifiers do not compile in this context
+
+// (void)(const std::string_view({})) /* a10 */; // Default `const CharT*`
+// CV qualifiers do not compile in this context
+  }
+
+  // Temporary Object
+  {
+(

[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

2021-12-01 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 391140.
CJ-Johnson added a comment.

Delete non-functional test cases (which were previously commented out)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113148/new/

https://reviews.llvm.org/D113148

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -0,0 +1,1102 @@
+// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
+
+namespace std {
+
+using size_t = long long;
+using nullptr_t = decltype(nullptr);
+
+template 
+T &&declval();
+
+template 
+struct type_identity { using type = T; };
+template 
+using type_identity_t = typename type_identity::type;
+
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+
+  basic_string_view(const CharT *);
+
+  // Not present in C++17 and C++20:
+  // basic_string_view(std::nullptr_t);
+
+  basic_string_view(const CharT *, size_t);
+
+  basic_string_view(const basic_string_view &);
+
+  basic_string_view &operator=(const basic_string_view &);
+};
+
+template 
+bool operator<(basic_string_view, basic_string_view);
+template 
+bool operator<(type_identity_t>,
+   basic_string_view);
+template 
+bool operator<(basic_string_view,
+   type_identity_t>);
+
+template 
+bool operator<=(basic_string_view, basic_string_view);
+template 
+bool operator<=(type_identity_t>,
+basic_string_view);
+template 
+bool operator<=(basic_string_view,
+type_identity_t>);
+
+template 
+bool operator>(basic_string_view, basic_string_view);
+template 
+bool operator>(type_identity_t>,
+   basic_string_view);
+template 
+bool operator>(basic_string_view,
+   type_identity_t>);
+
+template 
+bool operator>=(basic_string_view, basic_string_view);
+template 
+bool operator>=(type_identity_t>,
+basic_string_view);
+template 
+bool operator>=(basic_string_view,
+type_identity_t>);
+
+template 
+bool operator==(basic_string_view, basic_string_view);
+template 
+bool operator==(type_identity_t>,
+basic_string_view);
+template 
+bool operator==(basic_string_view,
+type_identity_t>);
+
+template 
+bool operator!=(basic_string_view, basic_string_view);
+template 
+bool operator!=(type_identity_t>,
+basic_string_view);
+template 
+bool operator!=(basic_string_view,
+type_identity_t>);
+
+using string_view = basic_string_view;
+
+} // namespace std
+
+void function(std::string_view);
+void function(std::string_view, std::string_view);
+
+void temporary_construction() /* a */ {
+  // Functional Cast
+  {
+(void)(std::string_view(nullptr)) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;
+
+(void)(std::string_view((nullptr))) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;
+
+(void)(std::string_view({nullptr})) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;
+
+(void)(std::string_view({(nullptr)})) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;
+
+(void)(std::string_view({})) /* a5 */; // Default `const CharT*`
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a5 */;
+  }
+
+  // Temporary Object
+  {
+(void)(std::string_view{nullptr}) /* a6 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a6 */;
+
+(void)(std::string_view{(nullptr)}) /* a7 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a7 */;
+
+(void)(std::string_view{{nullptr}}) /* a8 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)(st

[PATCH] D115121: Add support for return values in bugprone-stringview-nullptr

2021-12-05 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson created this revision.
CJ-Johnson added a reviewer: ymandel.
Herald added a subscriber: carlosgalvezp.
CJ-Johnson requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

bugprone-stringview-nullptr was not initially written with tests for return 
statements. After landing the check, the thought crossed my mind to add such 
tests. After writing them, I realized they needed additional handling in the 
matchers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115121

Files:
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -215,6 +215,37 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: constructing{{.*}}default
 // CHECK-FIXES: {{^}}(void)(static_cast("")) 
/* a28 */;
   }
+
+  // Return Value
+  {
+(void)([] -> std::string_view { return nullptr; }) /* a29 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)([] -> std::string_view { return {}; }) /* 
a29 */;
+
+(void)([] -> std::string_view { return (nullptr); }) /* a30 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)([] -> std::string_view { return {}; }) /* 
a30 */;
+
+(void)([] -> std::string_view { return {nullptr}; }) /* a31 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)([] -> std::string_view { return {}; }) /* 
a31 */;
+
+(void)([] -> std::string_view { return {(nullptr)}; }) /* a32 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)([] -> std::string_view { return {}; }) /* 
a32 */;
+
+(void)([] -> std::string_view { return {{nullptr}}; }) /* a33 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)([] -> std::string_view { return {}; }) /* 
a33 */;
+
+(void)([] -> std::string_view { return {{(nullptr)}}; }) /* a34 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)([] -> std::string_view { return {}; }) /* 
a34 */;
+
+(void)([] -> std::string_view { return {{}}; }) /* a35 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)([] -> std::string_view { return {}; }) /* 
a35 */;
+  }
 }
 
 void stack_construction() /* b */ {
Index: clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
@@ -74,6 +74,11 @@
   hasSourceExpression(StringViewConstructingFromNullExpr)),
   changeTo(node("null_argument_expr"), cat("\"\"")), construction_warning);
 
+  auto HandleTemporaryReturnValue = makeRule(
+  returnStmt(
+  
hasReturnValue(ignoringImpCasts(StringViewConstructingFromNullExpr))),
+  changeTo(node("construct_expr"), cat("{}")), construction_warning);
+
   auto HandleStackCopyInitialization = makeRule(
   varDecl(hasInitializer(implicitCastExpr(
   ignoringImpCasts(StringViewConstructingFromNullExpr,
@@ -169,15 +174,23 @@
   return applyFirst(
   {HandleTemporaryCXXFunctionalCastExpr,
HandleTemporaryCXXTemporaryObjectExprAndCompoundLiteralExpr,
-   HandleTemporaryCStyleCastExpr, HandleTemporaryCXXStaticCastExpr,
-   HandleStackCopyInitialization, HandleStackDirectInitialization,
+   HandleTemporaryCStyleCastExpr,
+   HandleTemporaryCXXStaticCastExpr,
+   HandleTemporaryReturnValue,
+   HandleStackCopyInitialization,
+   HandleStackDirectInitialization,
HandleStackDirectListAndCopyListInitialization,
-   HandleFieldCopyInitialization, HandleFieldOtherInitialization,
-   HandleConstructorInitialization, HandleDefaultArgumentInitialization,
-   HandleDefaultArgumentListInitialization, HandleHeapInitialization,
+   HandleFieldCopyInitialization,
+   HandleFieldOtherInitialization,
+   HandleConstructorInitialization,
+   HandleDefaultArgumentInitialization,
+   HandleDefaultArgumentListInitialization,
+   HandleHeapInitialization,
HandleFunctionArgumentInitialization,
-   HandleFunctionArgumentListInitialization, HandleAssignment,
-   HandleRelativeComparison, HandleEmptyEqualityComparison,
+   HandleFunctionArgumentListInitial

[PATCH] D115121: Add support for return values in bugprone-stringview-nullptr

2021-12-05 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp:174-194
   return applyFirst(
   {HandleTemporaryCXXFunctionalCastExpr,
HandleTemporaryCXXTemporaryObjectExprAndCompoundLiteralExpr,
-   HandleTemporaryCStyleCastExpr, HandleTemporaryCXXStaticCastExpr,
-   HandleStackCopyInitialization, HandleStackDirectInitialization,
+   HandleTemporaryCStyleCastExpr,
+   HandleTemporaryCXXStaticCastExpr,
+   HandleTemporaryReturnValue,
+   HandleStackCopyInitialization,

The diff isn't great here, but these weren't actually changed. I just inserted 
the new one, `HandleTemporaryReturnValue`, and it caused a reflow.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115121/new/

https://reviews.llvm.org/D115121

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115121: Add support for return values in bugprone-stringview-nullptr

2021-12-05 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 391940.
CJ-Johnson added a comment.

Add missing tests for function arguments and fix incorrect warning message for 
static_cast cases


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115121/new/

https://reviews.llvm.org/D115121

Files:
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -88,8 +88,21 @@
 
 } // namespace std
 
-void function(std::string_view);
-void function(std::string_view, std::string_view);
+void sv_function(std::string_view);
+void sv_function(std::string_view, std::string_view);
+
+// TODO: Handle cases where types, such as Class and Struct below, are
+//   constructed with null arguments.
+class Class {
+public:
+  Class(std::string_view);
+  Class(std::string_view, std::string_view);
+};
+struct Struct {
+  std::string_view first = {};
+  std::string_view second = {};
+};
+void type_function(Class, Struct);
 
 void temporary_construction() /* a */ {
   // Functional Cast
@@ -197,23 +210,54 @@
 // CHECK-FIXES: {{^}}(void)((const std::string_view){}) /* a24 */;
   }
 
+  // Return Value
+  {
+(void)([] -> std::string_view { return nullptr; }) /* a25 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)([] -> std::string_view { return {}; }) /* a25 */;
+
+(void)([] -> std::string_view { return (nullptr); }) /* a26 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)([] -> std::string_view { return {}; }) /* a26 */;
+
+(void)([] -> std::string_view { return {nullptr}; }) /* a27 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)([] -> std::string_view { return {}; }) /* a27 */;
+
+(void)([] -> std::string_view { return {(nullptr)}; }) /* a28 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)([] -> std::string_view { return {}; }) /* a28 */;
+
+(void)([] -> std::string_view { return {{nullptr}}; }) /* a29 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)([] -> std::string_view { return {}; }) /* a29 */;
+
+(void)([] -> std::string_view { return {{(nullptr)}}; }) /* a30 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)([] -> std::string_view { return {}; }) /* a30 */;
+
+(void)([] -> std::string_view { return {{}}; }) /* a31 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: constructing{{.*}}default
+// CHECK-FIXES: {{^}}(void)([] -> std::string_view { return {}; }) /* a31 */;
+  }
+
   // Static Cast
   {
-(void)(static_cast(nullptr)) /* a25 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}(void)(static_cast("")) /* a25 */;
+(void)(static_cast(nullptr)) /* a32 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: constructing basic_string_view from null is undefined; replace with the empty string
+// CHECK-FIXES: {{^}}(void)(static_cast("")) /* a32 */;
 
-(void)(static_cast((nullptr))) /* a26 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}(void)(static_cast("")) /* a26 */;
+(void)(static_cast((nullptr))) /* a33 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: constructing{{.*}}empty string
+// CHECK-FIXES: {{^}}(void)(static_cast("")) /* a33 */;
 
-(void)(static_cast(nullptr)) /* a27 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:48: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}(void)(static_cast("")) /* a27 */;
+(void)(static_cast(nullptr)) /* a34 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:48: warning: constructing{{.*}}empty string
+// CHECK-FIXES: {{^}}(void)(static_cast("")) /* a34 */;
 
-(void)(static_cast((nullptr))) /* a28 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:48: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}(void)(static_cast("")) /* a28 */;
+(void)(static_cast((nullptr))) /* a35 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:48: warning: constructing{{.*}}empty string
+// CHECK-FIXES: {{^}}(void)(static_cast("")) /* a35 */;
   }
 }
 
@@ -689,55 +733,73 @@
 }
 
 void function_invocation() /* f */ {
-  // Single Argument
+  // Single Argument Function Invocation
   {
-function(nullptr) /* f1 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:14: warn

[PATCH] D115121: Add support for return values in bugprone-stringview-nullptr

2021-12-05 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp:735
 
 void function_invocation() /* f */ {
+  // Single Argument Function Invocation

This diff is also noisy, but it's about adding missing test cases


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115121/new/

https://reviews.llvm.org/D115121

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115121: Add support for return values in bugprone-stringview-nullptr

2021-12-05 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp:94-95
+
+// TODO: Handle cases where types, such as Class and Struct below, are
+//   constructed with null arguments.
+class Class {

I attempted to address this TODO but it is quite the rabbit hole. If I just add 
a basic fallback matcher, `applyFirst(...)` does not have the behavior I 
desire. It was stomping on other, better fixes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115121/new/

https://reviews.llvm.org/D115121

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D117840: [clang-tidy] Update bugprone-stringview-nullptr to consistently prefer the empty string when passing arguments to constructors/functions

2022-01-20 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson created this revision.
Herald added subscribers: carlosgalvezp, xazax.hun.
CJ-Johnson requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Previously, function(nullptr) would have been fixed with function({}). This 
unfortunately can change overload resolution and even become ambiguous. 
T(nullptr) was already being fixed with T(""), so this change just brings 
function calls in line with that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117840

Files:
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -1039,24 +1039,24 @@
   // Function Argument Initialization
   {
 function(nullptr) /* f1 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}function({}) /* f1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing null as basic_string_view is undefined; replace with the empty string
+// CHECK-FIXES: {{^}}function("") /* f1 */;
 
 function((nullptr)) /* f2 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}function({}) /* f2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing{{.*}}empty string
+// CHECK-FIXES: {{^}}function("") /* f2 */;
 
 function({nullptr}) /* f3 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}function({}) /* f3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing{{.*}}empty string
+// CHECK-FIXES: {{^}}function("") /* f3 */;
 
 function({(nullptr)}) /* f4 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}function({}) /* f4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing{{.*}}empty string
+// CHECK-FIXES: {{^}}function("") /* f4 */;
 
 function({{}}) /* f5 */; // Default `const CharT*`
-// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}function({}) /* f5 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing{{.*}}empty string
+// CHECK-FIXES: {{^}}function("") /* f5 */;
   }
 
   // Function Argument Initialization With Temporary
@@ -1599,7 +1599,7 @@
   struct AcceptsSV {
 explicit AcceptsSV(std::string_view) {}
   } r1(nullptr);
-  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: passing null as basic_string_view is undefined; replace with the empty string
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: passing{{.*}}empty string
   // CHECK-FIXES: {{^}}  } r1("");
 
   (void)(AcceptsSV{nullptr}) /* r2 */;
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
@@ -43,9 +43,9 @@
   bool is_empty = sv.empty();
   bool isnt_empty = !sv.empty();
 
-  accepts_sv({});
+  accepts_sv("");
 
-  accepts_sv({});  // A
+  accepts_sv("");  // A
 
   accepts_sv({nullptr, 0});  // B
 
Index: clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
@@ -44,6 +44,9 @@
   auto static_cast_warning =
   cat("casting to basic_string_view from null is undefined; replace with "
   "the empty string");
+  auto argument_construction_warning =
+  cat("passing null as basic_string_view is undefined; replace with the "
+  "empty string");
   auto assignment_warning =
   cat("assignment to basic_string_view from null is undefined; replace "
   "with the default constructor");
@@ -53,9 +56,6 @@
   auto equality_comparison_warning =
   cat("comparing basic_string_view to null is undefined; replace with the "
   "emptiness query");
-  auto constructor_argument_warning =
-  cat("passing null as basic_string_view is undefined; replace with the "
-  "empty string");
 
   // Matches declarations and expressions of type `basic_string_view`
   auto HasBasicStringViewType = hasType(hasUnqualifiedDesugaredType(recordType(
@@ -211,11 +211,12 @@
   remove(node("null_arg_expr")), construction_warning);
 
   // `function(null_arg_expr)`
-  auto HandleFunct

[PATCH] D117840: [clang-tidy] Update bugprone-stringview-nullptr to consistently prefer the empty string when passing arguments to constructors/functions

2022-01-20 Thread CJ Johnson via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa5684114445a: [clang-tidy] Update 
bugprone-stringview-nullptr to consistently prefer the… (authored by 
CJ-Johnson).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117840/new/

https://reviews.llvm.org/D117840

Files:
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -1039,24 +1039,24 @@
   // Function Argument Initialization
   {
 function(nullptr) /* f1 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}function({}) /* f1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing null as basic_string_view is undefined; replace with the empty string
+// CHECK-FIXES: {{^}}function("") /* f1 */;
 
 function((nullptr)) /* f2 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}function({}) /* f2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing{{.*}}empty string
+// CHECK-FIXES: {{^}}function("") /* f2 */;
 
 function({nullptr}) /* f3 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}function({}) /* f3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing{{.*}}empty string
+// CHECK-FIXES: {{^}}function("") /* f3 */;
 
 function({(nullptr)}) /* f4 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}function({}) /* f4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing{{.*}}empty string
+// CHECK-FIXES: {{^}}function("") /* f4 */;
 
 function({{}}) /* f5 */; // Default `const CharT*`
-// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}function({}) /* f5 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing{{.*}}empty string
+// CHECK-FIXES: {{^}}function("") /* f5 */;
   }
 
   // Function Argument Initialization With Temporary
@@ -1599,7 +1599,7 @@
   struct AcceptsSV {
 explicit AcceptsSV(std::string_view) {}
   } r1(nullptr);
-  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: passing null as basic_string_view is undefined; replace with the empty string
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: passing{{.*}}empty string
   // CHECK-FIXES: {{^}}  } r1("");
 
   (void)(AcceptsSV{nullptr}) /* r2 */;
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-stringview-nullptr.rst
@@ -43,9 +43,9 @@
   bool is_empty = sv.empty();
   bool isnt_empty = !sv.empty();
 
-  accepts_sv({});
+  accepts_sv("");
 
-  accepts_sv({});  // A
+  accepts_sv("");  // A
 
   accepts_sv({nullptr, 0});  // B
 
Index: clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
@@ -44,6 +44,9 @@
   auto static_cast_warning =
   cat("casting to basic_string_view from null is undefined; replace with "
   "the empty string");
+  auto argument_construction_warning =
+  cat("passing null as basic_string_view is undefined; replace with the "
+  "empty string");
   auto assignment_warning =
   cat("assignment to basic_string_view from null is undefined; replace "
   "with the default constructor");
@@ -53,9 +56,6 @@
   auto equality_comparison_warning =
   cat("comparing basic_string_view to null is undefined; replace with the "
   "emptiness query");
-  auto constructor_argument_warning =
-  cat("passing null as basic_string_view is undefined; replace with the "
-  "empty string");
 
   // Matches declarations and expressions of type `basic_string_view`
   auto HasBasicStringViewType = hasType(hasUnqualifiedDesugaredType(recordType(
@@ -211,11 +211,12 @@
   remove(node("null_arg_expr")), construction_warning);
 
   // `function(null_arg_expr)`
-  auto HandleFunctionArgumentInitialization = makeRule(
-  callExpr(hasAn

[PATCH] D115121: Update bugprone-stringview-nullptr to prefer the empty string for most edits

2022-01-11 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 399130.
CJ-Johnson added a comment.

Switching back to original plan of adding support for return statements


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115121/new/

https://reviews.llvm.org/D115121

Files:
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -16,78 +16,112 @@
 template 
 class basic_string_view {
 public:
-  basic_string_view();
+  constexpr basic_string_view() {}
 
-  basic_string_view(const CharT *);
+  constexpr basic_string_view(const CharT *) {}
 
   // Not present in C++17 and C++20:
-  // basic_string_view(std::nullptr_t);
+  // constexpr basic_string_view(std::nullptr_t) {}
 
-  basic_string_view(const CharT *, size_t);
+  constexpr basic_string_view(const CharT *, size_t) {}
 
-  basic_string_view(const basic_string_view &);
+  constexpr basic_string_view(const basic_string_view &) {}
 
-  basic_string_view &operator=(const basic_string_view &);
+  constexpr basic_string_view &operator=(const basic_string_view &) {}
 };
 
 template 
-bool operator<(basic_string_view, basic_string_view);
+constexpr bool operator<(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<(type_identity_t>,
-   basic_string_view);
+constexpr bool operator<(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator<(basic_string_view,
-   type_identity_t>);
+constexpr bool operator<(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator<=(basic_string_view, basic_string_view);
+constexpr bool operator<=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(type_identity_t>,
-basic_string_view);
+constexpr bool operator<=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(basic_string_view,
-type_identity_t>);
+constexpr bool operator<=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>(basic_string_view, basic_string_view);
+constexpr bool operator>(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator>(type_identity_t>,
-   basic_string_view);
+constexpr bool operator>(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator>(basic_string_view,
-   type_identity_t>);
+constexpr bool operator>(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>=(basic_string_view, basic_string_view);
+constexpr bool operator>=(basic_string_view, basic_string_view);
 template 
-bool operator>=(type_identity_t>,
-basic_string_view);
+constexpr bool operator>=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator>=(basic_string_view,
-type_identity_t>);
+constexpr bool operator>=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator==(basic_string_view, basic_string_view);
+constexpr bool operator==(basic_string_view, basic_string_view);
 template 
-bool operator==(type_identity_t>,
-basic_string_view);
+constexpr bool operator==(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator==(basic_string_view,
-type_identity_t>);
+constexpr bool operator==(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator!=(basic_string_view, basic_string_view);
+constexpr bool operator!=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(type_identity_t>,
-basic_string_view);
+constexpr bool operator!=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(basic_string_view,
-type_identity_t>);
+constexpr bool operator!=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 using string_view = basic_string_view;
 
 } // namespace std
 
+using SV = std::string_view; // Used in some places for shorter line length
+
 void function(std::string_view);
 void function(std::string_view, std::string_view);
 
@@ -200,19 +234,19 @@
   // Static Cast
   {
 (void)(static_cast(nullptr)) /* a25 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:42: w

[PATCH] D115121: Update bugprone-stringview-nullptr to support return statements and constructors for any T which accepts basic_string_view

2022-01-11 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 399134.
CJ-Johnson edited the summary of this revision.
CJ-Johnson added a comment.

Nit


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115121/new/

https://reviews.llvm.org/D115121

Files:
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -16,78 +16,112 @@
 template 
 class basic_string_view {
 public:
-  basic_string_view();
+  constexpr basic_string_view() {}
 
-  basic_string_view(const CharT *);
+  constexpr basic_string_view(const CharT *) {}
 
   // Not present in C++17 and C++20:
-  // basic_string_view(std::nullptr_t);
+  // constexpr basic_string_view(std::nullptr_t) {}
 
-  basic_string_view(const CharT *, size_t);
+  constexpr basic_string_view(const CharT *, size_t) {}
 
-  basic_string_view(const basic_string_view &);
+  constexpr basic_string_view(const basic_string_view &) {}
 
-  basic_string_view &operator=(const basic_string_view &);
+  constexpr basic_string_view &operator=(const basic_string_view &) {}
 };
 
 template 
-bool operator<(basic_string_view, basic_string_view);
+constexpr bool operator<(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<(type_identity_t>,
-   basic_string_view);
+constexpr bool operator<(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator<(basic_string_view,
-   type_identity_t>);
+constexpr bool operator<(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator<=(basic_string_view, basic_string_view);
+constexpr bool operator<=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(type_identity_t>,
-basic_string_view);
+constexpr bool operator<=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(basic_string_view,
-type_identity_t>);
+constexpr bool operator<=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>(basic_string_view, basic_string_view);
+constexpr bool operator>(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator>(type_identity_t>,
-   basic_string_view);
+constexpr bool operator>(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator>(basic_string_view,
-   type_identity_t>);
+constexpr bool operator>(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>=(basic_string_view, basic_string_view);
+constexpr bool operator>=(basic_string_view, basic_string_view);
 template 
-bool operator>=(type_identity_t>,
-basic_string_view);
+constexpr bool operator>=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator>=(basic_string_view,
-type_identity_t>);
+constexpr bool operator>=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator==(basic_string_view, basic_string_view);
+constexpr bool operator==(basic_string_view, basic_string_view);
 template 
-bool operator==(type_identity_t>,
-basic_string_view);
+constexpr bool operator==(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator==(basic_string_view,
-type_identity_t>);
+constexpr bool operator==(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator!=(basic_string_view, basic_string_view);
+constexpr bool operator!=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(type_identity_t>,
-basic_string_view);
+constexpr bool operator!=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(basic_string_view,
-type_identity_t>);
+constexpr bool operator!=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 using string_view = basic_string_view;
 
 } // namespace std
 
+using SV = std::string_view; // Used in some places for shorter line length
+
 void function(std::string_view);
 void function(std::string_view, std::string_view);
 
@@ -200,19 +234,19 @@
   // Static Cast
   {
 (void)(static_cast(nullptr)) /* a25 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: constructing

[PATCH] D115121: Update bugprone-stringview-nullptr to support return statements and constructors for any T which accepts basic_string_view

2022-01-11 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 399135.
CJ-Johnson added a comment.

Rebase on head


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115121/new/

https://reviews.llvm.org/D115121

Files:
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -16,78 +16,112 @@
 template 
 class basic_string_view {
 public:
-  basic_string_view();
+  constexpr basic_string_view() {}
 
-  basic_string_view(const CharT *);
+  constexpr basic_string_view(const CharT *) {}
 
   // Not present in C++17 and C++20:
-  // basic_string_view(std::nullptr_t);
+  // constexpr basic_string_view(std::nullptr_t) {}
 
-  basic_string_view(const CharT *, size_t);
+  constexpr basic_string_view(const CharT *, size_t) {}
 
-  basic_string_view(const basic_string_view &);
+  constexpr basic_string_view(const basic_string_view &) {}
 
-  basic_string_view &operator=(const basic_string_view &);
+  constexpr basic_string_view &operator=(const basic_string_view &) {}
 };
 
 template 
-bool operator<(basic_string_view, basic_string_view);
+constexpr bool operator<(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<(type_identity_t>,
-   basic_string_view);
+constexpr bool operator<(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator<(basic_string_view,
-   type_identity_t>);
+constexpr bool operator<(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator<=(basic_string_view, basic_string_view);
+constexpr bool operator<=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(type_identity_t>,
-basic_string_view);
+constexpr bool operator<=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(basic_string_view,
-type_identity_t>);
+constexpr bool operator<=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>(basic_string_view, basic_string_view);
+constexpr bool operator>(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator>(type_identity_t>,
-   basic_string_view);
+constexpr bool operator>(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator>(basic_string_view,
-   type_identity_t>);
+constexpr bool operator>(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>=(basic_string_view, basic_string_view);
+constexpr bool operator>=(basic_string_view, basic_string_view);
 template 
-bool operator>=(type_identity_t>,
-basic_string_view);
+constexpr bool operator>=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator>=(basic_string_view,
-type_identity_t>);
+constexpr bool operator>=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator==(basic_string_view, basic_string_view);
+constexpr bool operator==(basic_string_view, basic_string_view);
 template 
-bool operator==(type_identity_t>,
-basic_string_view);
+constexpr bool operator==(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator==(basic_string_view,
-type_identity_t>);
+constexpr bool operator==(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator!=(basic_string_view, basic_string_view);
+constexpr bool operator!=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(type_identity_t>,
-basic_string_view);
+constexpr bool operator!=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(basic_string_view,
-type_identity_t>);
+constexpr bool operator!=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 using string_view = basic_string_view;
 
 } // namespace std
 
+using SV = std::string_view; // Used in some places for shorter line length
+
 void function(std::string_view);
 void function(std::string_view, std::string_view);
 
@@ -200,19 +234,19 @@
   // Static Cast
   {
 (void)(static_cast(nullptr)) /* a25 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: constructing{{.*}}default
+// CHECK-MESSAGES:

[PATCH] D115121: Update bugprone-stringview-nullptr to support return statements and constructors for any T which accepts basic_string_view

2022-01-11 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 399139.
CJ-Johnson added a comment.

Nit


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115121/new/

https://reviews.llvm.org/D115121

Files:
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -16,78 +16,112 @@
 template 
 class basic_string_view {
 public:
-  basic_string_view();
+  constexpr basic_string_view() {}
 
-  basic_string_view(const CharT *);
+  constexpr basic_string_view(const CharT *) {}
 
   // Not present in C++17 and C++20:
-  // basic_string_view(std::nullptr_t);
+  // constexpr basic_string_view(std::nullptr_t) {}
 
-  basic_string_view(const CharT *, size_t);
+  constexpr basic_string_view(const CharT *, size_t) {}
 
-  basic_string_view(const basic_string_view &);
+  constexpr basic_string_view(const basic_string_view &) {}
 
-  basic_string_view &operator=(const basic_string_view &);
+  constexpr basic_string_view &operator=(const basic_string_view &) {}
 };
 
 template 
-bool operator<(basic_string_view, basic_string_view);
+constexpr bool operator<(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<(type_identity_t>,
-   basic_string_view);
+constexpr bool operator<(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator<(basic_string_view,
-   type_identity_t>);
+constexpr bool operator<(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator<=(basic_string_view, basic_string_view);
+constexpr bool operator<=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(type_identity_t>,
-basic_string_view);
+constexpr bool operator<=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(basic_string_view,
-type_identity_t>);
+constexpr bool operator<=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>(basic_string_view, basic_string_view);
+constexpr bool operator>(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator>(type_identity_t>,
-   basic_string_view);
+constexpr bool operator>(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator>(basic_string_view,
-   type_identity_t>);
+constexpr bool operator>(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>=(basic_string_view, basic_string_view);
+constexpr bool operator>=(basic_string_view, basic_string_view);
 template 
-bool operator>=(type_identity_t>,
-basic_string_view);
+constexpr bool operator>=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator>=(basic_string_view,
-type_identity_t>);
+constexpr bool operator>=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator==(basic_string_view, basic_string_view);
+constexpr bool operator==(basic_string_view, basic_string_view);
 template 
-bool operator==(type_identity_t>,
-basic_string_view);
+constexpr bool operator==(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator==(basic_string_view,
-type_identity_t>);
+constexpr bool operator==(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator!=(basic_string_view, basic_string_view);
+constexpr bool operator!=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(type_identity_t>,
-basic_string_view);
+constexpr bool operator!=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(basic_string_view,
-type_identity_t>);
+constexpr bool operator!=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 using string_view = basic_string_view;
 
 } // namespace std
 
+using SV = std::string_view; // Used in some places for shorter line length
+
 void function(std::string_view);
 void function(std::string_view, std::string_view);
 
@@ -200,19 +234,19 @@
   // Static Cast
   {
 (void)(static_cast(nullptr)) /* a25 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: constructing{{.*}}default
+// CHECK-MESSAGES: :[[@LINE-1

[PATCH] D114823: Filter string_view from the nullptr diagnosis of bugprone-string-constructor to prevent duplicate warnings with bugprone-stringview-nullptr

2022-01-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 399370.
CJ-Johnson added a comment.

Only filter out basic_string_view when bugprone-stringview-nullptr is enabled


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114823/new/

https://reviews.llvm.org/D114823

Files:
  clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h


Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
@@ -30,6 +30,7 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
+  const bool IsStringviewNullptrCheckEnabled;
   const bool WarnOnLargeLength;
   const unsigned int LargeLengthThreshold;
   std::vector StringNames;
Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
@@ -43,6 +43,8 @@
 StringConstructorCheck::StringConstructorCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
+  IsStringviewNullptrCheckEnabled(
+  Context->isCheckEnabled("bugprone-stringview-nullptr")),
   WarnOnLargeLength(Options.get("WarnOnLargeLength", true)),
   LargeLengthThreshold(Options.get("LargeLengthThreshold", 0x80)),
   StringNames(utils::options::parseStringList(
@@ -121,17 +123,20 @@
   // Check the literal string constructor with char pointer.
   // [i.e. string (const char* s);]
   Finder->addMatcher(
-  traverse(TK_AsIs,
-   cxxConstructExpr(
-   hasDeclaration(cxxConstructorDecl(ofClass(cxxRecordDecl(
-   hasAnyName(removeNamespaces(StringNames)),
-   hasArgument(0, expr().bind("from-ptr")),
-   // do not match std::string(ptr, int)
-   // match std::string(ptr, alloc)
-   // match std::string(ptr)
-   anyOf(hasArgument(1, unless(hasType(isInteger(,
- argumentCountIs(1)))
-   .bind("constructor")),
+  traverse(
+  TK_AsIs,
+  cxxConstructExpr(
+  hasDeclaration(cxxConstructorDecl(ofClass(anyOf(
+  cxxRecordDecl(hasName("basic_string_view"))
+  .bind("basic_string_view_decl"),
+  cxxRecordDecl(hasAnyName(removeNamespaces(StringNames))),
+  hasArgument(0, expr().bind("from-ptr")),
+  // do not match std::string(ptr, int)
+  // match std::string(ptr, alloc)
+  // match std::string(ptr)
+  anyOf(hasArgument(1, unless(hasType(isInteger(,
+argumentCountIs(1)))
+  .bind("constructor")),
   this);
 }
 
@@ -167,6 +172,12 @@
 Ptr->EvaluateAsRValue(ConstPtr, Ctx) &&
 ((ConstPtr.Val.isInt() && ConstPtr.Val.getInt().isZero()) ||
  (ConstPtr.Val.isLValue() && ConstPtr.Val.isNullPointer( {
+  if (IsStringviewNullptrCheckEnabled &&
+  Result.Nodes.getNodeAs("basic_string_view_decl")) {
+// Filter out `basic_string_view` to avoid conflicts with
+// `bugprone-stringview-nullptr`
+return;
+  }
   diag(Loc, "constructing string from nullptr is undefined behaviour");
 }
   }


Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
@@ -30,6 +30,7 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
+  const bool IsStringviewNullptrCheckEnabled;
   const bool WarnOnLargeLength;
   const unsigned int LargeLengthThreshold;
   std::vector StringNames;
Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
@@ -43,6 +43,8 @@
 StringConstructorCheck::StringConstructorCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
+  IsStringviewNullptrCheckEnabled(
+  Context->isCheckEnabled("bugprone-stringview-nullptr")),
   WarnOnLargeLength(Options.get("WarnOnLargeLength", true)),
   LargeLengthThreshold(Options.get("LargeLengthThreshold", 0x80)),
   StringNames(utils::

[PATCH] D114823: Filter string_view from the nullptr diagnosis of bugprone-string-constructor to prevent duplicate warnings with bugprone-stringview-nullptr

2022-01-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added a comment.

In D114823#3229990 , @njames93 wrote:

> I'm in 2 minds about this. This diagnostic is a good fit for this warning and 
> shouldn't be removed. Likewise duplicate diagnostics from different checks is 
> annoying. Maybe a better path forward would be to suppress the diagnostic if 
> the `bugprone-stringview-nullptr` check is enabled. These kinds of intercheck 
> dependencies are found in modernize-prefer-member-init check IIRC. You can 
> just copy the impl from there.

Great suggestion! I've updated this diff to do exactly that. Thanks! :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114823/new/

https://reviews.llvm.org/D114823

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115121: Update bugprone-stringview-nullptr to support return statements and constructors for any T which accepts basic_string_view

2022-01-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 399376.
CJ-Johnson added a comment.

Nits


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115121/new/

https://reviews.llvm.org/D115121

Files:
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -16,78 +16,116 @@
 template 
 class basic_string_view {
 public:
-  basic_string_view();
+  constexpr basic_string_view() {}
 
-  basic_string_view(const CharT *);
+  constexpr basic_string_view(const CharT *) {}
 
   // Not present in C++17 and C++20:
-  // basic_string_view(std::nullptr_t);
+  // constexpr basic_string_view(std::nullptr_t) {}
 
-  basic_string_view(const CharT *, size_t);
+  constexpr basic_string_view(const CharT *, size_t) {}
 
-  basic_string_view(const basic_string_view &);
+  constexpr basic_string_view(const basic_string_view &) {}
 
-  basic_string_view &operator=(const basic_string_view &);
+  constexpr basic_string_view &operator=(const basic_string_view &) {}
 };
 
 template 
-bool operator<(basic_string_view, basic_string_view);
+constexpr bool operator<(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<(type_identity_t>,
-   basic_string_view);
+constexpr bool operator<(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator<(basic_string_view,
-   type_identity_t>);
+constexpr bool operator<(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator<=(basic_string_view, basic_string_view);
+constexpr bool operator<=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(type_identity_t>,
-basic_string_view);
+constexpr bool operator<=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(basic_string_view,
-type_identity_t>);
+constexpr bool operator<=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>(basic_string_view, basic_string_view);
+constexpr bool operator>(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator>(type_identity_t>,
-   basic_string_view);
+constexpr bool operator>(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator>(basic_string_view,
-   type_identity_t>);
+constexpr bool operator>(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>=(basic_string_view, basic_string_view);
+constexpr bool operator>=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator>=(type_identity_t>,
-basic_string_view);
+constexpr bool operator>=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator>=(basic_string_view,
-type_identity_t>);
+constexpr bool operator>=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator==(basic_string_view, basic_string_view);
+constexpr bool operator==(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator==(type_identity_t>,
-basic_string_view);
+constexpr bool operator==(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator==(basic_string_view,
-type_identity_t>);
+constexpr bool operator==(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator!=(basic_string_view, basic_string_view);
+constexpr bool operator!=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(type_identity_t>,
-basic_string_view);
+constexpr bool operator!=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(basic_string_view,
-type_identity_t>);
+constexpr bool operator!=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 using string_view = basic_string_view;
 
 } // namespace std
 
+using SV = std::string_view; // Used in some places for shorter line length
+
 void function(std::string_view);
 void function(std::string_view, std::string_view);
 
@@ -200,19 +238,19 @@
   // Static Cast
   {
 (void)(static_cast(nullptr)) /* a25 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: constructing{{.*}}defau

[PATCH] D115121: Update bugprone-stringview-nullptr to support return statements and constructors for any T which accepts basic_string_view

2022-01-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 399436.
CJ-Johnson marked an inline comment as done.
CJ-Johnson added a comment.

Add code comment about the choice of hasAnyArgument


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115121/new/

https://reviews.llvm.org/D115121

Files:
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -16,78 +16,116 @@
 template 
 class basic_string_view {
 public:
-  basic_string_view();
+  constexpr basic_string_view() {}
 
-  basic_string_view(const CharT *);
+  constexpr basic_string_view(const CharT *) {}
 
   // Not present in C++17 and C++20:
-  // basic_string_view(std::nullptr_t);
+  // constexpr basic_string_view(std::nullptr_t) {}
 
-  basic_string_view(const CharT *, size_t);
+  constexpr basic_string_view(const CharT *, size_t) {}
 
-  basic_string_view(const basic_string_view &);
+  constexpr basic_string_view(const basic_string_view &) {}
 
-  basic_string_view &operator=(const basic_string_view &);
+  constexpr basic_string_view &operator=(const basic_string_view &) {}
 };
 
 template 
-bool operator<(basic_string_view, basic_string_view);
+constexpr bool operator<(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<(type_identity_t>,
-   basic_string_view);
+constexpr bool operator<(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator<(basic_string_view,
-   type_identity_t>);
+constexpr bool operator<(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator<=(basic_string_view, basic_string_view);
+constexpr bool operator<=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(type_identity_t>,
-basic_string_view);
+constexpr bool operator<=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(basic_string_view,
-type_identity_t>);
+constexpr bool operator<=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>(basic_string_view, basic_string_view);
+constexpr bool operator>(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator>(type_identity_t>,
-   basic_string_view);
+constexpr bool operator>(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator>(basic_string_view,
-   type_identity_t>);
+constexpr bool operator>(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>=(basic_string_view, basic_string_view);
+constexpr bool operator>=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator>=(type_identity_t>,
-basic_string_view);
+constexpr bool operator>=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator>=(basic_string_view,
-type_identity_t>);
+constexpr bool operator>=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator==(basic_string_view, basic_string_view);
+constexpr bool operator==(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator==(type_identity_t>,
-basic_string_view);
+constexpr bool operator==(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator==(basic_string_view,
-type_identity_t>);
+constexpr bool operator==(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator!=(basic_string_view, basic_string_view);
+constexpr bool operator!=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(type_identity_t>,
-basic_string_view);
+constexpr bool operator!=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(basic_string_view,
-type_identity_t>);
+constexpr bool operator!=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 using string_view = basic_string_view;
 
 } // namespace std
 
+using SV = std::string_view; // Used in some places for shorter line length
+
 void function(std::string_view);
 void function(std::string_view, std::string_view);
 
@@ -200,19 +238,19 @@
   // Static Cast
   {
 (void)(static_cast(nu

[PATCH] D115121: Update bugprone-stringview-nullptr to support return statements and constructors for any T which accepts basic_string_view

2022-01-12 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp:263
+  auto HandleConstructorInvocation =
+  makeRule(cxxConstructExpr(hasAnyArgument(ignoringImpCasts(
+BasicStringViewConstructingFromNullExpr)),

ymandel wrote:
> precede with `argumentCountIs(1)`? Also, please comment on choice of 
> `hasAnyArgument` (copying what you wrote in the patch description is fine).
Added the code comments, but not the argument count matcher. This case 
intentionally matches any number of arguments since some types make take 2+ 
parameters where one of them is string_view.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115121/new/

https://reviews.llvm.org/D115121

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115121: Update bugprone-stringview-nullptr to support return statements and constructors for any T which accepts basic_string_view

2022-01-12 Thread CJ Johnson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7e29da875ca9: Add support for return values in 
bugprone-stringview-nullptr (authored by CJ-Johnson).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115121/new/

https://reviews.llvm.org/D115121

Files:
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -16,78 +16,116 @@
 template 
 class basic_string_view {
 public:
-  basic_string_view();
+  constexpr basic_string_view() {}
 
-  basic_string_view(const CharT *);
+  constexpr basic_string_view(const CharT *) {}
 
   // Not present in C++17 and C++20:
-  // basic_string_view(std::nullptr_t);
+  // constexpr basic_string_view(std::nullptr_t) {}
 
-  basic_string_view(const CharT *, size_t);
+  constexpr basic_string_view(const CharT *, size_t) {}
 
-  basic_string_view(const basic_string_view &);
+  constexpr basic_string_view(const basic_string_view &) {}
 
-  basic_string_view &operator=(const basic_string_view &);
+  constexpr basic_string_view &operator=(const basic_string_view &) {}
 };
 
 template 
-bool operator<(basic_string_view, basic_string_view);
+constexpr bool operator<(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<(type_identity_t>,
-   basic_string_view);
+constexpr bool operator<(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator<(basic_string_view,
-   type_identity_t>);
+constexpr bool operator<(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator<=(basic_string_view, basic_string_view);
+constexpr bool operator<=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(type_identity_t>,
-basic_string_view);
+constexpr bool operator<=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator<=(basic_string_view,
-type_identity_t>);
+constexpr bool operator<=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>(basic_string_view, basic_string_view);
+constexpr bool operator>(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator>(type_identity_t>,
-   basic_string_view);
+constexpr bool operator>(type_identity_t>,
+ basic_string_view) {
+  return {};
+}
 template 
-bool operator>(basic_string_view,
-   type_identity_t>);
+constexpr bool operator>(basic_string_view,
+ type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator>=(basic_string_view, basic_string_view);
+constexpr bool operator>=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator>=(type_identity_t>,
-basic_string_view);
+constexpr bool operator>=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator>=(basic_string_view,
-type_identity_t>);
+constexpr bool operator>=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator==(basic_string_view, basic_string_view);
+constexpr bool operator==(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator==(type_identity_t>,
-basic_string_view);
+constexpr bool operator==(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator==(basic_string_view,
-type_identity_t>);
+constexpr bool operator==(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 template 
-bool operator!=(basic_string_view, basic_string_view);
+constexpr bool operator!=(basic_string_view, basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(type_identity_t>,
-basic_string_view);
+constexpr bool operator!=(type_identity_t>,
+  basic_string_view) {
+  return {};
+}
 template 
-bool operator!=(basic_string_view,
-type_identity_t>);
+constexpr bool operator!=(basic_string_view,
+  type_identity_t>) {
+  return {};
+}
 
 using string_view = basic_string_view;
 
 } // namespace std
 
+using SV = std::string_view; // Used in some places for shorter line length
+
 void function(std::string_view);
 void function(std::string_view, std::string_view)

[PATCH] D114823: Filter string_view from the nullptr diagnosis of bugprone-string-constructor to prevent duplicate warnings with bugprone-stringview-nullptr

2022-01-12 Thread CJ Johnson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG81c330e23dd4: Filter string_view from the nullptr diagnosis 
of bugprone-string-constructor to… (authored by CJ-Johnson).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114823/new/

https://reviews.llvm.org/D114823

Files:
  clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h


Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
@@ -30,6 +30,7 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
+  const bool IsStringviewNullptrCheckEnabled;
   const bool WarnOnLargeLength;
   const unsigned int LargeLengthThreshold;
   std::vector StringNames;
Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
@@ -43,6 +43,8 @@
 StringConstructorCheck::StringConstructorCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
+  IsStringviewNullptrCheckEnabled(
+  Context->isCheckEnabled("bugprone-stringview-nullptr")),
   WarnOnLargeLength(Options.get("WarnOnLargeLength", true)),
   LargeLengthThreshold(Options.get("LargeLengthThreshold", 0x80)),
   StringNames(utils::options::parseStringList(
@@ -121,17 +123,20 @@
   // Check the literal string constructor with char pointer.
   // [i.e. string (const char* s);]
   Finder->addMatcher(
-  traverse(TK_AsIs,
-   cxxConstructExpr(
-   hasDeclaration(cxxConstructorDecl(ofClass(cxxRecordDecl(
-   hasAnyName(removeNamespaces(StringNames)),
-   hasArgument(0, expr().bind("from-ptr")),
-   // do not match std::string(ptr, int)
-   // match std::string(ptr, alloc)
-   // match std::string(ptr)
-   anyOf(hasArgument(1, unless(hasType(isInteger(,
- argumentCountIs(1)))
-   .bind("constructor")),
+  traverse(
+  TK_AsIs,
+  cxxConstructExpr(
+  hasDeclaration(cxxConstructorDecl(ofClass(anyOf(
+  cxxRecordDecl(hasName("basic_string_view"))
+  .bind("basic_string_view_decl"),
+  cxxRecordDecl(hasAnyName(removeNamespaces(StringNames))),
+  hasArgument(0, expr().bind("from-ptr")),
+  // do not match std::string(ptr, int)
+  // match std::string(ptr, alloc)
+  // match std::string(ptr)
+  anyOf(hasArgument(1, unless(hasType(isInteger(,
+argumentCountIs(1)))
+  .bind("constructor")),
   this);
 }
 
@@ -167,6 +172,12 @@
 Ptr->EvaluateAsRValue(ConstPtr, Ctx) &&
 ((ConstPtr.Val.isInt() && ConstPtr.Val.getInt().isZero()) ||
  (ConstPtr.Val.isLValue() && ConstPtr.Val.isNullPointer( {
+  if (IsStringviewNullptrCheckEnabled &&
+  Result.Nodes.getNodeAs("basic_string_view_decl")) {
+// Filter out `basic_string_view` to avoid conflicts with
+// `bugprone-stringview-nullptr`
+return;
+  }
   diag(Loc, "constructing string from nullptr is undefined behaviour");
 }
   }


Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
@@ -30,6 +30,7 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
+  const bool IsStringviewNullptrCheckEnabled;
   const bool WarnOnLargeLength;
   const unsigned int LargeLengthThreshold;
   std::vector StringNames;
Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
@@ -43,6 +43,8 @@
 StringConstructorCheck::StringConstructorCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
+  IsStringviewNullptrCheckEnabled(
+  Context->isCheckEnabled("bugprone-stringview-nullptr")),
   WarnOnLargeLength(Options.get("WarnOnLargeLength", true)),
   LargeLengthThreshold(Options.get("Lar

[PATCH] D115121: Add support for return values in bugprone-stringview-nullptr

2021-12-06 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 392157.
CJ-Johnson added a comment.

Switch to using empty string edits everywhere except equality comparison


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115121/new/

https://reviews.llvm.org/D115121

Files:
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp
@@ -88,132 +88,179 @@
 
 } // namespace std
 
-void function(std::string_view);
-void function(std::string_view, std::string_view);
+void sv_function(std::string_view);
+void sv_function(std::string_view, std::string_view);
+class ImplicitClass {
+public:
+  ImplicitClass() = delete;
+  explicit ImplicitClass(std::string_view);
+  ImplicitClass(std::string_view, std::string_view);
+};
+class ExplicitClass {
+public:
+  ExplicitClass() = delete;
+  explicit ExplicitClass(std::string_view);
+  ExplicitClass(std::string_view, std::string_view);
+};
+struct Struct {
+  std::string_view first = {};
+  std::string_view second = {};
+};
 
 void temporary_construction() /* a */ {
   // Functional Cast
   {
 (void)(std::string_view(nullptr)) /* a1 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
-// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a1 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the empty string
+// CHECK-FIXES: {{^}}(void)(std::string_view("")) /* a1 */;
 
 (void)(std::string_view((nullptr))) /* a2 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a2 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}empty string
+// CHECK-FIXES: {{^}}(void)(std::string_view("")) /* a2 */;
 
 (void)(std::string_view({nullptr})) /* a3 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a3 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}empty string
+// CHECK-FIXES: {{^}}(void)(std::string_view("")) /* a3 */;
 
 (void)(std::string_view({(nullptr)})) /* a4 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a4 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}empty string
+// CHECK-FIXES: {{^}}(void)(std::string_view("")) /* a4 */;
 
 (void)(std::string_view({})) /* a5 */; // Default `const CharT*`
-// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}(void)(std::string_view()) /* a5 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}empty string
+// CHECK-FIXES: {{^}}(void)(std::string_view("")) /* a5 */;
   }
 
   // Temporary Object
   {
 (void)(std::string_view{nullptr}) /* a6 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a6 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}empty string
+// CHECK-FIXES: {{^}}(void)(std::string_view{""}) /* a6 */;
 
 (void)(std::string_view{(nullptr)}) /* a7 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a7 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}empty string
+// CHECK-FIXES: {{^}}(void)(std::string_view{""}) /* a7 */;
 
 (void)(std::string_view{{nullptr}}) /* a8 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a8 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}empty string
+// CHECK-FIXES: {{^}}(void)(std::string_view{""}) /* a8 */;
 
 (void)(std::string_view{{(nullptr)}}) /* a9 */;
-// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a9 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}empty string
+// CHECK-FIXES: {{^}}(void)(std::string_view{""}) /* a9 */;
 
 (void)(std::string_view{{}}) /* a10 */; // Default `const CharT*`
-// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default
-// CHECK-FIXES: {{^}}(void)(std::string_view{}) /* a10 */;
+// CHECK-MESSAGES: :[[@LINE-1]]:

[PATCH] D115452: Prevent abseil-cleanup-ctad check from stomping on surrounding context

2021-12-09 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson created this revision.
CJ-Johnson added a reviewer: ymandel.
Herald added a subscriber: carlosgalvezp.
CJ-Johnson requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

This change applies two fixes to the abseil-cleanup-ctad check. It uses 
hasSingleDecl() to ensure only declStmt()s with one varDecl() are matched 
(leaving compount declStmt()s unchanged). It also addresses a bug in the 
handling of comments that surround the absl::MakeCleanup() calls by switching 
to the callArgs() combinator from Clang Transformer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115452

Files:
  clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
@@ -81,35 +81,25 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class 
template argument deduction pattern in C++17 and higher
   // CHECK-FIXES: {{^}}  absl::Cleanup a = [] {};{{$}}
 
-  // Removes extra parens
-  auto b = absl::MakeCleanup(([] {}));
+  auto b = absl::MakeCleanup(std::function([] {}));
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  absl::Cleanup b = [] {};{{$}}
+  // CHECK-FIXES: {{^}}  absl::Cleanup b = std::function([] {});{{$}}
 
-  auto c = absl::MakeCleanup(std::function([] {}));
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  absl::Cleanup c = std::function([] {});{{$}}
-
-  // Removes extra parens
-  auto d = absl::MakeCleanup((std::function([] {})));
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  absl::Cleanup d = std::function([] {});{{$}}
-
-  const auto e = absl::MakeCleanup([] {});
+  const auto c = absl::MakeCleanup([] {});
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  const absl::Cleanup e = [] {};{{$}}
+  // CHECK-FIXES: {{^}}  const absl::Cleanup c = [] {};{{$}}
 
-  // Removes extra parens
-  const auto f = absl::MakeCleanup(([] {}));
+  const auto d = absl::MakeCleanup(std::function([] {}));
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  const absl::Cleanup f = [] {};{{$}}
+  // CHECK-FIXES: {{^}}  const absl::Cleanup d = std::function([] 
{});{{$}}
 
-  const auto g = absl::MakeCleanup(std::function([] {}));
-  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  const absl::Cleanup g = std::function([] 
{});{{$}}
+  // Preserves extra parens
+  auto e = absl::MakeCleanup(([] {}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup e = ([] {});{{$}}
 
-  // Removes extra parens
-  const auto h = absl::MakeCleanup((std::function([] {})));
-  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
-  // CHECK-FIXES: {{^}}  const absl::Cleanup h = std::function([] 
{});{{$}}
+  // Preserves comments
+  auto f = /* a */ absl::MakeCleanup(/* b */ [] { /* c */ } /* d */) /* e */;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 
and higher
+  // CHECK-FIXES: {{^}}  absl::Cleanup f = /* a */ /* b */ [] { /* c */ } /* d 
*/ /* e */;{{$}}
 }
Index: clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
===
--- clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
+++ clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
@@ -28,16 +28,14 @@
  "deduction pattern in C++17 and higher");
 
   return makeRule(
-  declStmt(has(varDecl(
+  declStmt(hasSingleDecl(varDecl(
   hasType(autoType()), hasTypeLoc(typeLoc().bind("auto_type_loc")),
-  hasInitializer(traverse(
-  clang::TK_IgnoreUnlessSpelledInSource,
+  hasInitializer(hasDescendant(
   callExpr(callee(functionDecl(hasName("absl::MakeCleanup"))),
-   argumentCountIs(1),
-   hasArgument(0, expr().bind("make_cleanup_argument")))
+   argumentCountIs(1))
   .bind("make_cleanup_call")),
   {changeTo(node("auto_type_loc"), cat("absl::Cleanup")),
-   changeTo(node("make_cleanup_call"), 
cat(node("make_cleanup_argument")))},
+   changeTo(node("make_cleanup_call"), 
cat(callArgs("make_cleanup_call")))},
   warning_message);
 }
 


Index: clang-tools-ex