[libcxx] r331910 - Allow copy elision in path concatenation
Author: xbolva00 Date: Wed May 9 11:57:17 2018 New Revision: 331910 URL: http://llvm.org/viewvc/llvm-project?rev=331910&view=rev Log: Allow copy elision in path concatenation Summary: Just port of libstdc++'s fix to libc++ fs: https://github.com/gcc-mirror/gcc/commit/e6ac4004fe49d785c63bf87aec4b095b5ce1d19f Author of fix: Jonathan Wakely Reviewers: EricWF, mclow.lists Reviewed By: EricWF Subscribers: smeenai, christof, cfe-commits, llvm-commits Differential Revision: https://reviews.llvm.org/D46593 Modified: libcxx/trunk/include/experimental/filesystem Modified: libcxx/trunk/include/experimental/filesystem URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/filesystem?rev=331910&r1=331909&r2=331910&view=diff == --- libcxx/trunk/include/experimental/filesystem (original) +++ libcxx/trunk/include/experimental/filesystem Wed May 9 11:57:17 2018 @@ -1140,7 +1140,9 @@ bool operator>=(const path& __lhs, const inline _LIBCPP_INLINE_VISIBILITY path operator/(const path& __lhs, const path& __rhs) { -return path(__lhs) /= __rhs; +path __result(__lhs); +__result /= __rhs; +return __result; } template ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r333340 - [ClangDiagnostics] Silence warning about fallthrough after PrintFatalError
Author: xbolva00 Date: Sat May 26 02:24:00 2018 New Revision: 40 URL: http://llvm.org/viewvc/llvm-project?rev=40&view=rev Log: [ClangDiagnostics] Silence warning about fallthrough after PrintFatalError Summary: ClangDiagnosticsEmitter.cpp:1047:57: warning: this statement may fall through [-Wimplicit-fallthrough=] Builder.PrintFatalError("Unknown modifier type: " + Modifier); ~~^~ ClangDiagnosticsEmitter.cpp:1048:5: note: here case MT_Select: { ^ Reviewers: rsmith, rtrieu Reviewed By: rtrieu Subscribers: rtrieu, ilya-biryukov, ioeric, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D47340 Modified: cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp Modified: cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp?rev=40&r1=39&r2=40&view=diff == --- cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp (original) +++ cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp Sat May 26 02:24:00 2018 @@ -633,7 +633,7 @@ struct DiagnosticTextBuilder { return It->second.Root; } - void PrintFatalError(llvm::Twine const &Msg) const { + LLVM_ATTRIBUTE_NORETURN void PrintFatalError(llvm::Twine const &Msg) const { assert(EvaluatingRecord && "not evaluating a record?"); llvm::PrintFatalError(EvaluatingRecord->getLoc(), Msg); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r342139 - Print correctly dependency paths on Windows
Author: xbolva00 Date: Thu Sep 13 07:27:32 2018 New Revision: 342139 URL: http://llvm.org/viewvc/llvm-project?rev=342139&view=rev Log: Print correctly dependency paths on Windows Summary: Before: main.o: main.c ../include/lib\test.h After: main.o: main.c ../include/lib/test.h Fixes PR38877 Reviewers: zturner Subscribers: xbolva00, cfe-commits Differential Revision: https://reviews.llvm.org/D51847 Modified: cfe/trunk/lib/Frontend/DependencyFile.cpp cfe/trunk/test/Frontend/dependency-gen-escaping.c cfe/trunk/test/Frontend/dependency-gen.c cfe/trunk/test/Modules/relative-dep-gen.cpp Modified: cfe/trunk/lib/Frontend/DependencyFile.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DependencyFile.cpp?rev=342139&r1=342138&r2=342139&view=diff == --- cfe/trunk/lib/Frontend/DependencyFile.cpp (original) +++ cfe/trunk/lib/Frontend/DependencyFile.cpp Thu Sep 13 07:27:32 2018 @@ -386,28 +386,32 @@ bool DFGImpl::AddFilename(StringRef File /// for Windows file-naming info. static void PrintFilename(raw_ostream &OS, StringRef Filename, DependencyOutputFormat OutputFormat) { + // Convert filename to platform native path + llvm::SmallString<256> NativePath; + llvm::sys::path::native(Filename.str(), NativePath); + if (OutputFormat == DependencyOutputFormat::NMake) { // Add quotes if needed. These are the characters listed as "special" to // NMake, that are legal in a Windows filespec, and that could cause // misinterpretation of the dependency string. -if (Filename.find_first_of(" #${}^!") != StringRef::npos) - OS << '\"' << Filename << '\"'; +if (NativePath.find_first_of(" #${}^!") != StringRef::npos) + OS << '\"' << NativePath << '\"'; else - OS << Filename; + OS << NativePath; return; } assert(OutputFormat == DependencyOutputFormat::Make); - for (unsigned i = 0, e = Filename.size(); i != e; ++i) { -if (Filename[i] == '#') // Handle '#' the broken gcc way. + for (unsigned i = 0, e = NativePath.size(); i != e; ++i) { +if (NativePath[i] == '#') // Handle '#' the broken gcc way. OS << '\\'; -else if (Filename[i] == ' ') { // Handle space correctly. +else if (NativePath[i] == ' ') { // Handle space correctly. OS << '\\'; unsigned j = i; - while (j > 0 && Filename[--j] == '\\') + while (j > 0 && NativePath[--j] == '\\') OS << '\\'; -} else if (Filename[i] == '$') // $ is escaped by $$. +} else if (NativePath[i] == '$') // $ is escaped by $$. OS << '$'; -OS << Filename[i]; +OS << NativePath[i]; } } Modified: cfe/trunk/test/Frontend/dependency-gen-escaping.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/dependency-gen-escaping.c?rev=342139&r1=342138&r2=342139&view=diff == --- cfe/trunk/test/Frontend/dependency-gen-escaping.c (original) +++ cfe/trunk/test/Frontend/dependency-gen-escaping.c Thu Sep 13 07:27:32 2018 @@ -21,7 +21,7 @@ // Backslash followed by # or space should escape both characters, because // that's what GNU Make wants. GCC does the right thing with space, but not // #, so Clang does too. (There should be 3 backslashes before the #.) -// SEP2F: a\b\\#c\\\ d.h +// SEP2F: a{{[/\\]}}b{{[/\\]}}\#c{{/|}}\ d.h // With -fms-compatibility, Backslashes in #include are treated as path separators. // Backslashes are given in the emission for special characters, like 0x20 or 0x23. // SEP5C: a{{[/\\]}}b{{[/\\]}}\#c{{/|}}\ d.h Modified: cfe/trunk/test/Frontend/dependency-gen.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/dependency-gen.c?rev=342139&r1=342138&r2=342139&view=diff == --- cfe/trunk/test/Frontend/dependency-gen.c (original) +++ cfe/trunk/test/Frontend/dependency-gen.c Thu Sep 13 07:27:32 2018 @@ -4,19 +4,19 @@ // RUN: echo > %t.dir/a/b/x.h // RUN: cd %t.dir // RUN: %clang -MD -MF - %s -fsyntax-only -I a/b | FileCheck -check-prefix=CHECK-ONE %s -// CHECK-ONE: {{ }}a/b{{[/\\]}}x.h +// CHECK-ONE: {{ }}a{{[/\\]}}b{{[/\\]}}x.h // PR8974 (-include flag) // RUN: %clang -MD -MF - %s -fsyntax-only -include a/b/x.h -DINCLUDE_FLAG_TEST | FileCheck -check-prefix=CHECK-TWO %s -// CHECK-TWO: {{ }}a/b/x.h +// CHECK-TWO: {{ }}a{{[/\\]}}b{{[/\\]}}x.h // rdar://problem/9734352 (paths involving ".") // RUN: %clang -MD -MF - %s -fsyntax-only -I ./a/b | FileCheck -check-prefix=CHECK-THREE %s -// CHECK-THREE: {{ }}a/b{{[/\\]}}x.h +// CHECK-THREE: {{ }}a{{[/\\]}}b{{[/\\]}}x.h // RUN: %clang -MD -MF - %s -fsyntax-only -I .//./a/b/ | FileCheck -check-prefix=CHECK-FOUR %s -// CHECK-FOUR: {{ }}a/b{{[/\\]}}x.h +// CHECK-FOUR: {{ }}a{{[/\\]}}b{{[/\\]}}x.h // RUN: %clang -MD -MF - %s -fsyntax-only -I a/b/. | FileCheck -check-
r338385 - [RISCV] Add driver for riscv32-unknown-elf baremetal target
Author: xbolva00 Date: Tue Jul 31 07:21:46 2018 New Revision: 338385 URL: http://llvm.org/viewvc/llvm-project?rev=338385&view=rev Log: [RISCV] Add driver for riscv32-unknown-elf baremetal target Summary: This patch adds a driver for the baremetal RISC-V target (i.e. riscv32-unknown-elf). For reference, D39963 added basic target info and added support for riscv32-linux-unknown-elf. Patch by: asb (Alex Bradbury) Reviewers: efriedma, phosek, apazos, espindola, mgrang Reviewed By: mgrang Subscribers: jrtc27, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, emaste, mgorny, arichardson, rbar, johnrusso, simoncook, jordy.potman.lists, sabuasal, niosHD, kito-cheng, shiva0217, zzheng, edward-jones, mgrang, cfe-commits Differential Revision: https://reviews.llvm.org/D46822 Added: cfe/trunk/lib/Driver/ToolChains/RISCV.cpp cfe/trunk/lib/Driver/ToolChains/RISCV.h cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/ cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/bin/ cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/bin/riscv32-unknown-elf-ld (with props) cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/lib/ cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/lib/gcc/ cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/lib/gcc/riscv32-unknown-elf/ cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/lib/gcc/riscv32-unknown-elf/8.0.1/ cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/lib/gcc/riscv32-unknown-elf/8.0.1/crtbegin.o cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/lib/gcc/riscv32-unknown-elf/8.0.1/crtend.o cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/riscv32-unknown-elf/ cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/riscv32-unknown-elf/include/ cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/riscv32-unknown-elf/include/c++/ cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/riscv32-unknown-elf/include/c++/8.0.1/ cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/riscv32-unknown-elf/include/c++/8.0.1/.keep cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/riscv32-unknown-elf/lib/ cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/riscv32-unknown-elf/lib/crt0.o Modified: cfe/trunk/lib/Driver/CMakeLists.txt cfe/trunk/lib/Driver/Driver.cpp cfe/trunk/lib/Driver/ToolChains/Gnu.cpp cfe/trunk/test/Driver/riscv32-toolchain.c Modified: cfe/trunk/lib/Driver/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/CMakeLists.txt?rev=338385&r1=338384&r2=338385&view=diff == --- cfe/trunk/lib/Driver/CMakeLists.txt (original) +++ cfe/trunk/lib/Driver/CMakeLists.txt Tue Jul 31 07:21:46 2018 @@ -57,6 +57,7 @@ add_clang_library(clangDriver ToolChains/NetBSD.cpp ToolChains/OpenBSD.cpp ToolChains/PS4CPU.cpp + ToolChains/RISCV.cpp ToolChains/Solaris.cpp ToolChains/TCE.cpp ToolChains/WebAssembly.cpp Modified: cfe/trunk/lib/Driver/Driver.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=338385&r1=338384&r2=338385&view=diff == --- cfe/trunk/lib/Driver/Driver.cpp (original) +++ cfe/trunk/lib/Driver/Driver.cpp Tue Jul 31 07:21:46 2018 @@ -37,6 +37,7 @@ #include "ToolChains/NetBSD.h" #include "ToolChains/OpenBSD.h" #include "ToolChains/PS4CPU.h" +#include "ToolChains/RISCV.h" #include "ToolChains/Solaris.h" #include "ToolChains/TCE.h" #include "ToolChains/WebAssembly.h" @@ -4399,6 +4400,10 @@ const ToolChain &Driver::getToolChain(co case llvm::Triple::avr: TC = llvm::make_unique(*this, Target, Args); break; + case llvm::Triple::riscv32: + case llvm::Triple::riscv64: +TC = llvm::make_unique(*this, Target, Args); +break; default: if (Target.getVendor() == llvm::Triple::Myriad) TC = llvm::make_unique(*this, Target, Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=338385&r1=338384&r2=338385&view=diff == --- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Tue Jul 31 07:21:46 2018 @@ -1877,7 +1877,8 @@ void Generic_GCC::GCCInstallationDetecto static const char *const RISCV32LibDirs[] = {"/lib", "/lib32"}; static const char *const RISCVTriples[] = {"riscv32-unknown-linux-gnu", - "riscv64-unknown-linux-gnu"}; + "riscv64-unknown-linux-gnu", + "riscv32-unknown-elf"}; static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"}; static const char *const SPARCv8Triples[] = {"sparc-linux-gnu", Added: cfe/trunk/lib/Driver/ToolChains/RISCV.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/
r338971 - Fix tests for changed opt remarks format
Author: xbolva00 Date: Sun Aug 5 07:53:34 2018 New Revision: 338971 URL: http://llvm.org/viewvc/llvm-project?rev=338971&view=rev Log: Fix tests for changed opt remarks format Summary: Optimization remark format is slightly changed by LLVM patch D49412. Two tests are fixed with expected messages changed. Frankly speaking I have not tested this change yet. I will test when manage to setup the project. Reviewers: xbolva00 Reviewed By: xbolva00 Subscribers: mehdi_amini, eraman, steven_wu, dexonsmith Differential Revision: https://reviews.llvm.org/D50241 Modified: cfe/trunk/test/CodeGen/thinlto-diagnostic-handler-remarks-with-hotness.ll cfe/trunk/test/Frontend/optimization-remark-with-hotness.c Modified: cfe/trunk/test/CodeGen/thinlto-diagnostic-handler-remarks-with-hotness.ll URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/thinlto-diagnostic-handler-remarks-with-hotness.ll?rev=338971&r1=338970&r2=338971&view=diff == --- cfe/trunk/test/CodeGen/thinlto-diagnostic-handler-remarks-with-hotness.ll (original) +++ cfe/trunk/test/CodeGen/thinlto-diagnostic-handler-remarks-with-hotness.ll Sun Aug 5 07:53:34 2018 @@ -19,9 +19,10 @@ ; YAML-NEXT: - Callee: tinkywinky ; YAML-NEXT: - String: ' inlined into ' ; YAML-NEXT: - Caller: main -; YAML-NEXT: - String: ' with cost=' +; YAML-NEXT: - String: ' with ' +; YAML-NEXT: - String: '(cost=' ; YAML-NEXT: - Cost:'0' -; YAML-NEXT: - String: ' (threshold=' +; YAML-NEXT: - String: ', threshold=' ; YAML-NEXT: - Threshold: '337' ; YAML-NEXT: - String: ')' ; YAML-NEXT: ... @@ -29,7 +30,7 @@ ; Next try with pass remarks to stderr ; RUN: %clang -target x86_64-scei-ps4 -O2 -x ir %t.o -fthinlto-index=%t.thinlto.bc -mllvm -pass-remarks=inline -fdiagnostics-show-hotness -o %t2.o -c 2>&1 | FileCheck %s -; CHECK: tinkywinky inlined into main with cost=0 (threshold=337) (hotness: 300) +; CHECK: tinkywinky inlined into main with (cost=0, threshold=337) (hotness: 300) target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-scei-ps4" Modified: cfe/trunk/test/Frontend/optimization-remark-with-hotness.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/optimization-remark-with-hotness.c?rev=338971&r1=338970&r2=338971&view=diff == --- cfe/trunk/test/Frontend/optimization-remark-with-hotness.c (original) +++ cfe/trunk/test/Frontend/optimization-remark-with-hotness.c Sun Aug 5 07:53:34 2018 @@ -60,13 +60,13 @@ void bar(int x) { // THRESHOLD-NOT: hotness // NO_PGO: '-fdiagnostics-show-hotness' requires profile-guided optimization information // NO_PGO: '-fdiagnostics-hotness-threshold=' requires profile-guided optimization information - // expected-remark@+1 {{foo inlined into bar with cost=always (hotness:}} + // expected-remark@+1 {{foo inlined into bar with (cost=always): always inliner (hotness:}} sum += foo(x, x - 2); } int main(int argc, const char *argv[]) { for (int i = 0; i < 30; i++) -// expected-remark@+1 {{bar not inlined into main because it should never be inlined (cost=never) (hotness:}} +// expected-remark@+1 {{bar not inlined into main because it should never be inlined (cost=never): always inliner (hotness:}} bar(argc); return sum; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r344759 - [Diagnostics] Check for integer overflow in array size expressions
Author: xbolva00 Date: Thu Oct 18 13:49:06 2018 New Revision: 344759 URL: http://llvm.org/viewvc/llvm-project?rev=344759&view=rev Log: [Diagnostics] Check for integer overflow in array size expressions Summary: Fixes PR27439 Reviewers: rsmith, Rakete Reviewed By: rsmith Subscribers: Rakete, cfe-commits Differential Revision: https://reviews.llvm.org/D52750 Modified: cfe/trunk/include/clang/AST/Expr.h cfe/trunk/lib/AST/ExprConstant.cpp cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/Sema/integer-overflow.c Modified: cfe/trunk/include/clang/AST/Expr.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=344759&r1=344758&r2=344759&view=diff == --- cfe/trunk/include/clang/AST/Expr.h (original) +++ cfe/trunk/include/clang/AST/Expr.h Thu Oct 18 13:49:06 2018 @@ -631,8 +631,13 @@ public: /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded /// integer. This must be called on an expression that constant folds to an /// integer. - llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, -SmallVectorImpl *Diag = nullptr) const; + llvm::APSInt EvaluateKnownConstInt( + const ASTContext &Ctx, + SmallVectorImpl *Diag = nullptr) const; + + llvm::APSInt EvaluateKnownConstIntCheckOverflow( + const ASTContext &Ctx, + SmallVectorImpl *Diag = nullptr) const; void EvaluateForOverflow(const ASTContext &Ctx) const; Modified: cfe/trunk/lib/AST/ExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=344759&r1=344758&r2=344759&view=diff == --- cfe/trunk/lib/AST/ExprConstant.cpp (original) +++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Oct 18 13:49:06 2018 @@ -10851,6 +10851,19 @@ APSInt Expr::EvaluateKnownConstInt(const return EvalResult.Val.getInt(); } +APSInt Expr::EvaluateKnownConstIntCheckOverflow( +const ASTContext &Ctx, SmallVectorImpl *Diag) const { + EvalResult EvalResult; + EvalResult.Diag = Diag; + EvalInfo Info(Ctx, EvalResult, EvalInfo::EM_EvaluateForOverflow); + bool Result = ::EvaluateAsRValue(Info, this, EvalResult.Val); + (void)Result; + assert(Result && "Could not evaluate expression"); + assert(EvalResult.Val.isInt() && "Expression did not evaluate to integer"); + + return EvalResult.Val.getInt(); +} + void Expr::EvaluateForOverflow(const ASTContext &Ctx) const { bool IsConst; EvalResult EvalResult; Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=344759&r1=344758&r2=344759&view=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Oct 18 13:49:06 2018 @@ -14105,7 +14105,7 @@ Sema::VerifyIntegerConstantExpression(Ex // in the non-ICE case. if (!getLangOpts().CPlusPlus11 && E->isIntegerConstantExpr(Context)) { if (Result) - *Result = E->EvaluateKnownConstInt(Context); + *Result = E->EvaluateKnownConstIntCheckOverflow(Context); return E; } Modified: cfe/trunk/test/Sema/integer-overflow.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/integer-overflow.c?rev=344759&r1=344758&r2=344759&view=diff == --- cfe/trunk/test/Sema/integer-overflow.c (original) +++ cfe/trunk/test/Sema/integer-overflow.c Thu Oct 18 13:49:06 2018 @@ -172,6 +172,9 @@ void check_integer_overflows_in_function // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}} (void)f2(0, f0(4608 * 1024 * 1024)); } +void check_integer_overflows_in_array_size() { + int arr[4608 * 1024 * 1024]; // expected-warning {{overflow in expression; result is 536870912 with type 'int'}} +} struct s { unsigned x; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r344761 - [Diagnostics] Add missing expected warning to test file
Author: xbolva00 Date: Thu Oct 18 14:06:14 2018 New Revision: 344761 URL: http://llvm.org/viewvc/llvm-project?rev=344761&view=rev Log: [Diagnostics] Add missing expected warning to test file Modified: cfe/trunk/test/SemaCXX/enum.cpp Modified: cfe/trunk/test/SemaCXX/enum.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enum.cpp?rev=344761&r1=344760&r2=344761&view=diff == --- cfe/trunk/test/SemaCXX/enum.cpp (original) +++ cfe/trunk/test/SemaCXX/enum.cpp Thu Oct 18 14:06:14 2018 @@ -105,7 +105,7 @@ void PR8089() { // This is accepted as a GNU extension. In C++98, there was no provision for // expressions with UB to be non-constant. -enum { overflow = 123456 * 234567 }; +enum { overflow = 123456 * 234567 }; // expected-warning {{overflow in expression; result is -1106067520 with type 'int'}} #if __cplusplus >= 201103L // expected-warning@-2 {{not an integral constant expression}} // expected-note@-3 {{value 28958703552 is outside the range of representable values}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r344762 - [Test] Fix test file for C++98 mode
Author: xbolva00 Date: Thu Oct 18 14:26:01 2018 New Revision: 344762 URL: http://llvm.org/viewvc/llvm-project?rev=344762&view=rev Log: [Test] Fix test file for C++98 mode Modified: cfe/trunk/test/SemaCXX/enum.cpp Modified: cfe/trunk/test/SemaCXX/enum.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enum.cpp?rev=344762&r1=344761&r2=344762&view=diff == --- cfe/trunk/test/SemaCXX/enum.cpp (original) +++ cfe/trunk/test/SemaCXX/enum.cpp Thu Oct 18 14:26:01 2018 @@ -105,10 +105,12 @@ void PR8089() { // This is accepted as a GNU extension. In C++98, there was no provision for // expressions with UB to be non-constant. -enum { overflow = 123456 * 234567 }; // expected-warning {{overflow in expression; result is -1106067520 with type 'int'}} +enum { overflow = 123456 * 234567 }; #if __cplusplus >= 201103L // expected-warning@-2 {{not an integral constant expression}} // expected-note@-3 {{value 28958703552 is outside the range of representable values}} +#else +// expected-warning@-5 {{overflow in expression; result is -1106067520 with type 'int'}} #endif // PR28903 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r345847 - [Diagnostics] Implement -Wsizeof-pointer-div
Author: xbolva00 Date: Thu Nov 1 09:26:10 2018 New Revision: 345847 URL: http://llvm.org/viewvc/llvm-project?rev=345847&view=rev Log: [Diagnostics] Implement -Wsizeof-pointer-div Summary: void test(int *arr) { int arr_len = sizeof(arr) / sizeof(*arr); // warn, incorrect way to compute number of array elements } Enabled under -Wall (same behaviour as GCC) Reviewers: rsmith, MTC, aaron.ballman Reviewed By: aaron.ballman Subscribers: MTC, thakis, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D52949 Added: cfe/trunk/test/Sema/div-sizeof-ptr.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaExpr.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=345847&r1=345846&r2=345847&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Nov 1 09:26:10 2018 @@ -3294,6 +3294,10 @@ def warn_address_of_reference_null_compa InGroup; def note_reference_is_return_value : Note<"%0 returns a reference">; +def warn_division_sizeof_ptr : Warning< + "'%0' will return the size of the pointer, not the array itself">, + InGroup>; + def note_function_warning_silence : Note< "prefix with the address-of operator to silence this warning">; def note_function_to_function_call : Note< Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=345847&r1=345846&r2=345847&view=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Nov 1 09:26:10 2018 @@ -8726,6 +8726,32 @@ static void checkArithmeticNull(Sema &S, << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); } +static void DiagnoseDivisionSizeofPointer(Sema &S, Expr *LHS, Expr *RHS, + SourceLocation Loc) { + const auto *LUE = dyn_cast(LHS); + const auto *RUE = dyn_cast(RHS); + if (!LUE || !RUE) +return; + if (LUE->getKind() != UETT_SizeOf || LUE->isArgumentType() || + RUE->getKind() != UETT_SizeOf) +return; + + QualType LHSTy = LUE->getArgumentExpr()->IgnoreParens()->getType(); + QualType RHSTy; + + if (RUE->isArgumentType()) +RHSTy = RUE->getArgumentType(); + else +RHSTy = RUE->getArgumentExpr()->IgnoreParens()->getType(); + + if (!LHSTy->isPointerType() || RHSTy->isPointerType()) +return; + if (LHSTy->getPointeeType() != RHSTy) +return; + + S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS << LHS->getSourceRange(); +} + static void DiagnoseBadDivideOrRemainderValues(Sema& S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsDiv) { @@ -8756,8 +8782,10 @@ QualType Sema::CheckMultiplyDivideOperan if (compType.isNull() || !compType->isArithmeticType()) return InvalidOperands(Loc, LHS, RHS); - if (IsDiv) + if (IsDiv) { DiagnoseBadDivideOrRemainderValues(*this, LHS, RHS, Loc, IsDiv); +DiagnoseDivisionSizeofPointer(*this, LHS.get(), RHS.get(), Loc); + } return compType; } @@ -16603,4 +16631,4 @@ ExprResult Sema::ActOnObjCAvailabilityCh return new (Context) ObjCAvailabilityCheckExpr(Version, AtLoc, RParen, Context.BoolTy); -} +} \ No newline at end of file Added: cfe/trunk/test/Sema/div-sizeof-ptr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/div-sizeof-ptr.cpp?rev=345847&view=auto == --- cfe/trunk/test/Sema/div-sizeof-ptr.cpp (added) +++ cfe/trunk/test/Sema/div-sizeof-ptr.cpp Thu Nov 1 09:26:10 2018 @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 %s -verify -Wsizeof-pointer-div -fsyntax-only + +template +int f(Ty (&Array)[N]) { + return sizeof(Array) / sizeof(Ty); // Should not warn +} + +void test(int *p, int **q) { + int a1 = sizeof(p) / sizeof(*p); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}} + int a2 = sizeof p / sizeof *p; // expected-warning {{'sizeof p' will return the size of the pointer, not the array itself}} + int a3 = sizeof(*q) / sizeof(**q); // expected-warning {{'sizeof (*q)' will return the size of the pointer, not the array itself}} + int a4 = sizeof(p) / sizeof(int); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}} + int a5 = sizeof(p) / sizeof(p[0]); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}} + + // Should not warn + int b1 = sizeof(int *) / sizeof(int); + int b2 = sizeof(p) / sizeof(p); + int b3 = sizeof(*q) / sizeof(q); +
r346865 - [Diagnostics] Check integer to floating point number implicit conversions
Author: xbolva00 Date: Wed Nov 14 06:24:33 2018 New Revision: 346865 URL: http://llvm.org/viewvc/llvm-project?rev=346865&view=rev Log: [Diagnostics] Check integer to floating point number implicit conversions Summary: GCC already catches these situations so we should handle it too. GCC warns in C++ mode only (does anybody know why?). I think it is useful in C mode too. Reviewers: rsmith, erichkeane, aaron.ballman, efriedma, xbolva00 Reviewed By: xbolva00 Subscribers: efriedma, craig.topper, scanon, cfe-commits Differential Revision: https://reviews.llvm.org/D52835 Added: cfe/trunk/test/Sema/impcast-integer-float.c Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaChecking.cpp cfe/trunk/test/Sema/ext_vector_casts.c Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=346865&r1=346864&r2=346865&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Nov 14 06:24:33 2018 @@ -3229,6 +3229,10 @@ def warn_impcast_float_integer : Warning "implicit conversion turns floating-point number into integer: %0 to %1">, InGroup, DefaultIgnore; +def warn_impcast_precision_float_to_integer : Warning< + "implicit conversion from %0 to %1 changes value from %2 to %3">, + InGroup>; + def warn_impcast_float_to_integer : Warning< "implicit conversion from %0 to %1 changes value from %2 to %3">, InGroup, DefaultIgnore; Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=346865&r1=346864&r2=346865&view=diff == --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Nov 14 06:24:33 2018 @@ -105,6 +105,19 @@ SourceLocation Sema::getLocationOfString Context.getTargetInfo()); } +// FIXME: Force the precision of the source value down so we don't print +// digits which are usually useless (we don't really care here if we +// truncate a digit by accident in edge cases). Ideally, APFloat::toString +// would automatically print the shortest representation, but it's a bit +// tricky to implement. +static void PrettyPrintFloat(const llvm::APFloat &floatValue, + const llvm::fltSemantics &floatSem, + SmallVectorImpl &prettyFloatValue) { + unsigned precision = llvm::APFloat::semanticsPrecision(floatSem); + precision = llvm::divideCeil(precision * 59, 196); + floatValue.toString(prettyFloatValue, precision); +} + /// Checks that a call expression's argument count is the desired number. /// This is useful when doing custom type-checking. Returns true on error. static bool checkArgCount(Sema &S, CallExpr *call, unsigned desiredArgCount) { @@ -10473,15 +10486,8 @@ static void DiagnoseFloatingImpCast(Sema DiagID = diag::warn_impcast_float_to_integer; } - // FIXME: Force the precision of the source value down so we don't print - // digits which are usually useless (we don't really care here if we - // truncate a digit by accident in edge cases). Ideally, APFloat::toString - // would automatically print the shortest representation, but it's a bit - // tricky to implement. SmallString<16> PrettySourceValue; - unsigned precision = llvm::APFloat::semanticsPrecision(Value.getSemantics()); - precision = (precision * 59 + 195) / 196; - Value.toString(PrettySourceValue, precision); + PrettyPrintFloat(Value, Value.getSemantics(), PrettySourceValue); SmallString<16> PrettyTargetValue; if (IsBool) @@ -10914,6 +10920,32 @@ CheckImplicitConversion(Sema &S, Expr *E return; } + if (Source->isIntegerType() && TargetBT && TargetBT->isFloatingType()) { +llvm::APSInt IntValue; +if (E->EvaluateAsInt(IntValue, S.Context, Expr::SE_AllowSideEffects)) { + if (S.SourceMgr.isInSystemMacro(CC)) +return; + const llvm::fltSemantics &FloatSemantics = + S.Context.getFloatTypeSemantics(QualType(TargetBT, 0)); + llvm::APFloat FloatValue(FloatSemantics); + if (FloatValue.convertFromAPInt(IntValue, Source->isSignedIntegerType(), + llvm::APFloat::rmNearestTiesToEven) != + llvm::APFloat::opOK) { +SmallString<16> PrettyTargetValue; +SmallString<16> PrettySourceValue; +PrettyPrintFloat(FloatValue, FloatSemantics, PrettyTargetValue); +IntValue.toString(PrettySourceValue); + +S.DiagRuntimeBehavior( +E->getExprLoc(), E, +S.PDiag(diag::warn_impcast_precision_float_to_integer) +<< E->getType() << T << PrettySourceValue << PrettyTargetValue +
r346866 - Reverted D52835 to fix review comments
Author: xbolva00 Date: Wed Nov 14 06:27:51 2018 New Revision: 346866 URL: http://llvm.org/viewvc/llvm-project?rev=346866&view=rev Log: Reverted D52835 to fix review comments Removed: cfe/trunk/test/Sema/impcast-integer-float.c Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaChecking.cpp cfe/trunk/test/Sema/ext_vector_casts.c Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=346866&r1=346865&r2=346866&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Nov 14 06:27:51 2018 @@ -3229,10 +3229,6 @@ def warn_impcast_float_integer : Warning "implicit conversion turns floating-point number into integer: %0 to %1">, InGroup, DefaultIgnore; -def warn_impcast_precision_float_to_integer : Warning< - "implicit conversion from %0 to %1 changes value from %2 to %3">, - InGroup>; - def warn_impcast_float_to_integer : Warning< "implicit conversion from %0 to %1 changes value from %2 to %3">, InGroup, DefaultIgnore; Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=346866&r1=346865&r2=346866&view=diff == --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Nov 14 06:27:51 2018 @@ -105,19 +105,6 @@ SourceLocation Sema::getLocationOfString Context.getTargetInfo()); } -// FIXME: Force the precision of the source value down so we don't print -// digits which are usually useless (we don't really care here if we -// truncate a digit by accident in edge cases). Ideally, APFloat::toString -// would automatically print the shortest representation, but it's a bit -// tricky to implement. -static void PrettyPrintFloat(const llvm::APFloat &floatValue, - const llvm::fltSemantics &floatSem, - SmallVectorImpl &prettyFloatValue) { - unsigned precision = llvm::APFloat::semanticsPrecision(floatSem); - precision = llvm::divideCeil(precision * 59, 196); - floatValue.toString(prettyFloatValue, precision); -} - /// Checks that a call expression's argument count is the desired number. /// This is useful when doing custom type-checking. Returns true on error. static bool checkArgCount(Sema &S, CallExpr *call, unsigned desiredArgCount) { @@ -10486,8 +10473,15 @@ static void DiagnoseFloatingImpCast(Sema DiagID = diag::warn_impcast_float_to_integer; } + // FIXME: Force the precision of the source value down so we don't print + // digits which are usually useless (we don't really care here if we + // truncate a digit by accident in edge cases). Ideally, APFloat::toString + // would automatically print the shortest representation, but it's a bit + // tricky to implement. SmallString<16> PrettySourceValue; - PrettyPrintFloat(Value, Value.getSemantics(), PrettySourceValue); + unsigned precision = llvm::APFloat::semanticsPrecision(Value.getSemantics()); + precision = (precision * 59 + 195) / 196; + Value.toString(PrettySourceValue, precision); SmallString<16> PrettyTargetValue; if (IsBool) @@ -10920,32 +10914,6 @@ CheckImplicitConversion(Sema &S, Expr *E return; } - if (Source->isIntegerType() && TargetBT && TargetBT->isFloatingType()) { -llvm::APSInt IntValue; -if (E->EvaluateAsInt(IntValue, S.Context, Expr::SE_AllowSideEffects)) { - if (S.SourceMgr.isInSystemMacro(CC)) -return; - const llvm::fltSemantics &FloatSemantics = - S.Context.getFloatTypeSemantics(QualType(TargetBT, 0)); - llvm::APFloat FloatValue(FloatSemantics); - if (FloatValue.convertFromAPInt(IntValue, Source->isSignedIntegerType(), - llvm::APFloat::rmNearestTiesToEven) != - llvm::APFloat::opOK) { -SmallString<16> PrettyTargetValue; -SmallString<16> PrettySourceValue; -PrettyPrintFloat(FloatValue, FloatSemantics, PrettyTargetValue); -IntValue.toString(PrettySourceValue); - -S.DiagRuntimeBehavior( -E->getExprLoc(), E, -S.PDiag(diag::warn_impcast_precision_float_to_integer) -<< E->getType() << T << PrettySourceValue << PrettyTargetValue -<< E->getSourceRange() << clang::SourceRange(CC)); -return; - } -} - } - DiagnoseNullConversion(S, E, T, CC); S.DiscardMisalignedMemberAddress(Target, E); Modified: cfe/trunk/test/Sema/ext_vector_casts.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ext_vector_casts.c?rev=346866&r1=346865&r2=346866&view=diff ===
r359516 - [Diagnostics] Support -Wtype-limits for GCC compatibility
Author: xbolva00 Date: Mon Apr 29 16:24:00 2019 New Revision: 359516 URL: http://llvm.org/viewvc/llvm-project?rev=359516&view=rev Log: [Diagnostics] Support -Wtype-limits for GCC compatibility Summary: GCC's -Wtype-limits (part of -Wextra): Warn if a comparison is always true or always false due to the limited range of the data type Reviewers: rsmith, aaron.ballman, lebedev.ri, thakis Reviewed By: rsmith Subscribers: lebedev.ri, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58841 Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td cfe/trunk/test/Sema/compare.c cfe/trunk/test/Sema/tautological-constant-compare.c cfe/trunk/test/Sema/tautological-constant-enum-compare.c cfe/trunk/test/SemaCXX/compare.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=359516&r1=359515&r2=359516&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Mon Apr 29 16:24:00 2019 @@ -485,6 +485,8 @@ def TautologicalInRangeCompare : DiagGro [TautologicalTypeLimitCompare, TautologicalUnsignedZeroCompare, TautologicalUnsignedEnumZeroCompare]>; +// For compatibility with GCC; -Wtype-limits = -Wtautological-constant-in-range-compare +def TypeLimits : DiagGroup<"type-limits", [TautologicalInRangeCompare]>; def TautologicalOutOfRangeCompare : DiagGroup<"tautological-constant-out-of-range-compare">; def TautologicalConstantCompare : DiagGroup<"tautological-constant-compare", [TautologicalOutOfRangeCompare]>; Modified: cfe/trunk/test/Sema/compare.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compare.c?rev=359516&r1=359515&r2=359516&view=diff == --- cfe/trunk/test/Sema/compare.c (original) +++ cfe/trunk/test/Sema/compare.c Mon Apr 29 16:24:00 2019 @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare -Wtautological-constant-in-range-compare %s -Wno-unreachable-code +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare -Wtype-limits %s -Wno-unreachable-code int test(char *C) { // nothing here should warn. return C != ((void*)0); Modified: cfe/trunk/test/Sema/tautological-constant-compare.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/tautological-constant-compare.c?rev=359516&r1=359515&r2=359516&view=diff == --- cfe/trunk/test/Sema/tautological-constant-compare.c (original) +++ cfe/trunk/test/Sema/tautological-constant-compare.c Mon Apr 29 16:24:00 2019 @@ -2,6 +2,8 @@ // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtautological-constant-in-range-compare -DTEST -verify -x c++ %s // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtautological-type-limit-compare -DTEST -verify %s // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtautological-type-limit-compare -DTEST -verify -x c++ %s +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtype-limits -DTEST -verify %s +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtype-limits -DTEST -verify -x c++ %s // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wextra -Wno-sign-compare -verify %s // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wextra -Wno-sign-compare -verify -x c++ %s // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wall -verify %s Modified: cfe/trunk/test/Sema/tautological-constant-enum-compare.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/tautological-constant-enum-compare.c?rev=359516&r1=359515&r2=359516&view=diff == --- cfe/trunk/test/Sema/tautological-constant-enum-compare.c (original) +++ cfe/trunk/test/Sema/tautological-constant-enum-compare.c Mon Apr 29 16:24:00 2019 @@ -2,6 +2,8 @@ // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED -Wtautological-constant-in-range-compare -verify %s // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED -DSILENCE -Wno-tautological-constant-compare -verify %s // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED -DSILENCE -Wno-tautological-constant-compare -verify %s +// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED -Wtype-limits -verify %s +// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED -DSILENCE -Wno-type-limits -verify %s int main() { enum A { A_a = 2 }
r343560 - Added warning for unary minus used with unsigned type
Author: xbolva00 Date: Mon Oct 1 23:02:30 2018 New Revision: 343560 URL: http://llvm.org/viewvc/llvm-project?rev=343560&view=rev Log: Added warning for unary minus used with unsigned type Summary: Inspired by MSVC, which found some occurrences of this expression on our code base. Fixes PR38950 Reviewers: rsmith, craig.topper, spatel, RKSimon, aaron.ballman, thakis Reviewed By: rsmith Subscribers: joerg, Quuxplusone, lebedev.ri, craig.topper, RKSimon, cfe-commits Differential Revision: https://reviews.llvm.org/D52137 Added: cfe/trunk/test/Sema/unary-minus-integer-impcast.c Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaChecking.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=343560&r1=343559&r2=343560&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Oct 1 23:02:30 2018 @@ -3197,6 +3197,12 @@ def warn_impcast_integer_sign_conditiona def warn_impcast_integer_precision : Warning< "implicit conversion loses integer precision: %0 to %1">, InGroup, DefaultIgnore; +def warn_impcast_high_order_zero_bits : Warning< + "higher order bits are zeroes after implicit conversion">, + InGroup, DefaultIgnore; +def warn_impcast_nonnegative_result : Warning< + "the resulting value is always non-negative after implicit conversion">, + InGroup, DefaultIgnore; def warn_impcast_integer_64_32 : Warning< "implicit conversion loses integer precision: %0 to %1">, InGroup, DefaultIgnore; Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=343560&r1=343559&r2=343560&view=diff == --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Oct 1 23:02:30 2018 @@ -10896,6 +10896,19 @@ CheckImplicitConversion(Sema &S, Expr *E return DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_integer_precision); } + if (TargetRange.Width > SourceRange.Width) { +if (auto *UO = dyn_cast(E)) + if (UO->getOpcode() == UO_Minus) +if (Source->isUnsignedIntegerType()) { + if (Target->isUnsignedIntegerType()) +return DiagnoseImpCast(S, E, T, CC, + diag::warn_impcast_high_order_zero_bits); + if (Target->isSignedIntegerType()) +return DiagnoseImpCast(S, E, T, CC, + diag::warn_impcast_nonnegative_result); +} + } + if (TargetRange.Width == SourceRange.Width && !TargetRange.NonNegative && SourceRange.NonNegative && Source->isSignedIntegerType()) { // Warn when doing a signed to signed conversion, warn if the positive Added: cfe/trunk/test/Sema/unary-minus-integer-impcast.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/unary-minus-integer-impcast.c?rev=343560&view=auto == --- cfe/trunk/test/Sema/unary-minus-integer-impcast.c (added) +++ cfe/trunk/test/Sema/unary-minus-integer-impcast.c Mon Oct 1 23:02:30 2018 @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 %s -verify -Wconversion -fsyntax-only -triple x86_64-pc-linux-gnu +// RUN: %clang_cc1 %s -verify -Wconversion -fsyntax-only -triple i386-pc-linux-gnu + +void test(void) { + unsigned int a = 1; + + unsigned long long b = -a; // expected-warning {{higher order bits are zeroes after implicit conversion}} + long long c = -a; // expected-warning {{the resulting value is always non-negative after implicit conversion}} + + unsigned long b2 = -a; +#ifdef __x86_64__ +// expected-warning@-2 {{higher order bits are zeroes after implicit conversion}} +#endif + long c2 = -a; +#ifdef __x86_64__ +// expected-warning@-2 {{the resulting value is always non-negative after implicit conversion}} +#else +// expected-warning@-4 {{implicit conversion changes signedness: 'unsigned int' to 'long'}} +#endif +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r368658 - [NFC] Updated tests after r368657
Author: xbolva00 Date: Tue Aug 13 02:12:07 2019 New Revision: 368658 URL: http://llvm.org/viewvc/llvm-project?rev=368658&view=rev Log: [NFC] Updated tests after r368657 Modified: cfe/trunk/test/CodeGen/tbaa-struct.cpp cfe/trunk/test/CodeGenCXX/auto-var-init.cpp Modified: cfe/trunk/test/CodeGen/tbaa-struct.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/tbaa-struct.cpp?rev=368658&r1=368657&r2=368658&view=diff == --- cfe/trunk/test/CodeGen/tbaa-struct.cpp (original) +++ cfe/trunk/test/CodeGen/tbaa-struct.cpp Tue Aug 13 02:12:07 2019 @@ -17,7 +17,7 @@ typedef A __attribute__((may_alias)) AA; void copy(A *a1, A *a2) { // CHECK-LABEL: _Z4copyP1AS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %{{.*}}, i8* align 4 %{{.*}}, i64 16, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(16) %{{.*}}, i8* align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_A:![0-9]*]] *a1 = *a2; @@ -31,7 +31,7 @@ struct B { void copy2(B *b1, B *b2) { // CHECK-LABEL: _Z5copy2P1BS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %{{.*}}, i8* align 4 %{{.*}}, i64 24, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(24) %{{.*}}, i8* align 4 dereferenceable(24) %{{.*}}, i64 24, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS2:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_B:![0-9]*]] *b1 = *b2; @@ -49,7 +49,7 @@ union U { void copy3(U *u1, U *u2) { // CHECK-LABEL: _Z5copy3P1US0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %{{.*}}, i8* align 4 %{{.*}}, i64 12, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(12) %{{.*}}, i8* align 4 dereferenceable(12) %{{.*}}, i64 12, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS3:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_U:![0-9]*]] *u1 = *u2; @@ -65,7 +65,7 @@ struct C { void copy4(C *c1, C *c2) { // CHECK-LABEL: _Z5copy4P1CS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* {{.*}}, i64 3, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) {{.*}}, i8* align 1 dereferenceable(3) {{.*}}, i64 3, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS4:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_C:![0-9]*]] *c1 = *c2; @@ -80,7 +80,7 @@ struct D { void copy5(D *d1, D *d2) { // CHECK-LABEL: _Z5copy5P1DS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* {{.*}}, i64 6, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(6) {{.*}}, i8* align 1 dereferenceable(6) {{.*}}, i64 6, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS5:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_D:![0-9]*]] *d1 = *d2; @@ -88,7 +88,7 @@ void copy5(D *d1, D *d2) { void copy6(AA *a1, A *a2) { // CHECK-LABEL: _Z5copy6P1AS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %{{.*}}, i8* align 4 %{{.*}}, i64 16, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(16) %{{.*}}, i8* align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS]] // CHECK-NEW-SAME: !tbaa [[TAG_char:![0-9]*]] *a1 = *a2; @@ -96,7 +96,7 @@ void copy6(AA *a1, A *a2) { void copy7(A *a1, AA *a2) { // CHECK-LABEL: _Z5copy7P1AS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %{{.*}}, i8* align 4 %{{.*}}, i64 16, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(16) %{{.*}}, i8* align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS]] // CHECK-NEW-SAME: !tbaa [[TAG_char]] *a1 = *a2; Modified: cfe/trunk/test/CodeGenCXX/auto-var-init.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/auto-var-init.cpp?rev=368658&r1=368657&r2=368658&view=diff == --- cfe/trunk/test/CodeGenCXX/auto-var-init.cpp (original) +++ cfe/trunk/test/CodeGenCXX/auto-var-init.cpp Tue Aug 13 02:12:07 2019 @@ -830,7 +830,7 @@ TEST_UNINIT(paddedpackednested, paddedpa // PATTERN-LABEL: @test_paddedpackednested_uninit() // PATTERN-O0: call void @llvm.memcpy{{.*}} @__const.test_paddedpackednested_uninit.uninit // PATTERN-O1: getelementptr -// PATTERN-O1: call void @llvm.memset.p0i8.i64(i8* nonnull align 1 %0, i8 [[I8]], i64 10, i1 false +// PATTERN-O1: call void @llvm.memset.p0i8.i64(i8* nonnull align 1 dereferenceable(10) %0, i8 [[I8]], i64 10, i1 false // ZERO-LABEL: @test_paddedpackednested_uninit() // ZERO: call void @llvm.memset{{.*}}, i8 0, @@ -1043,7 +1043,7 @@ TEST_UNINIT(intptr4, int*[4]); // CHECK-NEXT: call void @{{.*}}used{{.*}}%uninit) // PATTERN-O1-LABEL: @test_intptr4_uninit() // PATTERN-O1: %1 = bitcast [4 x i32*]* %uninit to i8* -// PATTERN-O1-NEXT:
r368725 - [NFC] Updated tests after r368724
Author: xbolva00 Date: Tue Aug 13 10:19:16 2019 New Revision: 368725 URL: http://llvm.org/viewvc/llvm-project?rev=368725&view=rev Log: [NFC] Updated tests after r368724 Modified: cfe/trunk/test/CodeGen/tbaa-struct.cpp Modified: cfe/trunk/test/CodeGen/tbaa-struct.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/tbaa-struct.cpp?rev=368725&r1=368724&r2=368725&view=diff == --- cfe/trunk/test/CodeGen/tbaa-struct.cpp (original) +++ cfe/trunk/test/CodeGen/tbaa-struct.cpp Tue Aug 13 10:19:16 2019 @@ -17,7 +17,7 @@ typedef A __attribute__((may_alias)) AA; void copy(A *a1, A *a2) { // CHECK-LABEL: _Z4copyP1AS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(16) %{{.*}}, i8* align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias align 4 dereferenceable(16) %{{.*}}, i8* noalias align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_A:![0-9]*]] *a1 = *a2; @@ -31,7 +31,7 @@ struct B { void copy2(B *b1, B *b2) { // CHECK-LABEL: _Z5copy2P1BS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(24) %{{.*}}, i8* align 4 dereferenceable(24) %{{.*}}, i64 24, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias align 4 dereferenceable(24) %{{.*}}, i8* noalias align 4 dereferenceable(24) %{{.*}}, i64 24, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS2:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_B:![0-9]*]] *b1 = *b2; @@ -49,7 +49,7 @@ union U { void copy3(U *u1, U *u2) { // CHECK-LABEL: _Z5copy3P1US0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(12) %{{.*}}, i8* align 4 dereferenceable(12) %{{.*}}, i64 12, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias align 4 dereferenceable(12) %{{.*}}, i8* noalias align 4 dereferenceable(12) %{{.*}}, i64 12, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS3:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_U:![0-9]*]] *u1 = *u2; @@ -65,7 +65,7 @@ struct C { void copy4(C *c1, C *c2) { // CHECK-LABEL: _Z5copy4P1CS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) {{.*}}, i8* align 1 dereferenceable(3) {{.*}}, i64 3, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias align 1 dereferenceable(3) {{.*}}, i8* noalias align 1 dereferenceable(3) {{.*}}, i64 3, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS4:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_C:![0-9]*]] *c1 = *c2; @@ -80,7 +80,7 @@ struct D { void copy5(D *d1, D *d2) { // CHECK-LABEL: _Z5copy5P1DS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(6) {{.*}}, i8* align 1 dereferenceable(6) {{.*}}, i64 6, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias align 1 dereferenceable(6) {{.*}}, i8* noalias align 1 dereferenceable(6) {{.*}}, i64 6, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS5:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_D:![0-9]*]] *d1 = *d2; @@ -88,7 +88,7 @@ void copy5(D *d1, D *d2) { void copy6(AA *a1, A *a2) { // CHECK-LABEL: _Z5copy6P1AS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(16) %{{.*}}, i8* align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias align 4 dereferenceable(16) %{{.*}}, i8* noalias align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS]] // CHECK-NEW-SAME: !tbaa [[TAG_char:![0-9]*]] *a1 = *a2; @@ -96,7 +96,7 @@ void copy6(AA *a1, A *a2) { void copy7(A *a1, AA *a2) { // CHECK-LABEL: _Z5copy7P1AS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(16) %{{.*}}, i8* align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias align 4 dereferenceable(16) %{{.*}}, i8* noalias align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS]] // CHECK-NEW-SAME: !tbaa [[TAG_char]] *a1 = *a2; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r368809 - [Codegen] Updated test for D66158
Author: xbolva00 Date: Wed Aug 14 01:32:31 2019 New Revision: 368809 URL: http://llvm.org/viewvc/llvm-project?rev=368809&view=rev Log: [Codegen] Updated test for D66158 Reviewers: jdoerfert Reviewed By: jdoerfert Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66173 Modified: cfe/trunk/test/CodeGen/struct-copy.c Modified: cfe/trunk/test/CodeGen/struct-copy.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/struct-copy.c?rev=368809&r1=368808&r2=368809&view=diff == --- cfe/trunk/test/CodeGen/struct-copy.c (original) +++ cfe/trunk/test/CodeGen/struct-copy.c Wed Aug 14 01:32:31 2019 @@ -1,7 +1,39 @@ -// RUN: %clang_cc1 -emit-llvm %s -o - | grep 'call.*llvm.memcpy' +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py +// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s struct x { int a[100]; }; - +// CHECK-LABEL: @foo( +// CHECK-NEXT: entry: +// CHECK-NEXT:[[P_ADDR:%.*]] = alloca %struct.x*, align 8 +// CHECK-NEXT:[[Q_ADDR:%.*]] = alloca %struct.x*, align 8 +// CHECK-NEXT:store %struct.x* [[P:%.*]], %struct.x** [[P_ADDR]], align 8 +// CHECK-NEXT:store %struct.x* [[Q:%.*]], %struct.x** [[Q_ADDR]], align 8 +// CHECK-NEXT:[[TMP0:%.*]] = load %struct.x*, %struct.x** [[P_ADDR]], align 8 +// CHECK-NEXT:[[TMP1:%.*]] = load %struct.x*, %struct.x** [[Q_ADDR]], align 8 +// CHECK-NEXT:[[TMP2:%.*]] = bitcast %struct.x* [[TMP0]] to i8* +// CHECK-NEXT:[[TMP3:%.*]] = bitcast %struct.x* [[TMP1]] to i8* +// CHECK-NEXT:call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[TMP2]], i8* align 4 [[TMP3]], i64 400, i1 false) +// CHECK-NEXT:ret void +// void foo(struct x *P, struct x *Q) { *P = *Q; } + +// CHECK: declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg) + +// CHECK-LABEL: @bar( +// CHECK-NEXT: entry: +// CHECK-NEXT:[[P_ADDR:%.*]] = alloca %struct.x*, align 8 +// CHECK-NEXT:[[Q_ADDR:%.*]] = alloca %struct.x*, align 8 +// CHECK-NEXT:store %struct.x* [[P:%.*]], %struct.x** [[P_ADDR]], align 8 +// CHECK-NEXT:store %struct.x* [[Q:%.*]], %struct.x** [[Q_ADDR]], align 8 +// CHECK-NEXT:[[TMP0:%.*]] = load %struct.x*, %struct.x** [[P_ADDR]], align 8 +// CHECK-NEXT:[[TMP1:%.*]] = bitcast %struct.x* [[TMP0]] to i8* +// CHECK-NEXT:[[TMP2:%.*]] = load %struct.x*, %struct.x** [[Q_ADDR]], align 8 +// CHECK-NEXT:[[TMP3:%.*]] = bitcast %struct.x* [[TMP2]] to i8* +// CHECK-NEXT:call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[TMP1]], i8* align 4 [[TMP3]], i64 400, i1 false) +// CHECK-NEXT:ret void +// +void bar(struct x *P, struct x *Q) { + __builtin_memcpy(P, Q, sizeof(struct x)); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r368828 - [NFC] Make test more robust
Author: xbolva00 Date: Wed Aug 14 04:13:10 2019 New Revision: 368828 URL: http://llvm.org/viewvc/llvm-project?rev=368828&view=rev Log: [NFC] Make test more robust Currently fails on ARMs Modified: cfe/trunk/test/CodeGen/struct-copy.c Modified: cfe/trunk/test/CodeGen/struct-copy.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/struct-copy.c?rev=368828&r1=368827&r2=368828&view=diff == --- cfe/trunk/test/CodeGen/struct-copy.c (original) +++ cfe/trunk/test/CodeGen/struct-copy.c Wed Aug 14 04:13:10 2019 @@ -1,39 +1,17 @@ -// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py // RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s struct x { int a[100]; }; -// CHECK-LABEL: @foo( -// CHECK-NEXT: entry: -// CHECK-NEXT:[[P_ADDR:%.*]] = alloca %struct.x*, align 8 -// CHECK-NEXT:[[Q_ADDR:%.*]] = alloca %struct.x*, align 8 -// CHECK-NEXT:store %struct.x* [[P:%.*]], %struct.x** [[P_ADDR]], align 8 -// CHECK-NEXT:store %struct.x* [[Q:%.*]], %struct.x** [[Q_ADDR]], align 8 -// CHECK-NEXT:[[TMP0:%.*]] = load %struct.x*, %struct.x** [[P_ADDR]], align 8 -// CHECK-NEXT:[[TMP1:%.*]] = load %struct.x*, %struct.x** [[Q_ADDR]], align 8 -// CHECK-NEXT:[[TMP2:%.*]] = bitcast %struct.x* [[TMP0]] to i8* -// CHECK-NEXT:[[TMP3:%.*]] = bitcast %struct.x* [[TMP1]] to i8* -// CHECK-NEXT:call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[TMP2]], i8* align 4 [[TMP3]], i64 400, i1 false) -// CHECK-NEXT:ret void -// + void foo(struct x *P, struct x *Q) { +// CHECK-LABEL: @foo( +// CHECK:call void @llvm.memcpy.p0i8.p0i8.i64 *P = *Q; } // CHECK: declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg) -// CHECK-LABEL: @bar( -// CHECK-NEXT: entry: -// CHECK-NEXT:[[P_ADDR:%.*]] = alloca %struct.x*, align 8 -// CHECK-NEXT:[[Q_ADDR:%.*]] = alloca %struct.x*, align 8 -// CHECK-NEXT:store %struct.x* [[P:%.*]], %struct.x** [[P_ADDR]], align 8 -// CHECK-NEXT:store %struct.x* [[Q:%.*]], %struct.x** [[Q_ADDR]], align 8 -// CHECK-NEXT:[[TMP0:%.*]] = load %struct.x*, %struct.x** [[P_ADDR]], align 8 -// CHECK-NEXT:[[TMP1:%.*]] = bitcast %struct.x* [[TMP0]] to i8* -// CHECK-NEXT:[[TMP2:%.*]] = load %struct.x*, %struct.x** [[Q_ADDR]], align 8 -// CHECK-NEXT:[[TMP3:%.*]] = bitcast %struct.x* [[TMP2]] to i8* -// CHECK-NEXT:call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[TMP1]], i8* align 4 [[TMP3]], i64 400, i1 false) -// CHECK-NEXT:ret void -// void bar(struct x *P, struct x *Q) { +// CHECK-LABEL: @bar( +// CHECK:call void @llvm.memcpy.p0i8.p0i8.i64 __builtin_memcpy(P, Q, sizeof(struct x)); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r368863 - [NFC] Fix testcase for ARMs
Author: xbolva00 Date: Wed Aug 14 08:35:40 2019 New Revision: 368863 URL: http://llvm.org/viewvc/llvm-project?rev=368863&view=rev Log: [NFC] Fix testcase for ARMs Modified: cfe/trunk/test/CodeGen/struct-copy.c Modified: cfe/trunk/test/CodeGen/struct-copy.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/struct-copy.c?rev=368863&r1=368862&r2=368863&view=diff == --- cfe/trunk/test/CodeGen/struct-copy.c (original) +++ cfe/trunk/test/CodeGen/struct-copy.c Wed Aug 14 08:35:40 2019 @@ -4,14 +4,14 @@ struct x { int a[100]; }; void foo(struct x *P, struct x *Q) { // CHECK-LABEL: @foo( -// CHECK:call void @llvm.memcpy.p0i8.p0i8.i64 +// CHECK:call void @llvm.memcpy.p0i8.p0i8 *P = *Q; } -// CHECK: declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg) +// CHECK: declare void @llvm.memcpy.p0i8.p0i8{{.*}}(i8* noalias nocapture writeonly, i8* noalias nocapture readonly void bar(struct x *P, struct x *Q) { // CHECK-LABEL: @bar( -// CHECK:call void @llvm.memcpy.p0i8.p0i8.i64 +// CHECK:call void @llvm.memcpy.p0i8.p0i8 __builtin_memcpy(P, Q, sizeof(struct x)); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r368876 - [NFC] Updated tests after r368875
Author: xbolva00 Date: Wed Aug 14 09:50:34 2019 New Revision: 368876 URL: http://llvm.org/viewvc/llvm-project?rev=368876&view=rev Log: [NFC] Updated tests after r368875 Modified: cfe/trunk/test/CodeGen/tbaa-struct.cpp Modified: cfe/trunk/test/CodeGen/tbaa-struct.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/tbaa-struct.cpp?rev=368876&r1=368875&r2=368876&view=diff == --- cfe/trunk/test/CodeGen/tbaa-struct.cpp (original) +++ cfe/trunk/test/CodeGen/tbaa-struct.cpp Wed Aug 14 09:50:34 2019 @@ -17,7 +17,7 @@ typedef A __attribute__((may_alias)) AA; void copy(A *a1, A *a2) { // CHECK-LABEL: _Z4copyP1AS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias align 4 dereferenceable(16) %{{.*}}, i8* noalias align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(16) %{{.*}}, i8* align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_A:![0-9]*]] *a1 = *a2; @@ -31,7 +31,7 @@ struct B { void copy2(B *b1, B *b2) { // CHECK-LABEL: _Z5copy2P1BS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias align 4 dereferenceable(24) %{{.*}}, i8* noalias align 4 dereferenceable(24) %{{.*}}, i64 24, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(24) %{{.*}}, i8* align 4 dereferenceable(24) %{{.*}}, i64 24, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS2:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_B:![0-9]*]] *b1 = *b2; @@ -49,7 +49,7 @@ union U { void copy3(U *u1, U *u2) { // CHECK-LABEL: _Z5copy3P1US0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias align 4 dereferenceable(12) %{{.*}}, i8* noalias align 4 dereferenceable(12) %{{.*}}, i64 12, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(12) %{{.*}}, i8* align 4 dereferenceable(12) %{{.*}}, i64 12, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS3:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_U:![0-9]*]] *u1 = *u2; @@ -65,7 +65,7 @@ struct C { void copy4(C *c1, C *c2) { // CHECK-LABEL: _Z5copy4P1CS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias align 1 dereferenceable(3) {{.*}}, i8* noalias align 1 dereferenceable(3) {{.*}}, i64 3, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) {{.*}}, i8* align 1 dereferenceable(3) {{.*}}, i64 3, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS4:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_C:![0-9]*]] *c1 = *c2; @@ -80,7 +80,7 @@ struct D { void copy5(D *d1, D *d2) { // CHECK-LABEL: _Z5copy5P1DS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias align 1 dereferenceable(6) {{.*}}, i8* noalias align 1 dereferenceable(6) {{.*}}, i64 6, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(6) {{.*}}, i8* align 1 dereferenceable(6) {{.*}}, i64 6, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS5:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_D:![0-9]*]] *d1 = *d2; @@ -88,7 +88,7 @@ void copy5(D *d1, D *d2) { void copy6(AA *a1, A *a2) { // CHECK-LABEL: _Z5copy6P1AS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias align 4 dereferenceable(16) %{{.*}}, i8* noalias align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(16) %{{.*}}, i8* align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS]] // CHECK-NEW-SAME: !tbaa [[TAG_char:![0-9]*]] *a1 = *a2; @@ -96,7 +96,7 @@ void copy6(AA *a1, A *a2) { void copy7(A *a1, AA *a2) { // CHECK-LABEL: _Z5copy7P1AS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias align 4 dereferenceable(16) %{{.*}}, i8* noalias align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(16) %{{.*}}, i8* align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS]] // CHECK-NEW-SAME: !tbaa [[TAG_char]] *a1 = *a2; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r369206 - [Diagnostics] Improve -Wsizeof-pointer-div
Author: xbolva00 Date: Sun Aug 18 03:10:09 2019 New Revision: 369206 URL: http://llvm.org/viewvc/llvm-project?rev=369206&view=rev Log: [Diagnostics] Improve -Wsizeof-pointer-div Emit diag note with a location of pointer declaration. Revisited/added tests. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/Sema/div-sizeof-ptr.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=369206&r1=369205&r2=369206&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Aug 18 03:10:09 2019 @@ -3346,6 +3346,8 @@ def warn_address_of_reference_null_compa InGroup; def note_reference_is_return_value : Note<"%0 returns a reference">; +def note_pointer_declared_here : Note< + "pointer %0 declared here">; def warn_division_sizeof_ptr : Warning< "'%0' will return the size of the pointer, not the array itself">, InGroup>; Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=369206&r1=369205&r2=369206&view=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Aug 18 03:10:09 2019 @@ -9075,7 +9075,8 @@ static void DiagnoseDivisionSizeofPointe RUE->getKind() != UETT_SizeOf) return; - QualType LHSTy = LUE->getArgumentExpr()->IgnoreParens()->getType(); + const Expr *LHSArg = LUE->getArgumentExpr()->IgnoreParens(); + QualType LHSTy = LHSArg->getType(); QualType RHSTy; if (RUE->isArgumentType()) @@ -9085,10 +9086,15 @@ static void DiagnoseDivisionSizeofPointe if (!LHSTy->isPointerType() || RHSTy->isPointerType()) return; - if (LHSTy->getPointeeType() != RHSTy) + if (LHSTy->getPointeeType().getCanonicalType() != RHSTy.getCanonicalType()) return; S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS << LHS->getSourceRange(); + if (const auto *DRE = dyn_cast(LHSArg)) { +if (const ValueDecl *LHSArgDecl = DRE->getDecl()) + S.Diag(LHSArgDecl->getLocation(), diag::note_pointer_declared_here) + << LHSArgDecl; + } } static void DiagnoseBadDivideOrRemainderValues(Sema& S, ExprResult &LHS, Modified: cfe/trunk/test/Sema/div-sizeof-ptr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/div-sizeof-ptr.cpp?rev=369206&r1=369205&r2=369206&view=diff == --- cfe/trunk/test/Sema/div-sizeof-ptr.cpp (original) +++ cfe/trunk/test/Sema/div-sizeof-ptr.cpp Sun Aug 18 03:10:09 2019 @@ -5,12 +5,20 @@ int f(Ty (&Array)[N]) { return sizeof(Array) / sizeof(Ty); // Should not warn } -void test(int *p, int **q) { +typedef int int32; + +void test(int *p, int **q) { // expected-note 5 {{pointer 'p' declared here}} int a1 = sizeof(p) / sizeof(*p); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}} int a2 = sizeof p / sizeof *p; // expected-warning {{'sizeof p' will return the size of the pointer, not the array itself}} - int a3 = sizeof(*q) / sizeof(**q); // expected-warning {{'sizeof (*q)' will return the size of the pointer, not the array itself}} - int a4 = sizeof(p) / sizeof(int); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}} - int a5 = sizeof(p) / sizeof(p[0]); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}} + int a3 = sizeof(p) / sizeof(int); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}} + int a4 = sizeof(p) / sizeof(p[0]); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}} + int a5 = sizeof(p) / sizeof(int32); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}} + + int32 *d; // expected-note 2 {{pointer 'd' declared here}} + int a6 = sizeof(d) / sizeof(int32); // expected-warning {{'sizeof (d)' will return the size of the pointer, not the array itself}} + int a7 = sizeof(d) / sizeof(int); // expected-warning {{'sizeof (d)' will return the size of the pointer, not the array itself}} + + int a8 = sizeof(*q) / sizeof(**q); // expected-warning {{'sizeof (*q)' will return the size of the pointer, not the array itself}} // Should not warn int b1 = sizeof(int *) / sizeof(int); @@ -19,10 +27,10 @@ void test(int *p, int **q) { int b4 = sizeof(p) / sizeof(char); int arr[10]; - int b5 = sizeof(arr) / sizeof(*arr); - int b6 = sizeof(arr) / sizeof(arr[0]); - int b7 = sizeof(arr) / sizeof(int); + int c1 = sizeof(
r369217 - [Diagnostics] Diagnose misused xor as pow
Author: xbolva00 Date: Sun Aug 18 12:14:14 2019 New Revision: 369217 URL: http://llvm.org/viewvc/llvm-project?rev=369217&view=rev Log: [Diagnostics] Diagnose misused xor as pow Summary: Motivation: https://twitter.com/jfbastien/status/1139298419988549632 https://twitter.com/mikemx7f/status/1139335901790625793 https://codesearch.isocpp.org/cgi-bin/cgi_ppsearch?q=10+%5E&search=Search Reviewers: jfb, rsmith, regehr, aaron.ballman Reviewed By: aaron.ballman Subscribers: lebedev.ri, Quuxplusone, erik.pilkington, riccibruno, dexonsmith, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63423 Added: cfe/trunk/test/SemaCXX/warn-xor-as-pow.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaExpr.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=369217&r1=369216&r2=369217&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Sun Aug 18 12:14:14 2019 @@ -512,6 +512,7 @@ def CompareDistinctPointerType : DiagGro def GNUUnionCast : DiagGroup<"gnu-union-cast">; def GNUVariableSizedTypeNotAtEnd : DiagGroup<"gnu-variable-sized-type-not-at-end">; def Varargs : DiagGroup<"varargs">; +def XorUsedAsPow : DiagGroup<"xor-used-as-pow">; def Unsequenced : DiagGroup<"unsequenced">; // GCC name for -Wunsequenced Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=369217&r1=369216&r2=369217&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Aug 18 12:14:14 2019 @@ -3326,6 +3326,15 @@ def warn_address_of_reference_bool_conve "code; pointer may be assumed to always convert to true">, InGroup; +def warn_xor_used_as_pow_base_extra : Warning< + "result of '%0' is %1; did you mean '%2' (%3)?">, + InGroup; +def warn_xor_used_as_pow_base : Warning< + "result of '%0' is %1; did you mean '%2'?">, + InGroup; +def note_xor_used_as_pow_silence : Note< + "replace expression with '%0' to silence this warning">; + def warn_null_pointer_compare : Warning< "comparison of %select{address of|function|array}0 '%1' %select{not |}2" "equal to a null pointer is always %select{true|false}2">, Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=369217&r1=369216&r2=369217&view=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Aug 18 12:14:14 2019 @@ -11011,6 +11011,107 @@ QualType Sema::CheckVectorCompareOperand return GetSignedVectorType(vType); } +static void diagnoseXorMisusedAsPow(Sema &S, ExprResult &LHS, ExprResult &RHS, +SourceLocation Loc) { + // Do not diagnose macros. + if (Loc.isMacroID()) +return; + + bool Negative = false; + const auto *LHSInt = dyn_cast(LHS.get()); + const auto *RHSInt = dyn_cast(RHS.get()); + + if (!LHSInt) +return; + if (!RHSInt) { +// Check negative literals. +if (const auto *UO = dyn_cast(RHS.get())) { + if (UO->getOpcode() != UO_Minus) +return; + RHSInt = dyn_cast(UO->getSubExpr()); + if (!RHSInt) +return; + Negative = true; +} else { + return; +} + } + + if (LHSInt->getValue().getBitWidth() != RHSInt->getValue().getBitWidth()) +return; + + CharSourceRange ExprRange = CharSourceRange::getCharRange( + LHSInt->getBeginLoc(), S.getLocForEndOfToken(RHSInt->getLocation())); + llvm::StringRef ExprStr = + Lexer::getSourceText(ExprRange, S.getSourceManager(), S.getLangOpts()); + + CharSourceRange XorRange = + CharSourceRange::getCharRange(Loc, S.getLocForEndOfToken(Loc)); + llvm::StringRef XorStr = + Lexer::getSourceText(XorRange, S.getSourceManager(), S.getLangOpts()); + // Do not diagnose if xor keyword/macro is used. + if (XorStr == "xor") +return; + + const llvm::APInt &LeftSideValue = LHSInt->getValue(); + const llvm::APInt &RightSideValue = RHSInt->getValue(); + const llvm::APInt XorValue = LeftSideValue ^ RightSideValue; + + std::string LHSStr = Lexer::getSourceText( + CharSourceRange::getTokenRange(LHSInt->getSourceRange()), + S.getSourceManager(), S.getLangOpts()); + std::string RHSStr = Lexer::getSourceText( + CharSourceRange::getTokenRange(RHSInt->getSourceRange()), + S.getSourceManager(), S.getLangOpts()); + + int64_t RightSideIntValue = RightSideValue.getSExtVal
r360810 - [clang-format] Fixed self assignment
Author: xbolva00 Date: Wed May 15 13:29:33 2019 New Revision: 360810 URL: http://llvm.org/viewvc/llvm-project?rev=360810&view=rev Log: [clang-format] Fixed self assignment Reviewers: MyDeveloperDay, RKSimon Reviewed By: MyDeveloperDay Subscribers: RKSimon, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61281 Modified: cfe/trunk/lib/Format/FormatTokenLexer.cpp Modified: cfe/trunk/lib/Format/FormatTokenLexer.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatTokenLexer.cpp?rev=360810&r1=360809&r2=360810&view=diff == --- cfe/trunk/lib/Format/FormatTokenLexer.cpp (original) +++ cfe/trunk/lib/Format/FormatTokenLexer.cpp Wed May 15 13:29:33 2019 @@ -246,7 +246,6 @@ bool FormatTokenLexer::tryMergeCSharpNul StringRef(Identifier->TokenText.begin(), Question->TokenText.end() - Identifier->TokenText.begin()); Identifier->ColumnWidth += Question->ColumnWidth; - Identifier->Type = Identifier->Type; Tokens.erase(Tokens.end() - 1); return true; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r371605 - [Diagnostics] Add -Wsizeof-array-div
Author: xbolva00 Date: Wed Sep 11 03:59:47 2019 New Revision: 371605 URL: http://llvm.org/viewvc/llvm-project?rev=371605&view=rev Log: [Diagnostics] Add -Wsizeof-array-div Summary: Clang version of https://www.viva64.com/en/examples/v706/ Reviewers: rsmith Differential Revision: https://reviews.llvm.org/D67287 Added: cfe/trunk/test/Sema/div-sizeof-array.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaExpr.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=371605&r1=371604&r2=371605&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 11 03:59:47 2019 @@ -3406,6 +3406,10 @@ def note_pointer_declared_here : Note< def warn_division_sizeof_ptr : Warning< "'%0' will return the size of the pointer, not the array itself">, InGroup>; +def warn_division_sizeof_array : Warning< + "expression does not compute the number of elements in this array; element " + "type is %0, not %1">, + InGroup>; def note_function_warning_silence : Note< "prefix with the address-of operator to silence this warning">; Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=371605&r1=371604&r2=371605&view=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Sep 11 03:59:47 2019 @@ -9158,17 +9158,28 @@ static void DiagnoseDivisionSizeofPointe else RHSTy = RUE->getArgumentExpr()->IgnoreParens()->getType(); - if (!LHSTy->isPointerType() || RHSTy->isPointerType()) -return; - if (LHSTy->getPointeeType().getCanonicalType().getUnqualifiedType() != - RHSTy.getCanonicalType().getUnqualifiedType()) -return; + if (LHSTy->isPointerType() && !RHSTy->isPointerType()) { +if (!S.Context.hasSameUnqualifiedType(LHSTy->getPointeeType(), RHSTy)) + return; - S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS << LHS->getSourceRange(); - if (const auto *DRE = dyn_cast(LHSArg)) { -if (const ValueDecl *LHSArgDecl = DRE->getDecl()) - S.Diag(LHSArgDecl->getLocation(), diag::note_pointer_declared_here) - << LHSArgDecl; +S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS << LHS->getSourceRange(); +if (const auto *DRE = dyn_cast(LHSArg)) { + if (const ValueDecl *LHSArgDecl = DRE->getDecl()) +S.Diag(LHSArgDecl->getLocation(), diag::note_pointer_declared_here) +<< LHSArgDecl; +} + } else if (const auto *ArrayTy = S.Context.getAsArrayType(LHSTy)) { +QualType ArrayElemTy = ArrayTy->getElementType(); +if (ArrayElemTy->isDependentType() || RHSTy->isDependentType() || +S.Context.getTypeSize(ArrayElemTy) == S.Context.getTypeSize(RHSTy)) + return; +S.Diag(Loc, diag::warn_division_sizeof_array) +<< LHSArg->getSourceRange() << ArrayElemTy << RHSTy; +if (const auto *DRE = dyn_cast(LHSArg)) { + if (const ValueDecl *LHSArgDecl = DRE->getDecl()) +S.Diag(LHSArgDecl->getLocation(), diag::note_array_declared_here) +<< LHSArgDecl; +} } } Added: cfe/trunk/test/Sema/div-sizeof-array.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/div-sizeof-array.cpp?rev=371605&view=auto == --- cfe/trunk/test/Sema/div-sizeof-array.cpp (added) +++ cfe/trunk/test/Sema/div-sizeof-array.cpp Wed Sep 11 03:59:47 2019 @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 %s -verify -Wsizeof-array-div -fsyntax-only + +template +int f(Ty (&Array)[N]) { + return sizeof(Array) / sizeof(Ty); // Should not warn +} + +typedef int int32; + +void test(void) { + int arr[12];// expected-note 2 {{array 'arr' declared here}} + unsigned long long arr2[4]; + int *p = &arr[0]; + int a1 = sizeof(arr) / sizeof(*arr); + int a2 = sizeof arr / sizeof p; // expected-warning {{expression does not compute the number of elements in this array; element type is 'int', not 'int *'}} + int a4 = sizeof arr2 / sizeof p; + int a5 = sizeof(arr) / sizeof(short); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int', not 'short'}} + int a6 = sizeof(arr) / sizeof(int32); + int a7 = sizeof(arr) / sizeof(int); + int a9 = sizeof(arr) / sizeof(unsigned int); + const char arr3[2] = "A"; + int a10 = sizeof(arr3) / sizeof(char); + + int arr4[10][12]; // expected-note 3 {{array 'arr4' declared here}} + int b1 = sizeof(arr4) / sizeof(arr2[12]); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [12]', not '
r371646 - [NFC] Added triple to test file to avoid arm buildbots failures
Author: xbolva00 Date: Wed Sep 11 11:55:56 2019 New Revision: 371646 URL: http://llvm.org/viewvc/llvm-project?rev=371646&view=rev Log: [NFC] Added triple to test file to avoid arm buildbots failures Modified: cfe/trunk/test/Sema/div-sizeof-array.cpp Modified: cfe/trunk/test/Sema/div-sizeof-array.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/div-sizeof-array.cpp?rev=371646&r1=371645&r2=371646&view=diff == --- cfe/trunk/test/Sema/div-sizeof-array.cpp (original) +++ cfe/trunk/test/Sema/div-sizeof-array.cpp Wed Sep 11 11:55:56 2019 @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 %s -verify -Wsizeof-array-div -fsyntax-only +// RUN: %clang_cc1 %s -verify -Wsizeof-array-div -fsyntax-only -triple=x86_64-linux-gnu +// RUN: %clang_cc1 %s -verify -fsyntax-only -triple=x86_64-linux-gnu template int f(Ty (&Array)[N]) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r371924 - [Diagnostics] Added silence note for -Wsizeof-array-div; suggest extra parens
Author: xbolva00 Date: Sat Sep 14 12:38:55 2019 New Revision: 371924 URL: http://llvm.org/viewvc/llvm-project?rev=371924&view=rev Log: [Diagnostics] Added silence note for -Wsizeof-array-div; suggest extra parens Modified: cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/Sema/div-sizeof-array.cpp Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=371924&r1=371923&r2=371924&view=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Sep 14 12:38:55 2019 @@ -9200,6 +9200,8 @@ static void DiagnoseDivisionSizeofPointe S.Diag(LHSArgDecl->getLocation(), diag::note_array_declared_here) << LHSArgDecl; } + +S.Diag(Loc, diag::note_precedence_silence) << RHS; } } Modified: cfe/trunk/test/Sema/div-sizeof-array.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/div-sizeof-array.cpp?rev=371924&r1=371923&r2=371924&view=diff == --- cfe/trunk/test/Sema/div-sizeof-array.cpp (original) +++ cfe/trunk/test/Sema/div-sizeof-array.cpp Sat Sep 14 12:38:55 2019 @@ -9,21 +9,38 @@ int f(Ty (&Array)[N]) { typedef int int32; void test(void) { - int arr[12];// expected-note 2 {{array 'arr' declared here}} + int arr[12]; // expected-note 2 {{array 'arr' declared here}} unsigned long long arr2[4]; int *p = &arr[0]; int a1 = sizeof(arr) / sizeof(*arr); int a2 = sizeof arr / sizeof p; // expected-warning {{expression does not compute the number of elements in this array; element type is 'int', not 'int *'}} + // expected-note@-1 {{place parentheses around the 'sizeof p' expression to silence this warning}} int a4 = sizeof arr2 / sizeof p; int a5 = sizeof(arr) / sizeof(short); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int', not 'short'}} + // expected-note@-1 {{place parentheses around the 'sizeof(short)' expression to silence this warning}} int a6 = sizeof(arr) / sizeof(int32); int a7 = sizeof(arr) / sizeof(int); int a9 = sizeof(arr) / sizeof(unsigned int); const char arr3[2] = "A"; int a10 = sizeof(arr3) / sizeof(char); + int a11 = sizeof(arr2) / (sizeof(unsigned)); + int a12 = sizeof(arr) / (sizeof(short)); int arr4[10][12]; // expected-note 3 {{array 'arr4' declared here}} int b1 = sizeof(arr4) / sizeof(arr2[12]); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [12]', not 'unsigned long long'}} - int b2 = sizeof(arr4) / sizeof(int *);// expected-warning {{expression does not compute the number of elements in this array; element type is 'int [12]', not 'int *'}} - int b3 = sizeof(arr4) / sizeof(short *); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [12]', not 'short *'}} + // expected-note@-1 {{place parentheses around the 'sizeof (arr2[12])' expression to silence this warning}} + int b2 = sizeof(arr4) / sizeof(int *); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [12]', not 'int *'}} + // expected-note@-1 {{place parentheses around the 'sizeof(int *)' expression to silence this warning}} + int b3 = sizeof(arr4) / sizeof(short *); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [12]', not 'short *'}} + // expected-note@-1 {{place parentheses around the 'sizeof(short *)' expression to silence this warning}} + + int arr5[][5] = { // expected-note 2 {{array 'arr5' declared here}} + {1, 2, 3, 4, 5}, + {6, 7, 8, 9, 0}, + }; + int c1 = sizeof(arr5) / sizeof(*arr5); + int c2 = sizeof(arr5) / sizeof(**arr5); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [5]', not 'int'}} + // expected-note@-1 {{place parentheses around the 'sizeof (**arr5)' expression to silence this warning}} + int c3 = sizeof(arr5) / sizeof(int); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [5]', not 'int'}} + // expected-note@-1 {{place parentheses around the 'sizeof(int)' expression to silence this warning}} } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r372095 - [NFC] Updated test
Author: xbolva00 Date: Tue Sep 17 02:53:14 2019 New Revision: 372095 URL: http://llvm.org/viewvc/llvm-project?rev=372095&view=rev Log: [NFC] Updated test Modified: cfe/trunk/test/CodeGen/tbaa-struct.cpp Modified: cfe/trunk/test/CodeGen/tbaa-struct.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/tbaa-struct.cpp?rev=372095&r1=372094&r2=372095&view=diff == --- cfe/trunk/test/CodeGen/tbaa-struct.cpp (original) +++ cfe/trunk/test/CodeGen/tbaa-struct.cpp Tue Sep 17 02:53:14 2019 @@ -17,7 +17,7 @@ typedef A __attribute__((may_alias)) AA; void copy(A *a1, A *a2) { // CHECK-LABEL: _Z4copyP1AS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(16) %{{.*}}, i8* align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 4 dereferenceable(16) %{{.*}}, i8* nonnull align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_A:![0-9]*]] *a1 = *a2; @@ -31,7 +31,7 @@ struct B { void copy2(B *b1, B *b2) { // CHECK-LABEL: _Z5copy2P1BS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(24) %{{.*}}, i8* align 4 dereferenceable(24) %{{.*}}, i64 24, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 4 dereferenceable(24) %{{.*}}, i8* nonnull align 4 dereferenceable(24) %{{.*}}, i64 24, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS2:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_B:![0-9]*]] *b1 = *b2; @@ -49,7 +49,7 @@ union U { void copy3(U *u1, U *u2) { // CHECK-LABEL: _Z5copy3P1US0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(12) %{{.*}}, i8* align 4 dereferenceable(12) %{{.*}}, i64 12, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 4 dereferenceable(12) %{{.*}}, i8* nonnull align 4 dereferenceable(12) %{{.*}}, i64 12, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS3:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_U:![0-9]*]] *u1 = *u2; @@ -65,7 +65,7 @@ struct C { void copy4(C *c1, C *c2) { // CHECK-LABEL: _Z5copy4P1CS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) {{.*}}, i8* align 1 dereferenceable(3) {{.*}}, i64 3, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 1 dereferenceable(3) {{.*}}, i8* nonnull align 1 dereferenceable(3) {{.*}}, i64 3, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS4:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_C:![0-9]*]] *c1 = *c2; @@ -80,7 +80,7 @@ struct D { void copy5(D *d1, D *d2) { // CHECK-LABEL: _Z5copy5P1DS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(6) {{.*}}, i8* align 1 dereferenceable(6) {{.*}}, i64 6, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 1 dereferenceable(6) {{.*}}, i8* nonnull align 1 dereferenceable(6) {{.*}}, i64 6, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS5:!.*]] // CHECK-NEW-SAME: !tbaa [[TAG_D:![0-9]*]] *d1 = *d2; @@ -88,7 +88,7 @@ void copy5(D *d1, D *d2) { void copy6(AA *a1, A *a2) { // CHECK-LABEL: _Z5copy6P1AS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(16) %{{.*}}, i8* align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 4 dereferenceable(16) %{{.*}}, i8* nonnull align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS]] // CHECK-NEW-SAME: !tbaa [[TAG_char:![0-9]*]] *a1 = *a2; @@ -96,7 +96,7 @@ void copy6(AA *a1, A *a2) { void copy7(A *a1, AA *a2) { // CHECK-LABEL: _Z5copy7P1AS0_ -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 dereferenceable(16) %{{.*}}, i8* align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 4 dereferenceable(16) %{{.*}}, i8* nonnull align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false) // CHECK-OLD-SAME: !tbaa.struct [[TS]] // CHECK-NEW-SAME: !tbaa [[TAG_char]] *a1 = *a2; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r372531 - [Diagnostics] Warn if ?: with integer constants always evaluates to true
Author: xbolva00 Date: Sun Sep 22 15:00:48 2019 New Revision: 372531 URL: http://llvm.org/viewvc/llvm-project?rev=372531&view=rev Log: [Diagnostics] Warn if ?: with integer constants always evaluates to true Extracted from D63082. GCC has this warning under -Wint-in-bool-context, but as noted in the D63082's review, we should put it under TautologicalConstantCompare. Added: cfe/trunk/test/Sema/warn-integer-constants-in-ternary.c Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaChecking.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=372531&r1=372530&r2=372531&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Sep 22 15:00:48 2019 @@ -6137,6 +6137,10 @@ def warn_out_of_range_compare : Warning< InGroup; def warn_tautological_bool_compare : Warning, InGroup; +def warn_integer_constants_in_conditional_always_true : Warning< + "converting the result of '?:' with integer constants to a boolean always " + "evaluates to 'true'">, + InGroup; def warn_comparison_of_mixed_enum_types : Warning< "comparison of two values with different enumeration types" "%diff{ ($ and $)|}0,1">, Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=372531&r1=372530&r2=372531&view=diff == --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Sun Sep 22 15:00:48 2019 @@ -11256,6 +11256,44 @@ static bool isSameWidthConstantConversio return true; } +static void DiagnoseIntInBoolContext(Sema &S, const Expr *E) { + E = E->IgnoreParenImpCasts(); + SourceLocation ExprLoc = E->getExprLoc(); + + if (const auto *CO = dyn_cast(E)) { +const auto *LHS = dyn_cast(CO->getTrueExpr()); +if (!LHS) { + if (auto *UO = dyn_cast(CO->getTrueExpr())) { +if (UO->getOpcode() == UO_Minus) + LHS = dyn_cast(UO->getSubExpr()); +if (!LHS) + return; + } else { +return; + } +} + +const auto *RHS = dyn_cast(CO->getFalseExpr()); +if (!RHS) { + if (auto *UO = dyn_cast(CO->getFalseExpr())) { +if (UO->getOpcode() == UO_Minus) + RHS = dyn_cast(UO->getSubExpr()); +if (!RHS) + return; + } else { +return; + } +} + +if ((LHS->getValue() == 0 || LHS->getValue() == 1) && +(RHS->getValue() == 0 || RHS->getValue() == 1)) + // Do not diagnose common idioms + return; +if (LHS->getValue() != 0 && LHS->getValue() != 0) + S.Diag(ExprLoc, diag::warn_integer_constants_in_conditional_always_true); + } +} + static void CheckImplicitConversion(Sema &S, Expr *E, QualType T, SourceLocation CC, bool *ICContext = nullptr, @@ -11708,6 +11746,9 @@ static void CheckConditionalOperator(Sem CheckConditionalOperand(S, E->getTrueExpr(), T, CC, Suspicious); CheckConditionalOperand(S, E->getFalseExpr(), T, CC, Suspicious); + if (T->isBooleanType()) +DiagnoseIntInBoolContext(S, E); + // If -Wconversion would have warned about either of the candidates // for a signedness conversion to the context type... if (!Suspicious) return; Added: cfe/trunk/test/Sema/warn-integer-constants-in-ternary.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-integer-constants-in-ternary.c?rev=372531&view=auto == --- cfe/trunk/test/Sema/warn-integer-constants-in-ternary.c (added) +++ cfe/trunk/test/Sema/warn-integer-constants-in-ternary.c Sun Sep 22 15:00:48 2019 @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wtautological-constant-compare %s +// RUN: %clang_cc1 -x c -fsyntax-only -verify %s +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wtautological-constant-compare %s +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s + +#define ONE 1 +#define TWO 2 + +#define TERN(c, l, r) c ? l : r + +#ifdef __cplusplus +typedef bool boolean; +#else +typedef _Bool boolean; +#endif + +void test(boolean a) { + boolean r; + r = a ? (1) : TWO; + r = a ? 3 : TWO; // expected-warning {{converting the result of '?:' with integer constants to a boolean always evaluates to 'true'}} + r = a ? -2 : 0; // expected-warning {{converting the result of '?:' with integer constants to a boolean always evaluates to 'true'}} + r = a ? 3 : -2; // expected-warning {{converting the result of '?:' with integer constants to a boolean always evaluates to 'true'}} + r = a ? 0 : TWO; + r = a ? 3 : ONE; // expected-warning {{conve
r372533 - [NFC] Fixed failed test
Author: xbolva00 Date: Sun Sep 22 15:15:11 2019 New Revision: 372533 URL: http://llvm.org/viewvc/llvm-project?rev=372533&view=rev Log: [NFC] Fixed failed test Modified: cfe/trunk/test/SemaCXX/constexpr-builtin-bit-cast.cpp Modified: cfe/trunk/test/SemaCXX/constexpr-builtin-bit-cast.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constexpr-builtin-bit-cast.cpp?rev=372533&r1=372532&r2=372533&view=diff == --- cfe/trunk/test/SemaCXX/constexpr-builtin-bit-cast.cpp (original) +++ cfe/trunk/test/SemaCXX/constexpr-builtin-bit-cast.cpp Sun Sep 22 15:15:11 2019 @@ -220,7 +220,7 @@ void backtrace() { void test_array_fill() { constexpr unsigned char a[4] = {1, 2}; constexpr unsigned int i = bit_cast(a); - static_assert(i == LITTLE_END ? 0x0201 : 0x0102, ""); + static_assert(i == LITTLE_END ? 0x0201 : 0x0102, ""); // expected-warning {{converting the result of '?:' with integer constants to a boolean always evaluates to 'true'}} } typedef decltype(nullptr) nullptr_t; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r372575 - [NFC] Fixed clang wasm test after rL372573
Author: xbolva00 Date: Mon Sep 23 03:14:07 2019 New Revision: 372575 URL: http://llvm.org/viewvc/llvm-project?rev=372575&view=rev Log: [NFC] Fixed clang wasm test after rL372573 These tests should not depend on -O1.. Modified: cfe/trunk/test/CodeGenCXX/wasm-args-returns.cpp Modified: cfe/trunk/test/CodeGenCXX/wasm-args-returns.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/wasm-args-returns.cpp?rev=372575&r1=372574&r2=372575&view=diff == --- cfe/trunk/test/CodeGenCXX/wasm-args-returns.cpp (original) +++ cfe/trunk/test/CodeGenCXX/wasm-args-returns.cpp Mon Sep 23 03:14:07 2019 @@ -46,7 +46,7 @@ struct copy_ctor { copy_ctor(copy_ctor const &); }; test(copy_ctor); -// CHECK: define void @_Z7forward9copy_ctor(%struct.copy_ctor* noalias sret %{{.*}}, %struct.copy_ctor* %{{.*}}) +// CHECK: define void @_Z7forward9copy_ctor(%struct.copy_ctor* noalias sret %{{.*}}, %struct.copy_ctor* nonnull %{{.*}}) // // CHECK: declare %struct.copy_ctor* @_ZN9copy_ctorC1ERKS_(%struct.copy_ctor* returned, %struct.copy_ctor* dereferenceable(8)) // @@ -64,7 +64,7 @@ struct __attribute__((aligned(16))) alig aligned_copy_ctor(aligned_copy_ctor const &); }; test(aligned_copy_ctor); -// CHECK: define void @_Z7forward17aligned_copy_ctor(%struct.aligned_copy_ctor* noalias sret %{{.*}}, %struct.aligned_copy_ctor* %{{.*}}) +// CHECK: define void @_Z7forward17aligned_copy_ctor(%struct.aligned_copy_ctor* noalias sret %{{.*}}, %struct.aligned_copy_ctor* nonnull %{{.*}}) // // CHECK: declare %struct.aligned_copy_ctor* @_ZN17aligned_copy_ctorC1ERKS_(%struct.aligned_copy_ctor* returned, %struct.aligned_copy_ctor* dereferenceable(16)) // ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r372600 - [Diagnostics] Avoid -Wsizeof-array-div when dividing the size of a nested array by the size of the deepest base type
Author: xbolva00 Date: Mon Sep 23 05:54:35 2019 New Revision: 372600 URL: http://llvm.org/viewvc/llvm-project?rev=372600&view=rev Log: [Diagnostics] Avoid -Wsizeof-array-div when dividing the size of a nested array by the size of the deepest base type Modified: cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/Sema/div-sizeof-array.cpp Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=372600&r1=372599&r2=372600&view=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Sep 23 05:54:35 2019 @@ -9191,7 +9191,8 @@ static void DiagnoseDivisionSizeofPointe } } else if (const auto *ArrayTy = S.Context.getAsArrayType(LHSTy)) { QualType ArrayElemTy = ArrayTy->getElementType(); -if (ArrayElemTy->isDependentType() || RHSTy->isDependentType() || +if (ArrayElemTy != S.Context.getBaseElementType(ArrayTy) || +ArrayElemTy->isDependentType() || RHSTy->isDependentType() || S.Context.getTypeSize(ArrayElemTy) == S.Context.getTypeSize(RHSTy)) return; S.Diag(Loc, diag::warn_division_sizeof_array) Modified: cfe/trunk/test/Sema/div-sizeof-array.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/div-sizeof-array.cpp?rev=372600&r1=372599&r2=372600&view=diff == --- cfe/trunk/test/Sema/div-sizeof-array.cpp (original) +++ cfe/trunk/test/Sema/div-sizeof-array.cpp Mon Sep 23 05:54:35 2019 @@ -26,21 +26,18 @@ void test(void) { int a11 = sizeof(arr2) / (sizeof(unsigned)); int a12 = sizeof(arr) / (sizeof(short)); - int arr4[10][12]; // expected-note 3 {{array 'arr4' declared here}} - int b1 = sizeof(arr4) / sizeof(arr2[12]); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [12]', not 'unsigned long long'}} - // expected-note@-1 {{place parentheses around the 'sizeof (arr2[12])' expression to silence this warning}} - int b2 = sizeof(arr4) / sizeof(int *); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [12]', not 'int *'}} - // expected-note@-1 {{place parentheses around the 'sizeof(int *)' expression to silence this warning}} - int b3 = sizeof(arr4) / sizeof(short *); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [12]', not 'short *'}} - // expected-note@-1 {{place parentheses around the 'sizeof(short *)' expression to silence this warning}} - - int arr5[][5] = { // expected-note 2 {{array 'arr5' declared here}} + int arr4[10][12]; + int b1 = sizeof(arr4) / sizeof(arr2[12]); + int b2 = sizeof(arr4) / sizeof(int *); + int b3 = sizeof(arr4) / sizeof(short *); + int arr5[][5] = { {1, 2, 3, 4, 5}, {6, 7, 8, 9, 0}, }; int c1 = sizeof(arr5) / sizeof(*arr5); - int c2 = sizeof(arr5) / sizeof(**arr5); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [5]', not 'int'}} - // expected-note@-1 {{place parentheses around the 'sizeof (**arr5)' expression to silence this warning}} - int c3 = sizeof(arr5) / sizeof(int); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [5]', not 'int'}} - // expected-note@-1 {{place parentheses around the 'sizeof(int)' expression to silence this warning}} + int c2 = sizeof(arr5) / sizeof(**arr5); + int c3 = sizeof(arr5) / sizeof(int); + + float m[4][4]; + int d1 = sizeof(m) / sizeof(**m); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r372612 - [Diagnostics] Warn if '<<' in bool context with -Wint-in-bool-context (GCC compatibility)
Author: xbolva00 Date: Mon Sep 23 07:21:08 2019 New Revision: 372612 URL: http://llvm.org/viewvc/llvm-project?rev=372612&view=rev Log: [Diagnostics] Warn if '<<' in bool context with -Wint-in-bool-context (GCC compatibility) Extracted from D63082, addressed review comments related to a warning message. Added: cfe/trunk/test/Sema/warn-int-in-bool-context.c Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaChecking.cpp cfe/trunk/test/SemaCXX/cxx2a-explicit-bool.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=372612&r1=372611&r2=372612&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Mon Sep 23 07:21:08 2019 @@ -499,6 +499,7 @@ def StringCompare : DiagGroup<"string-co def StringPlusInt : DiagGroup<"string-plus-int">; def StringPlusChar : DiagGroup<"string-plus-char">; def StrncatSize : DiagGroup<"strncat-size">; +def IntInBoolContext : DiagGroup<"int-in-bool-context">; def TautologicalTypeLimitCompare : DiagGroup<"tautological-type-limit-compare">; def TautologicalUnsignedZeroCompare : DiagGroup<"tautological-unsigned-zero-compare">; def TautologicalUnsignedEnumZeroCompare : DiagGroup<"tautological-unsigned-enum-zero-compare">; @@ -821,6 +822,7 @@ def Most : DiagGroup<"most", [ Format, Implicit, InfiniteRecursion, +IntInBoolContext, MismatchedTags, MissingBraces, Move, Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=372612&r1=372611&r2=372612&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Sep 23 07:21:08 2019 @@ -5720,6 +5720,9 @@ def warn_precedence_conditional : Warnin def note_precedence_conditional_first : Note< "place parentheses around the '?:' expression to evaluate it first">; +def warn_left_shift_in_bool_context : Warning< + "converting the result of '<<' to a boolean; did you mean '(%0) != 0'?">, + InGroup; def warn_logical_instead_of_bitwise : Warning< "use of logical '%0' with constant operand">, InGroup>; Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=372612&r1=372611&r2=372612&view=diff == --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Sep 23 07:21:08 2019 @@ -11256,10 +11256,16 @@ static bool isSameWidthConstantConversio return true; } -static void DiagnoseIntInBoolContext(Sema &S, const Expr *E) { +static void DiagnoseIntInBoolContext(Sema &S, Expr *E) { E = E->IgnoreParenImpCasts(); SourceLocation ExprLoc = E->getExprLoc(); + if (const auto *BO = dyn_cast(E)) { +BinaryOperator::Opcode Opc = BO->getOpcode(); +if (Opc == BO_Shl) + S.Diag(ExprLoc, diag::warn_left_shift_in_bool_context) << E; + } + if (const auto *CO = dyn_cast(E)) { const auto *LHS = dyn_cast(CO->getTrueExpr()); if (!LHS) { @@ -11585,6 +11591,9 @@ static void CheckImplicitConversion(Sema S.DiscardMisalignedMemberAddress(Target, E); + if (Target->isBooleanType()) +DiagnoseIntInBoolContext(S, E); + if (!Source->isIntegerType() || !Target->isIntegerType()) return; Added: cfe/trunk/test/Sema/warn-int-in-bool-context.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-int-in-bool-context.c?rev=372612&view=auto == --- cfe/trunk/test/Sema/warn-int-in-bool-context.c (added) +++ cfe/trunk/test/Sema/warn-int-in-bool-context.c Mon Sep 23 07:21:08 2019 @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wint-in-bool-context %s +// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wall %s +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wint-in-bool-context %s +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wall %s + +#define ONE 1 +#define TWO 2 + +#define SHIFT(l, r) l << r + +#ifdef __cplusplus +typedef bool boolean; +#else +typedef _Bool boolean; +#endif + +int test(int a) { + boolean r; + r = (1 << 3); // expected-warning {{converting the result of '<<' to a boolean; did you mean '(1 << 3) != 0'?}} + r = TWO << 7; // expected-warning {{converting the result of '<<' to a boolean; did you mean '(2 << 7) != 0'?}} + r = a << 7; // expected-warning {{converting the result of '<<' to a boolean; did you mean '(a << 7) != 0'?}} + r = ONE << a; // expecte
r372664 - [Diagnostics] Warn for enum constants in bool context (-Wint-in-bool-context; GCC compatibility)
Author: xbolva00 Date: Mon Sep 23 15:09:49 2019 New Revision: 372664 URL: http://llvm.org/viewvc/llvm-project?rev=372664&view=rev Log: [Diagnostics] Warn for enum constants in bool context (-Wint-in-bool-context; GCC compatibility) Extracted from D63082. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/Sema/warn-int-in-bool-context.c Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=372664&r1=372663&r2=372664&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Sep 23 15:09:49 2019 @@ -5720,6 +5720,9 @@ def warn_precedence_conditional : Warnin def note_precedence_conditional_first : Note< "place parentheses around the '?:' expression to evaluate it first">; +def warn_enum_constant_in_bool_context : Warning< + "converting the enum constant to a boolean">, + InGroup; def warn_left_shift_in_bool_context : Warning< "converting the result of '<<' to a boolean; did you mean '(%0) != 0'?">, InGroup; @@ -6156,6 +6159,10 @@ def warn_comparison_of_mixed_enum_types "comparison of two values with different enumeration types" "%diff{ ($ and $)|}0,1">, InGroup; +def warn_conditional_mixed_enum_types : Warning< + "enumeration type mismatch in conditional expression" + "%diff{ ($ and $)|}0,1">, + InGroup; def warn_comparison_of_mixed_enum_types_switch : Warning< "comparison of two values with different enumeration types in switch statement" "%diff{ ($ and $)|}0,1">, Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=372664&r1=372663&r2=372664&view=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Sep 23 15:09:49 2019 @@ -11297,10 +11297,22 @@ inline QualType Sema::CheckLogicalOperan if (LHS.get()->getType()->isVectorType() || RHS.get()->getType()->isVectorType()) return CheckVectorLogicalOperands(LHS, RHS, Loc); + bool EnumConstantInBoolContext = false; + for (const ExprResult &HS : {LHS, RHS}) { +if (const auto *DREHS = dyn_cast(HS.get())) { + const auto *ECDHS = dyn_cast(DREHS->getDecl()); + if (ECDHS && ECDHS->getInitVal() != 0 && ECDHS->getInitVal() != 1) +EnumConstantInBoolContext = true; +} + } + + if (EnumConstantInBoolContext) +Diag(Loc, diag::warn_enum_constant_in_bool_context); + // Diagnose cases where the user write a logical and/or but probably meant a // bitwise one. We do this when the LHS is a non-bool integer and the RHS // is a constant. - if (LHS.get()->getType()->isIntegerType() && + if (!EnumConstantInBoolContext && LHS.get()->getType()->isIntegerType() && !LHS.get()->getType()->isBooleanType() && RHS.get()->getType()->isIntegerType() && !RHS.get()->isValueDependent() && // Don't warn in macros or template instantiations. Modified: cfe/trunk/test/Sema/warn-int-in-bool-context.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-int-in-bool-context.c?rev=372664&r1=372663&r2=372664&view=diff == --- cfe/trunk/test/Sema/warn-int-in-bool-context.c (original) +++ cfe/trunk/test/Sema/warn-int-in-bool-context.c Mon Sep 23 15:09:49 2019 @@ -14,7 +14,13 @@ typedef bool boolean; typedef _Bool boolean; #endif -int test(int a) { +enum num { + zero, + one, + two, +}; + +int test(int a, enum num n) { boolean r; r = (1 << 3); // expected-warning {{converting the result of '<<' to a boolean; did you mean '(1 << 3) != 0'?}} r = TWO << 7; // expected-warning {{converting the result of '<<' to a boolean; did you mean '(2 << 7) != 0'?}} @@ -26,6 +32,26 @@ int test(int a) { if (a << TWO) // expected-warning {{converting the result of '<<' to a boolean; did you mean '(a << 2) != 0'?}} return a; + if (n || two) +// expected-warning@-1 {{converting the enum constant to a boolean}} +return a; + + if (n == one || two) +// expected-warning@-1 {{converting the enum constant to a boolean}} +return a; + + if (r && two) +// expected-warning@-1 {{converting the enum constant to a boolean}} +return a; + + if (two && r) +// expected-warning@-1 {{converting the enum constant to a boolean}} +return a; + + if (n == one && two) +// expected-warning@-1 {{converting the enum constant to a boolean}} +return a; + // Don't warn in macros. return SHIFT(1, a); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r372708 - [Diagnostics] Do not diagnose unsigned shifts in boolean context (-Wint-in-bool-context)
Author: xbolva00 Date: Tue Sep 24 02:14:33 2019 New Revision: 372708 URL: http://llvm.org/viewvc/llvm-project?rev=372708&view=rev Log: [Diagnostics] Do not diagnose unsigned shifts in boolean context (-Wint-in-bool-context) I was looking at old GCC's patch. Current "trunk" version avoids warning for unsigned case, GCC warns only for signed shifts. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaChecking.cpp cfe/trunk/test/Sema/warn-int-in-bool-context.c Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=372708&r1=372707&r2=372708&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Sep 24 02:14:33 2019 @@ -5722,10 +5722,10 @@ def note_precedence_conditional_first : def warn_enum_constant_in_bool_context : Warning< "converting the enum constant to a boolean">, - InGroup; + InGroup, DefaultIgnore; def warn_left_shift_in_bool_context : Warning< "converting the result of '<<' to a boolean; did you mean '(%0) != 0'?">, - InGroup; + InGroup, DefaultIgnore; def warn_logical_instead_of_bitwise : Warning< "use of logical '%0' with constant operand">, InGroup>; Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=372708&r1=372707&r2=372708&view=diff == --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Sep 24 02:14:33 2019 @@ -11296,44 +11296,39 @@ static bool isSameWidthConstantConversio return true; } +static const IntegerLiteral *getIntegerLiteral(Expr *E) { + const auto *IL = dyn_cast(E); + if (!IL) { +if (auto *UO = dyn_cast(E)) { + if (UO->getOpcode() == UO_Minus) +return dyn_cast(UO->getSubExpr()); +} + } + + return IL; +} + static void DiagnoseIntInBoolContext(Sema &S, Expr *E) { E = E->IgnoreParenImpCasts(); SourceLocation ExprLoc = E->getExprLoc(); if (const auto *BO = dyn_cast(E)) { BinaryOperator::Opcode Opc = BO->getOpcode(); -if (Opc == BO_Shl) +// Do not diagnose unsigned shifts. +if (Opc == BO_Shl && E->getType()->isSignedIntegerType()) S.Diag(ExprLoc, diag::warn_left_shift_in_bool_context) << E; } if (const auto *CO = dyn_cast(E)) { -const auto *LHS = dyn_cast(CO->getTrueExpr()); -if (!LHS) { - if (auto *UO = dyn_cast(CO->getTrueExpr())) { -if (UO->getOpcode() == UO_Minus) - LHS = dyn_cast(UO->getSubExpr()); -if (!LHS) - return; - } else { -return; - } -} - -const auto *RHS = dyn_cast(CO->getFalseExpr()); -if (!RHS) { - if (auto *UO = dyn_cast(CO->getFalseExpr())) { -if (UO->getOpcode() == UO_Minus) - RHS = dyn_cast(UO->getSubExpr()); -if (!RHS) - return; - } else { -return; - } -} - +const auto *LHS = getIntegerLiteral(CO->getTrueExpr()); +if (!LHS) + return; +const auto *RHS = getIntegerLiteral(CO->getFalseExpr()); +if (!RHS) + return; if ((LHS->getValue() == 0 || LHS->getValue() == 1) && (RHS->getValue() == 0 || RHS->getValue() == 1)) - // Do not diagnose common idioms + // Do not diagnose common idioms. return; if (LHS->getValue() != 0 && LHS->getValue() != 0) S.Diag(ExprLoc, diag::warn_integer_constants_in_conditional_always_true); Modified: cfe/trunk/test/Sema/warn-int-in-bool-context.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-int-in-bool-context.c?rev=372708&r1=372707&r2=372708&view=diff == --- cfe/trunk/test/Sema/warn-int-in-bool-context.c (original) +++ cfe/trunk/test/Sema/warn-int-in-bool-context.c Tue Sep 24 02:14:33 2019 @@ -7,6 +7,8 @@ #define TWO 2 #define SHIFT(l, r) l << r +#define MM a << a +#define AF 1 << 7 #ifdef __cplusplus typedef bool boolean; @@ -20,15 +22,25 @@ enum num { two, }; -int test(int a, enum num n) { +int test(int a, unsigned b, enum num n) { boolean r; - r = (1 << 3); // expected-warning {{converting the result of '<<' to a boolean; did you mean '(1 << 3) != 0'?}} - r = TWO << 7; // expected-warning {{converting the result of '<<' to a boolean; did you mean '(2 << 7) != 0'?}} + r = a << a; // expected-warning {{converting the result of '<<' to a boolean; did you mean '(a << a) != 0'?}} + r = MM; // expected-warning {{converting the result of '<<' to a boolean; did you mean '(a << a) != 0'?}} + r = (1 << 7); // expected-warning {{converting the result of '<<' to a boolean; did you mean '(1 << 7) != 0'?}} + r = 2UL << 2;
r372709 - [NFC] Update test after r372708
Author: xbolva00 Date: Tue Sep 24 02:24:48 2019 New Revision: 372709 URL: http://llvm.org/viewvc/llvm-project?rev=372709&view=rev Log: [NFC] Update test after r372708 Modified: cfe/trunk/test/SemaCXX/cxx2a-explicit-bool.cpp Modified: cfe/trunk/test/SemaCXX/cxx2a-explicit-bool.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx2a-explicit-bool.cpp?rev=372709&r1=372708&r2=372709&view=diff == --- cfe/trunk/test/SemaCXX/cxx2a-explicit-bool.cpp (original) +++ cfe/trunk/test/SemaCXX/cxx2a-explicit-bool.cpp Tue Sep 24 02:24:48 2019 @@ -20,7 +20,7 @@ namespace special_cases template struct A { // expected-note@-1+ {{candidate constructor}} - explicit(1 << a) // expected-warning {{converting the result of '<<' to a boolean; did you mean '(1 << -1) != 0'?}} + explicit(1 << a) // expected-note@-1 {{negative shift count -1}} // expected-error@-2 {{explicit specifier argument is not a constant expression}} A(int); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r372749 - [Diagnostics] Handle tautological left shifts in boolean context
Author: xbolva00 Date: Tue Sep 24 06:14:18 2019 New Revision: 372749 URL: http://llvm.org/viewvc/llvm-project?rev=372749&view=rev Log: [Diagnostics] Handle tautological left shifts in boolean context Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaChecking.cpp cfe/trunk/test/Sema/warn-int-in-bool-context.c Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=372749&r1=372748&r2=372749&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Sep 24 06:14:18 2019 @@ -6155,6 +6155,10 @@ def warn_integer_constants_in_conditiona "converting the result of '?:' with integer constants to a boolean always " "evaluates to 'true'">, InGroup; +def warn_left_shift_always : Warning< + "converting the result of '<<' to a boolean always evaluates " + "to %select{false|true}0">, + InGroup; def warn_comparison_of_mixed_enum_types : Warning< "comparison of two values with different enumeration types" "%diff{ ($ and $)|}0,1">, Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=372749&r1=372748&r2=372749&view=diff == --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Sep 24 06:14:18 2019 @@ -11314,17 +11314,26 @@ static void DiagnoseIntInBoolContext(Sem if (const auto *BO = dyn_cast(E)) { BinaryOperator::Opcode Opc = BO->getOpcode(); +Expr::EvalResult Result; // Do not diagnose unsigned shifts. -if (Opc == BO_Shl && E->getType()->isSignedIntegerType()) - S.Diag(ExprLoc, diag::warn_left_shift_in_bool_context) << E; +if (Opc == BO_Shl) { + const auto *LHS = getIntegerLiteral(BO->getLHS()); + const auto *RHS = getIntegerLiteral(BO->getRHS()); + if (LHS && LHS->getValue() == 0) +S.Diag(ExprLoc, diag::warn_left_shift_always) << 0; + else if (RHS && RHS->getValue().isNonNegative() && + E->EvaluateAsInt(Result, S.Context, Expr::SE_AllowSideEffects)) +S.Diag(ExprLoc, diag::warn_left_shift_always) +<< (Result.Val.getInt() != 0); + else if (E->getType()->isSignedIntegerType()) +S.Diag(ExprLoc, diag::warn_left_shift_in_bool_context) << E; +} } if (const auto *CO = dyn_cast(E)) { const auto *LHS = getIntegerLiteral(CO->getTrueExpr()); -if (!LHS) - return; const auto *RHS = getIntegerLiteral(CO->getFalseExpr()); -if (!RHS) +if (!LHS || !RHS) return; if ((LHS->getValue() == 0 || LHS->getValue() == 1) && (RHS->getValue() == 0 || RHS->getValue() == 1)) Modified: cfe/trunk/test/Sema/warn-int-in-bool-context.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-int-in-bool-context.c?rev=372749&r1=372748&r2=372749&view=diff == --- cfe/trunk/test/Sema/warn-int-in-bool-context.c (original) +++ cfe/trunk/test/Sema/warn-int-in-bool-context.c Tue Sep 24 06:14:18 2019 @@ -24,12 +24,17 @@ enum num { int test(int a, unsigned b, enum num n) { boolean r; - r = a << a; // expected-warning {{converting the result of '<<' to a boolean; did you mean '(a << a) != 0'?}} - r = MM; // expected-warning {{converting the result of '<<' to a boolean; did you mean '(a << a) != 0'?}} - r = (1 << 7); // expected-warning {{converting the result of '<<' to a boolean; did you mean '(1 << 7) != 0'?}} - r = 2UL << 2; - r = 2 << b; // expected-warning {{converting the result of '<<' to a boolean; did you mean '(2 << b) != 0'?}} - r = (unsigned)(2 << b); + r = a << a;// expected-warning {{converting the result of '<<' to a boolean; did you mean '(a << a) != 0'?}} + r = MM;// expected-warning {{converting the result of '<<' to a boolean; did you mean '(a << a) != 0'?}} + r = (1 << 7); // expected-warning {{converting the result of '<<' to a boolean always evaluates to true}} + r = 2UL << 2; // expected-warning {{converting the result of '<<' to a boolean always evaluates to true}} + r = 0 << a;// expected-warning {{converting the result of '<<' to a boolean always evaluates to false}} + r = 0 << 2;// expected-warning {{converting the result of '<<' to a boolean always evaluates to false}} + r = 1 << 0;// expected-warning {{converting the result of '<<' to a boolean always evaluates to true}} + r = 1 << 2;// expected-warning {{converting the result of '<<' to a boolean always evaluates to true}} + r = 1ULL << 2; // expected-warning {{converting the result of '<<' to a boolean always evaluates to true}} + r = 2 << b;// expec
r372775 - [NFC] Strenghten preconditions for warning
Author: xbolva00 Date: Tue Sep 24 13:10:57 2019 New Revision: 372775 URL: http://llvm.org/viewvc/llvm-project?rev=372775&view=rev Log: [NFC] Strenghten preconditions for warning Modified: cfe/trunk/lib/Sema/SemaChecking.cpp Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=372775&r1=372774&r2=372775&view=diff == --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Sep 24 13:10:57 2019 @@ -11321,7 +11321,8 @@ static void DiagnoseIntInBoolContext(Sem const auto *RHS = getIntegerLiteral(BO->getRHS()); if (LHS && LHS->getValue() == 0) S.Diag(ExprLoc, diag::warn_left_shift_always) << 0; - else if (RHS && RHS->getValue().isNonNegative() && + else if (!E->isValueDependent() && LHS && RHS && + RHS->getValue().isNonNegative() && E->EvaluateAsInt(Result, S.Context, Expr::SE_AllowSideEffects)) S.Diag(ExprLoc, diag::warn_left_shift_always) << (Result.Val.getInt() != 0); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r373252 - [Diagnostics] Warn if enumeration type mismatch in conditional expression
Author: xbolva00 Date: Mon Sep 30 12:55:50 2019 New Revision: 373252 URL: http://llvm.org/viewvc/llvm-project?rev=373252&view=rev Log: [Diagnostics] Warn if enumeration type mismatch in conditional expression Summary: - Useful warning - GCC compatibility (GCC warns in C++ mode) Reviewers: rsmith, aaron.ballman Reviewed By: aaron.ballman Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67919 Added: cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c Modified: cfe/trunk/lib/Sema/SemaChecking.cpp Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=373252&r1=373251&r2=373252&view=diff == --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Sep 30 12:55:50 2019 @@ -11308,6 +11308,32 @@ static const IntegerLiteral *getIntegerL return IL; } +static void CheckConditionalWithEnumTypes(Sema &S, SourceLocation Loc, + Expr *LHS, Expr *RHS) { + QualType LHSStrippedType = LHS->IgnoreParenImpCasts()->getType(); + QualType RHSStrippedType = RHS->IgnoreParenImpCasts()->getType(); + + const auto *LHSEnumType = LHSStrippedType->getAs(); + if (!LHSEnumType) +return; + const auto *RHSEnumType = RHSStrippedType->getAs(); + if (!RHSEnumType) +return; + + // Ignore anonymous enums. + if (!LHSEnumType->getDecl()->hasNameForLinkage()) +return; + if (!RHSEnumType->getDecl()->hasNameForLinkage()) +return; + + if (S.Context.hasSameUnqualifiedType(LHSStrippedType, RHSStrippedType)) +return; + + S.Diag(Loc, diag::warn_conditional_mixed_enum_types) + << LHSStrippedType << RHSStrippedType << LHS->getSourceRange() + << RHS->getSourceRange(); +} + static void DiagnoseIntInBoolContext(Sema &S, Expr *E) { E = E->IgnoreParenImpCasts(); SourceLocation ExprLoc = E->getExprLoc(); @@ -11799,6 +11825,8 @@ static void CheckConditionalOperator(Sem bool Suspicious = false; CheckConditionalOperand(S, E->getTrueExpr(), T, CC, Suspicious); CheckConditionalOperand(S, E->getFalseExpr(), T, CC, Suspicious); + CheckConditionalWithEnumTypes(S, E->getBeginLoc(), E->getTrueExpr(), +E->getFalseExpr()); if (T->isBooleanType()) DiagnoseIntInBoolContext(S, E); Added: cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c?rev=373252&view=auto == --- cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c (added) +++ cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c Mon Sep 30 12:55:50 2019 @@ -0,0 +1,39 @@ +// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare %s +// RUN: %clang_cc1 -x c -fsyntax-only -verify %s +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare %s +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s + +enum ro { A = 0x10 }; +enum rw { B = 0xFF }; +enum { C = 0x1A}; + +enum { + STATUS_SUCCESS, + STATUS_FAILURE, + MAX_BASE_STATUS_CODE +}; + +enum ExtendedStatusCodes { + STATUS_SOMETHING_INTERESTING = MAX_BASE_STATUS_CODE + 1000, +}; + + +int get_flag(int cond) { + return cond ? A : B; + #ifdef __cplusplus + // expected-warning@-2 {{enumeration type mismatch in conditional expression ('ro' and 'rw')}} + #else + // expected-no-diagnostics + #endif +} + +// In the following cases we purposefully differ from GCC and dont warn because +// this code pattern is quite sensitive and we dont want to produce so many false positives. + +int get_flag_anon_enum(int cond) { + return cond ? A : C; +} + +int foo(int c) { + return c ? STATUS_SOMETHING_INTERESTING : STATUS_SUCCESS; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r373256 - [NFCI] Updated broken test
Author: xbolva00 Date: Mon Sep 30 13:23:22 2019 New Revision: 373256 URL: http://llvm.org/viewvc/llvm-project?rev=373256&view=rev Log: [NFCI] Updated broken test Modified: cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp Modified: cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp?rev=373256&r1=373255&r2=373256&view=diff == --- cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp (original) +++ cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp Mon Sep 30 13:23:22 2019 @@ -70,11 +70,15 @@ namespace test2 { int d1 = 1 ? i : Foo::D; // expected-warning {{operand of ? changes signedness: 'test2::Foo::Named4' to 'int'}} int d2 = 1 ? Foo::D : i; // expected-warning {{operand of ? changes signedness: 'test2::Foo::Named4' to 'int'}} int d3 = 1 ? B : Foo::D; // expected-warning {{operand of ? changes signedness: 'test2::Foo::Named4' to 'int'}} +// expected-warning@+1 {{enumeration type mismatch in conditional expression ('test2::Named2' and 'test2::Foo::Named4')}} int d4 = 1 ? Foo::D : B; // expected-warning {{operand of ? changes signedness: 'test2::Foo::Named4' to 'int'}} +// expected-warning@+1 {{enumeration type mismatch in conditional expression ('test2::Foo::Named4' and 'test2::Named2')}} int e1 = 1 ? i : E; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}} int e2 = 1 ? E : i; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}} int e3 = 1 ? E : B; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}} +// expected-warning@+1 {{enumeration type mismatch in conditional expression ('test2::Named5' and 'test2::Named2')}} int e4 = 1 ? B : E; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}} +// expected-warning@+1 {{enumeration type mismatch in conditional expression ('test2::Named2' and 'test2::Named5')}} } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r373258 - [NFC] Fix tests, second try
Author: xbolva00 Date: Mon Sep 30 13:41:56 2019 New Revision: 373258 URL: http://llvm.org/viewvc/llvm-project?rev=373258&view=rev Log: [NFC] Fix tests, second try Modified: cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp Modified: cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp?rev=373258&r1=373257&r2=373258&view=diff == --- cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp (original) +++ cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp Mon Sep 30 13:41:56 2019 @@ -70,15 +70,15 @@ namespace test2 { int d1 = 1 ? i : Foo::D; // expected-warning {{operand of ? changes signedness: 'test2::Foo::Named4' to 'int'}} int d2 = 1 ? Foo::D : i; // expected-warning {{operand of ? changes signedness: 'test2::Foo::Named4' to 'int'}} int d3 = 1 ? B : Foo::D; // expected-warning {{operand of ? changes signedness: 'test2::Foo::Named4' to 'int'}} -// expected-warning@+1 {{enumeration type mismatch in conditional expression ('test2::Named2' and 'test2::Foo::Named4')}} +// expected-warning@-1 {{enumeration type mismatch in conditional expression ('test2::Named2' and 'test2::Foo::Named4')}} int d4 = 1 ? Foo::D : B; // expected-warning {{operand of ? changes signedness: 'test2::Foo::Named4' to 'int'}} -// expected-warning@+1 {{enumeration type mismatch in conditional expression ('test2::Foo::Named4' and 'test2::Named2')}} +// expected-warning@-1 {{enumeration type mismatch in conditional expression ('test2::Foo::Named4' and 'test2::Named2')}} int e1 = 1 ? i : E; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}} int e2 = 1 ? E : i; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}} int e3 = 1 ? E : B; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}} -// expected-warning@+1 {{enumeration type mismatch in conditional expression ('test2::Named5' and 'test2::Named2')}} +// expected-warning@-1 {{enumeration type mismatch in conditional expression ('test2::Named5' and 'test2::Named2')}} int e4 = 1 ? B : E; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}} -// expected-warning@+1 {{enumeration type mismatch in conditional expression ('test2::Named2' and 'test2::Named5')}} +// expected-warning@-1 {{enumeration type mismatch in conditional expression ('test2::Named2' and 'test2::Named5')}} } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r373345 - [Diagnostics] Move warning into the subgroup (-Wenum-compare-conditional)
Author: xbolva00 Date: Tue Oct 1 08:44:38 2019 New Revision: 373345 URL: http://llvm.org/viewvc/llvm-project?rev=373345&view=rev Log: [Diagnostics] Move warning into the subgroup (-Wenum-compare-conditional) Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=373345&r1=373344&r2=373345&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Oct 1 08:44:38 2019 @@ -563,8 +563,9 @@ def CoveredSwitchDefault : DiagGroup<"co def SwitchBool : DiagGroup<"switch-bool">; def SwitchEnum : DiagGroup<"switch-enum">; def Switch : DiagGroup<"switch">; +def EnumCompareConditional : DiagGroup<"enum-compare-conditional">; def EnumCompareSwitch : DiagGroup<"enum-compare-switch">; -def EnumCompare : DiagGroup<"enum-compare", [EnumCompareSwitch]>; +def EnumCompare : DiagGroup<"enum-compare", [EnumCompareConditional, EnumCompareSwitch]>; def ImplicitFallthroughPerFunction : DiagGroup<"implicit-fallthrough-per-function">; def ImplicitFallthrough : DiagGroup<"implicit-fallthrough", Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=373345&r1=373344&r2=373345&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Oct 1 08:44:38 2019 @@ -6172,7 +6172,7 @@ def warn_comparison_of_mixed_enum_types def warn_conditional_mixed_enum_types : Warning< "enumeration type mismatch in conditional expression" "%diff{ ($ and $)|}0,1">, - InGroup; + InGroup; def warn_comparison_of_mixed_enum_types_switch : Warning< "comparison of two values with different enumeration types in switch statement" "%diff{ ($ and $)|}0,1">, Modified: cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c?rev=373345&r1=373344&r2=373345&view=diff == --- cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c (original) +++ cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c Tue Oct 1 08:44:38 2019 @@ -1,5 +1,7 @@ +// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare-conditional %s // RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare %s // RUN: %clang_cc1 -x c -fsyntax-only -verify %s +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare-conditional %s // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare %s // RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r373371 - [Diagnostics] Make -Wenum-compare-conditional off by default
Author: xbolva00 Date: Tue Oct 1 11:12:13 2019 New Revision: 373371 URL: http://llvm.org/viewvc/llvm-project?rev=373371&view=rev Log: [Diagnostics] Make -Wenum-compare-conditional off by default Too many false positives, eg. in Chromium. Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=373371&r1=373370&r2=373371&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Oct 1 11:12:13 2019 @@ -565,7 +565,7 @@ def SwitchEnum : DiagGroup<"switch-e def Switch : DiagGroup<"switch">; def EnumCompareConditional : DiagGroup<"enum-compare-conditional">; def EnumCompareSwitch : DiagGroup<"enum-compare-switch">; -def EnumCompare : DiagGroup<"enum-compare", [EnumCompareConditional, EnumCompareSwitch]>; +def EnumCompare : DiagGroup<"enum-compare", [EnumCompareSwitch]>; def ImplicitFallthroughPerFunction : DiagGroup<"implicit-fallthrough-per-function">; def ImplicitFallthrough : DiagGroup<"implicit-fallthrough", Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=373371&r1=373370&r2=373371&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Oct 1 11:12:13 2019 @@ -6172,7 +6172,7 @@ def warn_comparison_of_mixed_enum_types def warn_conditional_mixed_enum_types : Warning< "enumeration type mismatch in conditional expression" "%diff{ ($ and $)|}0,1">, - InGroup; + InGroup, DefaultIgnore; def warn_comparison_of_mixed_enum_types_switch : Warning< "comparison of two values with different enumeration types in switch statement" "%diff{ ($ and $)|}0,1">, Modified: cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c?rev=373371&r1=373370&r2=373371&view=diff == --- cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c (original) +++ cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c Tue Oct 1 11:12:13 2019 @@ -1,9 +1,5 @@ // RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare-conditional %s -// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare %s -// RUN: %clang_cc1 -x c -fsyntax-only -verify %s // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare-conditional %s -// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare %s -// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s enum ro { A = 0x10 }; enum rw { B = 0xFF }; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r373375 - [NFC] Updated tests after rL373371
Author: xbolva00 Date: Tue Oct 1 11:18:45 2019 New Revision: 373375 URL: http://llvm.org/viewvc/llvm-project?rev=373375&view=rev Log: [NFC] Updated tests after rL373371 Forgot to run check-clang-semacxx. Modified: cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp Modified: cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp?rev=373375&r1=373374&r2=373375&view=diff == --- cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp (original) +++ cfe/trunk/test/SemaCXX/warn-sign-conversion.cpp Tue Oct 1 11:18:45 2019 @@ -70,15 +70,11 @@ namespace test2 { int d1 = 1 ? i : Foo::D; // expected-warning {{operand of ? changes signedness: 'test2::Foo::Named4' to 'int'}} int d2 = 1 ? Foo::D : i; // expected-warning {{operand of ? changes signedness: 'test2::Foo::Named4' to 'int'}} int d3 = 1 ? B : Foo::D; // expected-warning {{operand of ? changes signedness: 'test2::Foo::Named4' to 'int'}} -// expected-warning@-1 {{enumeration type mismatch in conditional expression ('test2::Named2' and 'test2::Foo::Named4')}} int d4 = 1 ? Foo::D : B; // expected-warning {{operand of ? changes signedness: 'test2::Foo::Named4' to 'int'}} -// expected-warning@-1 {{enumeration type mismatch in conditional expression ('test2::Foo::Named4' and 'test2::Named2')}} int e1 = 1 ? i : E; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}} int e2 = 1 ? E : i; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}} int e3 = 1 ? E : B; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}} -// expected-warning@-1 {{enumeration type mismatch in conditional expression ('test2::Named5' and 'test2::Named2')}} int e4 = 1 ? B : E; // expected-warning {{operand of ? changes signedness: 'test2::Named5' to 'int'}} -// expected-warning@-1 {{enumeration type mismatch in conditional expression ('test2::Named2' and 'test2::Named5')}} } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r373614 - [Diagnostics] Bitwise negation of a boolean expr always evaluates to true; warn with -Wbool-operation
Author: xbolva00 Date: Thu Oct 3 08:17:59 2019 New Revision: 373614 URL: http://llvm.org/viewvc/llvm-project?rev=373614&view=rev Log: [Diagnostics] Bitwise negation of a boolean expr always evaluates to true; warn with -Wbool-operation Requested here: http://lists.llvm.org/pipermail/cfe-dev/2019-October/063452.html Added: cfe/trunk/test/Sema/warn-bitwise-negation-bool.c Modified: cfe/trunk/lib/Sema/SemaExpr.cpp Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=373614&r1=373613&r2=373614&view=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Oct 3 08:17:59 2019 @@ -13470,7 +13470,6 @@ ExprResult Sema::CreateBuiltinUnaryOp(So if (Input.isInvalid()) return ExprError(); resultType = Input.get()->getType(); - if (resultType->isDependentType()) break; // C99 6.5.3.3p1. We allow complex int and float as a GCC extension. @@ -13478,6 +13477,9 @@ ExprResult Sema::CreateBuiltinUnaryOp(So // C99 does not support '~' for complex conjugation. Diag(OpLoc, diag::ext_integer_complement_complex) << resultType << Input.get()->getSourceRange(); +else if (Input.get()->IgnoreParenImpCasts()->getType()->isBooleanType()) + Diag(OpLoc, diag::warn_bitwise_negation_bool) + << FixItHint::CreateReplacement(OpLoc, "!"); else if (resultType->hasIntegerRepresentation()) break; else if (resultType->isExtVectorType() && Context.getLangOpts().OpenCL) { Added: cfe/trunk/test/Sema/warn-bitwise-negation-bool.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-bitwise-negation-bool.c?rev=373614&view=auto == --- cfe/trunk/test/Sema/warn-bitwise-negation-bool.c (added) +++ cfe/trunk/test/Sema/warn-bitwise-negation-bool.c Thu Oct 3 08:17:59 2019 @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wbool-operation %s +// RUN: %clang_cc1 -x c -fsyntax-only -verify %s +// RUN: %clang_cc1 -x c -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wbool-operation %s +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s +// RUN: %clang_cc1 -x c++ -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s + +#ifdef __cplusplus +typedef bool boolean; +#else +typedef _Bool boolean; +#endif + +void test(boolean b, int i) { + b = ~b; // expected-warning {{bitwise negation of a boolean expression always evaluates to 'true'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!" + b = ~(b); // expected-warning {{bitwise negation of a boolean expression always evaluates to 'true'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!" + b = ~i; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r373616 - [NFC] Added missing changes for rL373614
Author: xbolva00 Date: Thu Oct 3 08:26:26 2019 New Revision: 373616 URL: http://llvm.org/viewvc/llvm-project?rev=373616&view=rev Log: [NFC] Added missing changes for rL373614 Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=373616&r1=373615&r2=373616&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Oct 3 08:26:26 2019 @@ -6635,6 +6635,9 @@ def note_member_declared_here : Note< "member %0 declared here">; def note_member_first_declared_here : Note< "member %0 first declared here">; +def warn_bitwise_negation_bool : Warning< + "bitwise negation of a boolean expression always evaluates to 'true'">, + InGroup>; def err_decrement_bool : Error<"cannot decrement expression of type bool">; def warn_increment_bool : Warning< "incrementing expression of type bool is deprecated and " ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r373743 - [NFCI] Improve the -Wbool-operation's warning message
Author: xbolva00 Date: Fri Oct 4 05:55:13 2019 New Revision: 373743 URL: http://llvm.org/viewvc/llvm-project?rev=373743&view=rev Log: [NFCI] Improve the -Wbool-operation's warning message Based on the request from the post commit review. Also added one new test. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/test/Sema/warn-bitwise-negation-bool.c Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=373743&r1=373742&r2=373743&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Oct 4 05:55:13 2019 @@ -6638,7 +6638,7 @@ def note_member_declared_here : Note< def note_member_first_declared_here : Note< "member %0 first declared here">; def warn_bitwise_negation_bool : Warning< - "bitwise negation of a boolean expression always evaluates to 'true'">, + "bitwise negation of a boolean expression; did you mean a logicial negation?">, InGroup>; def err_decrement_bool : Error<"cannot decrement expression of type bool">; def warn_increment_bool : Warning< Modified: cfe/trunk/test/Sema/warn-bitwise-negation-bool.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-bitwise-negation-bool.c?rev=373743&r1=373742&r2=373743&view=diff == --- cfe/trunk/test/Sema/warn-bitwise-negation-bool.c (original) +++ cfe/trunk/test/Sema/warn-bitwise-negation-bool.c Fri Oct 4 05:55:13 2019 @@ -12,9 +12,11 @@ typedef _Bool boolean; #endif void test(boolean b, int i) { - b = ~b; // expected-warning {{bitwise negation of a boolean expression always evaluates to 'true'}} + b = ~b; // expected-warning {{bitwise negation of a boolean expression; did you mean a logicial negation?}} // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!" - b = ~(b); // expected-warning {{bitwise negation of a boolean expression always evaluates to 'true'}} + b = ~(b); // expected-warning {{bitwise negation of a boolean expression; did you mean a logicial negation?}} // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!" b = ~i; + i = ~b; // expected-warning {{bitwise negation of a boolean expression; did you mean a logicial negation?}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!" } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r373817 - [Diagnostics] Use Expr::isKnownToHaveBooleanValue() to check bitwise negation of bool in languages without a bool type
Author: xbolva00 Date: Sat Oct 5 01:02:11 2019 New Revision: 373817 URL: http://llvm.org/viewvc/llvm-project?rev=373817&view=rev Log: [Diagnostics] Use Expr::isKnownToHaveBooleanValue() to check bitwise negation of bool in languages without a bool type Thanks for this advice, Richard Trieu! Modified: cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/Sema/warn-bitwise-negation-bool.c Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=373817&r1=373816&r2=373817&view=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Oct 5 01:02:11 2019 @@ -13479,7 +13479,7 @@ ExprResult Sema::CreateBuiltinUnaryOp(So // C99 does not support '~' for complex conjugation. Diag(OpLoc, diag::ext_integer_complement_complex) << resultType << Input.get()->getSourceRange(); -else if (Input.get()->IgnoreParenImpCasts()->getType()->isBooleanType()) +else if (Input.get()->isKnownToHaveBooleanValue()) Diag(OpLoc, diag::warn_bitwise_negation_bool) << FixItHint::CreateReplacement(OpLoc, "!"); else if (resultType->hasIntegerRepresentation()) Modified: cfe/trunk/test/Sema/warn-bitwise-negation-bool.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-bitwise-negation-bool.c?rev=373817&r1=373816&r2=373817&view=diff == --- cfe/trunk/test/Sema/warn-bitwise-negation-bool.c (original) +++ cfe/trunk/test/Sema/warn-bitwise-negation-bool.c Sat Oct 5 01:02:11 2019 @@ -19,4 +19,6 @@ void test(boolean b, int i) { b = ~i; i = ~b; // expected-warning {{bitwise negation of a boolean expression; did you mean logical negation?}} // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!" + b = ~(i > 4); // expected-warning {{bitwise negation of a boolean expression; did you mean logical negation?}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!" } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r373818 - [NFCI] Slightly improve warning message
Author: xbolva00 Date: Sat Oct 5 01:09:06 2019 New Revision: 373818 URL: http://llvm.org/viewvc/llvm-project?rev=373818&view=rev Log: [NFCI] Slightly improve warning message Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/test/SemaCXX/warn-xor-as-pow.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=373818&r1=373817&r2=373818&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Oct 5 01:09:06 2019 @@ -3402,7 +3402,7 @@ def warn_address_of_reference_bool_conve InGroup; def warn_xor_used_as_pow : Warning< - "result of '%0' is %1; did you mean an exponentiation?">, + "result of '%0' is %1; did you mean exponentiation?">, InGroup; def warn_xor_used_as_pow_base_extra : Warning< "result of '%0' is %1; did you mean '%2' (%3)?">, Modified: cfe/trunk/test/SemaCXX/warn-xor-as-pow.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-xor-as-pow.cpp?rev=373818&r1=373817&r2=373818&view=diff == --- cfe/trunk/test/SemaCXX/warn-xor-as-pow.cpp (original) +++ cfe/trunk/test/SemaCXX/warn-xor-as-pow.cpp Sat Oct 5 01:09:06 2019 @@ -79,7 +79,7 @@ void test(unsigned a, unsigned b) { res = 2 ^ 32; // expected-warning {{result of '2 ^ 32' is 34; did you mean '1LL << 32'?}} // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:15}:"1LL << 32" // expected-note@-2 {{replace expression with '0x2 ^ 32' or use 'xor' instead of '^' to silence this warning}} - res = 2 ^ 64; // expected-warning {{result of '2 ^ 64' is 66; did you mean an exponentiation?}} + res = 2 ^ 64; // expected-warning {{result of '2 ^ 64' is 66; did you mean exponentiation?}} // expected-note@-1 {{replace expression with '0x2 ^ 64' or use 'xor' instead of '^' to silence this warning}} res = 2 ^ 65; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r373828 - [Diagnostics] Highlight expr's source range for -Wbool-operation
Author: xbolva00 Date: Sat Oct 5 06:28:15 2019 New Revision: 373828 URL: http://llvm.org/viewvc/llvm-project?rev=373828&view=rev Log: [Diagnostics] Highlight expr's source range for -Wbool-operation Warning message looks better; and GCC adds it too. Modified: cfe/trunk/lib/Sema/SemaExpr.cpp Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=373828&r1=373827&r2=373828&view=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Oct 5 06:28:15 2019 @@ -13481,6 +13481,7 @@ ExprResult Sema::CreateBuiltinUnaryOp(So << resultType << Input.get()->getSourceRange(); else if (Input.get()->isKnownToHaveBooleanValue()) Diag(OpLoc, diag::warn_bitwise_negation_bool) + << Input.get()->getSourceRange() << FixItHint::CreateReplacement(OpLoc, "!"); else if (resultType->hasIntegerRepresentation()) break; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r373973 - [Diagnostics] Emit better -Wbool-operation's warning message if we known that the result is always true
Author: xbolva00 Date: Mon Oct 7 14:57:03 2019 New Revision: 373973 URL: http://llvm.org/viewvc/llvm-project?rev=373973&view=rev Log: [Diagnostics] Emit better -Wbool-operation's warning message if we known that the result is always true Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaChecking.cpp cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/Sema/warn-bitwise-negation-bool.c Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=373973&r1=373972&r2=373973&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Oct 7 14:57:03 2019 @@ -6638,7 +6638,8 @@ def note_member_declared_here : Note< def note_member_first_declared_here : Note< "member %0 first declared here">; def warn_bitwise_negation_bool : Warning< - "bitwise negation of a boolean expression; did you mean logical negation?">, + "bitwise negation of a boolean expression%select{;| always evaluates to 'true';}0 " + "did you mean logical negation?">, InGroup>; def err_decrement_bool : Error<"cannot decrement expression of type bool">; def warn_increment_bool : Warning< Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=373973&r1=373972&r2=373973&view=diff == --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Oct 7 14:57:03 2019 @@ -11896,6 +11896,13 @@ static void AnalyzeImplicitConversions(S if (E->isTypeDependent() || E->isValueDependent()) return; + if (const auto *UO = dyn_cast(E)) +if (UO->getOpcode() == UO_Not && +UO->getSubExpr()->isKnownToHaveBooleanValue()) + S.Diag(UO->getBeginLoc(), diag::warn_bitwise_negation_bool) + << OrigE->getSourceRange() << T->isBooleanType() + << FixItHint::CreateReplacement(UO->getBeginLoc(), "!"); + // For conditional operators, we analyze the arguments as if they // were being fed directly into the output. if (isa(E)) { Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=373973&r1=373972&r2=373973&view=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Oct 7 14:57:03 2019 @@ -13479,10 +13479,6 @@ ExprResult Sema::CreateBuiltinUnaryOp(So // C99 does not support '~' for complex conjugation. Diag(OpLoc, diag::ext_integer_complement_complex) << resultType << Input.get()->getSourceRange(); -else if (Input.get()->isKnownToHaveBooleanValue()) - Diag(OpLoc, diag::warn_bitwise_negation_bool) - << Input.get()->getSourceRange() - << FixItHint::CreateReplacement(OpLoc, "!"); else if (resultType->hasIntegerRepresentation()) break; else if (resultType->isExtVectorType() && Context.getLangOpts().OpenCL) { Modified: cfe/trunk/test/Sema/warn-bitwise-negation-bool.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-bitwise-negation-bool.c?rev=373973&r1=373972&r2=373973&view=diff == --- cfe/trunk/test/Sema/warn-bitwise-negation-bool.c (original) +++ cfe/trunk/test/Sema/warn-bitwise-negation-bool.c Mon Oct 7 14:57:03 2019 @@ -12,13 +12,13 @@ typedef _Bool boolean; #endif void test(boolean b, int i) { - b = ~b; // expected-warning {{bitwise negation of a boolean expression; did you mean logical negation?}} + b = ~b; // expected-warning {{bitwise negation of a boolean expression always evaluates to 'true'; did you mean logical negation?}} // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!" - b = ~(b); // expected-warning {{bitwise negation of a boolean expression; did you mean logical negation?}} + b = ~(b); // expected-warning {{bitwise negation of a boolean expression always evaluates to 'true'; did you mean logical negation?}} // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!" b = ~i; i = ~b; // expected-warning {{bitwise negation of a boolean expression; did you mean logical negation?}} // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!" - b = ~(i > 4); // expected-warning {{bitwise negation of a boolean expression; did you mean logical negation?}} + b = ~(i > 4); // expected-warning {{bitwise negation of a boolean expression always evaluates to 'true'; did you mean logical negation?}} // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!" } ___ cfe-commits mailing list cfe-commits@lis
r370594 - [clang] Warning for non-final classes with final destructors
Author: xbolva00 Date: Sat Aug 31 11:31:19 2019 New Revision: 370594 URL: http://llvm.org/viewvc/llvm-project?rev=370594&view=rev Log: [clang] Warning for non-final classes with final destructors Marking a class' destructor final prevents the class from being inherited from. However, it is a subtle and awkward way to express that at best, and unintended at worst. It may also generate worse code (in other compilers) than marking the class itself final. For these reasons, this revision adds a warning for nonfinal classes with final destructors, with a note to suggest marking the class final to silence the warning. See https://reviews.llvm.org/D66621 for more background. Patch by logan-5 (Logan Smith) Differential Revision: https://reviews.llvm.org/D66711 Added: cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=370594&r1=370593&r2=370594&view=diff == --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sat Aug 31 11:31:19 2019 @@ -6236,6 +6236,19 @@ void Sema::CheckCompletedCXXClass(CXXRec } } + // Warn if the class has a final destructor but is not itself marked final. + if (!Record->hasAttr()) { +if (const CXXDestructorDecl *dtor = Record->getDestructor()) { + if (const FinalAttr *FA = dtor->getAttr()) { +Diag(FA->getLocation(), diag::warn_final_dtor_non_final_class) + << FA->isSpelledAsSealed(); +Diag(Record->getLocation(), diag::note_final_dtor_non_final_class_silence) + << Context.getRecordType(Record) + << FA->isSpelledAsSealed(); + } +} + } + // See if trivial_abi has to be dropped. if (Record->hasAttr()) checkIllFormedTrivialABIStruct(*Record); Modified: cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp?rev=370594&r1=370593&r2=370594&view=diff == --- cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp (original) +++ cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp Sat Aug 31 11:31:19 2019 @@ -440,6 +440,11 @@ struct SealedType sealed : SomeBase { // expected-error@+1 {{base 'SealedType' is marked 'sealed'}} struct InheritFromSealed : SealedType {}; +class SealedDestructor { // expected-note {{mark 'SealedDestructor' as 'sealed' to silence this warning}} +// expected-warning@+1 {{'sealed' keyword is a Microsoft extension}} +virtual ~SealedDestructor() sealed; // expected-warning {{class with destructor marked 'sealed' cannot be inherited from}} +}; + void AfterClassBody() { // expected-warning@+1 {{attribute 'deprecated' is ignored, place it after "struct" to apply attribute to type declaration}} struct D {} __declspec(deprecated); Added: cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp?rev=370594&view=auto == --- cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp (added) +++ cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp Sat Aug 31 11:31:19 2019 @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s -Wfinal-dtor-non-final-class + +class A { +~A(); +}; + +class B { // expected-note {{mark 'B' as 'final' to silence this warning}} +virtual ~B() final; // expected-warning {{class with destructor marked 'final' cannot be inherited from}} +}; + +class C final { +virtual ~C() final; +}; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r370595 - [NFC] Fix for rL370594
Author: xbolva00 Date: Sat Aug 31 11:35:44 2019 New Revision: 370595 URL: http://llvm.org/viewvc/llvm-project?rev=370595&view=rev Log: [NFC] Fix for rL370594 Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=370595&r1=370594&r2=370595&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Sat Aug 31 11:35:44 2019 @@ -113,6 +113,7 @@ def DeleteNonVirtualDtor : DiagGroup<"de [DeleteNonAbstractNonVirtualDtor, DeleteAbstractNonVirtualDtor]>; def AbstractFinalClass : DiagGroup<"abstract-final-class">; +def FinalDtorNonFinalClass : DiagGroup<"final-dtor-non-final-class">; def CXX11CompatDeprecatedWritableStr : DiagGroup<"c++11-compat-deprecated-writable-strings">; Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=370595&r1=370594&r2=370595&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Aug 31 11:35:44 2019 @@ -2224,6 +2224,11 @@ def err_class_marked_final_used_as_base "base %0 is marked '%select{final|sealed}1'">; def warn_abstract_final_class : Warning< "abstract class is marked '%select{final|sealed}0'">, InGroup; +def warn_final_dtor_non_final_class : Warning< + "class with destructor marked '%select{final|sealed}0' cannot be inherited from">, + InGroup; +def note_final_dtor_non_final_class_silence : Note< + "mark %0 as '%select{final|sealed}1' to silence this warning">; // C++11 attributes def err_repeat_attribute : Error<"%0 attribute cannot be repeated">; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r370597 - [clang] Devirtualization for classes with destructors marked as 'final'
Author: xbolva00 Date: Sat Aug 31 11:52:44 2019 New Revision: 370597 URL: http://llvm.org/viewvc/llvm-project?rev=370597&view=rev Log: [clang] Devirtualization for classes with destructors marked as 'final' A class with a destructor marked final cannot be derived from, so it should afford the same devirtualization opportunities as marking the entire class final. Patch by logan-5 (Logan Smith) Reviewed by rsmith Differential Revision: https://reviews.llvm.org/D66621 Modified: cfe/trunk/lib/AST/DeclCXX.cpp cfe/trunk/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp Modified: cfe/trunk/lib/AST/DeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=370597&r1=370596&r2=370597&view=diff == --- cfe/trunk/lib/AST/DeclCXX.cpp (original) +++ cfe/trunk/lib/AST/DeclCXX.cpp Sat Aug 31 11:52:44 2019 @@ -2067,10 +2067,15 @@ CXXMethodDecl *CXXMethodDecl::getDevirtu if (DevirtualizedMethod->hasAttr()) return DevirtualizedMethod; - // Similarly, if the class itself is marked 'final' it can't be overridden - // and we can therefore devirtualize the member function call. + // Similarly, if the class itself or its destructor is marked 'final', + // the class can't be derived from and we can therefore devirtualize the + // member function call. if (BestDynamicDecl->hasAttr()) return DevirtualizedMethod; + if (const auto *dtor = BestDynamicDecl->getDestructor()) { +if (dtor->hasAttr()) + return DevirtualizedMethod; + } if (const auto *DRE = dyn_cast(Base)) { if (const auto *VD = dyn_cast(DRE->getDecl())) Modified: cfe/trunk/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp?rev=370597&r1=370596&r2=370597&view=diff == --- cfe/trunk/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp (original) +++ cfe/trunk/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp Sat Aug 31 11:52:44 2019 @@ -24,11 +24,24 @@ namespace Test2 { } } -namespace Test3 { +namespace Test2a { struct A { +virtual ~A() final {} virtual int f(); }; + // CHECK-LABEL: define i32 @_ZN6Test2a1fEPNS_1AE + int f(A *a) { +// CHECK: call i32 @_ZN6Test2a1A1fEv +return a->f(); + } +} + + +namespace Test3 { + struct A { +virtual int f(); }; + struct B final : A { }; // CHECK-LABEL: define i32 @_ZN5Test31fEPNS_1BE ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r370737 - Added fixit notes for -Wfinal-dtor-non-final-class
Author: xbolva00 Date: Tue Sep 3 03:32:21 2019 New Revision: 370737 URL: http://llvm.org/viewvc/llvm-project?rev=370737&view=rev Log: Added fixit notes for -Wfinal-dtor-non-final-class Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=370737&r1=370736&r2=370737&view=diff == --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Sep 3 03:32:21 2019 @@ -6241,10 +6241,14 @@ void Sema::CheckCompletedCXXClass(CXXRec if (const CXXDestructorDecl *dtor = Record->getDestructor()) { if (const FinalAttr *FA = dtor->getAttr()) { Diag(FA->getLocation(), diag::warn_final_dtor_non_final_class) - << FA->isSpelledAsSealed(); -Diag(Record->getLocation(), diag::note_final_dtor_non_final_class_silence) - << Context.getRecordType(Record) - << FA->isSpelledAsSealed(); +<< FA->isSpelledAsSealed() +<< FixItHint::CreateRemoval(FA->getLocation()) +<< FixItHint::CreateInsertion( + getLocForEndOfToken(Record->getLocation()), + (FA->isSpelledAsSealed() ? " sealed" : " final")); +Diag(Record->getLocation(), + diag::note_final_dtor_non_final_class_silence) +<< Context.getRecordType(Record) << FA->isSpelledAsSealed(); } } } Modified: cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp?rev=370737&r1=370736&r2=370737&view=diff == --- cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp (original) +++ cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp Tue Sep 3 03:32:21 2019 @@ -1,11 +1,14 @@ // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s -Wfinal-dtor-non-final-class +// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -Wfinal-dtor-non-final-class -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s class A { ~A(); }; class B { // expected-note {{mark 'B' as 'final' to silence this warning}} +// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:8-[[@LINE-1]]:8}:" final" virtual ~B() final; // expected-warning {{class with destructor marked 'final' cannot be inherited from}} +// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:18-[[@LINE-1]]:23}:"" }; class C final { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r370740 - Fixit for -Wfinal-dtor-non-final-class
Author: xbolva00 Date: Tue Sep 3 03:54:25 2019 New Revision: 370740 URL: http://llvm.org/viewvc/llvm-project?rev=370740&view=rev Log: Fixit for -Wfinal-dtor-non-final-class Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=370740&r1=370739&r2=370740&view=diff == --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Sep 3 03:54:25 2019 @@ -6242,7 +6242,6 @@ void Sema::CheckCompletedCXXClass(CXXRec if (const FinalAttr *FA = dtor->getAttr()) { Diag(FA->getLocation(), diag::warn_final_dtor_non_final_class) << FA->isSpelledAsSealed() -<< FixItHint::CreateRemoval(FA->getLocation()) << FixItHint::CreateInsertion( getLocForEndOfToken(Record->getLocation()), (FA->isSpelledAsSealed() ? " sealed" : " final")); Modified: cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp?rev=370740&r1=370739&r2=370740&view=diff == --- cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp (original) +++ cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp Tue Sep 3 03:54:25 2019 @@ -8,7 +8,6 @@ class A { class B { // expected-note {{mark 'B' as 'final' to silence this warning}} // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:8-[[@LINE-1]]:8}:" final" virtual ~B() final; // expected-warning {{class with destructor marked 'final' cannot be inherited from}} -// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:18-[[@LINE-1]]:23}:"" }; class C final { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r371122 - [Diagnostics] Minor improvements for -Wxor-used-as-pow
Author: xbolva00 Date: Thu Sep 5 13:50:48 2019 New Revision: 371122 URL: http://llvm.org/viewvc/llvm-project?rev=371122&view=rev Log: [Diagnostics] Minor improvements for -Wxor-used-as-pow Extracted from D66397; implemented suggestion for 2^64; tests revisited. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/SemaCXX/warn-xor-as-pow.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=371122&r1=371121&r2=371122&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Sep 5 13:50:48 2019 @@ -3354,6 +3354,9 @@ def warn_address_of_reference_bool_conve "code; pointer may be assumed to always convert to true">, InGroup; +def warn_xor_used_as_pow : Warning< + "result of '%0' is %1; did you mean an exponentiation?">, + InGroup; def warn_xor_used_as_pow_base_extra : Warning< "result of '%0' is %1; did you mean '%2' (%3)?">, InGroup; @@ -3361,7 +3364,7 @@ def warn_xor_used_as_pow_base : Warning< "result of '%0' is %1; did you mean '%2'?">, InGroup; def note_xor_used_as_pow_silence : Note< - "replace expression with '%0' to silence this warning">; + "replace expression with '%0' %select{|or use 'xor' instead of '^' }1to silence this warning">; def warn_null_pointer_compare : Warning< "comparison of %select{address of|function|array}0 '%1' %select{not |}2" Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=371122&r1=371121&r2=371122&view=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep 5 13:50:48 2019 @@ -11081,33 +11081,42 @@ QualType Sema::CheckVectorCompareOperand return GetSignedVectorType(vType); } -static void diagnoseXorMisusedAsPow(Sema &S, ExprResult &LHS, ExprResult &RHS, -SourceLocation Loc) { +static void diagnoseXorMisusedAsPow(Sema &S, const ExprResult &XorLHS, +const ExprResult &XorRHS, +const SourceLocation Loc) { // Do not diagnose macros. if (Loc.isMacroID()) return; bool Negative = false; - const auto *LHSInt = dyn_cast(LHS.get()); - const auto *RHSInt = dyn_cast(RHS.get()); + bool ExplicitPlus = false; + const auto *LHSInt = dyn_cast(XorLHS.get()); + const auto *RHSInt = dyn_cast(XorRHS.get()); if (!LHSInt) return; if (!RHSInt) { // Check negative literals. -if (const auto *UO = dyn_cast(RHS.get())) { - if (UO->getOpcode() != UO_Minus) +if (const auto *UO = dyn_cast(XorRHS.get())) { + UnaryOperatorKind Opc = UO->getOpcode(); + if (Opc != UO_Minus && Opc != UO_Plus) return; RHSInt = dyn_cast(UO->getSubExpr()); if (!RHSInt) return; - Negative = true; + Negative = (Opc == UO_Minus); + ExplicitPlus = !Negative; } else { return; } } - if (LHSInt->getValue().getBitWidth() != RHSInt->getValue().getBitWidth()) + const llvm::APInt &LeftSideValue = LHSInt->getValue(); + llvm::APInt RightSideValue = RHSInt->getValue(); + if (LeftSideValue != 2 && LeftSideValue != 10) +return; + + if (LeftSideValue.getBitWidth() != RightSideValue.getBitWidth()) return; CharSourceRange ExprRange = CharSourceRange::getCharRange( @@ -11123,10 +11132,6 @@ static void diagnoseXorMisusedAsPow(Sema if (XorStr == "xor") return; - const llvm::APInt &LeftSideValue = LHSInt->getValue(); - const llvm::APInt &RightSideValue = RHSInt->getValue(); - const llvm::APInt XorValue = LeftSideValue ^ RightSideValue; - std::string LHSStr = Lexer::getSourceText( CharSourceRange::getTokenRange(LHSInt->getSourceRange()), S.getSourceManager(), S.getLangOpts()); @@ -11134,23 +11139,30 @@ static void diagnoseXorMisusedAsPow(Sema CharSourceRange::getTokenRange(RHSInt->getSourceRange()), S.getSourceManager(), S.getLangOpts()); - int64_t RightSideIntValue = RightSideValue.getSExtValue(); if (Negative) { -RightSideIntValue = -RightSideIntValue; +RightSideValue = -RightSideValue; RHSStr = "-" + RHSStr; + } else if (ExplicitPlus) { +RHSStr = "+" + RHSStr; } StringRef LHSStrRef = LHSStr; StringRef RHSStrRef = RHSStr; - // Do not diagnose binary, hexadecimal, octal literals. + // Do not diagnose literals with digit separators, binary, hexadecimal, octal + // literals. if (LHSStrRef.startswith("0b") || LHSStrRef.startswith("0B") || RHSStrRef.startswith("0b") || RHSStrRef.startswith("0B") || LHSStrRef.startswith("0x") || LHSStrRef.s
r371222 - [Diagnostics] Refactor code for -Wsizeof-pointer-div, catch more cases; also add -Wsizeof-array-div
Author: xbolva00 Date: Fri Sep 6 09:12:48 2019 New Revision: 371222 URL: http://llvm.org/viewvc/llvm-project?rev=371222&view=rev Log: [Diagnostics] Refactor code for -Wsizeof-pointer-div, catch more cases; also add -Wsizeof-array-div Previously, -Wsizeof-pointer-div failed to catch: const int *r; sizeof(r) / sizeof(int); Now fixed. Also introduced -Wsizeof-array-div which catches bugs like: sizeof(r) / sizeof(short); (Array element type does not match type of sizeof operand). Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaChecking.cpp cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/Sema/div-sizeof-ptr.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=371222&r1=371221&r2=371222&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Sep 6 09:12:48 2019 @@ -3391,6 +3391,10 @@ def note_pointer_declared_here : Note< def warn_division_sizeof_ptr : Warning< "'%0' will return the size of the pointer, not the array itself">, InGroup>; +def warn_division_sizeof_array : Warning< + "expresion will return the incorrect number of elements in the array; the array " + "element type is %0, not %1">, + InGroup>; def note_function_warning_silence : Note< "prefix with the address-of operator to silence this warning">; @@ -8003,7 +8007,7 @@ def warn_array_index_precedes_bounds : W def warn_array_index_exceeds_bounds : Warning< "array index %0 is past the end of the array (which contains %1 " "element%s2)">, InGroup; -def note_array_index_out_of_bounds : Note< +def note_array_declared_here : Note< "array %0 declared here">; def warn_printf_insufficient_data_args : Warning< Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=371222&r1=371221&r2=371222&view=diff == --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Sep 6 09:12:48 2019 @@ -13008,7 +13008,7 @@ void Sema::CheckArrayAccess(const Expr * if (ND) DiagRuntimeBehavior(ND->getBeginLoc(), BaseExpr, -PDiag(diag::note_array_index_out_of_bounds) +PDiag(diag::note_array_declared_here) << ND->getDeclName()); } Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=371222&r1=371221&r2=371222&view=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Sep 6 09:12:48 2019 @@ -9135,7 +9135,7 @@ static void checkArithmeticNull(Sema &S, << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); } -static void DiagnoseDivisionSizeofPointer(Sema &S, Expr *LHS, Expr *RHS, +static void DiagnoseDivisionSizeofPointerOrArray(Sema &S, Expr *LHS, Expr *RHS, SourceLocation Loc) { const auto *LUE = dyn_cast(LHS); const auto *RUE = dyn_cast(RHS); @@ -9154,16 +9154,29 @@ static void DiagnoseDivisionSizeofPointe else RHSTy = RUE->getArgumentExpr()->IgnoreParens()->getType(); - if (!LHSTy->isPointerType() || RHSTy->isPointerType()) -return; - if (LHSTy->getPointeeType().getCanonicalType() != RHSTy.getCanonicalType()) -return; - - S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS << LHS->getSourceRange(); - if (const auto *DRE = dyn_cast(LHSArg)) { -if (const ValueDecl *LHSArgDecl = DRE->getDecl()) - S.Diag(LHSArgDecl->getLocation(), diag::note_pointer_declared_here) - << LHSArgDecl; + if (LHSTy->isPointerType() && !RHSTy->isPointerType()) { +if (LHSTy->getPointeeType().getCanonicalType().getUnqualifiedType() != +RHSTy.getCanonicalType().getUnqualifiedType()) + return; + +S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS << LHS->getSourceRange(); +if (const auto *DRE = dyn_cast(LHSArg)) { + if (const ValueDecl *LHSArgDecl = DRE->getDecl()) +S.Diag(LHSArgDecl->getLocation(), diag::note_pointer_declared_here) +<< LHSArgDecl; +} + } else if (isa(LHSTy) && !RHSTy->isArrayType()) { +QualType ArrayElemTy = cast(LHSTy)->getElementType(); +if (isa(ArrayElemTy) || +ArrayElemTy.getCanonicalType().getUnqualifiedType() == +RHSTy.getCanonicalType().getUnqualifiedType()) + return; +S.Diag(Loc, diag::warn_division_sizeof_array) << ArrayElemTy << RHSTy; +if (const auto *DRE = dyn_cast(LHSArg)) { + if (const ValueDecl *LHSArgDecl = DRE->getDecl()) +S.Diag(LHSArgDecl->getLoca
r371223 - [NFC] Added new tests for r371222
Author: xbolva00 Date: Fri Sep 6 09:18:18 2019 New Revision: 371223 URL: http://llvm.org/viewvc/llvm-project?rev=371223&view=rev Log: [NFC] Added new tests for r371222 Added: cfe/trunk/test/Sema/div-sizeof-array.cpp Added: cfe/trunk/test/Sema/div-sizeof-array.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/div-sizeof-array.cpp?rev=371223&view=auto == --- cfe/trunk/test/Sema/div-sizeof-array.cpp (added) +++ cfe/trunk/test/Sema/div-sizeof-array.cpp Fri Sep 6 09:18:18 2019 @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 %s -verify -Wsizeof-array-div -fsyntax-only + +template +int f(Ty (&Array)[N]) { + return sizeof(Array) / sizeof(Ty); // Should not warn +} + +typedef int int32; + +void test(void) { + int arr[12]; // expected-note 2 {{array 'arr' declared here}} + unsigned long long arr2[4]; // expected-note {{array 'arr2' declared here}} + int *p = &arr[0]; + int a1 = sizeof(arr) / sizeof(*arr); + int a2 = sizeof arr / sizeof p; // expected-warning {{expresion will return the incorrect number of elements in the array; the array element type is 'int', not 'int *'}} + int a4 = sizeof arr2 / sizeof p; // expected-warning {{expresion will return the incorrect number of elements in the array; the array element type is 'unsigned long long', not 'int *'}} + int a5 = sizeof(arr) / sizeof(short); // expected-warning {{expresion will return the incorrect number of elements in the array; the array element type is 'int', not 'short'}} + int a6 = sizeof(arr) / sizeof(int32); + const char arr3[2] = "A"; + int a7 = sizeof(arr3) / sizeof(char); + + int arr4[10][12]; + int b1 = sizeof(arr4) / sizeof(arr2[12]); + int b2 = sizeof(arr4) / sizeof(int *); + int b3 = sizeof(arr4) / sizeof(short *); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r371226 - [NFCI] Unbreak buildbots
Author: xbolva00 Date: Fri Sep 6 09:30:44 2019 New Revision: 371226 URL: http://llvm.org/viewvc/llvm-project?rev=371226&view=rev Log: [NFCI] Unbreak buildbots Removed: cfe/trunk/test/Sema/div-sizeof-array.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaExpr.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=371226&r1=371225&r2=371226&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Sep 6 09:30:44 2019 @@ -3391,10 +3391,6 @@ def note_pointer_declared_here : Note< def warn_division_sizeof_ptr : Warning< "'%0' will return the size of the pointer, not the array itself">, InGroup>; -def warn_division_sizeof_array : Warning< - "expresion will return the incorrect number of elements in the array; the array " - "element type is %0, not %1">, - InGroup>; def note_function_warning_silence : Note< "prefix with the address-of operator to silence this warning">; Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=371226&r1=371225&r2=371226&view=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Sep 6 09:30:44 2019 @@ -9154,29 +9154,17 @@ static void DiagnoseDivisionSizeofPointe else RHSTy = RUE->getArgumentExpr()->IgnoreParens()->getType(); - if (LHSTy->isPointerType() && !RHSTy->isPointerType()) { -if (LHSTy->getPointeeType().getCanonicalType().getUnqualifiedType() != -RHSTy.getCanonicalType().getUnqualifiedType()) - return; + if (!LHSTy->isPointerType() || RHSTy->isPointerType()) +return; + if (LHSTy->getPointeeType().getCanonicalType().getUnqualifiedType() != + RHSTy.getCanonicalType().getUnqualifiedType()) +return; -S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS << LHS->getSourceRange(); -if (const auto *DRE = dyn_cast(LHSArg)) { - if (const ValueDecl *LHSArgDecl = DRE->getDecl()) -S.Diag(LHSArgDecl->getLocation(), diag::note_pointer_declared_here) -<< LHSArgDecl; -} - } else if (isa(LHSTy) && !RHSTy->isArrayType()) { -QualType ArrayElemTy = cast(LHSTy)->getElementType(); -if (isa(ArrayElemTy) || -ArrayElemTy.getCanonicalType().getUnqualifiedType() == -RHSTy.getCanonicalType().getUnqualifiedType()) - return; -S.Diag(Loc, diag::warn_division_sizeof_array) << ArrayElemTy << RHSTy; -if (const auto *DRE = dyn_cast(LHSArg)) { - if (const ValueDecl *LHSArgDecl = DRE->getDecl()) -S.Diag(LHSArgDecl->getLocation(), diag::note_array_declared_here) -<< LHSArgDecl; -} + S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS << LHS->getSourceRange(); + if (const auto *DRE = dyn_cast(LHSArg)) { +if (const ValueDecl *LHSArgDecl = DRE->getDecl()) + S.Diag(LHSArgDecl->getLocation(), diag::note_pointer_declared_here) + << LHSArgDecl; } } Removed: cfe/trunk/test/Sema/div-sizeof-array.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/div-sizeof-array.cpp?rev=371225&view=auto == --- cfe/trunk/test/Sema/div-sizeof-array.cpp (original) +++ cfe/trunk/test/Sema/div-sizeof-array.cpp (removed) @@ -1,26 +0,0 @@ -// RUN: %clang_cc1 %s -verify -Wsizeof-array-div -fsyntax-only - -template -int f(Ty (&Array)[N]) { - return sizeof(Array) / sizeof(Ty); // Should not warn -} - -typedef int int32; - -void test(void) { - int arr[12]; // expected-note 2 {{array 'arr' declared here}} - unsigned long long arr2[4]; // expected-note {{array 'arr2' declared here}} - int *p = &arr[0]; - int a1 = sizeof(arr) / sizeof(*arr); - int a2 = sizeof arr / sizeof p; // expected-warning {{expresion will return the incorrect number of elements in the array; the array element type is 'int', not 'int *'}} - int a4 = sizeof arr2 / sizeof p; // expected-warning {{expresion will return the incorrect number of elements in the array; the array element type is 'unsigned long long', not 'int *'}} - int a5 = sizeof(arr) / sizeof(short); // expected-warning {{expresion will return the incorrect number of elements in the array; the array element type is 'int', not 'short'}} - int a6 = sizeof(arr) / sizeof(int32); - const char arr3[2] = "A"; - int a7 = sizeof(arr3) / sizeof(char); - - int arr4[10][12]; - int b1 = sizeof(arr4) / sizeof(arr2[12]); - int b2 = sizeof(arr4) / sizeof(int *); - int b3 = sizeof(arr4) / sizeof(short *); -} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://l