[PATCH] D46033: add check for long double for __builtin_dump_struct
aaron.ballman accepted this revision. aaron.ballman added a comment. This revision is now accepted and ready to land. LGTM! Repository: rC Clang https://reviews.llvm.org/D46033 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45686: [Tooling] Clean up tmp files when creating a fixed compilation database
dstenb added a comment. Ping. It feels a bit nasty that the tools leave behind temporary files, so I think that it would be good to find a fix for that. Repository: rC Clang https://reviews.llvm.org/D45686 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42966: Fix USR generation in the presence of #line directives or linemarkes
ilya-biryukov added a comment. In https://reviews.llvm.org/D42966#1077249, @mikhail.ramalho wrote: > They are declared in some file defined by the line markers; the file are > not registered in the SourceManager as actual files, so getting the > FileEntry will always fail, that's why I changed it to get the PresumedLoc. That's the part I'm confused about. Does any of the examples in the current patch have this case (files are not registered in the source manager, but defined by the file markers)? I assume all examples in the current patch will produce USRs even without your changes, is this correct or am I missing something? > More general question is: how do we want USRs for function parameters to > >> work, specifically should USR of the same param of different declarations >> be the same or different? > > That's a good point, this patch will generated different names for the same > function param if a function is first defined then declared somewhere else. > > I guess it should follow the USR generation pattern for FunctionDecls, what > do you think? I guess it depends on the use-case, but USRs for function params do not seem to provide much value if they aren't equal across different decls of the same function. But I'm not sure whether they were designed with this use-case in mind or not. E.g. if they **are** equal, we can two `Decl`s with the same USR, but different names: int func(int param1); int func(int param2); // param1 and param2 could both have the same USR, but different names. That might (or might not) be surprising. Repository: rC Clang https://reviews.llvm.org/D42966 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45179: [libc++] Add _LIBCPP_FORCE_NODISCARD define to force-enable nodiscard in pre-C++17
lebedev.ri added inline comments. Comment at: test/libcxx/diagnostics/force_nodiscard.pass.cpp:16 +// MODULES_DEFINES: _LIBCPP_FORCE_NODISCARD +#define _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17 +#define _LIBCPP_FORCE_NODISCARD lebedev.ri wrote: > Quuxplusone wrote: > > What is the purpose of `_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17`? I guess I > > could understand a blanket opt-in "please don't warn me about discarded > > [[nodiscard]] results"; but that should be (and is) spelled > > `-Wno-unused-result`, and it has nothing to do with C++17. > > > > I like how this patch defines `_LIBCPP_NODISCARD` in non-C++17 modes; > > that's going to be very useful. But I think all these opt-in mechanisms are > > confusing and not-helpful. > > > > If we must have an opt-in/out mechanism (which I don't believe we do), > > please consider adding the following two lines to `<__config>` and removing > > the rest: > > > > #ifdef _LIBCPP_NODISCARD > > // the user has given us their preferred spelling; use it > > unconditionally > > #elif __has_cpp_attribute(nodiscard) && _LIBCPP_STD_VER > 17 > > [... etc etc ...] > > > > If we must have an opt-in/out mechanism (which I don't believe we do) > > Yes, we do. > Opt-out is pre-existing, and removing it would be an [unacceptable] > regression. > Opt-in is an enhancement. Of course, it would be nice to always default it to > on, > but as it was disscussed with @mclow.lists, this is simply not going to > happen. > This is the best we'll get. > > ``` > #ifdef _LIBCPP_NODISCARD > // the user has given us their preferred spelling; use it unconditionally > ``` > So you propose to shift the burden of picking which define to use to each and > every > libc++ user (who wants to enable nodiscard attribute for pre-C++17/whatever) > out there? > I really don't see how that would be better. I tried to do that, but completely failed to come up with testing, so i'm not going to do this here, sorry. Repository: rCXX libc++ https://reviews.llvm.org/D45179 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45179: [libc++] Add _LIBCPP_FORCE_NODISCARD define to force-enable nodiscard in pre-C++17
lebedev.ri updated this revision to Diff 143872. lebedev.ri marked 8 inline comments as done. lebedev.ri added a comment. Updated based on @mclow.lists review. Repository: rCXX libc++ https://reviews.llvm.org/D45179 Files: include/__config test/libcxx/diagnostics/force_nodiscard.fail.cpp test/libcxx/diagnostics/force_nodiscard.pass.cpp Index: test/libcxx/diagnostics/force_nodiscard.pass.cpp === --- /dev/null +++ test/libcxx/diagnostics/force_nodiscard.pass.cpp @@ -0,0 +1,25 @@ +// -*- C++ -*- +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// Test that _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17 overrides +// _LIBCPP_FORCE_NODISCARD define, always. + +// MODULES_DEFINES: _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17 +// MODULES_DEFINES: _LIBCPP_FORCE_NODISCARD +#define _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17 +#define _LIBCPP_FORCE_NODISCARD +#include <__config> + +_LIBCPP_NODISCARD_AFTER_CXX17 int foo() { return 6; } + +int main () +{ + foo(); // no error here! +} Index: test/libcxx/diagnostics/force_nodiscard.fail.cpp === --- /dev/null +++ test/libcxx/diagnostics/force_nodiscard.fail.cpp @@ -0,0 +1,29 @@ +// -*- C++ -*- +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// Test that _LIBCPP_FORCE_NODISCARD always enables nodiscard, regardless of +// the standard version. + +// REQUIRES: clang || apple-clang + +// This won't work in gcc before c++17. + +// MODULES_DEFINES: _LIBCPP_FORCE_NODISCARD +#define _LIBCPP_FORCE_NODISCARD +#include <__config> + +_LIBCPP_NODISCARD_AFTER_CXX17 int foo() { return 6; } + +int main () +{ +foo(); // expected-error {{ignoring return value of function declared with}} +// The actual attribute used may be different, so it should not be +// specified, or the test will spuriously fail. +} Index: include/__config === --- include/__config +++ include/__config @@ -1015,8 +1015,23 @@ # define _LIBCPP_CONSTEXPR_AFTER_CXX17 #endif +// NOTE: Do not use [[nodiscard]] in pre-C++17 mode +// to avoid -Wc++17-extensions warning. +// And we can't use GCC's [[gnu::warn_unused_result]] and +// __attribute__((warn_unused_result)), +// because GCC does not silence them via (void) cast. +#if __has_cpp_attribute(nodiscard) && _LIBCPP_STD_VER >= 17 +# define _LIBCPP_NODISCARD [[nodiscard]] +#elif __has_cpp_attribute(clang::warn_unused_result) +# define _LIBCPP_NODISCARD [[clang::warn_unused_result]] +#else +# define _LIBCPP_NODISCARD +#endif + #if __has_cpp_attribute(nodiscard) && _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) # define _LIBCPP_NODISCARD_AFTER_CXX17 [[nodiscard]] +#elif !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) && defined(_LIBCPP_FORCE_NODISCARD) +# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD #else # define _LIBCPP_NODISCARD_AFTER_CXX17 #endif Index: test/libcxx/diagnostics/force_nodiscard.pass.cpp === --- /dev/null +++ test/libcxx/diagnostics/force_nodiscard.pass.cpp @@ -0,0 +1,25 @@ +// -*- C++ -*- +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// Test that _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17 overrides +// _LIBCPP_FORCE_NODISCARD define, always. + +// MODULES_DEFINES: _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17 +// MODULES_DEFINES: _LIBCPP_FORCE_NODISCARD +#define _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17 +#define _LIBCPP_FORCE_NODISCARD +#include <__config> + +_LIBCPP_NODISCARD_AFTER_CXX17 int foo() { return 6; } + +int main () +{ + foo(); // no error here! +} Index: test/libcxx/diagnostics/force_nodiscard.fail.cpp === --- /dev/null +++ test/libcxx/diagnostics/force_nodiscard.fail.cpp @@ -0,0 +1,29 @@ +// -*- C++ -*- +//===--===// +// +// The LLVM Compi
[PATCH] D42966: Fix USR generation in the presence of #line directives or linemarkes
ilya-biryukov added a comment. > I assume all examples in the current patch will produce USRs even without > your changes, is this correct or am I missing something? Or is the that whenever there's a `#line` directive we get into a "virtual" file that's not registered in the `SourceManager`? Repository: rC Clang https://reviews.llvm.org/D42966 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46030: [TargetInfo] Sort target features before passing them to the backend
fhahn accepted this revision. fhahn added a comment. This revision is now accepted and ready to land. Thanks Eli, LGTM! Comment at: lib/Basic/Targets.cpp:641 Opts->Features.push_back((F.getValue() ? "+" : "-") + F.getKey().str()); + llvm::sort(Opts->Features.begin(), Opts->Features.end()); Could you add a comment here briefly explaining why we sort here? Repository: rC Clang https://reviews.llvm.org/D46030 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r330802 - Fix buildbot problems after rC330794
Author: bjope Date: Wed Apr 25 02:04:12 2018 New Revision: 330802 URL: http://llvm.org/viewvc/llvm-project?rev=330802&view=rev Log: Fix buildbot problems after rC330794 Avoiding error: no matching function for call to 'makeArrayRef' at ../tools/clang/lib/Parse/ParseTemplate.cpp:373:17 By using a local C array as input to makeArrayRef. Not sure if this is the best solution, but it makes the code compile again. Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=330802&r1=330801&r2=330802&view=diff == --- cfe/trunk/lib/Parse/ParseTemplate.cpp (original) +++ cfe/trunk/lib/Parse/ParseTemplate.cpp Wed Apr 25 02:04:12 2018 @@ -370,7 +370,8 @@ Parser::ParseConceptDefinition(SourceLoc if (DSC != DeclSpecContext::DSC_template_param) { SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch); } else { - SkipUntil(llvm::makeArrayRef({tok::comma, tok::greater}), + tok::TokenKind Tokens[] = { tok::comma, tok::greater }; + SkipUntil(llvm::makeArrayRef(Tokens), StopAtSemi | StopBeforeMatch); } return; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D43750: Allow writing calling convention attributes on function types
aaron.ballman added a comment. Ping https://reviews.llvm.org/D43750 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46019: [ASTImporter] Fix isa cast assert
martong added a comment. Hi Aleksei, Thanks for the review. We faced this assert during the CTU analysis of protobuf. We tried hard to synthesize a minimal test example both by hand and by executing creduce on multiple files. Unfortunately, we were unable to reduce to such a minimal example, yet. Nevertheless, this fix solved the problem in protobuf. `E->getFoundDecl().getDecl()` can be null when a member expression does not involve lookup. (Note, it may involve a lookup in case of a using directive which refers to a member function in a base class template.) I hoped that this patch could be accepted without tests, since it is very small and the changes are pretty straight forward, so I thought it can be easily verified by a review. Repository: rC Clang https://reviews.llvm.org/D46019 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46001: [CodeComplete] Expose helpers to get RawComment of completion result.
ioeric added a comment. This seems to do what we want for clangd, but we should also get the code owner or someone who knows the code better to take a look. Repository: rC Clang https://reviews.llvm.org/D46001 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r330803 - [clangd] Minor fixes for C++ standard library header mapping.
Author: ioeric Date: Wed Apr 25 02:17:05 2018 New Revision: 330803 URL: http://llvm.org/viewvc/llvm-project?rev=330803&view=rev Log: [clangd] Minor fixes for C++ standard library header mapping. Modified: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp Modified: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp?rev=330803&r1=330802&r2=330803&view=diff == --- clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp (original) +++ clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp Wed Apr 25 02:17:05 2018 @@ -78,6 +78,7 @@ collectIWYUHeaderMaps(CanonicalIncludes void addSystemHeadersMapping(CanonicalIncludes *Includes) { static const std::vector> SymbolMap = { + {"std::addressof", ""}, // Map symbols in to their preferred includes. {"std::basic_filebuf", ""}, {"std::basic_fstream", ""}, @@ -120,6 +121,9 @@ void addSystemHeadersMapping(CanonicalIn {"std::basic_streambuf", ""}, {"std::streambuf", ""}, {"std::wstreambuf", ""}, + {"std::uint_least16_t", ""}, // redeclares these + {"std::uint_least32_t", ""}, + {"std::declval", ""}, }; for (const auto &Pair : SymbolMap) Includes->addSymbolMapping(Pair.first, Pair.second); @@ -191,16 +195,18 @@ void addSystemHeadersMapping(CanonicalIn {"include/_G_config.h$", ""}, {"include/assert.h$", ""}, {"algorithm$", ""}, + {"valarray$", ""}, {"array$", ""}, {"atomic$", ""}, {"backward/auto_ptr.h$", ""}, {"backward/binders.h$", ""}, {"bits/algorithmfwd.h$", ""}, - {"bits/alloc_traits.h$", ""}, + {"bits/alloc_traits.h$", ""}, {"bits/allocated_ptr.h$", ""}, {"bits/allocator.h$", ""}, {"bits/atomic_base.h$", ""}, {"bits/atomic_lockfree_defines.h$", ""}, + {"bits/atomic_futex.h$", ""}, {"bits/basic_ios.h$", ""}, {"bits/basic_ios.tcc$", ""}, {"bits/basic_string.h$", ""}, @@ -211,19 +217,21 @@ void addSystemHeadersMapping(CanonicalIn {"bits/cpp_type_traits.h$", ""}, {"bits/cxxabi_forced.h$", ""}, {"bits/deque.tcc$", ""}, + {"bits/exception.h$", ""}, {"bits/exception_defines.h$", ""}, {"bits/exception_ptr.h$", ""}, {"bits/forward_list.h$", ""}, {"bits/forward_list.tcc$", ""}, {"bits/fstream.tcc$", ""}, {"bits/functexcept.h$", ""}, - {"bits/functional_hash.h$", ""}, + {"bits/functional_hash.h$", ""}, {"bits/gslice.h$", ""}, {"bits/gslice_array.h$", ""}, {"bits/hash_bytes.h$", ""}, {"bits/hashtable.h$", ""}, {"bits/hashtable_policy.h$", ""}, {"bits/indirect_array.h$", ""}, + {"bits/invoke.h$", ""}, {"bits/ios_base.h$", ""}, {"bits/istream.tcc$", ""}, {"bits/list.tcc$", ""}, @@ -241,25 +249,33 @@ void addSystemHeadersMapping(CanonicalIn {"bits/nested_exception.h$", ""}, {"bits/ostream.tcc$", ""}, {"bits/ostream_insert.h$", ""}, - {"bits/postypes.h$", ""}, + {"bits/parse_numbers.h$", ""}, + {"bits/postypes.h$", ""}, {"bits/predefined_ops.h$", ""}, {"bits/ptr_traits.h$", ""}, + {"bits/quoted_string.h$", ""}, {"bits/random.h$", ""}, {"bits/random.tcc$", ""}, {"bits/range_access.h$", ""}, + {"bits/refwrap.h$", ""}, {"bits/regex.h$", ""}, + {"bits/regex_automaton.h$", ""}, {"bits/regex_compiler.h$", ""}, {"bits/regex_constants.h$", ""}, {"bits/regex_cursor.h$", ""}, {"bits/regex_error.h$", ""}, + {"bits/regex_executor.h$", ""}, {"bits/regex_grep_matcher.h$", ""}, {"bits/regex_grep_matcher.tcc$", ""}, {"bits/regex_nfa.h$", ""}, + {"bits/regex_scanner.h$", ""}, {"bits/shared_ptr.h$", ""}, {"bits/shared_ptr_base.h$", ""}, - {"bits/shared_ptr_atomic.h$", ""}, + {"bits/shared_ptr_atomic.h$", ""}, {"bits/slice_array.h$", ""}, {"bits/sstream.tcc$", ""}, + {"bits/std_abs.h$", ""}, + {"bits/std_function.h$", ""}, {"bits/std_mutex.h$", ""}, {"bits/stl_algo.h$", ""}, {"bits/stl_algobase.h$", ""}, @@ -270,7 +286,7 @@ void addSystemHeadersMapping(CanonicalIn {"bits/stl_heap.h$", ""}, {"bits/stl_iterator.h$", ""}, {"bits/stl_iterator_base_funcs.h$", ""}, - {"bits/stl_iterator_base_types.h$", ""}, + {"bits/stl_iterator_base_types.h$", ""}, {"bits/stl_list.h$", ""},
FW: [Diffusion] rC330802: Fix buildbot problems after rC330794
Hello Faisal. Lots of buildbots have failed after your commit "[c++2a] [concepts] Add rudimentary parsing support for template concept declarations" (rC330794) Here is an example from http://lab.llvm.org:8011/builders/clang-x86_64-linux-abi-test/builds/25483/steps/build-unified-tree/logs/stdio >>> FAILED: tools/clang/lib/Parse/CMakeFiles/clangParse.dir/ParseTemplate.cpp.o /usr/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/clang/lib/Parse -I/home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/lib/Parse -I/home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/include -Itools/clang/include -Iinclude -I/home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/include -fPIC -fvisibility-inlines-hidden -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3-UNDEBUG -fno-exceptions -fno-rtti -MD -MT tools/clang/lib/Parse/CMakeFiles/clangParse.dir/ParseTemplate.cpp.o -MF tools/clang/lib/Parse/CMakeFiles/clangParse.dir/ParseTemplate.cpp.o.d -o tools/clang/lib/Parse/CMakeFiles/clangParse.dir/ParseTemplate.cpp.o -c /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/lib/Parse/ParseTemplate.cpp /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/lib/Parse/ParseTemplate.cpp: In member function ‘void clang::Parser::ParseConceptDefinition(clang::SourceLocation, clang::DeclSpec&, const clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, clang::Parser::DeclSpecContext)’: /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/lib/Parse/ParseTemplate.cpp:373:62: error: no matching function for call to ‘makeArrayRef()’ SkipUntil(llvm::makeArrayRef({tok::comma, tok::greater}), ^ /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/lib/Parse/ParseTemplate.cpp:373:62: note: candidates are: In file included from /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/include/llvm/ADT/APFloat.h:21:0, from /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/include/clang/AST/APValue.h:18, from /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/include/clang/AST/Decl.h:17, from /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/include/clang/AST/ASTTypeTraits.h:20, from /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/include/clang/AST/ASTContext.h:18, from /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/lib/Parse/ParseTemplate.cpp:14: /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/include/llvm/ADT/ArrayRef.h:451:15: note: template llvm::ArrayRef llvm::makeArrayRef(const T&) ArrayRef makeArrayRef(const T &OneElt) { ^ /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/include/llvm/ADT/ArrayRef.h:451:15: note: template argument deduction/substitution failed: /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/lib/Parse/ParseTemplate.cpp:373:62: note: couldn't deduce template parameter ‘T’ SkipUntil(llvm::makeArrayRef({tok::comma, tok::greater}), I made a quick fix in rC330802, where I use a local array as input to the makeArrayRef. With such a fix the code started to compile again for me. But I advise you to look at my fix to verify that I did not mess up anything. Regards, Björn -Original Message- From: Bjorn Pettersson via Phabricator [mailto:revi...@reviews.llvm.org] Sent: den 25 april 2018 11:08 To: Björn Pettersson A Subject: [Diffusion] rC330802: Fix buildbot problems after rC330794 bjope committed rC330802: Fix buildbot problems after rC330794. Fix buildbot problems after https://reviews.llvm.org/rC330794 Avoiding error: no matching function for call to 'makeArrayRef' at ../tools/clang/lib/Parse/ParseTemplate.cpp:373:17 By using a local C array as input to makeArrayRef. Not sure if this is the best solution, but it makes the code compile again. Files: /cfe/trunk/lib/Parse/ParseTemplate.cpp PATCH Index: lib/Parse/ParseTemplate.cpp === --- lib/Parse/ParseTemplate.cpp (revision 330801) +++ lib/Parse/ParseTemplate.cpp (revision 330802) @@ -370,7 +370,8 @@ if (DSC != DeclSpecContext::DSC_template_param) { SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch); } else { - SkipUntil(llvm::makeArr
[PATCH] D46035: [clangd] Fix unicode handling, using UTF-16 where LSP requires it.
hokein accepted this revision. hokein added a comment. This revision is now accepted and ready to land. Cool, the code looks good to me (just a few nits), thanks for the descriptive comments! > This seems likely to cause problems with editors that have the same bug, and > treat the protocol as if columns are UTF-8 bytes. But we can find and fix > those. VSCode is fine I think, but we need to fix our internal ycm vim integration. Comment at: clangd/SourceCode.cpp:25 +// Returns true if CB returned true, false if we hit the end of string. +template +bool iterateCodepoints(StringRef U8, const Callback &CB) { Can we make it `static`? The callback type is function, the reason why using template here is mainly to save some keystroke? Comment at: clangd/SourceCode.cpp:53 +// to UTF-8, and returns the length in bytes. +static size_t measureUTF16(StringRef U8, int Units, bool &Valid) { + size_t Result = 0; nit: consider naming the parameter `U16Units`? Comment at: clangd/SourceCode.cpp:72 + size_t Count = 0; + iterateCodepoints(U8, [&](int U8Len, int U16Len) { +Count += U16Len; Maybe add an `assume` to ensure `iterateCodepoints` always return false (reach the end of the U8)? Comment at: clangd/SourceCode.cpp:137 +P.character = +utf16Len(Code.substr(LocInfo.second - ColumnInBytes, ColumnInBytes)); + } nit: it took me a while to understand what the sub-expression `Code.substr(LocInfo.second - ColumnInBytes, ColumnInBytes)` does, maybe abstract it out with a descriptive name? Also it is not straight-forward to understand what `LocInfo.second` is without navigating to `getDecomposedSpellingLoc`. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D46035 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45532: [StaticAnalyzer] Checker to find uninitialized fields after a constructor call
Szelethus updated this revision to Diff 143875. Szelethus added a comment. In this diff I - added a `Pedantic` flag that is set to false by default to filter out results from objects that don't have a single field initialized, - made it so that fields that are declared in system headers are now ignored, - refactored `isFullyInitialized` to `hasUnintializedFields` (it returned true when there were in fact uninit fields), - fixed everything mentioned in inline comments aside from the naming and the category, - added TODOs for `FieldChainInfo::toString`, I decided to fix those in a later patch to keep the diff just a little bit smaller, - added many more test cases, including tests for the `Pedantic` flag - added support for arrays. Granted, they worked wonderfully with the checker before, but there was nothing mentioned about them in the code. If you like how I implemented the `Pedantic` flag, then I think only the naming and choosing the correct category is left. I also rechecked the entire LLVM/Clang project before the system header fix and after the fix with `Pedantic` set to true and set to false. Here are my findings: How many reports did the checker emit? - Without fields in system headers being ignored: 208 (only functional had some fields uninitialized) - With fields in system headers being ignored and `Pedantic` set to true: 181 - With fields in system headers being ignored and `Pedantic` set to false: 150 Most of these are intentional, as a very large portion of the project is performance critical. I did however find some constructors with the checker that would benefit from having the rest of their fields initialized. I also found some constructors that didn't use `= default` for no good reason. https://reviews.llvm.org/D45532 Files: include/clang/StaticAnalyzer/Checkers/Checkers.td lib/StaticAnalyzer/Checkers/CMakeLists.txt lib/StaticAnalyzer/Checkers/CtorUninitializedMemberChecker.cpp test/Analysis/Inputs/system-header-simulator-ctor-uninitialized-member.h test/Analysis/ctor-uninitialized-member-inheritance.cpp test/Analysis/ctor-uninitialized-member.cpp Index: test/Analysis/ctor-uninitialized-member.cpp === --- /dev/null +++ test/Analysis/ctor-uninitialized-member.cpp @@ -0,0 +1,1404 @@ +//RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.CtorUninitializedMember -analyzer-config alpha.cplusplus.CtorUninitializedMember:Pedantic=true -std=c++11 -DPEDANTIC -verify %s + +//RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.CtorUninitializedMember -std=c++11 -verify %s + +//===--===// +// Default constructor test. +//===--===// + +class CompilerGeneratedConstructorTest { + int a, b, c, d, e, f, g, h, i, j; + +public: + CompilerGeneratedConstructorTest() = default; +}; + +void f000() { + CompilerGeneratedConstructorTest(); +} + +#ifdef PEDANTIC +class DefaultConstructorTest { + int a; // expected-note{{uninitialized field 'this->a'}} + +public: + DefaultConstructorTest(); +}; + +DefaultConstructorTest::DefaultConstructorTest() = default; + +void f00() { + DefaultConstructorTest(); // expected-warning{{1 uninitialized field}} +} +#else +class DefaultConstructorTest { + int a; + +public: + DefaultConstructorTest(); +}; + +DefaultConstructorTest::DefaultConstructorTest() = default; + +void f00() { + DefaultConstructorTest(); +} +#endif // PEDANTIC + +//===--===// +// Initializer list test. +//===--===// + +class InitListTest1 { + int a; + int b; + +public: + InitListTest1() + : a(1), +b(2) { +// All good! + } +}; + +void f01() { + InitListTest1(); +} + +class InitListTest2 { + int a; + int b; // expected-note{{uninitialized field 'this->b'}} + +public: + InitListTest2() + : a(3) {} // expected-warning{{1 uninitialized field}} +}; + +void f02() { + InitListTest2(); +} + +class InitListTest3 { + int a; // expected-note{{uninitialized field 'this->a'}} + int b; + +public: + InitListTest3() + : b(4) {} // expected-warning{{1 uninitialized field}} +}; + +void f03() { + InitListTest3(); +} + +//===--===// +// Constructor body test. +//===--===// + +class CtorBodyTest1 { + int a, b; + +public: + CtorBodyTest1() { +a = 5; +b = 6; +// All good! + } +}; + +void f04() { + CtorBodyTest1(); +} + +class CtorBodyTest2 { + int a; + int b; // expected-note{{uninitialized field 'this->b'}} + +public: + CtorBodyTest2() { +a = 7; // expected-warning{{1 uninitialized field}} + } +}; + +void f05() { + CtorBodyTest2(); +} + +class C
[PATCH] D45719: [clang-Format] Fix indentation of member call after block
ank added a comment. ping Repository: rC Clang https://reviews.llvm.org/D45719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41537: Optionally add code completion results for arrow instead of dot
ilya-biryukov added a comment. Important: please upload the patch with full context diff Comment at: include/clang-c/Index.h:5278 + /** + * \brief Whether to try dot to arrow correction if arrow operator can be applied. + */ This implies that "dot to arrow" is the only available correction. Maybe rephrase to mention that others are possible in theory? E.g. ```Whether to include completion items with corrections (small fix-its), e.g. change '.' to '->' on member access, etc.``` Comment at: include/clang/Sema/CodeCompleteConsumer.h:415 +/// diagnostic. +class FullFixItHint : public FixItHint { +public: Why do we need this wrapper? It seems that storing `SourceManager` and `LangOpts` in each fix-it is clearly confusing (they are the same for all diags in the file). All clients that want to access the fix-it should have a reference to an existing `SourceManager`, right? Comment at: include/clang/Sema/CodeCompleteConsumer.h:577 + /// \brief For this completion result correction is required. + std::vector Corrections; + Storing fix-its in `CodeCompletionString` seems like to be against its original intention, i.e. now it depends on `SourceLocation`s, which require `SourceManager`, etc. Is there a way to get to a `CodeCompletionResult` from `libclang`? Storing fix-its there would be ideal. Comment at: include/clang/Sema/CodeCompleteConsumer.h:704 +CXAvailabilityKind Availability, +const std::vector &Corrections) : Allocator(Allocator), CCTUInfo(CCTUInfo), Priority(Priority), Maybe accept the vector by value instead of const reference to allow the clients to `std::move` the argument and avoid copies? https://reviews.llvm.org/D41537 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45921: Add getDeserializationListener to ASTReader
yamaguchi added a comment. Do you mean something like `addDeserializationListener` which create a multiplex listener with an existing listener? I think that'll be good as well! https://reviews.llvm.org/D45921 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46000: [AST] Added a helper to extract a user-friendly text of a comment.
ilya-biryukov updated this revision to Diff 143881. ilya-biryukov added a comment. Added forgotten bits of the change Repository: rC Clang https://reviews.llvm.org/D46000 Files: include/clang/AST/CommentLexer.h include/clang/AST/RawCommentList.h lib/AST/CommentLexer.cpp lib/AST/RawCommentList.cpp Index: lib/AST/RawCommentList.cpp === --- lib/AST/RawCommentList.cpp +++ lib/AST/RawCommentList.cpp @@ -335,3 +335,91 @@ BeforeThanCompare(SourceMgr)); std::swap(Comments, MergedComments); } + +std::string RawComment::getFormattedText(const ASTContext &Ctx) const { + auto &SourceMgr = Ctx.getSourceManager(); + llvm::StringRef CommentText = getRawText(SourceMgr); + if (CommentText.empty()) +return ""; // we couldn't retreive the comment. + + llvm::BumpPtrAllocator Allocator; + comments::Lexer L(Allocator, Ctx.getDiagnostics(), +Ctx.getCommentCommandTraits(), getSourceRange().getBegin(), +CommentText.begin(), CommentText.end(), +/*ParseCommentText=*/false); + + // Trim whitespace at the start of \p S of length up to the value of \p + // MaxSkip. + auto SkipWs = [](llvm::StringRef S, unsigned MaxSkip) -> llvm::StringRef { +unsigned SkipLen = std::min( +MaxSkip, (unsigned)std::min(S.size(), S.find_first_not_of(" \t"))); +return S.drop_front(SkipLen); + }; + + std::string Result; + unsigned IndentColumn = 0; + + // Processes one line of the comment and adds it to the result. + // Handles skipping the indent at the start of the line. + // Returns false when eof is reached and true otherwise. + auto LexLine = [&](bool IsFirstLine) -> bool { +comments::Token Tok; +// Lex the first token on the line. We handle it separately, because we to +// fix up its indentation. +L.lex(Tok); +if (Tok.is(comments::tok::eof)) + return false; +if (Tok.is(comments::tok::newline)) { + Result += "\n"; + return true; +} +llvm::StringRef TokText = L.getSpelling(Tok, SourceMgr); +bool LocInvalid = false; +unsigned TokColumn = +SourceMgr.getSpellingColumnNumber(Tok.getLocation(), &LocInvalid); +if (LocInvalid) + TokColumn = 0; +// Compute the length of whitespace we're allowed to skip. +unsigned MaxSkip; +if (IsFirstLine) { + // For the first line we skip all leading ws. + MaxSkip = std::numeric_limits::max(); +} else { + // For the rest, we skip up to the column of first non-ws symbol on the + // first line.. + MaxSkip = std::max((int)IndentColumn - (int)TokColumn, 0); +} +llvm::StringRef Trimmed = SkipWs(TokText, MaxSkip); +Result += Trimmed; +// Remember the amount of whitespace we skipped in the first line to remove +// indent up to that column in the following lines. +if (IsFirstLine) + IndentColumn = TokColumn + TokText.size() - Trimmed.size(); +// Lex all tokens in the rest of the line. +for (L.lex(Tok); Tok.isNot(comments::tok::eof); L.lex(Tok)) { + if (Tok.is(comments::tok::newline)) { +Result += "\n"; +return true; + } + Result += L.getSpelling(Tok, SourceMgr); +} +// We've reached the end of the line. +return false; + }; + + auto DropTrailingNewLines = [](std::string &Str) { +while (Str.back() == '\n') + Str.pop_back(); + }; + + // Proces first line separately to remember indent for the following lines. + if (!LexLine(/*IsFirstLine=*/true)) { +DropTrailingNewLines(Result); +return Result; + } + // Process the rest of the lines. + while (LexLine(/*IsFirstLine=*/false)) +; + DropTrailingNewLines(Result); + return Result; +} Index: lib/AST/CommentLexer.cpp === --- lib/AST/CommentLexer.cpp +++ lib/AST/CommentLexer.cpp @@ -291,6 +291,14 @@ } void Lexer::lexCommentText(Token &T) { + if (ParseCommands) +lexCommentTextWithCommands(T); + else +lexCommentTextWithoutCommands(T); +} + +void Lexer::lexCommentTextWithCommands(Token &T) { + assert(ParseCommands); assert(CommentState == LCS_InsideBCPLComment || CommentState == LCS_InsideCComment); @@ -448,6 +456,39 @@ } } +void Lexer::lexCommentTextWithoutCommands(Token &T) { + assert(!ParseCommands); + assert(CommentState == LCS_InsideBCPLComment || + CommentState == LCS_InsideCComment); + assert(State == LS_Normal); + + const char *TokenPtr = BufferPtr; + assert(TokenPtr < CommentEnd); + while (TokenPtr != CommentEnd) { +switch(*TokenPtr) { + case '\n': + case '\r': +TokenPtr = skipNewline(TokenPtr, CommentEnd); +formTokenWithChars(T, TokenPtr, tok::newline); + +if (CommentState == LCS_InsideCComment) + skipLineStartingDecorations(); +return; + + default: { +size_t End = StringRef(TokenPtr, CommentEnd - TokenPt
[PATCH] D46002: [clangd] Parse all comments in Sema and completion.
sammccall added a comment. Code looks good/simple, just a couple of design questions Comment at: clangd/ClangdUnit.cpp:362 CI->getFrontendOpts().DisableFree = false; +CI->getLangOpts()->CommentOpts.ParseAllComments = true; } Any idea about whether this will affect performance significantly? Less for this patch, and more for whether this should be an option in the future that we might e.g. only do during indexing. Comment at: clangd/CodeComplete.cpp:707 CI->getFrontendOpts().DisableFree = false; + CI->getLangOpts()->CommentOpts.ParseAllComments = true; Are we sure we want to do this in code complete? I would have thought the more natural approach would be to implement resolve in terms of lookup in the index, and only provide it there. The lack of good support for resolve in YCM LSP shouldn't be a problem as YCM doesn't actually use doc comments (I think?). Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D46002 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: FW: [Diffusion] rC330802: Fix buildbot problems after rC330794
That should work - although i wonder if we still need makeArrayRef once we explicitly declare an array - either way thank you for fixing it Bjorn!! Faisal Vali On Wed, Apr 25, 2018 at 4:16 AM, Björn Pettersson A wrote: > Hello Faisal. > > Lots of buildbots have failed after your commit "[c++2a] [concepts] Add > rudimentary parsing support for template concept declarations" (rC330794) > > Here is an example from > http://lab.llvm.org:8011/builders/clang-x86_64-linux-abi-test/builds/25483/steps/build-unified-tree/logs/stdio > > > FAILED: tools/clang/lib/Parse/CMakeFiles/clangParse.dir/ParseTemplate.cpp.o > /usr/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE > -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS > -Itools/clang/lib/Parse > -I/home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/lib/Parse > > -I/home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/include > -Itools/clang/include -Iinclude > -I/home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/include > -fPIC -fvisibility-inlines-hidden -std=c++11 -Wall -W -Wno-unused-parameter > -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic > -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor > -Wno-comment -ffunction-sections -fdata-sections -fno-common > -Woverloaded-virtual -fno-strict-aliasing -O3-UNDEBUG -fno-exceptions > -fno-rtti -MD -MT > tools/clang/lib/Parse/CMakeFiles/clangParse.dir/ParseTemplate.cpp.o -MF > tools/clang/lib/Parse/CMakeFiles/clangParse.dir/ParseTemplate.cpp.o.d -o > tools/clang/lib/Parse/CMakeFiles/clangParse.dir/ParseTemplate.cpp.o -c > /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/lib/Parse/ParseTemplate.cpp > /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/lib/Parse/ParseTemplate.cpp: > In member function ‘void > clang::Parser::ParseConceptDefinition(clang::SourceLocation, > clang::DeclSpec&, const clang::Parser::ParsedTemplateInfo&, > clang::AccessSpecifier, clang::Parser::DeclSpecContext)’: > /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/lib/Parse/ParseTemplate.cpp:373:62: > error: no matching function for call to ‘makeArrayRef( initializer list>)’ >SkipUntil(llvm::makeArrayRef({tok::comma, tok::greater}), > ^ > /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/lib/Parse/ParseTemplate.cpp:373:62: > note: candidates are: > In file included from > /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/include/llvm/ADT/APFloat.h:21:0, > from > /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/include/clang/AST/APValue.h:18, > from > /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/include/clang/AST/Decl.h:17, > from > /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/include/clang/AST/ASTTypeTraits.h:20, > from > /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/include/clang/AST/ASTContext.h:18, > from > /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/lib/Parse/ParseTemplate.cpp:14: > /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/include/llvm/ADT/ArrayRef.h:451:15: > note: template llvm::ArrayRef llvm::makeArrayRef(const T&) >ArrayRef makeArrayRef(const T &OneElt) { >^ > /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/include/llvm/ADT/ArrayRef.h:451:15: > note: template argument deduction/substitution failed: > /home/buildslave/buildslave1a/clang-x86_64-linux-abi-test/llvm/tools/clang/lib/Parse/ParseTemplate.cpp:373:62: > note: couldn't deduce template parameter ‘T’ >SkipUntil(llvm::makeArrayRef({tok::comma, tok::greater}), > > > > I made a quick fix in rC330802, where I use a local array as input to the > makeArrayRef. > With such a fix the code started to compile again for me. > But I advise you to look at my fix to verify that I did not mess up anything. > > Regards, > Björn > > -Original Message- > From: Bjorn Pettersson via Phabricator [mailto:revi...@reviews.llvm.org] > Sent: den 25 april 2018 11:08 > To: Björn Pettersson A > Subject: [Diffusion] rC330802: Fix buildbot problems after rC330794 > > bjope committed rC330802: Fix buildbot problems after rC330794. > > Fix buildbot problems after https://reviews.llvm.org/rC330794 > > Avoiding > > error: no matching function for call to 'makeArrayRef' > > at > > ../tools/clang/lib/Parse/ParseTemplate.cpp:373:17 > > By using a local C array as input to makeArrayRef. > > Not sure if this is the best solution, but it makes the code > compile again. > > > Files: > /cfe/trunk/lib
[PATCH] D46001: [CodeComplete] Expose helpers to get RawComment of completion result.
ilya-biryukov updated this revision to Diff 143882. ilya-biryukov added a comment. Remove accidentally added changes that should be part of https://reviews.llvm.org/D46000 Repository: rC Clang https://reviews.llvm.org/D46001 Files: include/clang/Sema/CodeCompleteConsumer.h lib/Sema/SemaCodeComplete.cpp Index: lib/Sema/SemaCodeComplete.cpp === --- lib/Sema/SemaCodeComplete.cpp +++ lib/Sema/SemaCodeComplete.cpp @@ -2765,27 +2765,11 @@ if (Declaration) { Result.addParentContext(Declaration->getDeclContext()); Pattern->ParentName = Result.getParentName(); - // Provide code completion comment for self.GetterName where - // GetterName is the getter method for a property with name - // different from the property name (declared via a property - // getter attribute. - const NamedDecl *ND = Declaration; - if (const ObjCMethodDecl *M = dyn_cast(ND)) -if (M->isPropertyAccessor()) - if (const ObjCPropertyDecl *PDecl = M->findPropertyDecl()) -if (PDecl->getGetterName() == M->getSelector() && -PDecl->getIdentifier() != M->getIdentifier()) { - if (const RawComment *RC = -Ctx.getRawCommentForAnyRedecl(M)) { -Result.addBriefComment(RC->getBriefText(Ctx)); -Pattern->BriefComment = Result.getBriefComment(); - } - else if (const RawComment *RC = - Ctx.getRawCommentForAnyRedecl(PDecl)) { -Result.addBriefComment(RC->getBriefText(Ctx)); -Pattern->BriefComment = Result.getBriefComment(); - } -} + if (const RawComment *RC = + getPatternCompletionComment(Ctx, Declaration)) { +Result.addBriefComment(RC->getBriefText(Ctx)); +Pattern->BriefComment = Result.getBriefComment(); + } } return Pattern; @@ -2845,14 +2829,9 @@ if (IncludeBriefComments) { // Add documentation comment, if it exists. -if (const RawComment *RC = Ctx.getRawCommentForAnyRedecl(ND)) { +if (const RawComment *RC = getCompletionComment(Ctx, Declaration)) { Result.addBriefComment(RC->getBriefText(Ctx)); } -else if (const ObjCMethodDecl *OMD = dyn_cast(ND)) - if (OMD->isPropertyAccessor()) -if (const ObjCPropertyDecl *PDecl = OMD->findPropertyDecl()) - if (const RawComment *RC = Ctx.getRawCommentForAnyRedecl(PDecl)) -Result.addBriefComment(RC->getBriefText(Ctx)); } if (StartsNestedNameSpecifier) { @@ -3042,6 +3021,61 @@ return Result.TakeString(); } +const RawComment *clang::getCompletionComment(const ASTContext &Ctx, + const NamedDecl *ND) { + if (!ND) +return nullptr; + if (auto *RC = Ctx.getRawCommentForAnyRedecl(ND)) +return RC; + + // Try to find comment from a property for ObjC methods. + const ObjCMethodDecl *M = dyn_cast(ND); + if (!M) +return nullptr; + const ObjCPropertyDecl *PDecl = M->findPropertyDecl(); + if (!PDecl) +return nullptr; + + return Ctx.getRawCommentForAnyRedecl(PDecl); +} + +const RawComment *clang::getPatternCompletionComment(const ASTContext &Ctx, + const NamedDecl *ND) { + const ObjCMethodDecl *M = dyn_cast_or_null(ND); + if (!M || !M->isPropertyAccessor()) +return nullptr; + + // Provide code completion comment for self.GetterName where + // GetterName is the getter method for a property with name + // different from the property name (declared via a property + // getter attribute. + const ObjCPropertyDecl *PDecl = M->findPropertyDecl(); + if (!PDecl) +return nullptr; + if (PDecl->getGetterName() == M->getSelector() && + PDecl->getIdentifier() != M->getIdentifier()) { +if (auto *RC = Ctx.getRawCommentForAnyRedecl(M)) + return RC; +if (auto *RC = Ctx.getRawCommentForAnyRedecl(PDecl)) + return RC; + } + return nullptr; +} + +/// \brief Get the documentation comment used to produce +/// CodeCompletionString::BriefComment. +const RawComment *clang::getParameterComment( +const ASTContext &Ctx, +const CodeCompleteConsumer::OverloadCandidate &Result, +unsigned CurrentArg) { + auto FDecl = Result.getFunction(); + if (!FDecl) +return nullptr; + if (CurrentArg < FDecl->getNumParams()) +return Ctx.getRawCommentForAnyRedecl(FDecl->getParamDecl(CurrentArg)); + return nullptr; +} + /// \brief Add function overload parameter chunks to the given code completion /// string. static void AddOverloadParameterChunks(ASTContext &Context, @@ -3137,10 +3171,10 @@ } if (FDecl) { -if (IncludeBriefComments && CurrentArg < FDecl->getNumParams()) - if (auto RC = S.getASTContext().getRawCommentForAnyRedecl( - FDecl->getParamDecl(CurrentArg))) +if (IncludeBriefComments) { + if
[PATCH] D41537: Optionally add code completion results for arrow instead of dot
yvvan added inline comments. Comment at: include/clang-c/Index.h:5278 + /** + * \brief Whether to try dot to arrow correction if arrow operator can be applied. + */ ilya-biryukov wrote: > This implies that "dot to arrow" is the only available correction. Maybe > rephrase to mention that others are possible in theory? > E.g. > ```Whether to include completion items with corrections (small fix-its), e.g. > change '.' to '->' on member access, etc.``` thanks, forgot to change that one Comment at: include/clang/Sema/CodeCompleteConsumer.h:415 +/// diagnostic. +class FullFixItHint : public FixItHint { +public: ilya-biryukov wrote: > Why do we need this wrapper? > It seems that storing `SourceManager` and `LangOpts` in each fix-it is > clearly confusing (they are the same for all diags in the file). > All clients that want to access the fix-it should have a reference to an > existing `SourceManager`, right? My first version took source manager and language options from CXCodeCompleteResults (which is in fact AllocatedCXCodeCompleteResults) so I needed to pass it as an extra parameter which looks kind of ugly, The single CXCodeCompleteResult does not have them. But I can leave CXCodeCompleteResults pointer as a parameter to avoid this wrapper. And since it's a libclang design part it probably should be fixed/workarounded there. Comment at: include/clang/Sema/CodeCompleteConsumer.h:577 + /// \brief For this completion result correction is required. + std::vector Corrections; + ilya-biryukov wrote: > Storing fix-its in `CodeCompletionString` seems like to be against its > original intention, i.e. now it depends on `SourceLocation`s, which require > `SourceManager`, etc. > Is there a way to get to a `CodeCompletionResult` from `libclang`? Storing > fix-its there would be ideal. CodeCompletionString is an abstraction used by libclang to store everything. So every completion detail getter in libclang works through it. CXCompletionResult stores only cursor kind and a pointer to that string. Comment at: include/clang/Sema/CodeCompleteConsumer.h:704 +CXAvailabilityKind Availability, +const std::vector &Corrections) : Allocator(Allocator), CCTUInfo(CCTUInfo), Priority(Priority), ilya-biryukov wrote: > Maybe accept the vector by value instead of const reference to allow the > clients to `std::move` the argument and avoid copies? but if it's accepted by value - it's one copy already by default Instead I can add one more constructor with rvalue reference. https://reviews.llvm.org/D41537 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46001: [CodeComplete] Expose helpers to get RawComment of completion result.
ilya-biryukov added a reviewer: arphaman. ilya-biryukov added a subscriber: arphaman. ilya-biryukov added a comment. In https://reviews.llvm.org/D46001#1077781, @ioeric wrote: > This seems to do what we want for clangd, but we should also get the code > owner or someone who knows the code better to take a look. Added @arphaman. Alex reviewed some of our code completion patches before. This should give us enough coverage to make sure we don't go in the wrong direction. If there's someone else who should be in the reviewers list, please don't hesitate to add them. Repository: rC Clang https://reviews.llvm.org/D46001 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46049: [OpenCL] Add constant address space to __func__ in AST
Anastasia created this revision. Anastasia added reviewers: yaxunl, bader. String literals must be in `constant` address space. https://reviews.llvm.org/D46049 Files: lib/Sema/SemaExpr.cpp test/SemaOpenCL/predefind-expr.cl Index: test/SemaOpenCL/predefind-expr.cl === --- /dev/null +++ test/SemaOpenCL/predefind-expr.cl @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -verify + +void f() { +char * f1 = __func__;//expected-error{{initializing 'char *' with an expression of type 'const __constant char *' changes address space of pointer}} +constant char * f2 = __func__;//expected-warning{{initializing '__constant char *' with an expression of type 'const __constant char [2]' discards qualifiers}} +constant const char * f3 = __func__; +} Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -3052,6 +3052,8 @@ /*Pascal*/ false, ResTy, Loc); } else { ResTy = Context.CharTy.withConst(); + if (LangOpts.OpenCL) + ResTy = Context.getAddrSpaceQualType(ResTy, LangAS::opencl_constant); ResTy = Context.getConstantArrayType(ResTy, LengthI, ArrayType::Normal, /*IndexTypeQuals*/ 0); SL = StringLiteral::Create(Context, Str, StringLiteral::Ascii, Index: test/SemaOpenCL/predefind-expr.cl === --- /dev/null +++ test/SemaOpenCL/predefind-expr.cl @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -verify + +void f() { +char * f1 = __func__;//expected-error{{initializing 'char *' with an expression of type 'const __constant char *' changes address space of pointer}} +constant char * f2 = __func__;//expected-warning{{initializing '__constant char *' with an expression of type 'const __constant char [2]' discards qualifiers}} +constant const char * f3 = __func__; +} Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -3052,6 +3052,8 @@ /*Pascal*/ false, ResTy, Loc); } else { ResTy = Context.CharTy.withConst(); + if (LangOpts.OpenCL) + ResTy = Context.getAddrSpaceQualType(ResTy, LangAS::opencl_constant); ResTy = Context.getConstantArrayType(ResTy, LengthI, ArrayType::Normal, /*IndexTypeQuals*/ 0); SL = StringLiteral::Create(Context, Str, StringLiteral::Ascii, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r330808 - add check for long double for __builtin_dump_struct
Author: paulsemel Date: Wed Apr 25 03:09:20 2018 New Revision: 330808 URL: http://llvm.org/viewvc/llvm-project?rev=330808&view=rev Log: add check for long double for __builtin_dump_struct Modified: cfe/trunk/test/CodeGen/dump-struct-builtin.c Modified: cfe/trunk/test/CodeGen/dump-struct-builtin.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/dump-struct-builtin.c?rev=330808&r1=330807&r2=330808&view=diff == --- cfe/trunk/test/CodeGen/dump-struct-builtin.c (original) +++ cfe/trunk/test/CodeGen/dump-struct-builtin.c Wed Apr 25 03:09:20 2018 @@ -107,6 +107,12 @@ // CHECK-NEXT: [[FORMAT_U17:@[0-9]+]] = private unnamed_addr constant [6 x i8] c"%hhd\0A\00" // CHECK-NEXT: [[END_STRUCT_U17:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00" +// CHECK: @unit18.a = private unnamed_addr constant %struct.U18A { x86_fp80 0xK3FFF8FCD67FD3F5B6000 }, align 16 +// CHECK-NEXT: [[STRUCT_STR_U18:@[0-9]+]] = private unnamed_addr constant [15 x i8] c"struct U18A {\0A\00" +// CHECK-NEXT: [[FIELD_U18:@[0-9]+]] = private unnamed_addr constant [17 x i8] c"long double a : \00" +// CHECK-NEXT: [[FORMAT_U18:@[0-9]+]] = private unnamed_addr constant [5 x i8] c"%Lf\0A\00" +// CHECK-NEXT: [[END_STRUCT_U18:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00" + int printf(const char *fmt, ...) { return 0; } @@ -417,6 +423,24 @@ void unit17() { __builtin_dump_struct(&a, &printf); } +void unit18() { + struct U18A { +long double a; + }; + + struct U18A a = { + .a = 1.123456, + }; + + // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* [[STRUCT_STR_U18]], i32 0, i32 0)) + // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U18A, %struct.U18A* %a, i32 0, i32 0 + // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* [[FIELD_U18]], i32 0, i32 0)) + // CHECK: [[LOAD1:%[0-9]+]] = load x86_fp80, x86_fp80* [[RES1]], + // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U18]], i32 0, i32 0), x86_fp80 [[LOAD1]]) + // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* [[END_STRUCT_U18]], i32 0, i32 0) + __builtin_dump_struct(&a, &printf); +} + void test1() { struct T1A { int a; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46033: add check for long double for __builtin_dump_struct
paulsemel closed this revision. paulsemel added a comment. commited on r330808 Repository: rC Clang https://reviews.llvm.org/D46033 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46050: [Frontend] Avoid running plugins during code completion parse
nik created this revision. Herald added a subscriber: cfe-commits. The parsing that is done for code completion is a special case that will discard any generated diagnostics, so avoid running plugins for this case in the first place to avoid performance penalties due to the plugins. Repository: rC Clang https://reviews.llvm.org/D46050 Files: lib/Frontend/FrontendAction.cpp Index: lib/Frontend/FrontendAction.cpp === --- lib/Frontend/FrontendAction.cpp +++ lib/Frontend/FrontendAction.cpp @@ -153,6 +153,10 @@ if (FrontendPluginRegistry::begin() == FrontendPluginRegistry::end()) return Consumer; + // If this is a code completion run, avoid invoking the plugin consumers + if (CI.hasCodeCompletionConsumer()) + return Consumer; + // Collect the list of plugins that go before the main action (in Consumers) // or after it (in AfterConsumers) std::vector> Consumers; Index: lib/Frontend/FrontendAction.cpp === --- lib/Frontend/FrontendAction.cpp +++ lib/Frontend/FrontendAction.cpp @@ -153,6 +153,10 @@ if (FrontendPluginRegistry::begin() == FrontendPluginRegistry::end()) return Consumer; + // If this is a code completion run, avoid invoking the plugin consumers + if (CI.hasCodeCompletionConsumer()) + return Consumer; + // Collect the list of plugins that go before the main action (in Consumers) // or after it (in AfterConsumers) std::vector> Consumers; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46002: [clangd] Parse all comments in Sema and completion.
ilya-biryukov added inline comments. Comment at: clangd/ClangdUnit.cpp:362 CI->getFrontendOpts().DisableFree = false; +CI->getLangOpts()->CommentOpts.ParseAllComments = true; } sammccall wrote: > Any idea about whether this will affect performance significantly? > Less for this patch, and more for whether this should be an option in the > future that we might e.g. only do during indexing. Hopefully, there should be no significant difference, but I'll do some benchmarks with both real code and artificial comment-heave code to make sure that's the case. It would certainly eat a bit more memory, but it shouldn't be significant as we only store an extra list of sourceranges for comments. Even for this patch, maybe we would want to only enable it in the AST but not in the preamble. I'll get some numbers and come back to this. Comment at: clangd/CodeComplete.cpp:707 CI->getFrontendOpts().DisableFree = false; + CI->getLangOpts()->CommentOpts.ParseAllComments = true; sammccall wrote: > Are we sure we want to do this in code complete? I would have thought the > more natural approach would be to implement resolve in terms of lookup in the > index, and only provide it there. > The lack of good support for resolve in YCM LSP shouldn't be a problem as YCM > doesn't actually use doc comments (I think?). It seems to give a better user-experience: - Some items come only from Sema, so getting documentation for local variables and class members is currently only possible through Sema. We could probably omit the docs for the local vars and put class members into the index, though. - If the comment for the completion is in the current file, we should prefer the latest version, not one from the index that might be stale. However, it does mean sending docs along with the results, I don't think LSP will allow us to properly handle the lifetime of docs from the completion AST, so we won't be able to delay their result until resolve time. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D46002 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45719: [clang-Format] Fix indentation of member call after block
klimek added inline comments. Comment at: unittests/Format/FormatTest.cpp:4359 + "return 3;\n" + " }).as("");\n" + "}"); What would be interesting is tests that: a) have another value after the closing }; doesn't really make sense in this test, but usually these are in calls f([]() { ... }, foo, bar).call(...) b) make .as("") have paramters that go beyond the limit c) add another chained call behind .as(""). Repository: rC Clang https://reviews.llvm.org/D45719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46049: [OpenCL] Add constant address space to __func__ in AST
svenvh added inline comments. Comment at: lib/Sema/SemaExpr.cpp:3056 + if (LangOpts.OpenCL) + ResTy = Context.getAddrSpaceQualType(ResTy, LangAS::opencl_constant); ResTy = Context.getConstantArrayType(ResTy, LengthI, ArrayType::Normal, Nitpick: local indent style is 2 spaces. Comment at: test/SemaOpenCL/predefind-expr.cl:1 +// RUN: %clang_cc1 %s -verify + predefind-expr.cl -> predefined_expr.cl Also please indent the function body. https://reviews.llvm.org/D46049 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46050: [Frontend] Avoid running plugins during code completion parse
nik updated this revision to Diff 143894. nik added a comment. only clang-format fixes Repository: rC Clang https://reviews.llvm.org/D46050 Files: lib/Frontend/FrontendAction.cpp Index: lib/Frontend/FrontendAction.cpp === --- lib/Frontend/FrontendAction.cpp +++ lib/Frontend/FrontendAction.cpp @@ -153,6 +153,10 @@ if (FrontendPluginRegistry::begin() == FrontendPluginRegistry::end()) return Consumer; + // If this is a code completion run, avoid invoking the plugin consumers + if (CI.hasCodeCompletionConsumer()) +return Consumer; + // Collect the list of plugins that go before the main action (in Consumers) // or after it (in AfterConsumers) std::vector> Consumers; Index: lib/Frontend/FrontendAction.cpp === --- lib/Frontend/FrontendAction.cpp +++ lib/Frontend/FrontendAction.cpp @@ -153,6 +153,10 @@ if (FrontendPluginRegistry::begin() == FrontendPluginRegistry::end()) return Consumer; + // If this is a code completion run, avoid invoking the plugin consumers + if (CI.hasCodeCompletionConsumer()) +return Consumer; + // Collect the list of plugins that go before the main action (in Consumers) // or after it (in AfterConsumers) std::vector> Consumers; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45722: [X86] Lowering SAD (sum of absolute differences) intrinsics to native IR (clang side)
mike.dvoretsky updated this revision to Diff 143893. mike.dvoretsky marked 4 inline comments as done. mike.dvoretsky added a subscriber: ashlykov. mike.dvoretsky added a comment. Updated per comments. https://reviews.llvm.org/D45722 Files: clang/lib/CodeGen/CGBuiltin.cpp clang/test/CodeGen/avx2-builtins.c clang/test/CodeGen/avx512bw-builtins.c clang/test/CodeGen/sse2-builtins.c Index: clang/test/CodeGen/sse2-builtins.c === --- clang/test/CodeGen/sse2-builtins.c +++ clang/test/CodeGen/sse2-builtins.c @@ -893,7 +893,33 @@ __m128i test_mm_sad_epu8(__m128i A, __m128i B) { // CHECK-LABEL: test_mm_sad_epu8 - // CHECK: call <2 x i64> @llvm.x86.sse2.psad.bw(<16 x i8> %{{.*}}, <16 x i8> %{{.*}}) + // CHECK: %{{.*}} = icmp ugt <16 x i8> %{{.*}}, %{{.*}} + // CHECK: %{{.*}} = sub <16 x i8> %{{.*}}, %{{.*}} + // CHECK: %{{.*}} = sub <16 x i8> %{{.*}}, %{{.*}} + // CHECK: %{{.*}} = select <16 x i1> %{{.*}}, <16 x i8> %{{.*}}, <16 x i8> %{{.*}} + // CHECK: %{{.*}} = shufflevector <16 x i8> %{{.*}}, <16 x i8> %{{.*}}, <2 x i32> + // CHECK: %{{.*}} = zext <2 x i8> %{{.*}} to <2 x i64> + // CHECK: %{{.*}} = shufflevector <16 x i8> %{{.*}}, <16 x i8> %{{.*}}, <2 x i32> + // CHECK: %{{.*}} = zext <2 x i8> %{{.*}} to <2 x i64> + // CHECK: %{{.*}} = add <2 x i64> %{{.*}}, %{{.*}} + // CHECK: %{{.*}} = shufflevector <16 x i8> %{{.*}}, <16 x i8> %{{.*}}, <2 x i32> + // CHECK: %{{.*}} = zext <2 x i8> %{{.*}} to <2 x i64> + // CHECK: %{{.*}} = add <2 x i64> %{{.*}}, %{{.*}} + // CHECK: %{{.*}} = shufflevector <16 x i8> %{{.*}}, <16 x i8> %{{.*}}, <2 x i32> + // CHECK: %{{.*}} = zext <2 x i8> %{{.*}} to <2 x i64> + // CHECK: %{{.*}} = add <2 x i64> %{{.*}}, %{{.*}} + // CHECK: %{{.*}} = shufflevector <16 x i8> %{{.*}}, <16 x i8> %{{.*}}, <2 x i32> + // CHECK: %{{.*}} = zext <2 x i8> %{{.*}} to <2 x i64> + // CHECK: %{{.*}} = add <2 x i64> %{{.*}}, %{{.*}} + // CHECK: %{{.*}} = shufflevector <16 x i8> %{{.*}}, <16 x i8> %{{.*}}, <2 x i32> + // CHECK: %{{.*}} = zext <2 x i8> %{{.*}} to <2 x i64> + // CHECK: %{{.*}} = add <2 x i64> %{{.*}}, %{{.*}} + // CHECK: %{{.*}} = shufflevector <16 x i8> %{{.*}}, <16 x i8> %{{.*}}, <2 x i32> + // CHECK: %{{.*}} = zext <2 x i8> %{{.*}} to <2 x i64> + // CHECK: %{{.*}} = add <2 x i64> %{{.*}}, %{{.*}} + // CHECK: %{{.*}} = shufflevector <16 x i8> %{{.*}}, <16 x i8> %{{.*}}, <2 x i32> + // CHECK: %{{.*}} = zext <2 x i8> %{{.*}} to <2 x i64> + // CHECK: %{{.*}} = add <2 x i64> %{{.*}}, %{{.*}} return _mm_sad_epu8(A, B); } Index: clang/test/CodeGen/avx512bw-builtins.c === --- clang/test/CodeGen/avx512bw-builtins.c +++ clang/test/CodeGen/avx512bw-builtins.c @@ -1945,7 +1945,33 @@ __m512i test_mm512_sad_epu8(__m512i __A, __m512i __B) { // CHECK-LABEL: @test_mm512_sad_epu8 - // CHECK: @llvm.x86.avx512.psad.bw.512 + // CHECK: %{{.*}} = icmp ugt <64 x i8> %{{.*}}, %{{.*}} + // CHECK: %{{.*}} = sub <64 x i8> %{{.*}}, %{{.*}} + // CHECK: %{{.*}} = sub <64 x i8> %{{.*}}, %{{.*}} + // CHECK: %{{.*}} = select <64 x i1> %{{.*}}, <64 x i8> %{{.*}}, <64 x i8> %{{.*}} + // CHECK: %{{.*}} = shufflevector <64 x i8> %{{.*}}, <64 x i8> %{{.*}}, <8 x i32> + // CHECK: %{{.*}} = zext <8 x i8> %{{.*}} to <8 x i64> + // CHECK: %{{.*}} = shufflevector <64 x i8> %{{.*}}, <64 x i8> %{{.*}}, <8 x i32> + // CHECK: %{{.*}} = zext <8 x i8> %{{.*}} to <8 x i64> + // CHECK: %{{.*}} = add <8 x i64> %{{.*}}, %{{.*}} + // CHECK: %{{.*}} = shufflevector <64 x i8> %{{.*}}, <64 x i8> %{{.*}}, <8 x i32> + // CHECK: %{{.*}} = zext <8 x i8> %{{.*}} to <8 x i64> + // CHECK: %{{.*}} = add <8 x i64> %{{.*}}, %{{.*}} + // CHECK: %{{.*}} = shufflevector <64 x i8> %{{.*}}, <64 x i8> %{{.*}}, <8 x i32> + // CHECK: %{{.*}} = zext <8 x i8> %{{.*}} to <8 x i64> + // CHECK: %{{.*}} = add <8 x i64> %{{.*}}, %{{.*}} + // CHECK: %{{.*}} = shufflevector <64 x i8> %{{.*}}, <64 x i8> %{{.*}}, <8 x i32> + // CHECK: %{{.*}} = zext <8 x i8> %{{.*}} to <8 x i64> + // CHECK: %{{.*}} = add <8 x i64> %{{.*}}, %{{.*}} + // CHECK: %{{.*}} = shufflevector <64 x i8> %{{.*}}, <64 x i8> %{{.*}}, <8 x i32> + // CHECK: %{{.*}} = zext <8 x i8> %{{.*}} to <8 x i64> + // CHECK: %{{.*}} = add <8 x i64> %{{.*}}, %{{.*}} + // CHECK: %{{.*}} = shufflevector <64 x i8> %{{.*}}, <64 x i8> %{{.*}}, <8 x i32> + // CHECK: %{{.*}} = zext <8 x i8> %{{.*}} to <8 x i64> + // CHECK: %{{.*}} = add <8 x i64> %{{.*}}, %{{.*}} + // CHECK: %{{.*}} = shufflevector <64 x i8> %{{.*}}, <64 x i8> %{{.*}}, <8 x i32> + // CHECK: %{{.*}} = zext <8 x i8> %{{.*}} to <8 x i64> + // CHECK: %{{.*}} = add <8 x i64> %{{.*}}, %{{.*}} return _mm512_sad_epu8(__A, __B); } Index: clang/test/CodeGen/avx2-builtins.c === --- clang/test/CodeGen/avx2-builtins.c +++ clang/test/CodeGen/avx2-builtins.c @@ -943,7 +943,33 @@
[PATCH] D46019: [ASTImporter] Fix isa cast assert
a.sidorin added a comment. > `E->getFoundDecl().getDecl()` can be null when a member expression does not > involve lookup. (Note, it may involve a lookup in case of a using directive > which refers to a member function in a base class template.) Yes, a pretty weird example. Unfortunately, they are pretty common for XTU. > I hoped that this patch could be accepted without tests, since it is very > small and the changes are pretty straight forward, so I thought it can be > easily verified by a review. Yes, this is the reason why I have accepted it initially. I think we can accept this patch without a test but I'd like to get a somebody else's review. @xazax.hun, @szepet, could you take a look? @martong Could you include the reason why this patch lacks tests into the commit message (including description of the situation where the code fails)? Repository: rC Clang https://reviews.llvm.org/D46019 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46019: [ASTImporter] Fix isa cast assert
xazax.hun accepted this revision. xazax.hun added a comment. With a sufficiently detailed commit message, i.e.: what version of a project should be cheked out and how the analyzer needs to be ivoked to reproduce the problem I am ok with committing this without a test. Repository: rC Clang https://reviews.llvm.org/D46019 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D44435: CUDA ctor/dtor Module-Unique Symbol Name
SimeonEhrig added inline comments. Comment at: lib/CodeGen/CGCUDANV.cpp:287 +CtorSuffix.append("_"); +CtorSuffix.append(ModuleName); + } tra wrote: > SimeonEhrig wrote: > > tra wrote: > > > There is a general problem with this approach. File name can contain the > > > characters that PTX does not allow. > > > We currently only deal with '.' and '@', but that's not enough here. > > > You may want to either mangle the name somehow to avoid/convert illegal > > > characters or use some other way to provide unique suffix. Hex-encoded > > > hash of the file name would avoid this problem, for example. > > > > > > > > > > > Maybe I'm wrong but I think, that should be no problem, because the > > generating of a cuda ctor/dtor have nothing to do with the PTX generation. > > > > The function 'makeModuleCtorFunction' should just generate llvm ir code for > > the host (e.g. x86_64). > > > > If I'm wrong, could you tell me please, where in the source code the > > 'makeModuleCtorFunction' affect the PTX generation. > You are correct that PTX is irrelevant here. I've completely missed that this > will be generated for the host, which is more forgiving. > > That said, I'm still not completely sure whether we're guaranteed that using > arbitrary characters in a symbol name is OK on x86 and, potentially, other > host platforms. As an experiment, try using a module which has a space in its > name. At line 295 and 380 in CGCUDANV.cpp I use a sanitizer function, which replace all symbols without [a-zA-Z0-9._] with a '_'. It's the same solution like in D34059. So I think, it would works in general. Only for information. I tested it with a module name, which includes a whitespace and without the sanitizer. It works on Linux x86 and the ELF format. There was an whitespace in the symbol of the cuda module ctor (I checked it with readelf). In general, do you think my solution approach is technically okay? Your answer will be really helpful for internal usage in our cling project. At the moment I developed the cling-cuda-interpreter based on this patch and it would helps a lot of, if I can say, that the patch doesn't cause any problem with the CUDA-environment. https://reviews.llvm.org/D44435 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46000: [AST] Added a helper to extract a user-friendly text of a comment.
ioeric added a comment. Overall looks good. Could you add tests for the new methods? Comment at: lib/AST/CommentLexer.cpp:294 void Lexer::lexCommentText(Token &T) { + if (ParseCommands) +lexCommentTextWithCommands(T); micro-nit: I'd probably ``` return ParseCommands ? lexWithCommands(T) : lexWithoutCommands(T); ``` Comment at: lib/AST/CommentLexer.cpp:471 + case '\r': +TokenPtr = skipNewline(TokenPtr, CommentEnd); +formTokenWithChars(T, TokenPtr, tok::newline); Can we share code with `lexCommentTextWithCommands` for these two common cases? Comment at: lib/AST/RawCommentList.cpp:353 + // MaxSkip. + auto SkipWs = [](llvm::StringRef S, unsigned MaxSkip) -> llvm::StringRef { +unsigned SkipLen = std::min( nit: `SkipWhitespaces` for readability? Comment at: lib/AST/RawCommentList.cpp:380 +SourceMgr.getSpellingColumnNumber(Tok.getLocation(), &LocInvalid); +if (LocInvalid) + TokColumn = 0; Explain when this would be invalid and why `TokColumn = 0` is used? Comment at: lib/AST/RawCommentList.cpp:383 +// Compute the length of whitespace we're allowed to skip. +unsigned MaxSkip; +if (IsFirstLine) { nit: `unsigned MaxSkip = IsFirstLine ? ... : ...;` Comment at: lib/AST/RawCommentList.cpp:392 +} +llvm::StringRef Trimmed = SkipWs(TokText, MaxSkip); +Result += Trimmed; I'd probably make `SkipWs` return the number of white spaces skipped and do the drop-front here, so that you could simplify the awkward calculation of `IndentColumn` below. Repository: rC Clang https://reviews.llvm.org/D46000 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D43322: Diagnose cases of "return x" that should be "return std::move(x)" for efficiency
thakis added a comment. This is a cool warning, thanks for adding it. We ran into one thing while enabling this in Chromium that I'd like to mention here. We have code that basically does: struct Foo { using passwords_iterator = std::map, ReverseStringLess>::const_iterator; std::map, ReverseStringLess> passwords_; passwords_iterator get(const base::string16& in) { auto it = passwords_.lower_bound(in); return it; } }; Here, the warning gets emitted because `auto it` becomes a non-const iterator, and passwords_iterator is a const_iterator. Maybe the warning could suggest something like "cv qualifiers don't match, make them match" on a note in addition or instead of std::move() for this case? And then someone else pointed out that http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1579 might mean that the code-as is should be fine too in C++14 – I don't know if that's true, but maybe you could comment on that too :-) (references: https://cs.chromium.org/chromium/src/components/password_manager/core/browser/password_reuse_detector.h?type=cs&q=passwords_iterator&sq=package:chromium&l=64 https://chromium-review.googlesource.com/c/chromium/src/+/1025435/6/components/password_manager/core/browser/password_reuse_detector.cc https://chromium-review.googlesource.com/c/chromium/src/+/1025435/8/components/password_manager/core/browser/password_reuse_detector.cc ) Repository: rC Clang https://reviews.llvm.org/D43322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46027: [clang-tidy] Fix PR35824
aaron.ballman added a comment. > Which solution do you prefer? If I understand the issue properly: both. :-) Having the AST track information that's been folded away is still useful -- some users are using the AST for purposes other than codegen, and the fact that a construct has been folded away is good to know about while still retaining as much AST fidelity as possible. On the other hand, from an AST matcher perspective, I think it's natural for users to write `ifStmt(isConstexpr())` and so that seems like a useful extension to the matcher. Further, it is extensible if the committee adds other constexpr foo statements. As for which solution gets used by this check to fix the PR, I don't have a strong opinion at this time (currently at WG14 meetings and a bit distracted). Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D46027 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46007: [analyzer] Add `TaintBugVisitor` to the ArrayBoundV2, DivideZero and VLASize.
MTC marked an inline comment as done. MTC added inline comments. Comment at: lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp:75 auto report = llvm::make_unique(*BT, os.str(), N); + report->addVisitor(std::move(Visitor)); report->addRange(SizeE->getSourceRange()); a.sidorin wrote: > In this patch, sometimes we check the visitor to be non-null, sometimes not. > As I can see, `BugReport::addVisitor()` works well with `nullptr` arguments > (it checks arguments) so I think we can omit the checks. Thanks for your reminder, a.sidorin! My mistakes led to some checkers doing the check and some did not check! But as you said, there is no need to check the nullptr. I will update the patch. Repository: rC Clang https://reviews.llvm.org/D46007 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46007: [analyzer] Add `TaintBugVisitor` to the ArrayBoundV2, DivideZero and VLASize.
MTC updated this revision to Diff 143908. MTC marked an inline comment as done. MTC added a comment. Since `BugReport::addVisitor()` has checks for the null `Visitor`, remove the checks before `BugReport->addVisitor()`. Repository: rC Clang https://reviews.llvm.org/D46007 Files: lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp test/Analysis/taint-diagnostic-visitor.c Index: test/Analysis/taint-diagnostic-visitor.c === --- test/Analysis/taint-diagnostic-visitor.c +++ test/Analysis/taint-diagnostic-visitor.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.security.taint,core -analyzer-output=text -verify %s +// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.security.taint,core,alpha.security.ArrayBoundV2 -analyzer-output=text -verify %s // This file is for testing enhanced diagnostics produced by the GenericTaintChecker @@ -11,3 +11,26 @@ scanf("%s", buf); // expected-note {{Taint originated here}} system(buf); // expected-warning {{Untrusted data is passed to a system call}} // expected-note {{Untrusted data is passed to a system call (CERT/STR02-C. Sanitize data passed to complex subsystems)}} } + +int taintDiagnosticOutOfBound() { + int index; + int Array[] = {1, 2, 3, 4, 5}; + scanf("%d", &index); // expected-note {{Taint originated here}} + return Array[index]; // expected-warning {{Out of bound memory access (index is tainted)}} + // expected-note@-1 {{Out of bound memory access (index is tainted)}} +} + +int taintDiagnosticDivZero(int operand) { + scanf("%d", &operand); // expected-note {{Value assigned to 'operand'}} + // expected-note@-1 {{Taint originated here}} + return 10 / operand; // expected-warning {{Division by a tainted value, possibly zero}} + // expected-note@-1 {{Division by a tainted value, possibly zero}} +} + +void taintDiagnosticVLA() { + int x; + scanf("%d", &x); // expected-note {{Value assigned to 'x'}} + // expected-note@-1 {{Taint originated here}} + int vla[x]; // expected-warning {{Declared variable-length array (VLA) has tainted size}} + // expected-note@-1 {{Declared variable-length array (VLA) has tainted size}} +} Index: lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp === --- lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp +++ lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp @@ -32,19 +32,18 @@ mutable std::unique_ptr BT; enum VLASize_Kind { VLA_Garbage, VLA_Zero, VLA_Tainted, VLA_Negative }; - void reportBug(VLASize_Kind Kind, - const Expr *SizeE, - ProgramStateRef State, - CheckerContext &C) const; + void reportBug(VLASize_Kind Kind, const Expr *SizeE, ProgramStateRef State, + CheckerContext &C, + std::unique_ptr Visitor = nullptr) const; + public: void checkPreStmt(const DeclStmt *DS, CheckerContext &C) const; }; } // end anonymous namespace -void VLASizeChecker::reportBug(VLASize_Kind Kind, - const Expr *SizeE, - ProgramStateRef State, - CheckerContext &C) const { +void VLASizeChecker::reportBug( +VLASize_Kind Kind, const Expr *SizeE, ProgramStateRef State, +CheckerContext &C, std::unique_ptr Visitor) const { // Generate an error node. ExplodedNode *N = C.generateErrorNode(State); if (!N) @@ -73,6 +72,7 @@ } auto report = llvm::make_unique(*BT, os.str(), N); + report->addVisitor(std::move(Visitor)); report->addRange(SizeE->getSourceRange()); bugreporter::trackNullOrUndefValue(N, SizeE, *report); C.emitReport(std::move(report)); @@ -108,7 +108,8 @@ // Check if the size is tainted. if (state->isTainted(sizeV)) { -reportBug(VLA_Tainted, SE, nullptr, C); +reportBug(VLA_Tainted, SE, nullptr, C, + llvm::make_unique(sizeV)); return; } Index: lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp === --- lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp +++ lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp @@ -24,22 +24,23 @@ namespace { class DivZeroChecker : public Checker< check::PreStmt > { mutable std::unique_ptr BT; - void reportBug(const char *Msg, - ProgramStateRef StateZero, - CheckerContext &C) const ; + void reportBug(const char *Msg, ProgramStateRef StateZero, CheckerContext &C, + std::unique_ptr Visitor = nullptr) const; + public: void checkPreStmt(const BinaryOperator *B, CheckerContext &C) const; }; } // end anonymous namespace -void DivZeroChecker::reportBug(const char *Msg, - ProgramStateR
[PATCH] D45284: [RISCV] More validations on the input value of -march=
asb accepted this revision. asb added a comment. This revision is now accepted and ready to land. Looks good to me - thanks! https://reviews.llvm.org/D45284 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r330821 - Fix failure in lit test kernel-call.cu due to name mangling
Author: yaxunl Date: Wed Apr 25 06:07:58 2018 New Revision: 330821 URL: http://llvm.org/viewvc/llvm-project?rev=330821&view=rev Log: Fix failure in lit test kernel-call.cu due to name mangling Modified: cfe/trunk/test/CodeGenCUDA/kernel-call.cu Modified: cfe/trunk/test/CodeGenCUDA/kernel-call.cu URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCUDA/kernel-call.cu?rev=330821&r1=330820&r2=330821&view=diff == --- cfe/trunk/test/CodeGenCUDA/kernel-call.cu (original) +++ cfe/trunk/test/CodeGenCUDA/kernel-call.cu Wed Apr 25 06:07:58 2018 @@ -4,14 +4,14 @@ #include "Inputs/cuda.h" -// CHECK-LABEL: define{{.*}} void @_Z2g1i +// CHECK-LABEL: define{{.*}}g1 // HIP: call{{.*}}hipSetupArgument // HIP: call{{.*}}hipLaunchByPtr // CUDA: call{{.*}}cudaSetupArgument // CUDA: call{{.*}}cudaLaunch __global__ void g1(int x) {} -// CHECK-LABEL: define{{.*}} i32 @main +// CHECK-LABEL: define{{.*}}main int main(void) { // HIP: call{{.*}}hipConfigureCall // CUDA: call{{.*}}cudaConfigureCall ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46056: Move _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS macro to build system
tzik created this revision. tzik added reviewers: rsmith, thakis. Herald added subscribers: cfe-commits, mgorny. _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS is currently used to bring back std::unexpected, which is removed in C++17, but still needed for libc++abi for backward compatibility. This macro used to define in cxa_exception.cpp only, but actually needed for all sources that touches exceptions. So, a build-system-level macro is better fit to define this macro. Repository: rCXXA libc++abi https://reviews.llvm.org/D46056 Files: CMakeLists.txt src/cxa_exception.cpp test/test_exception_storage.pass.cpp Index: test/test_exception_storage.pass.cpp === --- test/test_exception_storage.pass.cpp +++ test/test_exception_storage.pass.cpp @@ -7,11 +7,6 @@ // //===--===// -// FIXME: cxa_exception.hpp directly references `std::unexpected` and friends. -// This breaks this test when compiled in C++17. For now fix this by manually -// re-enabling the STL functions. -#define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS - #include #include #include Index: src/cxa_exception.cpp === --- src/cxa_exception.cpp +++ src/cxa_exception.cpp @@ -11,8 +11,6 @@ // //===--===// -#define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS - #include "cxxabi.h" #include // for std::terminate Index: CMakeLists.txt === --- CMakeLists.txt +++ CMakeLists.txt @@ -387,6 +387,10 @@ # Prevent libc++abi from having library dependencies on libc++ add_definitions(-D_LIBCPP_DISABLE_EXTERN_TEMPLATE) +# Bring back `std::unexpected`, which is removed in C++17, to support +# pre-C++17. +add_definitions(-D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS) + if (MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) endif() Index: test/test_exception_storage.pass.cpp === --- test/test_exception_storage.pass.cpp +++ test/test_exception_storage.pass.cpp @@ -7,11 +7,6 @@ // //===--===// -// FIXME: cxa_exception.hpp directly references `std::unexpected` and friends. -// This breaks this test when compiled in C++17. For now fix this by manually -// re-enabling the STL functions. -#define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS - #include #include #include Index: src/cxa_exception.cpp === --- src/cxa_exception.cpp +++ src/cxa_exception.cpp @@ -11,8 +11,6 @@ // //===--===// -#define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS - #include "cxxabi.h" #include // for std::terminate Index: CMakeLists.txt === --- CMakeLists.txt +++ CMakeLists.txt @@ -387,6 +387,10 @@ # Prevent libc++abi from having library dependencies on libc++ add_definitions(-D_LIBCPP_DISABLE_EXTERN_TEMPLATE) +# Bring back `std::unexpected`, which is removed in C++17, to support +# pre-C++17. +add_definitions(-D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS) + if (MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) endif() ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r330824 - [HIP] Add predefined macros __HIPCC__ and __HIP_DEVICE_COMPILE__
Author: yaxunl Date: Wed Apr 25 06:33:19 2018 New Revision: 330824 URL: http://llvm.org/viewvc/llvm-project?rev=330824&view=rev Log: [HIP] Add predefined macros __HIPCC__ and __HIP_DEVICE_COMPILE__ Differential Revision: https://reviews.llvm.org/D45441 Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp cfe/trunk/test/Preprocessor/predefined-macros.c Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=330824&r1=330823&r2=330824&view=diff == --- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original) +++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Wed Apr 25 06:33:19 2018 @@ -473,8 +473,12 @@ static void InitializeStandardPredefined Builder.defineMacro("__ASSEMBLER__"); if (LangOpts.CUDA && !LangOpts.HIP) Builder.defineMacro("__CUDA__"); - if (LangOpts.HIP) + if (LangOpts.HIP) { Builder.defineMacro("__HIP__"); +Builder.defineMacro("__HIPCC__"); +if (LangOpts.CUDAIsDevice) + Builder.defineMacro("__HIP_DEVICE_COMPILE__"); + } } /// Initialize the predefined C++ language feature test macros defined in @@ -1033,7 +1037,7 @@ static void InitializePredefinedMacros(c } // CUDA device path compilaton - if (LangOpts.CUDAIsDevice) { + if (LangOpts.CUDAIsDevice && !LangOpts.HIP) { // The CUDA_ARCH value is set for the GPU target specified in the NVPTX // backend's target defines. Builder.defineMacro("__CUDA_ARCH__"); Modified: cfe/trunk/test/Preprocessor/predefined-macros.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/predefined-macros.c?rev=330824&r1=330823&r2=330824&view=diff == --- cfe/trunk/test/Preprocessor/predefined-macros.c (original) +++ cfe/trunk/test/Preprocessor/predefined-macros.c Wed Apr 25 06:33:19 2018 @@ -277,3 +277,18 @@ // RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir-unknown-unknown \ // RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR // CHECK-SPIR: #define __IMAGE_SUPPORT__ 1 + +// RUN: %clang_cc1 %s -E -dM -o - -x hip -triple amdgcn-amd-amdhsa \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-HIP +// CHECK-HIP-NOT: #define __CUDA_ARCH__ +// CHECK-HIP: #define __HIPCC__ 1 +// CHECK-HIP-NOT: #define __HIP_DEVICE_COMPILE__ 1 +// CHECK-HIP: #define __HIP__ 1 + +// RUN: %clang_cc1 %s -E -dM -o - -x hip -triple amdgcn-amd-amdhsa \ +// RUN: -fcuda-is-device \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-HIP-DEV +// CHECK-HIP-DEV-NOT: #define __CUDA_ARCH__ +// CHECK-HIP-DEV: #define __HIPCC__ 1 +// CHECK-HIP-DEV: #define __HIP_DEVICE_COMPILE__ 1 +// CHECK-HIP-DEV: #define __HIP__ 1 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45441: [HIP] Add predefined macros __HIPCC__ and __HIP_DEVICE_COMPILE__
This revision was automatically updated to reflect the committed changes. yaxunl marked an inline comment as done. Closed by commit rC330824: [HIP] Add predefined macros __HIPCC__ and __HIP_DEVICE_COMPILE__ (authored by yaxunl, committed by ). Changed prior to commit: https://reviews.llvm.org/D45441?vs=141648&id=143917#toc Repository: rC Clang https://reviews.llvm.org/D45441 Files: lib/Frontend/InitPreprocessor.cpp test/Preprocessor/predefined-macros.c Index: lib/Frontend/InitPreprocessor.cpp === --- lib/Frontend/InitPreprocessor.cpp +++ lib/Frontend/InitPreprocessor.cpp @@ -473,8 +473,12 @@ Builder.defineMacro("__ASSEMBLER__"); if (LangOpts.CUDA && !LangOpts.HIP) Builder.defineMacro("__CUDA__"); - if (LangOpts.HIP) + if (LangOpts.HIP) { Builder.defineMacro("__HIP__"); +Builder.defineMacro("__HIPCC__"); +if (LangOpts.CUDAIsDevice) + Builder.defineMacro("__HIP_DEVICE_COMPILE__"); + } } /// Initialize the predefined C++ language feature test macros defined in @@ -1033,7 +1037,7 @@ } // CUDA device path compilaton - if (LangOpts.CUDAIsDevice) { + if (LangOpts.CUDAIsDevice && !LangOpts.HIP) { // The CUDA_ARCH value is set for the GPU target specified in the NVPTX // backend's target defines. Builder.defineMacro("__CUDA_ARCH__"); Index: test/Preprocessor/predefined-macros.c === --- test/Preprocessor/predefined-macros.c +++ test/Preprocessor/predefined-macros.c @@ -277,3 +277,18 @@ // RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir-unknown-unknown \ // RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR // CHECK-SPIR: #define __IMAGE_SUPPORT__ 1 + +// RUN: %clang_cc1 %s -E -dM -o - -x hip -triple amdgcn-amd-amdhsa \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-HIP +// CHECK-HIP-NOT: #define __CUDA_ARCH__ +// CHECK-HIP: #define __HIPCC__ 1 +// CHECK-HIP-NOT: #define __HIP_DEVICE_COMPILE__ 1 +// CHECK-HIP: #define __HIP__ 1 + +// RUN: %clang_cc1 %s -E -dM -o - -x hip -triple amdgcn-amd-amdhsa \ +// RUN: -fcuda-is-device \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-HIP-DEV +// CHECK-HIP-DEV-NOT: #define __CUDA_ARCH__ +// CHECK-HIP-DEV: #define __HIPCC__ 1 +// CHECK-HIP-DEV: #define __HIP_DEVICE_COMPILE__ 1 +// CHECK-HIP-DEV: #define __HIP__ 1 Index: lib/Frontend/InitPreprocessor.cpp === --- lib/Frontend/InitPreprocessor.cpp +++ lib/Frontend/InitPreprocessor.cpp @@ -473,8 +473,12 @@ Builder.defineMacro("__ASSEMBLER__"); if (LangOpts.CUDA && !LangOpts.HIP) Builder.defineMacro("__CUDA__"); - if (LangOpts.HIP) + if (LangOpts.HIP) { Builder.defineMacro("__HIP__"); +Builder.defineMacro("__HIPCC__"); +if (LangOpts.CUDAIsDevice) + Builder.defineMacro("__HIP_DEVICE_COMPILE__"); + } } /// Initialize the predefined C++ language feature test macros defined in @@ -1033,7 +1037,7 @@ } // CUDA device path compilaton - if (LangOpts.CUDAIsDevice) { + if (LangOpts.CUDAIsDevice && !LangOpts.HIP) { // The CUDA_ARCH value is set for the GPU target specified in the NVPTX // backend's target defines. Builder.defineMacro("__CUDA_ARCH__"); Index: test/Preprocessor/predefined-macros.c === --- test/Preprocessor/predefined-macros.c +++ test/Preprocessor/predefined-macros.c @@ -277,3 +277,18 @@ // RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir-unknown-unknown \ // RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR // CHECK-SPIR: #define __IMAGE_SUPPORT__ 1 + +// RUN: %clang_cc1 %s -E -dM -o - -x hip -triple amdgcn-amd-amdhsa \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-HIP +// CHECK-HIP-NOT: #define __CUDA_ARCH__ +// CHECK-HIP: #define __HIPCC__ 1 +// CHECK-HIP-NOT: #define __HIP_DEVICE_COMPILE__ 1 +// CHECK-HIP: #define __HIP__ 1 + +// RUN: %clang_cc1 %s -E -dM -o - -x hip -triple amdgcn-amd-amdhsa \ +// RUN: -fcuda-is-device \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-HIP-DEV +// CHECK-HIP-DEV-NOT: #define __CUDA_ARCH__ +// CHECK-HIP-DEV: #define __HIPCC__ 1 +// CHECK-HIP-DEV: #define __HIP_DEVICE_COMPILE__ 1 +// CHECK-HIP-DEV: #define __HIP__ 1 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46056: Move _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS macro to build system
tzik added a comment. rsmith: Could you PTAL to this? This is an attempt to resolve https://bugs.llvm.org/show_bug.cgi?id=34103. Though we already have a way to bring back std::unexpected to libc++abi, we currently don't apply it properly, IMO. Repository: rCXXA libc++abi https://reviews.llvm.org/D46056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46000: [AST] Added a helper to extract a user-friendly text of a comment.
ilya-biryukov added a comment. In https://reviews.llvm.org/D46000#1077926, @ioeric wrote: > Overall looks good. Could you add tests for the new methods? Sure. There are a few tests in https://reviews.llvm.org/D46002, but I haven't (yet) moved them to clang. Repository: rC Clang https://reviews.llvm.org/D46000 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45179: [libc++] Add _LIBCPP_FORCE_NODISCARD define to force-enable nodiscard in pre-C++17
mclow.lists added inline comments. Comment at: test/libcxx/diagnostics/force_nodiscard.fail.cpp:22 + +_LIBCPP_NODISCARD_AFTER_CXX17 int foo() { return 6; } + Shouldn't this be just `_LIBCPP_NODISCARD` ? Repository: rCXX libc++ https://reviews.llvm.org/D45179 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D39053: [Bitfield] Add more cases to making the bitfield a separate location
spetrovic updated this revision to Diff 143918. spetrovic added a comment. Comments addressed https://reviews.llvm.org/D39053 Files: include/clang/Driver/Options.td lib/CodeGen/CGRecordLayoutBuilder.cpp test/CodeGenCXX/finegrain-bitfield-type.cpp Index: test/CodeGenCXX/finegrain-bitfield-type.cpp === --- test/CodeGenCXX/finegrain-bitfield-type.cpp +++ test/CodeGenCXX/finegrain-bitfield-type.cpp @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -triple x86_64-linux-gnu -ffine-grained-bitfield-accesses \ +// RUN: -emit-llvm -o - %s | FileCheck %s +struct S4 { + unsigned long f1:28; + unsigned long f2:4; + unsigned long f3:12; +}; +struct S4 a4; + +struct S5 { + unsigned long f1:28; + unsigned long f2:4; + unsigned long f3:28; + unsigned long f4:4; + unsigned long f5:12; +}; +struct S5 a5; + +// CHECK: %struct.S4 = type { i32, i16 } +// CHECK-NOT: %struct.S4 = type { i48 } +// CHECK: %struct.S5 = type { i32, i32, i16, [6 x i8] } +// CHECK-NOT: %struct.S5 = type { i80 } \ No newline at end of file Index: lib/CodeGen/CGRecordLayoutBuilder.cpp === --- lib/CodeGen/CGRecordLayoutBuilder.cpp +++ lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -404,19 +404,20 @@ return; } - // Check if current Field is better as a single field run. When current field + // Check if OffsetInRecord is better as a single field run. When OffsetInRecord // has legal integer width, and its bitfield offset is naturally aligned, it // is better to make the bitfield a separate storage component so as it can be // accessed directly with lower cost. - auto IsBetterAsSingleFieldRun = [&](RecordDecl::field_iterator Field) { + auto IsBetterAsSingleFieldRun = [&](uint64_t OffsetInRecord, + uint64_t StartBitOffset) { if (!Types.getCodeGenOpts().FineGrainedBitfieldAccesses) return false; -unsigned Width = Field->getBitWidthValue(Context); -if (!DataLayout.isLegalInteger(Width)) +if (!DataLayout.isLegalInteger(OffsetInRecord)) return false; -// Make sure Field is natually aligned if it is treated as an IType integer. -if (getFieldBitOffset(*Field) % -Context.toBits(getAlignment(getIntNType(Width))) != +// Make sure StartBitOffset is natually aligned if it is treated as an +// IType integer. + if (StartBitOffset % +Context.toBits(getAlignment(getIntNType(OffsetInRecord))) != 0) return false; return true; @@ -435,23 +436,24 @@ Run = Field; StartBitOffset = getFieldBitOffset(*Field); Tail = StartBitOffset + Field->getBitWidthValue(Context); -StartFieldAsSingleRun = IsBetterAsSingleFieldRun(Run); +StartFieldAsSingleRun = IsBetterAsSingleFieldRun(Tail - StartBitOffset, + StartBitOffset); } ++Field; continue; } // If the start field of a new run is better as a single run, or -// if current field is better as a single run, or +// if current field (or consecutive fields) is better as a single run, or // if current field has zero width bitfield and either // UseZeroLengthBitfieldAlignment or UseBitFieldTypeAlignment is set to // true, or // if the offset of current field is inconsistent with the offset of // previous field plus its offset, // skip the block below and go ahead to emit the storage. // Otherwise, try to add bitfields to the run. if (!StartFieldAsSingleRun && Field != FieldEnd && -!IsBetterAsSingleFieldRun(Field) && +!IsBetterAsSingleFieldRun(Tail - StartBitOffset, StartBitOffset) && (!Field->isZeroLengthBitField(Context) || (!Context.getTargetInfo().useZeroLengthBitfieldAlignment() && !Context.getTargetInfo().useBitFieldTypeAlignment())) && Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -1138,7 +1138,7 @@ def ffine_grained_bitfield_accesses : Flag<["-"], "ffine-grained-bitfield-accesses">, Group, Flags<[CC1Option]>, - HelpText<"Use separate accesses for bitfields with legal widths and alignments.">; + HelpText<"Use separate accesses for consecutive bitfield runs with legal widths and alignments.">; def fno_fine_grained_bitfield_accesses : Flag<["-"], "fno-fine-grained-bitfield-accesses">, Group, Flags<[CC1Option]>, HelpText<"Use large-integer access for consecutive bitfield runs.">; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45294: [libcxx] [test] Remove non-portable assertions from filebuf tests
mclow.lists accepted this revision. mclow.lists added a comment. This revision is now accepted and ready to land. This looks OK to me. https://reviews.llvm.org/D45294 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45179: [libc++] Add _LIBCPP_FORCE_NODISCARD define to force-enable nodiscard in pre-C++17
lebedev.ri added inline comments. Comment at: test/libcxx/diagnostics/force_nodiscard.fail.cpp:22 + +_LIBCPP_NODISCARD_AFTER_CXX17 int foo() { return 6; } + mclow.lists wrote: > Shouldn't this be just `_LIBCPP_NODISCARD` ? > I don't think so? I thought we are intentionally testing the same macro that libc++ is using internally. Repository: rCXX libc++ https://reviews.llvm.org/D45179 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46049: [OpenCL] Add constant address space to __func__ in AST
bader added inline comments. Comment at: lib/Sema/SemaExpr.cpp:3059 /*IndexTypeQuals*/ 0); SL = StringLiteral::Create(Context, Str, StringLiteral::Ascii, /*Pascal*/ false, ResTy, Loc); Will it work if we fix this issue inside StringLiteral::Create method? I just hope it will help us avoid code duplication. https://reviews.llvm.org/D46049 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38845: [ASTImporter] Support importing UnresolvedMemberExpr, DependentNameType, DependentScopeDeclRefExpr
szepet updated this revision to Diff 143925. szepet added a comment. Rewritten the tests using the newly added TEST_P method. This patch failed earlier when -fdelayed-template-parsing flag was enabled, however, the actual import process was OK but the original AST havent included the checked nodes. TEST_P made possible to check whether the original code contains the node we would like to import (and we test only in this case, since otherwise it does not make sense). https://reviews.llvm.org/D38845 Files: lib/AST/ASTImporter.cpp unittests/AST/ASTImporterTest.cpp Index: unittests/AST/ASTImporterTest.cpp === --- unittests/AST/ASTImporterTest.cpp +++ unittests/AST/ASTImporterTest.cpp @@ -1503,5 +1503,91 @@ ParameterizedTests, ImportFunctions, ::testing::Values(ArgVector(), ArgVector{"-fdelayed-template-parsing"}),); +const internal::VariadicDynCastAllOfMatcher +unresolvedMemberExpr; + +struct NoDelayedTemplateParsing : ASTImporterTestBase {}; +TEST_P(NoDelayedTemplateParsing, UnresolvedMemberExpr) { + auto Code = "struct S { template void mem(); };" + "template void declToImport() {" + " S s;" + " s.mem();" + "}"; + Decl *FromTU = getTuDecl(Code, Lang_CXX); + auto Pattern = functionTemplateDecl(has(functionDecl( + has(compoundStmt(has(callExpr(has(unresolvedMemberExpr(); + auto *FromUME = + FirstDeclMatcher().match(FromTU, Pattern); + if (!FromUME) +return; + + auto To = cast(Import(FromUME, Lang_CXX)); + EXPECT_TRUE(FirstDeclMatcher().match(To, Pattern)); +} + +const internal::VariadicDynCastAllOfMatcher +dependentScopeDeclRefExpr; +TEST_P(NoDelayedTemplateParsing, ImportDependentScopeDeclRefExpr) { + llvm::SmallVector Codes; + Codes.push_back("template struct S;" + "template void declToImport() {" + " S::foo;" + "}"); + + Codes.push_back("template struct S;" + "template void declToImport() {" + " S::template foo;" + "}"); + + Codes.push_back("template struct S;" + "template void declToImport() {" + " S::template foo<>;" + "}"); + + Codes.push_back("template struct S;" + "template void declToImport() {" + " S::template foo;" + "}"); + + auto Pattern = functionTemplateDecl( + has(functionDecl(has(compoundStmt(has(dependentScopeDeclRefExpr())); + llvm::SmallVector FromTUs; + // Converting code texts into TUs + std::transform(Codes.begin(), Codes.end(), std::back_inserter(FromTUs), + [this](StringRef Code) { + static int cnt = 0; + ++cnt; + return getTuDecl(Code, Lang_CXX, +std::to_string(cnt) + std::string(".cc")); + }); + + for (llvm::SmallVector::const_iterator TB = FromTUs.begin(), +TE = FromTUs.end(); + TB != TE; ++TB) { +auto *FromDSDRE = +FirstDeclMatcher().match(*TB, Pattern); +if (!FromDSDRE) + return; + +auto To = cast(Import(FromDSDRE, Lang_CXX)); +EXPECT_TRUE(FirstDeclMatcher().match(To, Pattern)); + } +} + +INSTANTIATE_TEST_CASE_P(ParameterizedTests, NoDelayedTemplateParsing, +::testing::Values(ArgVector()), ); + +const internal::VariadicDynCastAllOfMatcher +dependentNameType; +TEST(ImportExpr, DependentNameType) { + MatchVerifier Verifier; + testImport("template struct declToImport {" + " typedef typename T::type dependent_name;" + "};", + Lang_CXX11, "", Lang_CXX11, Verifier, + classTemplateDecl(has( + cxxRecordDecl(has(typedefDecl(has(dependentNameType(; +} + } // end namespace ast_matchers } // end namespace clang Index: lib/AST/ASTImporter.cpp === --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -121,7 +121,7 @@ QualType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T); QualType VisitTemplateSpecializationType(const TemplateSpecializationType *T); QualType VisitElaboratedType(const ElaboratedType *T); -// FIXME: DependentNameType +QualType VisitDependentNameType(const DependentNameType *T); QualType VisitPackExpansionType(const PackExpansionType *T); QualType VisitDependentTemplateSpecializationType( const DependentTemplateSpecializationType *T); @@ -347,8 +347,10 @@ Expr *VisitCXXConstructExpr(CXXConstructExpr *E); Expr *VisitCXXMemberCallExpr(CXXMemberCallExpr *E); Expr *VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); +Expr *VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); Expr *VisitCXXU
[PATCH] D45839: [analyzer] Add support for WebKit "unified sources".
probinson added a comment. In https://reviews.llvm.org/D45839#1077258, @NoQ wrote: > Aha, ok, yeah, that sounds like a lot, thank you. I think i'll follow up with > a separate commit that will enable first-level-code-file-include analysis in > all files under an on-by-default `-analyzer-config` flag, would that make > sense? Works for me, thanks! https://reviews.llvm.org/D45839 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45179: [libc++] Add _LIBCPP_FORCE_NODISCARD define to force-enable nodiscard in pre-C++17
mclow.lists added inline comments. Comment at: test/libcxx/diagnostics/force_nodiscard.fail.cpp:22 + +_LIBCPP_NODISCARD_AFTER_CXX17 int foo() { return 6; } + lebedev.ri wrote: > mclow.lists wrote: > > Shouldn't this be just `_LIBCPP_NODISCARD` ? > > > I don't think so? > I thought we are intentionally testing the same macro that libc++ is using > internally. Ok, I see what you're saying. This test is testing if a function marked `_LIBCPP_NODISCARD_AFTER_CXX17` gives an error if `_LIBCPP_FORCE_NODISCARD` is defined. But then you need another test, just like this, with `_LIBCPP_NODISCARD int foo() { return 6; }` to make sure that that gives an error as well. (and a passing test, that shows that if you don't opt-in, you get no error) Repository: rCXX libc++ https://reviews.llvm.org/D45179 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45179: [libc++] Add _LIBCPP_FORCE_NODISCARD define to force-enable nodiscard in pre-C++17
mclow.lists added a comment. BTW, you can gang several failing tests together, and check all the error messages - see libcxx/test/libcxx/containers/unord/unord.set/missing_hash_specialization.fail.cpp for an example. Repository: rCXX libc++ https://reviews.llvm.org/D45179 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46000: [AST] Added a helper to extract a user-friendly text of a comment.
ilya-biryukov updated this revision to Diff 143928. ilya-biryukov marked an inline comment as done. ilya-biryukov added a comment. - Attempt to reuse lexing code with/without command parsing. - Get rid of SkipWs. Repository: rC Clang https://reviews.llvm.org/D46000 Files: include/clang/AST/CommentLexer.h include/clang/AST/RawCommentList.h lib/AST/CommentLexer.cpp lib/AST/RawCommentList.cpp Index: lib/AST/RawCommentList.cpp === --- lib/AST/RawCommentList.cpp +++ lib/AST/RawCommentList.cpp @@ -335,3 +335,88 @@ BeforeThanCompare(SourceMgr)); std::swap(Comments, MergedComments); } + +std::string RawComment::getFormattedText(const ASTContext &Ctx) const { + auto &SourceMgr = Ctx.getSourceManager(); + llvm::StringRef CommentText = getRawText(SourceMgr); + if (CommentText.empty()) +return ""; // we couldn't retreive the comment. + + llvm::BumpPtrAllocator Allocator; + comments::Lexer L(Allocator, Ctx.getDiagnostics(), +Ctx.getCommentCommandTraits(), getSourceRange().getBegin(), +CommentText.begin(), CommentText.end(), +/*ParseCommentText=*/false); + + std::string Result; + unsigned IndentColumn = 0; + + // Processes one line of the comment and adds it to the result. + // Handles skipping the indent at the start of the line. + // Returns false when eof is reached and true otherwise. + auto LexLine = [&](bool IsFirstLine) -> bool { +comments::Token Tok; +// Lex the first token on the line. We handle it separately, because we to +// fix up its indentation. +L.lex(Tok); +if (Tok.is(comments::tok::eof)) + return false; +if (Tok.is(comments::tok::newline)) { + Result += "\n"; + return true; +} +llvm::StringRef TokText = L.getSpelling(Tok, SourceMgr); +bool LocInvalid = false; +unsigned TokColumn = +SourceMgr.getSpellingColumnNumber(Tok.getLocation(), &LocInvalid); +if (LocInvalid) + TokColumn = 0; +// Compute the length of whitespace we're allowed to skip. +size_t MaxSkip; +if (IsFirstLine) { + // For the first line we skip all leading ws. + MaxSkip = std::numeric_limits::max(); +} else { + // For the rest, we skip up to the column of first non-ws symbol on the + // first line.. + MaxSkip = std::max((int)IndentColumn - (int)TokColumn, 0); +} +// Amount of leading whitespace in TokText. +size_t WhitespaceLen = TokText.find_first_not_of(" \t"); +if (WhitespaceLen == StringRef::npos) + WhitespaceLen = TokText.size(); +// Remember the amount of whitespace we skipped in the first line to remove +// indent up to that column in the following lines. +if (IsFirstLine) + IndentColumn = TokColumn + WhitespaceLen; + +llvm::StringRef Trimmed = TokText.drop_front(std::min(MaxSkip, WhitespaceLen)); +Result += Trimmed; +// Lex all tokens in the rest of the line. +for (L.lex(Tok); Tok.isNot(comments::tok::eof); L.lex(Tok)) { + if (Tok.is(comments::tok::newline)) { +Result += "\n"; +return true; + } + Result += L.getSpelling(Tok, SourceMgr); +} +// We've reached the end of the line. +return false; + }; + + auto DropTrailingNewLines = [](std::string &Str) { +while (Str.back() == '\n') + Str.pop_back(); + }; + + // Proces first line separately to remember indent for the following lines. + if (!LexLine(/*IsFirstLine=*/true)) { +DropTrailingNewLines(Result); +return Result; + } + // Process the rest of the lines. + while (LexLine(/*IsFirstLine=*/false)) +; + DropTrailingNewLines(Result); + return Result; +} Index: lib/AST/CommentLexer.cpp === --- lib/AST/CommentLexer.cpp +++ lib/AST/CommentLexer.cpp @@ -291,159 +291,181 @@ } void Lexer::lexCommentText(Token &T) { + if (ParseCommands) { +if (tryLexCommands(T)) + return; + } + lexCommentTextWithoutCommands(T); +} + +bool Lexer::tryLexCommands(Token &T) { assert(CommentState == LCS_InsideBCPLComment || CommentState == LCS_InsideCComment); + if (!ParseCommands) +return false; switch (State) { case LS_Normal: break; case LS_VerbatimBlockFirstLine: lexVerbatimBlockFirstLine(T); -return; +return true; case LS_VerbatimBlockBody: lexVerbatimBlockBody(T); -return; +return true; case LS_VerbatimLineText: lexVerbatimLineText(T); -return; +return true; case LS_HTMLStartTag: lexHTMLStartTag(T); -return; +return true; case LS_HTMLEndTag: lexHTMLEndTag(T); -return; +return true; } assert(State == LS_Normal); const char *TokenPtr = BufferPtr; assert(TokenPtr < CommentEnd); - while (TokenPtr != CommentEnd) { -switch(*TokenPtr) { - case '\\': - case '@': { -// Commands that sta
[PATCH] D46000: [AST] Added a helper to extract a user-friendly text of a comment.
ilya-biryukov added inline comments. Comment at: lib/AST/CommentLexer.cpp:471 + case '\r': +TokenPtr = skipNewline(TokenPtr, CommentEnd); +formTokenWithChars(T, TokenPtr, tok::newline); ioeric wrote: > Can we share code with `lexCommentTextWithCommands` for these two common > cases? I couldn't come up with a way to do that previsouly. Made another attempt which seems to work. Please take a look, the change is somewhat non-trivial (includes removing the loop that seems redundant) Comment at: lib/AST/RawCommentList.cpp:380 +SourceMgr.getSpellingColumnNumber(Tok.getLocation(), &LocInvalid); +if (LocInvalid) + TokColumn = 0; ioeric wrote: > Explain when this would be invalid and why `TokColumn = 0` is used? I don't know whether this can be even be invalid, but I'm not confident enough to add an assert there. `TokColumn = 0` seems like a reasonable way to recover if we can't compute the column number, i.e. assume the line starts at the first column if SourceLocation of the line was invalid for any reason. This whole column thing looks weird to me, maybe I should just remove it altogether and just remove the same amount of whitespace in all the lines. WDYT? Comment at: lib/AST/RawCommentList.cpp:383 +// Compute the length of whitespace we're allowed to skip. +unsigned MaxSkip; +if (IsFirstLine) { ioeric wrote: > nit: `unsigned MaxSkip = IsFirstLine ? ... : ...;` That would force to get rid of the comments in the if branches, but they seem to be useful. Am I missing an obvious style that would preserve the comments? Comment at: lib/AST/RawCommentList.cpp:392 +} +llvm::StringRef Trimmed = SkipWs(TokText, MaxSkip); +Result += Trimmed; ioeric wrote: > I'd probably make `SkipWs` return the number of white spaces skipped and do > the drop-front here, so that you could simplify the awkward calculation of > `IndentColumn` below. Got rid of it altogether. The code seems is clearer now, thanks for the suggestion! Repository: rC Clang https://reviews.llvm.org/D46000 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46050: [Frontend] Avoid running plugins during code completion parse
thakis added a comment. Seems reasonable; can you add a test for this (maybe somewhere in clang/test/Frontend/plugin*)? Repository: rC Clang https://reviews.llvm.org/D46050 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46000: [AST] Added a helper to extract a user-friendly text of a comment.
ilya-biryukov updated this revision to Diff 143929. ilya-biryukov added a comment. - Update a comment after latest changes Repository: rC Clang https://reviews.llvm.org/D46000 Files: include/clang/AST/CommentLexer.h include/clang/AST/RawCommentList.h lib/AST/CommentLexer.cpp lib/AST/RawCommentList.cpp Index: lib/AST/RawCommentList.cpp === --- lib/AST/RawCommentList.cpp +++ lib/AST/RawCommentList.cpp @@ -335,3 +335,88 @@ BeforeThanCompare(SourceMgr)); std::swap(Comments, MergedComments); } + +std::string RawComment::getFormattedText(const ASTContext &Ctx) const { + auto &SourceMgr = Ctx.getSourceManager(); + llvm::StringRef CommentText = getRawText(SourceMgr); + if (CommentText.empty()) +return ""; // we couldn't retreive the comment. + + llvm::BumpPtrAllocator Allocator; + comments::Lexer L(Allocator, Ctx.getDiagnostics(), +Ctx.getCommentCommandTraits(), getSourceRange().getBegin(), +CommentText.begin(), CommentText.end(), +/*ParseCommentText=*/false); + + std::string Result; + unsigned IndentColumn = 0; + + // Processes one line of the comment and adds it to the result. + // Handles skipping the indent at the start of the line. + // Returns false when eof is reached and true otherwise. + auto LexLine = [&](bool IsFirstLine) -> bool { +comments::Token Tok; +// Lex the first token on the line. We handle it separately, because we to +// fix up its indentation. +L.lex(Tok); +if (Tok.is(comments::tok::eof)) + return false; +if (Tok.is(comments::tok::newline)) { + Result += "\n"; + return true; +} +llvm::StringRef TokText = L.getSpelling(Tok, SourceMgr); +bool LocInvalid = false; +unsigned TokColumn = +SourceMgr.getSpellingColumnNumber(Tok.getLocation(), &LocInvalid); +if (LocInvalid) + TokColumn = 0; +// Compute the length of whitespace we're allowed to skip. +size_t MaxSkip; +if (IsFirstLine) { + // For the first line we skip all leading ws. + MaxSkip = std::numeric_limits::max(); +} else { + // For the rest, we skip up to the column of first non-ws symbol on the + // first line.. + MaxSkip = std::max((int)IndentColumn - (int)TokColumn, 0); +} +// Amount of leading whitespace in TokText. +size_t WhitespaceLen = TokText.find_first_not_of(" \t"); +if (WhitespaceLen == StringRef::npos) + WhitespaceLen = TokText.size(); +// Remember the amount of whitespace we skipped in the first line to remove +// indent up to that column in the following lines. +if (IsFirstLine) + IndentColumn = TokColumn + WhitespaceLen; + +llvm::StringRef Trimmed = TokText.drop_front(std::min(MaxSkip, WhitespaceLen)); +Result += Trimmed; +// Lex all tokens in the rest of the line. +for (L.lex(Tok); Tok.isNot(comments::tok::eof); L.lex(Tok)) { + if (Tok.is(comments::tok::newline)) { +Result += "\n"; +return true; + } + Result += L.getSpelling(Tok, SourceMgr); +} +// We've reached the end of the line. +return false; + }; + + auto DropTrailingNewLines = [](std::string &Str) { +while (Str.back() == '\n') + Str.pop_back(); + }; + + // Proces first line separately to remember indent for the following lines. + if (!LexLine(/*IsFirstLine=*/true)) { +DropTrailingNewLines(Result); +return Result; + } + // Process the rest of the lines. + while (LexLine(/*IsFirstLine=*/false)) +; + DropTrailingNewLines(Result); + return Result; +} Index: lib/AST/CommentLexer.cpp === --- lib/AST/CommentLexer.cpp +++ lib/AST/CommentLexer.cpp @@ -291,159 +291,181 @@ } void Lexer::lexCommentText(Token &T) { + if (ParseCommands) { +if (tryLexCommands(T)) + return; + } + lexCommentTextWithoutCommands(T); +} + +bool Lexer::tryLexCommands(Token &T) { assert(CommentState == LCS_InsideBCPLComment || CommentState == LCS_InsideCComment); + if (!ParseCommands) +return false; switch (State) { case LS_Normal: break; case LS_VerbatimBlockFirstLine: lexVerbatimBlockFirstLine(T); -return; +return true; case LS_VerbatimBlockBody: lexVerbatimBlockBody(T); -return; +return true; case LS_VerbatimLineText: lexVerbatimLineText(T); -return; +return true; case LS_HTMLStartTag: lexHTMLStartTag(T); -return; +return true; case LS_HTMLEndTag: lexHTMLEndTag(T); -return; +return true; } assert(State == LS_Normal); const char *TokenPtr = BufferPtr; assert(TokenPtr < CommentEnd); - while (TokenPtr != CommentEnd) { -switch(*TokenPtr) { - case '\\': - case '@': { -// Commands that start with a backslash and commands that start with -// 'at' have equivalent semantic
[PATCH] D46000: [AST] Added a helper to extract a user-friendly text of a comment.
ilya-biryukov updated this revision to Diff 143930. ilya-biryukov added a comment. - Fix indentation Repository: rC Clang https://reviews.llvm.org/D46000 Files: include/clang/AST/CommentLexer.h include/clang/AST/RawCommentList.h lib/AST/CommentLexer.cpp lib/AST/RawCommentList.cpp Index: lib/AST/RawCommentList.cpp === --- lib/AST/RawCommentList.cpp +++ lib/AST/RawCommentList.cpp @@ -335,3 +335,88 @@ BeforeThanCompare(SourceMgr)); std::swap(Comments, MergedComments); } + +std::string RawComment::getFormattedText(const ASTContext &Ctx) const { + auto &SourceMgr = Ctx.getSourceManager(); + llvm::StringRef CommentText = getRawText(SourceMgr); + if (CommentText.empty()) +return ""; // we couldn't retreive the comment. + + llvm::BumpPtrAllocator Allocator; + comments::Lexer L(Allocator, Ctx.getDiagnostics(), +Ctx.getCommentCommandTraits(), getSourceRange().getBegin(), +CommentText.begin(), CommentText.end(), +/*ParseCommentText=*/false); + + std::string Result; + unsigned IndentColumn = 0; + + // Processes one line of the comment and adds it to the result. + // Handles skipping the indent at the start of the line. + // Returns false when eof is reached and true otherwise. + auto LexLine = [&](bool IsFirstLine) -> bool { +comments::Token Tok; +// Lex the first token on the line. We handle it separately, because we to +// fix up its indentation. +L.lex(Tok); +if (Tok.is(comments::tok::eof)) + return false; +if (Tok.is(comments::tok::newline)) { + Result += "\n"; + return true; +} +llvm::StringRef TokText = L.getSpelling(Tok, SourceMgr); +bool LocInvalid = false; +unsigned TokColumn = +SourceMgr.getSpellingColumnNumber(Tok.getLocation(), &LocInvalid); +if (LocInvalid) + TokColumn = 0; +// Compute the length of whitespace we're allowed to skip. +size_t MaxSkip; +if (IsFirstLine) { + // For the first line we skip all leading ws. + MaxSkip = std::numeric_limits::max(); +} else { + // For the rest, we skip up to the column of first non-ws symbol on the + // first line.. + MaxSkip = std::max((int)IndentColumn - (int)TokColumn, 0); +} +// Amount of leading whitespace in TokText. +size_t WhitespaceLen = TokText.find_first_not_of(" \t"); +if (WhitespaceLen == StringRef::npos) + WhitespaceLen = TokText.size(); +// Remember the amount of whitespace we skipped in the first line to remove +// indent up to that column in the following lines. +if (IsFirstLine) + IndentColumn = TokColumn + WhitespaceLen; + +llvm::StringRef Trimmed = TokText.drop_front(std::min(MaxSkip, WhitespaceLen)); +Result += Trimmed; +// Lex all tokens in the rest of the line. +for (L.lex(Tok); Tok.isNot(comments::tok::eof); L.lex(Tok)) { + if (Tok.is(comments::tok::newline)) { +Result += "\n"; +return true; + } + Result += L.getSpelling(Tok, SourceMgr); +} +// We've reached the end of the line. +return false; + }; + + auto DropTrailingNewLines = [](std::string &Str) { +while (Str.back() == '\n') + Str.pop_back(); + }; + + // Proces first line separately to remember indent for the following lines. + if (!LexLine(/*IsFirstLine=*/true)) { +DropTrailingNewLines(Result); +return Result; + } + // Process the rest of the lines. + while (LexLine(/*IsFirstLine=*/false)) +; + DropTrailingNewLines(Result); + return Result; +} Index: lib/AST/CommentLexer.cpp === --- lib/AST/CommentLexer.cpp +++ lib/AST/CommentLexer.cpp @@ -291,159 +291,181 @@ } void Lexer::lexCommentText(Token &T) { + if (ParseCommands) { +if (tryLexCommands(T)) + return; + } + lexCommentTextWithoutCommands(T); +} + +bool Lexer::tryLexCommands(Token &T) { assert(CommentState == LCS_InsideBCPLComment || CommentState == LCS_InsideCComment); + if (!ParseCommands) +return false; switch (State) { case LS_Normal: break; case LS_VerbatimBlockFirstLine: lexVerbatimBlockFirstLine(T); -return; +return true; case LS_VerbatimBlockBody: lexVerbatimBlockBody(T); -return; +return true; case LS_VerbatimLineText: lexVerbatimLineText(T); -return; +return true; case LS_HTMLStartTag: lexHTMLStartTag(T); -return; +return true; case LS_HTMLEndTag: lexHTMLEndTag(T); -return; +return true; } assert(State == LS_Normal); const char *TokenPtr = BufferPtr; assert(TokenPtr < CommentEnd); - while (TokenPtr != CommentEnd) { -switch(*TokenPtr) { - case '\\': - case '@': { -// Commands that start with a backslash and commands that start with -// 'at' have equivalent semantics. But we keep inform
[libcxx] r330828 - Fix static initialization of std::atomic_flag; Fixes PR#37226. Thanks to Ricky Zhou for the report and test case.
Author: marshall Date: Wed Apr 25 07:27:29 2018 New Revision: 330828 URL: http://llvm.org/viewvc/llvm-project?rev=330828&view=rev Log: Fix static initialization of std::atomic_flag; Fixes PR#37226. Thanks to Ricky Zhou for the report and test case. Modified: libcxx/trunk/include/atomic libcxx/trunk/test/libcxx/atomics/atomics.flag/init_bool.pass.cpp Modified: libcxx/trunk/include/atomic URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/atomic?rev=330828&r1=330827&r2=330828&view=diff == --- libcxx/trunk/include/atomic (original) +++ libcxx/trunk/include/atomic Wed Apr 25 07:27:29 2018 @@ -1741,7 +1741,7 @@ typedef struct atomic_flag atomic_flag() _NOEXCEPT : __a_() {} #endif // _LIBCPP_CXX03_LANG -_LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION #ifndef _LIBCPP_CXX03_LANG Modified: libcxx/trunk/test/libcxx/atomics/atomics.flag/init_bool.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/atomics/atomics.flag/init_bool.pass.cpp?rev=330828&r1=330827&r2=330828&view=diff == --- libcxx/trunk/test/libcxx/atomics/atomics.flag/init_bool.pass.cpp (original) +++ libcxx/trunk/test/libcxx/atomics/atomics.flag/init_bool.pass.cpp Wed Apr 25 07:27:29 2018 @@ -18,8 +18,15 @@ #include #include + // Ensure that static initialization happens; this is PR#37226 +extern std::atomic_flag global; +struct X { X() { global.test_and_set(); }}; +X x; +std::atomic_flag global = ATOMIC_FLAG_INIT; + int main() { +assert(global.test_and_set() == 1); { std::atomic_flag f(false); assert(f.test_and_set() == 0); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46062: [clang-format] Start formatting cpp code in raw strings in google style
krasimir created this revision. krasimir added a reviewer: klimek. Herald added a subscriber: cfe-commits. This adds some delimiters to detect cpp code in raw strings. Repository: rC Clang https://reviews.llvm.org/D46062 Files: lib/Format/Format.cpp Index: lib/Format/Format.cpp === --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -718,20 +718,39 @@ GoogleStyle.ObjCSpaceAfterProperty = false; GoogleStyle.ObjCSpaceBeforeProtocolList = true; GoogleStyle.PointerAlignment = FormatStyle::PAS_Left; - GoogleStyle.RawStringFormats = {{ - FormatStyle::LK_TextProto, - /*Delimiters=*/ + GoogleStyle.RawStringFormats = { { - "pb", - "PB", - "proto", - "PROTO", + FormatStyle::LK_Cpp, + /*Delimiters=*/ + { + "cc", + "CC", + "cpp", + "Cpp", + "CPP", + "c++", + "C++", + }, + /*EnclosingFunctionNames=*/ + {}, + /*CanonicalDelimiter=*/"", + /*BasedOnStyle=*/"google", }, - /*EnclosingFunctionNames=*/ - {}, - /*CanonicalDelimiter=*/"", - /*BasedOnStyle=*/"google", - }}; + { + FormatStyle::LK_TextProto, + /*Delimiters=*/ + { + "pb", + "PB", + "proto", + "PROTO", + }, + /*EnclosingFunctionNames=*/ + {}, + /*CanonicalDelimiter=*/"", + /*BasedOnStyle=*/"google", + }, + }; GoogleStyle.SpacesBeforeTrailingComments = 2; GoogleStyle.Standard = FormatStyle::LS_Auto; Index: lib/Format/Format.cpp === --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -718,20 +718,39 @@ GoogleStyle.ObjCSpaceAfterProperty = false; GoogleStyle.ObjCSpaceBeforeProtocolList = true; GoogleStyle.PointerAlignment = FormatStyle::PAS_Left; - GoogleStyle.RawStringFormats = {{ - FormatStyle::LK_TextProto, - /*Delimiters=*/ + GoogleStyle.RawStringFormats = { { - "pb", - "PB", - "proto", - "PROTO", + FormatStyle::LK_Cpp, + /*Delimiters=*/ + { + "cc", + "CC", + "cpp", + "Cpp", + "CPP", + "c++", + "C++", + }, + /*EnclosingFunctionNames=*/ + {}, + /*CanonicalDelimiter=*/"", + /*BasedOnStyle=*/"google", }, - /*EnclosingFunctionNames=*/ - {}, - /*CanonicalDelimiter=*/"", - /*BasedOnStyle=*/"google", - }}; + { + FormatStyle::LK_TextProto, + /*Delimiters=*/ + { + "pb", + "PB", + "proto", + "PROTO", + }, + /*EnclosingFunctionNames=*/ + {}, + /*CanonicalDelimiter=*/"", + /*BasedOnStyle=*/"google", + }, + }; GoogleStyle.SpacesBeforeTrailingComments = 2; GoogleStyle.Standard = FormatStyle::LS_Auto; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46062: [clang-format] Start formatting cpp code in raw strings in google style
klimek accepted this revision. klimek added a comment. This revision is now accepted and ready to land. LG Repository: rC Clang https://reviews.llvm.org/D46062 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r330832 - [clang-format] Start formatting cpp code in raw strings in google style
Author: krasimir Date: Wed Apr 25 07:56:19 2018 New Revision: 330832 URL: http://llvm.org/viewvc/llvm-project?rev=330832&view=rev Log: [clang-format] Start formatting cpp code in raw strings in google style Summary: This adds some delimiters to detect cpp code in raw strings. Reviewers: klimek Reviewed By: klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D46062 Modified: cfe/trunk/lib/Format/Format.cpp Modified: cfe/trunk/lib/Format/Format.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=330832&r1=330831&r2=330832&view=diff == --- cfe/trunk/lib/Format/Format.cpp (original) +++ cfe/trunk/lib/Format/Format.cpp Wed Apr 25 07:56:19 2018 @@ -718,20 +718,39 @@ FormatStyle getGoogleStyle(FormatStyle:: GoogleStyle.ObjCSpaceAfterProperty = false; GoogleStyle.ObjCSpaceBeforeProtocolList = true; GoogleStyle.PointerAlignment = FormatStyle::PAS_Left; - GoogleStyle.RawStringFormats = {{ - FormatStyle::LK_TextProto, - /*Delimiters=*/ + GoogleStyle.RawStringFormats = { { - "pb", - "PB", - "proto", - "PROTO", + FormatStyle::LK_Cpp, + /*Delimiters=*/ + { + "cc", + "CC", + "cpp", + "Cpp", + "CPP", + "c++", + "C++", + }, + /*EnclosingFunctionNames=*/ + {}, + /*CanonicalDelimiter=*/"", + /*BasedOnStyle=*/"google", }, - /*EnclosingFunctionNames=*/ - {}, - /*CanonicalDelimiter=*/"", - /*BasedOnStyle=*/"google", - }}; + { + FormatStyle::LK_TextProto, + /*Delimiters=*/ + { + "pb", + "PB", + "proto", + "PROTO", + }, + /*EnclosingFunctionNames=*/ + {}, + /*CanonicalDelimiter=*/"", + /*BasedOnStyle=*/"google", + }, + }; GoogleStyle.SpacesBeforeTrailingComments = 2; GoogleStyle.Standard = FormatStyle::LS_Auto; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46062: [clang-format] Start formatting cpp code in raw strings in google style
This revision was automatically updated to reflect the committed changes. Closed by commit rC330832: [clang-format] Start formatting cpp code in raw strings in google style (authored by krasimir, committed by ). Changed prior to commit: https://reviews.llvm.org/D46062?vs=143931&id=143933#toc Repository: rC Clang https://reviews.llvm.org/D46062 Files: lib/Format/Format.cpp Index: lib/Format/Format.cpp === --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -718,20 +718,39 @@ GoogleStyle.ObjCSpaceAfterProperty = false; GoogleStyle.ObjCSpaceBeforeProtocolList = true; GoogleStyle.PointerAlignment = FormatStyle::PAS_Left; - GoogleStyle.RawStringFormats = {{ - FormatStyle::LK_TextProto, - /*Delimiters=*/ + GoogleStyle.RawStringFormats = { { - "pb", - "PB", - "proto", - "PROTO", + FormatStyle::LK_Cpp, + /*Delimiters=*/ + { + "cc", + "CC", + "cpp", + "Cpp", + "CPP", + "c++", + "C++", + }, + /*EnclosingFunctionNames=*/ + {}, + /*CanonicalDelimiter=*/"", + /*BasedOnStyle=*/"google", }, - /*EnclosingFunctionNames=*/ - {}, - /*CanonicalDelimiter=*/"", - /*BasedOnStyle=*/"google", - }}; + { + FormatStyle::LK_TextProto, + /*Delimiters=*/ + { + "pb", + "PB", + "proto", + "PROTO", + }, + /*EnclosingFunctionNames=*/ + {}, + /*CanonicalDelimiter=*/"", + /*BasedOnStyle=*/"google", + }, + }; GoogleStyle.SpacesBeforeTrailingComments = 2; GoogleStyle.Standard = FormatStyle::LS_Auto; Index: lib/Format/Format.cpp === --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -718,20 +718,39 @@ GoogleStyle.ObjCSpaceAfterProperty = false; GoogleStyle.ObjCSpaceBeforeProtocolList = true; GoogleStyle.PointerAlignment = FormatStyle::PAS_Left; - GoogleStyle.RawStringFormats = {{ - FormatStyle::LK_TextProto, - /*Delimiters=*/ + GoogleStyle.RawStringFormats = { { - "pb", - "PB", - "proto", - "PROTO", + FormatStyle::LK_Cpp, + /*Delimiters=*/ + { + "cc", + "CC", + "cpp", + "Cpp", + "CPP", + "c++", + "C++", + }, + /*EnclosingFunctionNames=*/ + {}, + /*CanonicalDelimiter=*/"", + /*BasedOnStyle=*/"google", }, - /*EnclosingFunctionNames=*/ - {}, - /*CanonicalDelimiter=*/"", - /*BasedOnStyle=*/"google", - }}; + { + FormatStyle::LK_TextProto, + /*Delimiters=*/ + { + "pb", + "PB", + "proto", + "PROTO", + }, + /*EnclosingFunctionNames=*/ + {}, + /*CanonicalDelimiter=*/"", + /*BasedOnStyle=*/"google", + }, + }; GoogleStyle.SpacesBeforeTrailingComments = 2; GoogleStyle.Standard = FormatStyle::LS_Auto; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46050: [Frontend] Avoid running plugins during code completion parse
john.brawn added a comment. I know very little about how code completion works, but it's not immediately obvious to me that disabling plugin ast consumers when code completion is enabled is necessarily correct. In what kind of scenario would we both have a plugin loaded that wants to insert an ast consumer before/after the main one, and also be doing code completion? Repository: rC Clang https://reviews.llvm.org/D46050 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D44932: [CodeComplete] Fix completion in the middle of ident in ctor lists.
ilya-biryukov updated this revision to Diff 143935. ilya-biryukov marked an inline comment as done. ilya-biryukov added a comment. - Fix the comment Repository: rC Clang https://reviews.llvm.org/D44932 Files: lib/Lex/Lexer.cpp test/CodeCompletion/ctor-initializer.cpp test/CodeCompletion/end-of-file.cpp Index: test/CodeCompletion/end-of-file.cpp === --- /dev/null +++ test/CodeCompletion/end-of-file.cpp @@ -0,0 +1,7 @@ +// Check that clang does not crash when completing at the last char in the +// buffer. +// NOTE: This file must *NOT* have newline at the end. +// RUN: %clang_cc1 -code-completion-at=%s:7:2 %s | FileCheck %s +// CHECK: COMPLETION: foo +using foo = int***; +f \ No newline at end of file Index: test/CodeCompletion/ctor-initializer.cpp === --- test/CodeCompletion/ctor-initializer.cpp +++ test/CodeCompletion/ctor-initializer.cpp @@ -58,5 +58,9 @@ // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s // RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s // CHECK-CC7: COMPLETION: Pattern : member1(<#args#> + // Check in the middle and at the end of identifier too. + // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:13 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s + // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:16 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s + // CHECK-CC8: COMPLETION: Pattern : member2(<#args#> int member1, member2; }; Index: lib/Lex/Lexer.cpp === --- lib/Lex/Lexer.cpp +++ lib/Lex/Lexer.cpp @@ -1654,7 +1654,21 @@ if (isCodeCompletionPoint(CurPtr)) { // Return the code-completion token. Result.setKind(tok::code_completion); - cutOffLexing(); + // Skip the code-completion char and all immediate identifier characters. + // This ensures we get consistent behavior when completing at any point in + // an identifier (i.e. at the start, in the middle, at the end). Note that + // only simple cases (i.e. [a-zA-Z0-9_]) are supported to keep the code + // simpler. + assert(*CurPtr == 0 && "Completion character must be 0"); + ++CurPtr; + // Note that code completion token is not added as a separate character + // when the completion point is at the end of the buffer. Therefore, we need + // to check if the buffer has ended. + if (CurPtr < BufferEnd) { +while (isIdentifierBody(*CurPtr)) + ++CurPtr; + } + BufferPtr = CurPtr; return true; } Index: test/CodeCompletion/end-of-file.cpp === --- /dev/null +++ test/CodeCompletion/end-of-file.cpp @@ -0,0 +1,7 @@ +// Check that clang does not crash when completing at the last char in the +// buffer. +// NOTE: This file must *NOT* have newline at the end. +// RUN: %clang_cc1 -code-completion-at=%s:7:2 %s | FileCheck %s +// CHECK: COMPLETION: foo +using foo = int***; +f \ No newline at end of file Index: test/CodeCompletion/ctor-initializer.cpp === --- test/CodeCompletion/ctor-initializer.cpp +++ test/CodeCompletion/ctor-initializer.cpp @@ -58,5 +58,9 @@ // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s // RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s // CHECK-CC7: COMPLETION: Pattern : member1(<#args#> + // Check in the middle and at the end of identifier too. + // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:13 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s + // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:16 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s + // CHECK-CC8: COMPLETION: Pattern : member2(<#args#> int member1, member2; }; Index: lib/Lex/Lexer.cpp === --- lib/Lex/Lexer.cpp +++ lib/Lex/Lexer.cpp @@ -1654,7 +1654,21 @@ if (isCodeCompletionPoint(CurPtr)) { // Return the code-completion token. Result.setKind(tok::code_completion); - cutOffLexing(); + // Skip the code-completion char and all immediate identifier characters. + // This ensures we get consistent behavior when completing at any point in + // an identifier (i.e. at the start, in the middle, at the end). Note that + // only simple cases (i.e. [a-zA-Z0-9_]) are supported to keep the code + // simpler. + assert(*CurPtr == 0 && "Completion character must be 0"); + ++CurPtr; + // Note that code completion token is not added a
[PATCH] D46065: [clangd] Add "str()" method to SymbolID.
hokein created this revision. hokein added a reviewer: ioeric. Herald added subscribers: jkorous, MaskRay, ilya-biryukov, klimek. This is a convenient function when we try to get std::string of SymbolID. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D46065 Files: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp clangd/index/Index.cpp clangd/index/Index.h Index: clangd/index/Index.h === --- clangd/index/Index.h +++ clangd/index/Index.h @@ -69,6 +69,9 @@ return HashValue < Sym.HashValue; } + // Returns a 40-bytes hex encoded string. + std::string str() const; + private: static constexpr unsigned HashByteLength = 20; Index: clangd/index/Index.cpp === --- clangd/index/Index.cpp +++ clangd/index/Index.cpp @@ -31,6 +31,13 @@ return OS; } +std::string SymbolID::str() const { + std::string ID; + llvm::raw_string_ostream OS(ID); + OS << *this; + return OS.str(); +} + void operator>>(StringRef Str, SymbolID &ID) { std::string HexString = fromHex(Str); assert(HexString.size() == ID.HashValue.size()); Index: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp === --- clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp +++ clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp @@ -78,10 +78,7 @@ auto Symbols = Collector->takeSymbols(); for (const auto &Sym : Symbols) { - std::string IDStr; - llvm::raw_string_ostream OS(IDStr); - OS << Sym.ID; - Ctx->reportResult(OS.str(), SymbolToYAML(Sym)); + Ctx->reportResult(Sym.ID.str(), SymbolToYAML(Sym)); } } Index: clangd/index/Index.h === --- clangd/index/Index.h +++ clangd/index/Index.h @@ -69,6 +69,9 @@ return HashValue < Sym.HashValue; } + // Returns a 40-bytes hex encoded string. + std::string str() const; + private: static constexpr unsigned HashByteLength = 20; Index: clangd/index/Index.cpp === --- clangd/index/Index.cpp +++ clangd/index/Index.cpp @@ -31,6 +31,13 @@ return OS; } +std::string SymbolID::str() const { + std::string ID; + llvm::raw_string_ostream OS(ID); + OS << *this; + return OS.str(); +} + void operator>>(StringRef Str, SymbolID &ID) { std::string HexString = fromHex(Str); assert(HexString.size() == ID.HashValue.size()); Index: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp === --- clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp +++ clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp @@ -78,10 +78,7 @@ auto Symbols = Collector->takeSymbols(); for (const auto &Sym : Symbols) { - std::string IDStr; - llvm::raw_string_ostream OS(IDStr); - OS << Sym.ID; - Ctx->reportResult(OS.str(), SymbolToYAML(Sym)); + Ctx->reportResult(Sym.ID.str(), SymbolToYAML(Sym)); } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46064: [llvm-objcopy] Add --localize-symbol option
paulsemel created this revision. paulsemel added reviewers: jakehehrlich, echristo. Herald added a subscriber: llvm-commits. This option permit to localize a symbol by given its name. Repository: rL LLVM https://reviews.llvm.org/D46064 Files: test/tools/llvm-objcopy/localize.test tools/llvm-objcopy/Opts.td tools/llvm-objcopy/llvm-objcopy.cpp Index: tools/llvm-objcopy/llvm-objcopy.cpp === --- tools/llvm-objcopy/llvm-objcopy.cpp +++ tools/llvm-objcopy/llvm-objcopy.cpp @@ -118,6 +118,7 @@ std::vector Keep; std::vector OnlyKeep; std::vector AddSection; + std::vector LocalizeSymbol; bool StripAll; bool StripAllGNU; bool StripDebug; @@ -196,6 +197,14 @@ }); } + if (!Config.LocalizeSymbol.empty()) { +Obj.SymbolTable->localize([&Config](const Symbol &Sym) { + return std::find(std::begin(Config.LocalizeSymbol), + std::end(Config.LocalizeSymbol), + Sym.Name) != std::end(Config.LocalizeSymbol); +}); + } + SectionPred RemovePred = [](const SectionBase &) { return false; }; // Removes: @@ -398,6 +407,8 @@ Config.StripNonAlloc = InputArgs.hasArg(OBJCOPY_strip_non_alloc); Config.ExtractDWO = InputArgs.hasArg(OBJCOPY_extract_dwo); Config.LocalizeHidden = InputArgs.hasArg(OBJCOPY_localize_hidden); + for (auto Arg : InputArgs.filtered(OBJCOPY_localize_symbol)) +Config.LocalizeSymbol.push_back(Arg->getValue()); return Config; } Index: tools/llvm-objcopy/Opts.td === --- tools/llvm-objcopy/Opts.td +++ tools/llvm-objcopy/Opts.td @@ -56,3 +56,8 @@ HelpText<"Remove all sections that are not DWARF .dwo sections from file">; def localize_hidden : Flag<["-", "--"], "localize-hidden">, HelpText<"Mark all symbols that have hidden or internal visibility as local">; +defm localize_symbol : Eq<"localize-symbol">, + MetaVarName<"symbol">, + HelpText<"Localize ">; +def L : JoinedOrSeparate<["-"], "L">, +Alias; Index: test/tools/llvm-objcopy/localize.test === --- /dev/null +++ test/tools/llvm-objcopy/localize.test @@ -0,0 +1,104 @@ +# RUN: yaml2obj %s > %t +# RUN: llvm-objcopy --localize-symbol defaultGlobal %t %t2 +# RUN: llvm-readobj -symbols %t2 | FileCheck %s + +!ELF +FileHeader: + Class: ELFCLASS64 + Data:ELFDATA2LSB + Type:ET_REL + Machine: EM_X86_64 +Sections: + - Name:.text +Type:SHT_PROGBITS +Flags: [ SHF_ALLOC, SHF_EXECINSTR ] +Address: 0x1000 +AddressAlign:0x0010 +Size:64 + - Name:.data +Type:SHT_PROGBITS +Flags: [ SHF_ALLOC ] +Address: 0x2000 +AddressAlign:0x0010 +Content: "" +Symbols: + Local: +- Name: hiddenLocal + Type: STT_FUNC + Section: .text + Value:0x1008 + Size: 8 + Visibility: STV_HIDDEN + Weak: +- Name: hiddenWeak + Type: STT_FUNC + Section: .text + Value:0x1010 + Size: 8 + Visibility: STV_HIDDEN + Global: +- Name: defaultGlobal + Type: STT_FUNC + Size: 8 + Section: .text + Value:0x1000 +- Name: hiddenGlobal + Type: STT_OBJECT + Section: .data + Value:0x2006 + Size: 2 + Visibility: STV_HIDDEN + +#CHECK: Symbols [ +#CHECK-NEXT: Symbol { +#CHECK-NEXT:Name: +#CHECK-NEXT:Value: 0x0 +#CHECK-NEXT:Size: 0 +#CHECK-NEXT:Binding: Local +#CHECK-NEXT:Type: None +#CHECK-NEXT:Other: 0 +#CHECK-NEXT:Section: Undefined +#CHECK-NEXT: } +#CHECK-NEXT: Symbol { +#CHECK-NEXT:Name: hiddenLocal +#CHECK-NEXT:Value: 0x1008 +#CHECK-NEXT:Size: 8 +#CHECK-NEXT:Binding: Local +#CHECK-NEXT:Type: Function +#CHECK-NEXT:Other [ +#CHECK-NEXT: STV_HIDDEN +#CHECK-NEXT:] +#CHECK-NEXT:Section: .text +#CHECK-NEXT: } +#CHECK-NEXT: Symbol { +#CHECK-NEXT:Name: defaultGlobal +#CHECK-NEXT:Value: 0x1000 +#CHECK-NEXT:Size: 8 +#CHECK-NEXT:Binding: Local +#CHECK-NEXT:Type: Function +#CHECK-NEXT:Other: 0 +#CHECK-NEXT:Section: .text +#CHECK-NEXT: } +#CHECK-NEXT: Symbol { +#CHECK-NEXT:Name: hiddenGlobal +#CHECK-NEXT:Value: 0x2006 +#CHECK-NEXT:Size: 2 +#CHECK-NEXT:Binding: Global +#CHECK-NEXT:Type: Object +#CHECK-NEXT:Other [ +#CHECK-NEXT: STV_HIDDEN +#CHECK-NEXT:] +#CHECK-NEXT:Section: .data +#CHECK-NEXT: } +#CHECK-NEXT: Symbol { +#CHECK-NEXT:Name: hiddenWeak +#CHECK-NEXT:Value: 0x1010 +#CHECK-NEXT:Size: 8 +#CHECK-NEXT:Binding: Weak +#CHECK-NEXT:Type: Function +#CHECK-NEXT:Other [ +#CHECK-NEXT:
[PATCH] D46015: [OpenCL] Add separate read_only and write_only pipe IR types
stuart updated this revision to Diff 143938. stuart edited the summary of this revision. stuart added a comment. Changed new getPipeType() method to have protected visibility. Updated summary to explain the need for the extra builtin implementation functions. https://reviews.llvm.org/D46015 Files: lib/CodeGen/CGBuiltin.cpp lib/CodeGen/CGOpenCLRuntime.cpp lib/CodeGen/CGOpenCLRuntime.h test/CodeGenOpenCL/opencl_types.cl test/CodeGenOpenCL/pipe_builtin.cl test/CodeGenOpenCL/pipe_types.cl test/Index/pipe-size.cl Index: test/Index/pipe-size.cl === --- test/Index/pipe-size.cl +++ test/Index/pipe-size.cl @@ -5,12 +5,12 @@ __kernel void testPipe( pipe int test ) { int s = sizeof(test); -// X86: store %opencl.pipe_t* %test, %opencl.pipe_t** %test.addr, align 8 +// X86: store %opencl.pipe_ro_t* %test, %opencl.pipe_ro_t** %test.addr, align 8 // X86: store i32 8, i32* %s, align 4 -// SPIR: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t addrspace(1)** %test.addr, align 4 +// SPIR: store %opencl.pipe_ro_t addrspace(1)* %test, %opencl.pipe_ro_t addrspace(1)** %test.addr, align 4 // SPIR: store i32 4, i32* %s, align 4 -// SPIR64: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t addrspace(1)** %test.addr, align 8 +// SPIR64: store %opencl.pipe_ro_t addrspace(1)* %test, %opencl.pipe_ro_t addrspace(1)** %test.addr, align 8 // SPIR64: store i32 8, i32* %s, align 4 -// AMDGCN: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t addrspace(1)* addrspace(5)* %test.addr, align 8 +// AMDGCN: store %opencl.pipe_ro_t addrspace(1)* %test, %opencl.pipe_ro_t addrspace(1)* addrspace(5)* %test.addr, align 8 // AMDGCN: store i32 8, i32 addrspace(5)* %s, align 4 } Index: test/CodeGenOpenCL/pipe_types.cl === --- test/CodeGenOpenCL/pipe_types.cl +++ test/CodeGenOpenCL/pipe_types.cl @@ -1,34 +1,35 @@ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s -// CHECK: %opencl.pipe_t = type opaque +// CHECK: %opencl.pipe_ro_t = type opaque +// CHECK: %opencl.pipe_wo_t = type opaque typedef unsigned char __attribute__((ext_vector_type(3))) uchar3; typedef int __attribute__((ext_vector_type(4))) int4; void test1(read_only pipe int p) { -// CHECK: define void @test1(%opencl.pipe_t* %p) +// CHECK: define void @test1(%opencl.pipe_ro_t* %p) reserve_id_t rid; // CHECK: %rid = alloca %opencl.reserve_id_t } void test2(write_only pipe float p) { -// CHECK: define void @test2(%opencl.pipe_t* %p) +// CHECK: define void @test2(%opencl.pipe_wo_t* %p) } void test3(read_only pipe const int p) { -// CHECK: define void @test3(%opencl.pipe_t* %p) +// CHECK: define void @test3(%opencl.pipe_ro_t* %p) } void test4(read_only pipe uchar3 p) { -// CHECK: define void @test4(%opencl.pipe_t* %p) +// CHECK: define void @test4(%opencl.pipe_ro_t* %p) } void test5(read_only pipe int4 p) { -// CHECK: define void @test5(%opencl.pipe_t* %p) +// CHECK: define void @test5(%opencl.pipe_ro_t* %p) } typedef read_only pipe int MyPipe; kernel void test6(MyPipe p) { -// CHECK: define spir_kernel void @test6(%opencl.pipe_t* %p) +// CHECK: define spir_kernel void @test6(%opencl.pipe_ro_t* %p) } struct Person { @@ -41,7 +42,7 @@ read_only pipe struct Person SPipe) { // CHECK: define void @test_reserved_read_pipe read_pipe (SPipe, SDst); - // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8) + // CHECK: call i32 @__read_pipe_2(%opencl.pipe_ro_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8) read_pipe (SPipe, SDst); - // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8) + // CHECK: call i32 @__read_pipe_2(%opencl.pipe_ro_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8) } Index: test/CodeGenOpenCL/pipe_builtin.cl === --- test/CodeGenOpenCL/pipe_builtin.cl +++ test/CodeGenOpenCL/pipe_builtin.cl @@ -1,79 +1,93 @@ // RUN: %clang_cc1 -emit-llvm -cl-ext=+cl_khr_subgroups -O0 -cl-std=CL2.0 -o - %s | FileCheck %s -// CHECK: %opencl.pipe_t = type opaque -// CHECK: %opencl.reserve_id_t = type opaque +// CHECK-DAG: %opencl.pipe_ro_t = type opaque +// CHECK-DAG: %opencl.pipe_wo_t = type opaque +// CHECK-DAG: %opencl.reserve_id_t = type opaque #pragma OPENCL EXTENSION cl_khr_subgroups : enable void test1(read_only pipe int p, global int *ptr) { - // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}}, i32 4, i32 4) + // CHECK: call i32 @__read_pipe_2(%opencl.pipe_ro_t* %{{.*}}, i8* %{{.*}}, i32 4, i32 4) read_pipe(p, ptr); - // CHECK: call %opencl.reserve_id_t* @__reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4) + // CHECK: call %opencl.reserve_id_t* @__reserve_read_pipe(%opencl.pipe_ro_t* %
r330833 - [CodeComplete] Fix completion in the middle of ident in ctor lists.
Author: ibiryukov Date: Wed Apr 25 08:13:34 2018 New Revision: 330833 URL: http://llvm.org/viewvc/llvm-project?rev=330833&view=rev Log: [CodeComplete] Fix completion in the middle of ident in ctor lists. Summary: The example that was broken before (^ designates completion points): class Foo { Foo() : fie^ld^() {} // no completions were provided here. int field; }; To fix it we don't cut off lexing after an identifier followed by code completion token is lexed. Instead we skip the rest of identifier and continue lexing. This is consistent with behavior of completion when completion token is right before the identifier. Reviewers: sammccall, aaron.ballman, bkramer, sepavloff, arphaman, rsmith Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D44932 Added: cfe/trunk/test/CodeCompletion/end-of-file.cpp Modified: cfe/trunk/lib/Lex/Lexer.cpp cfe/trunk/test/CodeCompletion/ctor-initializer.cpp Modified: cfe/trunk/lib/Lex/Lexer.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=330833&r1=330832&r2=330833&view=diff == --- cfe/trunk/lib/Lex/Lexer.cpp (original) +++ cfe/trunk/lib/Lex/Lexer.cpp Wed Apr 25 08:13:34 2018 @@ -1654,7 +1654,21 @@ FinishIdentifier: if (isCodeCompletionPoint(CurPtr)) { // Return the code-completion token. Result.setKind(tok::code_completion); - cutOffLexing(); + // Skip the code-completion char and all immediate identifier characters. + // This ensures we get consistent behavior when completing at any point in + // an identifier (i.e. at the start, in the middle, at the end). Note that + // only simple cases (i.e. [a-zA-Z0-9_]) are supported to keep the code + // simpler. + assert(*CurPtr == 0 && "Completion character must be 0"); + ++CurPtr; + // Note that code completion token is not added as a separate character + // when the completion point is at the end of the buffer. Therefore, we need + // to check if the buffer has ended. + if (CurPtr < BufferEnd) { +while (isIdentifierBody(*CurPtr)) + ++CurPtr; + } + BufferPtr = CurPtr; return true; } Modified: cfe/trunk/test/CodeCompletion/ctor-initializer.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/ctor-initializer.cpp?rev=330833&r1=330832&r2=330833&view=diff == --- cfe/trunk/test/CodeCompletion/ctor-initializer.cpp (original) +++ cfe/trunk/test/CodeCompletion/ctor-initializer.cpp Wed Apr 25 08:13:34 2018 @@ -58,5 +58,9 @@ struct B { // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s // RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s // CHECK-CC7: COMPLETION: Pattern : member1(<#args#> + // Check in the middle and at the end of identifier too. + // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:13 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s + // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:16 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s + // CHECK-CC8: COMPLETION: Pattern : member2(<#args#> int member1, member2; }; Added: cfe/trunk/test/CodeCompletion/end-of-file.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/end-of-file.cpp?rev=330833&view=auto == --- cfe/trunk/test/CodeCompletion/end-of-file.cpp (added) +++ cfe/trunk/test/CodeCompletion/end-of-file.cpp Wed Apr 25 08:13:34 2018 @@ -0,0 +1,7 @@ +// Check that clang does not crash when completing at the last char in the +// buffer. +// NOTE: This file must *NOT* have newline at the end. +// RUN: %clang_cc1 -code-completion-at=%s:7:2 %s | FileCheck %s +// CHECK: COMPLETION: foo +using foo = int***; +f \ No newline at end of file ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D44932: [CodeComplete] Fix completion in the middle of ident in ctor lists.
This revision was automatically updated to reflect the committed changes. Closed by commit rL330833: [CodeComplete] Fix completion in the middle of ident in ctor lists. (authored by ibiryukov, committed by ). Herald added a subscriber: llvm-commits. Repository: rL LLVM https://reviews.llvm.org/D44932 Files: cfe/trunk/lib/Lex/Lexer.cpp cfe/trunk/test/CodeCompletion/ctor-initializer.cpp cfe/trunk/test/CodeCompletion/end-of-file.cpp Index: cfe/trunk/lib/Lex/Lexer.cpp === --- cfe/trunk/lib/Lex/Lexer.cpp +++ cfe/trunk/lib/Lex/Lexer.cpp @@ -1654,7 +1654,21 @@ if (isCodeCompletionPoint(CurPtr)) { // Return the code-completion token. Result.setKind(tok::code_completion); - cutOffLexing(); + // Skip the code-completion char and all immediate identifier characters. + // This ensures we get consistent behavior when completing at any point in + // an identifier (i.e. at the start, in the middle, at the end). Note that + // only simple cases (i.e. [a-zA-Z0-9_]) are supported to keep the code + // simpler. + assert(*CurPtr == 0 && "Completion character must be 0"); + ++CurPtr; + // Note that code completion token is not added as a separate character + // when the completion point is at the end of the buffer. Therefore, we need + // to check if the buffer has ended. + if (CurPtr < BufferEnd) { +while (isIdentifierBody(*CurPtr)) + ++CurPtr; + } + BufferPtr = CurPtr; return true; } Index: cfe/trunk/test/CodeCompletion/ctor-initializer.cpp === --- cfe/trunk/test/CodeCompletion/ctor-initializer.cpp +++ cfe/trunk/test/CodeCompletion/ctor-initializer.cpp @@ -58,5 +58,9 @@ // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s // RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s // CHECK-CC7: COMPLETION: Pattern : member1(<#args#> + // Check in the middle and at the end of identifier too. + // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:13 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s + // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:16 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s + // CHECK-CC8: COMPLETION: Pattern : member2(<#args#> int member1, member2; }; Index: cfe/trunk/test/CodeCompletion/end-of-file.cpp === --- cfe/trunk/test/CodeCompletion/end-of-file.cpp +++ cfe/trunk/test/CodeCompletion/end-of-file.cpp @@ -0,0 +1,7 @@ +// Check that clang does not crash when completing at the last char in the +// buffer. +// NOTE: This file must *NOT* have newline at the end. +// RUN: %clang_cc1 -code-completion-at=%s:7:2 %s | FileCheck %s +// CHECK: COMPLETION: foo +using foo = int***; +f \ No newline at end of file Index: cfe/trunk/lib/Lex/Lexer.cpp === --- cfe/trunk/lib/Lex/Lexer.cpp +++ cfe/trunk/lib/Lex/Lexer.cpp @@ -1654,7 +1654,21 @@ if (isCodeCompletionPoint(CurPtr)) { // Return the code-completion token. Result.setKind(tok::code_completion); - cutOffLexing(); + // Skip the code-completion char and all immediate identifier characters. + // This ensures we get consistent behavior when completing at any point in + // an identifier (i.e. at the start, in the middle, at the end). Note that + // only simple cases (i.e. [a-zA-Z0-9_]) are supported to keep the code + // simpler. + assert(*CurPtr == 0 && "Completion character must be 0"); + ++CurPtr; + // Note that code completion token is not added as a separate character + // when the completion point is at the end of the buffer. Therefore, we need + // to check if the buffer has ended. + if (CurPtr < BufferEnd) { +while (isIdentifierBody(*CurPtr)) + ++CurPtr; + } + BufferPtr = CurPtr; return true; } Index: cfe/trunk/test/CodeCompletion/ctor-initializer.cpp === --- cfe/trunk/test/CodeCompletion/ctor-initializer.cpp +++ cfe/trunk/test/CodeCompletion/ctor-initializer.cpp @@ -58,5 +58,9 @@ // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s // RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s // CHECK-CC7: COMPLETION: Pattern : member1(<#args#> + // Check in the middle and at the end of identifier too. + // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:13 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s + // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-comple
[PATCH] D44932: [CodeComplete] Fix completion in the middle of ident in ctor lists.
This revision was automatically updated to reflect the committed changes. Closed by commit rC330833: [CodeComplete] Fix completion in the middle of ident in ctor lists. (authored by ibiryukov, committed by ). Changed prior to commit: https://reviews.llvm.org/D44932?vs=143935&id=143942#toc Repository: rL LLVM https://reviews.llvm.org/D44932 Files: lib/Lex/Lexer.cpp test/CodeCompletion/ctor-initializer.cpp test/CodeCompletion/end-of-file.cpp Index: test/CodeCompletion/ctor-initializer.cpp === --- test/CodeCompletion/ctor-initializer.cpp +++ test/CodeCompletion/ctor-initializer.cpp @@ -58,5 +58,9 @@ // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s // RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s // CHECK-CC7: COMPLETION: Pattern : member1(<#args#> + // Check in the middle and at the end of identifier too. + // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:13 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s + // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:16 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s + // CHECK-CC8: COMPLETION: Pattern : member2(<#args#> int member1, member2; }; Index: test/CodeCompletion/end-of-file.cpp === --- test/CodeCompletion/end-of-file.cpp +++ test/CodeCompletion/end-of-file.cpp @@ -0,0 +1,7 @@ +// Check that clang does not crash when completing at the last char in the +// buffer. +// NOTE: This file must *NOT* have newline at the end. +// RUN: %clang_cc1 -code-completion-at=%s:7:2 %s | FileCheck %s +// CHECK: COMPLETION: foo +using foo = int***; +f \ No newline at end of file Index: lib/Lex/Lexer.cpp === --- lib/Lex/Lexer.cpp +++ lib/Lex/Lexer.cpp @@ -1654,7 +1654,21 @@ if (isCodeCompletionPoint(CurPtr)) { // Return the code-completion token. Result.setKind(tok::code_completion); - cutOffLexing(); + // Skip the code-completion char and all immediate identifier characters. + // This ensures we get consistent behavior when completing at any point in + // an identifier (i.e. at the start, in the middle, at the end). Note that + // only simple cases (i.e. [a-zA-Z0-9_]) are supported to keep the code + // simpler. + assert(*CurPtr == 0 && "Completion character must be 0"); + ++CurPtr; + // Note that code completion token is not added as a separate character + // when the completion point is at the end of the buffer. Therefore, we need + // to check if the buffer has ended. + if (CurPtr < BufferEnd) { +while (isIdentifierBody(*CurPtr)) + ++CurPtr; + } + BufferPtr = CurPtr; return true; } Index: test/CodeCompletion/ctor-initializer.cpp === --- test/CodeCompletion/ctor-initializer.cpp +++ test/CodeCompletion/ctor-initializer.cpp @@ -58,5 +58,9 @@ // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s // RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s // CHECK-CC7: COMPLETION: Pattern : member1(<#args#> + // Check in the middle and at the end of identifier too. + // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:13 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s + // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:16 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s + // CHECK-CC8: COMPLETION: Pattern : member2(<#args#> int member1, member2; }; Index: test/CodeCompletion/end-of-file.cpp === --- test/CodeCompletion/end-of-file.cpp +++ test/CodeCompletion/end-of-file.cpp @@ -0,0 +1,7 @@ +// Check that clang does not crash when completing at the last char in the +// buffer. +// NOTE: This file must *NOT* have newline at the end. +// RUN: %clang_cc1 -code-completion-at=%s:7:2 %s | FileCheck %s +// CHECK: COMPLETION: foo +using foo = int***; +f \ No newline at end of file Index: lib/Lex/Lexer.cpp === --- lib/Lex/Lexer.cpp +++ lib/Lex/Lexer.cpp @@ -1654,7 +1654,21 @@ if (isCodeCompletionPoint(CurPtr)) { // Return the code-completion token. Result.setKind(tok::code_completion); - cutOffLexing(); + // Skip the code-completion char and all immediate identifier characters. + // This ensures we get consistent behavior when completing at any point in + // an identifier (i.e. at the start, in the middle, at the end). Note that + // only simple cases (i.e. [a-zA-Z0
[PATCH] D46065: [clangd] Add "str()" method to SymbolID.
ioeric accepted this revision. ioeric added a comment. This revision is now accepted and ready to land. lgtm with a nit Comment at: clangd/index/Index.h:72 + // Returns a 40-bytes hex encoded string. + std::string str() const; I think Sam wants to reduce the size to 20 bytes. Maybe just drop the "40-bytes" part? Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D46065 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46066: [analyzer] Add checker for underflowing unsigned integers
pfultz2 created this revision. pfultz2 added reviewers: NoQ, xazax.hun, dkrupp, whisperity, george.karpenkov. pfultz2 added a project: clang. Herald added subscribers: cfe-commits, a.sidorin, rnkovacs, szepet, mgorny. This will check for when assigning a negative value to an unsigned integer, when it happens implicitly. Repository: rC Clang https://reviews.llvm.org/D46066 Files: include/clang/StaticAnalyzer/Checkers/Checkers.td lib/StaticAnalyzer/Checkers/CMakeLists.txt lib/StaticAnalyzer/Checkers/UnderflowChecker.cpp test/Analysis/underflow.cpp Index: test/Analysis/underflow.cpp === --- /dev/null +++ test/Analysis/underflow.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.Underflow -verify %s + +void foo(unsigned int i); + +void f1() { + unsigned int i = -1; // expected-warning {{Underflow unsigned integer}} + unsigned int j = 0; +} + +void f2() { + foo(-1); // expected-warning {{Underflow unsigned integer}} + foo(0); +} + +void f3() { + long x = -1; + int y = 0; + foo(x); // expected-warning {{Underflow unsigned integer}} + foo(y); +} Index: lib/StaticAnalyzer/Checkers/UnderflowChecker.cpp === --- /dev/null +++ lib/StaticAnalyzer/Checkers/UnderflowChecker.cpp @@ -0,0 +1,93 @@ +//== UnderflowCheck.cpp - Division by zero checker --*- C++ -*--==// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// +// +// This defines UnderflowCheck, a builtin check in ExprEngine that performs +// checks for assigning negative values to unsigned integers +// +//===--===// + +#include "ClangSACheckers.h" +#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" +#include "clang/StaticAnalyzer/Core/Checker.h" +#include "clang/StaticAnalyzer/Core/CheckerManager.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" + +using namespace clang; +using namespace ento; + +namespace { +class UnderflowCheck : public Checker> { + mutable std::unique_ptr BT; + void reportBug(const char *Msg, ProgramStateRef StateZero, + CheckerContext &C) const; + +public: + void checkPreStmt(const ImplicitCastExpr *CE, CheckerContext &C) const; +}; +} // end anonymous namespace + +void UnderflowCheck::reportBug(const char *Msg, ProgramStateRef StateZero, + CheckerContext &C) const { + if (ExplodedNode *N = C.generateErrorNode(StateZero)) { +if (!BT) + BT.reset(new BuiltinBug(this, "Underflow unsigned integer")); +C.emitReport(llvm::make_unique(*BT, BT->getDescription(), N)); + } +} + +void UnderflowCheck::checkPreStmt(const ImplicitCastExpr *CE, + CheckerContext &C) const { + + if (!CE->getType()->isUnsignedIntegerType() || CE->getType()->isBooleanType()) +return; + + const Expr *E = CE->getSubExpr(); + if (!E) +return; + QualType valTy = E->getType(); + if (valTy->isUnsignedIntegerType()) +return; + Optional DV = C.getSVal(E).getAs(); + + if (!DV) +return; + + // Check for negative + ProgramStateRef state = C.getState(); + SValBuilder &svalBuilder = C.getSValBuilder(); + ConstraintManager &CM = C.getConstraintManager(); + + // First, ensure that the value is >= 0. + DefinedSVal zeroVal = svalBuilder.makeIntVal(0, valTy); + SVal greaterThanOrEqualToZeroVal = svalBuilder.evalBinOp( + state, BO_GE, *DV, zeroVal, svalBuilder.getConditionType()); + + Optional greaterThanEqualToZero = + greaterThanOrEqualToZeroVal.getAs(); + + if (!greaterThanEqualToZero) { +// The SValBuilder cannot construct a valid SVal for this condition. +// This means we cannot properly reason about it. +return; + } + + ProgramStateRef stateLT, stateGE; + std::tie(stateGE, stateLT) = CM.assumeDual(state, *greaterThanEqualToZero); + + // Is it possible for the value to be less than zero? + if (stateLT && !stateGE) { +reportBug("Underflow unsigned integer", stateLT, C); +// In either case, we are done. +return; + } +} + +void ento::registerUnderflowChecker(CheckerManager &mgr) { + mgr.registerChecker(); +} Index: lib/StaticAnalyzer/Checkers/CMakeLists.txt === --- lib/StaticAnalyzer/Checkers/CMakeLists.txt +++ lib/StaticAnalyzer/Checkers/CMakeLists.txt @@ -91,6 +91,7 @@ UndefResultChecker.cpp UndefinedArraySubscriptChecker.cpp UndefinedAssignmentChecker.cpp + UnderflowChecker.cpp UnixAPIChecker.cpp UnreachableCodeChecker.cpp VforkChecker.cpp Index: include/clang/StaticAnalyzer/Checkers/Checkers.td ===
[PATCH] D46015: [OpenCL] Add separate read_only and write_only pipe IR types
AlexeySotkin added a comment. There should not be need for bitcast. Could give an example ? Thanks. https://reviews.llvm.org/D46015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46015: [OpenCL] Add separate read_only and write_only pipe IR types
stuart added a comment. In https://reviews.llvm.org/D46015#1077401, @AlexeySotkin wrote: > It is not clear why we need two versions of get_pipe_num_packets and > get_pipe_max_packets builtins. There is only one instruction per builtin in > the SPIR-V spec. I think splitting the IR type is enough for translation to > SPIR-V purposes. This is so that when we emit the builtin expression, we can call a function that matches the access qualifier of the argument to the builtin, without the need for a bitcast of either the builtin's argument or the __get_pipe_max/num_packets() function itself. Comment at: lib/CodeGen/CGOpenCLRuntime.h:65 virtual llvm::Type *getPipeType(const PipeType *T); + virtual llvm::Type *getPipeType(const PipeType *T, StringRef Name, + llvm::Type *&PipeTy); AlexeySotkin wrote: > I'm not sure that it is a good idea to make this function public, as its > parameter supposed to be a reference to protected member. That's a good point. I have changed the function to be protected, to match the visibility of the data member. https://reviews.llvm.org/D46015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r330835 - [clangd] Add "str()" method to SymbolID.
Author: hokein Date: Wed Apr 25 08:27:09 2018 New Revision: 330835 URL: http://llvm.org/viewvc/llvm-project?rev=330835&view=rev Log: [clangd] Add "str()" method to SymbolID. Summary: This is a convenient function when we try to get std::string of SymbolID. Reviewers: ioeric Subscribers: klimek, ilya-biryukov, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D46065 Modified: clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp clang-tools-extra/trunk/clangd/index/Index.cpp clang-tools-extra/trunk/clangd/index/Index.h Modified: clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp?rev=330835&r1=330834&r2=330835&view=diff == --- clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp (original) +++ clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp Wed Apr 25 08:27:09 2018 @@ -78,10 +78,7 @@ public: auto Symbols = Collector->takeSymbols(); for (const auto &Sym : Symbols) { - std::string IDStr; - llvm::raw_string_ostream OS(IDStr); - OS << Sym.ID; - Ctx->reportResult(OS.str(), SymbolToYAML(Sym)); + Ctx->reportResult(Sym.ID.str(), SymbolToYAML(Sym)); } } Modified: clang-tools-extra/trunk/clangd/index/Index.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=330835&r1=330834&r2=330835&view=diff == --- clang-tools-extra/trunk/clangd/index/Index.cpp (original) +++ clang-tools-extra/trunk/clangd/index/Index.cpp Wed Apr 25 08:27:09 2018 @@ -31,6 +31,13 @@ raw_ostream &operator<<(raw_ostream &OS, return OS; } +std::string SymbolID::str() const { + std::string ID; + llvm::raw_string_ostream OS(ID); + OS << *this; + return OS.str(); +} + void operator>>(StringRef Str, SymbolID &ID) { std::string HexString = fromHex(Str); assert(HexString.size() == ID.HashValue.size()); Modified: clang-tools-extra/trunk/clangd/index/Index.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=330835&r1=330834&r2=330835&view=diff == --- clang-tools-extra/trunk/clangd/index/Index.h (original) +++ clang-tools-extra/trunk/clangd/index/Index.h Wed Apr 25 08:27:09 2018 @@ -69,6 +69,9 @@ public: return HashValue < Sym.HashValue; } + // Returns a 40-bytes hex encoded string. + std::string str() const; + private: static constexpr unsigned HashByteLength = 20; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46065: [clangd] Add "str()" method to SymbolID.
hokein marked an inline comment as done. hokein added inline comments. Comment at: clangd/index/Index.h:72 + // Returns a 40-bytes hex encoded string. + std::string str() const; ioeric wrote: > I think Sam wants to reduce the size to 20 bytes. Maybe just drop the > "40-bytes" part? The comment clarifies the current behavior of the method, I prefer to keep it. We can change it at the time when we reduce the size :) Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D46065 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46065: [clangd] Add "str()" method to SymbolID.
This revision was automatically updated to reflect the committed changes. hokein marked an inline comment as done. Closed by commit rL330835: [clangd] Add "str()" method to SymbolID. (authored by hokein, committed by ). Herald added a subscriber: llvm-commits. Repository: rL LLVM https://reviews.llvm.org/D46065 Files: clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp clang-tools-extra/trunk/clangd/index/Index.cpp clang-tools-extra/trunk/clangd/index/Index.h Index: clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp === --- clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp +++ clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp @@ -78,10 +78,7 @@ auto Symbols = Collector->takeSymbols(); for (const auto &Sym : Symbols) { - std::string IDStr; - llvm::raw_string_ostream OS(IDStr); - OS << Sym.ID; - Ctx->reportResult(OS.str(), SymbolToYAML(Sym)); + Ctx->reportResult(Sym.ID.str(), SymbolToYAML(Sym)); } } Index: clang-tools-extra/trunk/clangd/index/Index.h === --- clang-tools-extra/trunk/clangd/index/Index.h +++ clang-tools-extra/trunk/clangd/index/Index.h @@ -69,6 +69,9 @@ return HashValue < Sym.HashValue; } + // Returns a 40-bytes hex encoded string. + std::string str() const; + private: static constexpr unsigned HashByteLength = 20; Index: clang-tools-extra/trunk/clangd/index/Index.cpp === --- clang-tools-extra/trunk/clangd/index/Index.cpp +++ clang-tools-extra/trunk/clangd/index/Index.cpp @@ -31,6 +31,13 @@ return OS; } +std::string SymbolID::str() const { + std::string ID; + llvm::raw_string_ostream OS(ID); + OS << *this; + return OS.str(); +} + void operator>>(StringRef Str, SymbolID &ID) { std::string HexString = fromHex(Str); assert(HexString.size() == ID.HashValue.size()); Index: clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp === --- clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp +++ clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp @@ -78,10 +78,7 @@ auto Symbols = Collector->takeSymbols(); for (const auto &Sym : Symbols) { - std::string IDStr; - llvm::raw_string_ostream OS(IDStr); - OS << Sym.ID; - Ctx->reportResult(OS.str(), SymbolToYAML(Sym)); + Ctx->reportResult(Sym.ID.str(), SymbolToYAML(Sym)); } } Index: clang-tools-extra/trunk/clangd/index/Index.h === --- clang-tools-extra/trunk/clangd/index/Index.h +++ clang-tools-extra/trunk/clangd/index/Index.h @@ -69,6 +69,9 @@ return HashValue < Sym.HashValue; } + // Returns a 40-bytes hex encoded string. + std::string str() const; + private: static constexpr unsigned HashByteLength = 20; Index: clang-tools-extra/trunk/clangd/index/Index.cpp === --- clang-tools-extra/trunk/clangd/index/Index.cpp +++ clang-tools-extra/trunk/clangd/index/Index.cpp @@ -31,6 +31,13 @@ return OS; } +std::string SymbolID::str() const { + std::string ID; + llvm::raw_string_ostream OS(ID); + OS << *this; + return OS.str(); +} + void operator>>(StringRef Str, SymbolID &ID) { std::string HexString = fromHex(Str); assert(HexString.size() == ID.HashValue.size()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46000: [AST] Added a helper to extract a user-friendly text of a comment.
ilya-biryukov added inline comments. Comment at: lib/AST/RawCommentList.cpp:380 +SourceMgr.getSpellingColumnNumber(Tok.getLocation(), &LocInvalid); +if (LocInvalid) + TokColumn = 0; ilya-biryukov wrote: > ioeric wrote: > > Explain when this would be invalid and why `TokColumn = 0` is used? > I don't know whether this can be even be invalid, but I'm not confident > enough to add an assert there. > `TokColumn = 0` seems like a reasonable way to recover if we can't compute > the column number, i.e. assume the line starts at the first column if > SourceLocation of the line was invalid for any reason. > > This whole column thing looks weird to me, maybe I should just remove it > altogether and just remove the same amount of whitespace in all the lines. > WDYT? On a second thought, now I remember why I added this in the first place. To support the following example we want to take column numbers into account: ``` class Foo { /* A block comment spanning multiple lines has too many spaces on the all lines except the first one. */ int func(); }; ``` Repository: rC Clang https://reviews.llvm.org/D46000 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46015: [OpenCL] Add separate read_only and write_only pipe IR types
stuart added a comment. In https://reviews.llvm.org/D46015#1078217, @AlexeySotkin wrote: > There should not be need for bitcast. Could give an example ? Thanks. If I have a `write_only` pipe as the argument to `get_pipe_max_packets()`, and this uses a single `__get_pipe_num_packets()` function taking a `read_only` pipe, we will automatically get a bitcast: %20 = call i32 bitcast (i32 (%opencl.pipe_ro_t*, i32, i32)* @__get_pipe_max_packets to i32 (%opencl.pipe_wo_t*, i32, i32)*)(%opencl.pipe_wo_t* %19, i32 4, i32 4) https://reviews.llvm.org/D46015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46066: [analyzer] Add checker for underflowing unsigned integers
xazax.hun added a comment. Isn't this case already covered by conversion checker? https://github.com/llvm-mirror/clang/blob/master/lib/StaticAnalyzer/Checkers/ConversionChecker.cpp Repository: rC Clang https://reviews.llvm.org/D46066 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46015: [OpenCL] Add separate read_only and write_only pipe IR types
AlexeySotkin added a comment. In https://reviews.llvm.org/D46015#1078235, @stuart wrote: > In https://reviews.llvm.org/D46015#1078217, @AlexeySotkin wrote: > > > There should not be need for bitcast. Could give an example ? Thanks. > > > If I have a `write_only` pipe as the argument to `get_pipe_max_packets()`, > and this uses a single `__get_pipe_num_packets()` function taking a > `read_only` pipe, we will automatically get a bitcast: > > %20 = call i32 bitcast (i32 (%opencl.pipe_ro_t*, i32, i32)* > @__get_pipe_max_packets to i32 (%opencl.pipe_wo_t*, i32, > i32)*)(%opencl.pipe_wo_t* %19, i32 4, i32 4) > Sorry, but I don't quite understand what does `get_pipe_max_packets()`, **uses** `__get_pipe_num_packets()` mean. Could you clarify? Possibly OpenCL C source example could help. Thanks https://reviews.llvm.org/D46015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libcxx] r330838 - Disable the test I just added when testing C++03.
Author: marshall Date: Wed Apr 25 09:09:47 2018 New Revision: 330838 URL: http://llvm.org/viewvc/llvm-project?rev=330838&view=rev Log: Disable the test I just added when testing C++03. Modified: libcxx/trunk/test/libcxx/atomics/atomics.flag/init_bool.pass.cpp Modified: libcxx/trunk/test/libcxx/atomics/atomics.flag/init_bool.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/atomics/atomics.flag/init_bool.pass.cpp?rev=330838&r1=330837&r2=330838&view=diff == --- libcxx/trunk/test/libcxx/atomics/atomics.flag/init_bool.pass.cpp (original) +++ libcxx/trunk/test/libcxx/atomics/atomics.flag/init_bool.pass.cpp Wed Apr 25 09:09:47 2018 @@ -18,15 +18,21 @@ #include #include - // Ensure that static initialization happens; this is PR#37226 +#include "test_macros.h" + +#if TEST_STD_VER >= 11 +// Ensure that static initialization happens; this is PR#37226 extern std::atomic_flag global; struct X { X() { global.test_and_set(); }}; X x; std::atomic_flag global = ATOMIC_FLAG_INIT; +#endif int main() { +#if TEST_STD_VER >= 11 assert(global.test_and_set() == 1); +#endif { std::atomic_flag f(false); assert(f.test_and_set() == 0); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r330839 - Make add_clang_unittest formatting a bit more consistent.
Author: nico Date: Wed Apr 25 09:20:43 2018 New Revision: 330839 URL: http://llvm.org/viewvc/llvm-project?rev=330839&view=rev Log: Make add_clang_unittest formatting a bit more consistent. Modified: cfe/trunk/unittests/ASTMatchers/CMakeLists.txt cfe/trunk/unittests/ASTMatchers/Dynamic/CMakeLists.txt Modified: cfe/trunk/unittests/ASTMatchers/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/CMakeLists.txt?rev=330839&r1=330838&r2=330839&view=diff == --- cfe/trunk/unittests/ASTMatchers/CMakeLists.txt (original) +++ cfe/trunk/unittests/ASTMatchers/CMakeLists.txt Wed Apr 25 09:20:43 2018 @@ -15,7 +15,8 @@ add_clang_unittest(ASTMatchersTests ASTMatchersInternalTest.cpp ASTMatchersNodeTest.cpp ASTMatchersNarrowingTest.cpp - ASTMatchersTraversalTest.cpp) + ASTMatchersTraversalTest.cpp + ) target_link_libraries(ASTMatchersTests PRIVATE Modified: cfe/trunk/unittests/ASTMatchers/Dynamic/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/Dynamic/CMakeLists.txt?rev=330839&r1=330838&r2=330839&view=diff == --- cfe/trunk/unittests/ASTMatchers/Dynamic/CMakeLists.txt (original) +++ cfe/trunk/unittests/ASTMatchers/Dynamic/CMakeLists.txt Wed Apr 25 09:20:43 2018 @@ -5,7 +5,8 @@ set(LLVM_LINK_COMPONENTS add_clang_unittest(DynamicASTMatchersTests VariantValueTest.cpp ParserTest.cpp - RegistryTest.cpp) + RegistryTest.cpp + ) target_link_libraries(DynamicASTMatchersTests PRIVATE ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D40937: [clang-tidy] Infinite loop checker
szepet updated this revision to Diff 143949. szepet marked 2 inline comments as done. szepet added a comment. Changes made based on comments. The CFG recreating problem is handled the following (only for this check): Always store the last visited function and its CFG* (in form of the Sequence*) and check if we are visiting it again. If so, then the check reuses the previous one, if not, then replaces them. As far as I know the AST traverse done by the tidy fits this model (at least for this check, since it not uses narrowing matchers to other functions). Sure, it would be better to find a general solution to this problem, and make the CFG reusable by every check which needs it, but I would left it for a follow-up (and a change like this probably would worth an own patch/review anyway). https://reviews.llvm.org/D40937 Files: clang-tidy/bugprone/BugproneTidyModule.cpp clang-tidy/bugprone/CMakeLists.txt clang-tidy/bugprone/InfiniteLoopCheck.cpp clang-tidy/bugprone/InfiniteLoopCheck.h docs/ReleaseNotes.rst docs/clang-tidy/checks/bugprone-infinite-loop.rst docs/clang-tidy/checks/list.rst test/clang-tidy/bugprone-infinite-loop.cpp Index: test/clang-tidy/bugprone-infinite-loop.cpp === --- /dev/null +++ test/clang-tidy/bugprone-infinite-loop.cpp @@ -0,0 +1,121 @@ +// RUN: %check_clang_tidy %s bugprone-infinite-loop %t + +void simple_infinite_loop1() { + int i = 0; + int j = 0; + while (i < 10) { +// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the condition variable (i) is not updated in the loop body [bugprone-infinite-loop] +j++; + } + + do { +// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the condition variable (i) is not updated in the loop body +j++; + } while (i < 10); + + for (i = 0; i < 10; ++j) { +// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the condition variable (i) is not updated in the loop body + } +} + +void simple_infinite_loop2() { + int i = 0; + int j = 0; + int Limit = 10; + while (i < Limit) { +// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: none of the condition variables (i, Limit) are updated in the loop body [bugprone-infinite-loop] +j++; + } + + do { +// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: none of the condition variables (i, Limit) are updated in the loop body +j++; + } while (i < Limit); + + for (i = 0; i < Limit; ++j) { +// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: none of the condition variables (i, Limit) are updated in the loop body + } +} + +void simple_not_infinite() { + int i = 0; + int Limit = 100; + while (i < Limit) { // Not an error since 'Limit' is updated +Limit--; + } + do { +Limit--; + } while (i < Limit); + + for (i = 0; i < Limit; Limit--) { + } +} + +void escape_before1() { + int i = 0; + int Limit = 100; + int *p = &i; + while (i < Limit) { // Not an error, since p is alias of i. +*++p; + } + + do { +*++p; + } while (i < Limit); + + for (i = 0; i < Limit; *++p) { +; + } +} + +void escape_before2() { + int i = 0; + int Limit = 100; + int *p = &i; + while (i < Limit) { // We do not warn since the var 'i' is escaped but it is + // an actual error, since the pointer 'p' is increased. +*(p++); + } +} + +void escape_after() { + int i = 0; + int j = 0; + int Limit = 10; + + while (i < Limit) { +// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: none of the condition variables (i, Limit) are updated in the loop body + } + int *p = &i; +} + +int glob; +void glob_var(int &x) { + int i = 0, Limit = 100; + while (x < Limit) { // Not an error since 'x' can be an alias of glob. +glob++; + } +} + +void glob_var2() { + int i = 0, Limit = 100; + while (glob < Limit) { // Since 'glob' is declared out of the function we do not warn. +i++; + } +} + +struct X { + void memberExpr_test(int i) { +while (i < m) { // False negative: No warning, since skipping the case where +// a memberExpr can be found in the condition. + ; +} + } + + void memberExpr_test2(int i) { +while (i < m) { + --m; +} + } + int m; +}; Index: docs/clang-tidy/checks/list.rst === --- docs/clang-tidy/checks/list.rst +++ docs/clang-tidy/checks/list.rst @@ -28,6 +28,7 @@ bugprone-forwarding-reference-overload bugprone-inaccurate-erase bugprone-incorrect-roundings + bugprone-infinite-loop bugprone-integer-division bugprone-lambda-function-name bugprone-macro-parentheses Index: docs/clang-tidy/checks/bugprone-infinite-loop.rst === --- /dev/null +++ docs/clang-tidy/checks/bugprone-infinite-loop.rst @@ -0,0 +1,30 @@ +.. title:: clang-tidy - bugprone-infinite-loop + +bugprone-infinite-loop +== + +Finds loops where none of the condition variables are updated in the body. This +performs a ver
[PATCH] D45722: [X86] Lowering SAD (sum of absolute differences) intrinsics to native IR (clang side)
craig.topper accepted this revision. craig.topper added a comment. This revision is now accepted and ready to land. LGTM https://reviews.llvm.org/D45722 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D44387: [x86] Introduce the pconfig/encl[u|s|v] intrinsics
craig.topper added inline comments. Comment at: lib/Headers/pconfigintrin.h:28 + +#ifndef _PCONFIGINTRIN_H +#define _PCONFIGINTRIN_H I think all our other headers use double underscore here. Comment at: lib/Headers/sgxintrin.h:28 + +#ifndef _SGXINTRIN_H +#define _SGXINTRIN_H double underscore https://reviews.llvm.org/D44387 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46015: [OpenCL] Add separate read_only and write_only pipe IR types
stuart added a comment. In https://reviews.llvm.org/D46015#1078260, @AlexeySotkin wrote: > In https://reviews.llvm.org/D46015#1078235, @stuart wrote: > > > In https://reviews.llvm.org/D46015#1078217, @AlexeySotkin wrote: > > > > > There should not be need for bitcast. Could give an example ? Thanks. > > > > > > If I have a `write_only` pipe as the argument to `get_pipe_max_packets()`, > > and this uses a single `__get_pipe_num_packets()` function taking a > > `read_only` pipe, we will automatically get a bitcast: > > > > %20 = call i32 bitcast (i32 (%opencl.pipe_ro_t*, i32, i32)* > > @__get_pipe_max_packets to i32 (%opencl.pipe_wo_t*, i32, > > i32)*)(%opencl.pipe_wo_t* %19, i32 4, i32 4) > > > > > Sorry, but I don't quite understand what does `get_pipe_max_packets()`, > **uses** `__get_pipe_num_packets()` mean. Could you clarify? Possibly OpenCL > C source example could help. I mean that without these two separate versions, the call to `__get_pipe_num_packets()` that is emitted can include a bitcast. For example: void foo(read_only pipe int r, write_only pipe int w) { get_pipe_num_packets(w); get_pipe_num_packets(r); } `get_pipe_num_packets(w)` is seen first, causing `i32 @__get_pipe_num_packets(%opencl.pipe_wo_t*, i32, i32)` to be implicitly declared. When the call to `__get_pipe_num_packets()` is emitted, this will be with an autogenerated bitcast from the type of the implicit declaration, i.e. `i32 (%opencl.pipe_wo_t*, i32, i32)*` to the type in the emitted expression, i.e. `i32 (%opencl.pipe_ro_t*, i32, i32)*`. Here is the relevant section of IR: %0 = load %opencl.pipe_wo_t*, %opencl.pipe_wo_t** %w.addr, align 8 %1 = call i32 @__get_pipe_num_packets_ro(%opencl.pipe_wo_t* %0, i32 4, i32 4) %2 = load %opencl.pipe_ro_t*, %opencl.pipe_ro_t** %r.addr, align 8 %3 = call i32 bitcast (i32 (%opencl.pipe_wo_t*, i32, i32)* @__get_pipe_num_packets_ro to i32 (%opencl.pipe_ro_t*, i32, i32)*)(%opencl.pipe_ro_t* %2, i32 4, i32 4) If we swap the two calls to `__get_pipe_num_packets()` in the example above, then the type of the implicit declaration will be `i32 (%opencl.pipe_ro_t*, i32, i32)*` and bitcasts will instead be automatically generated when using `get_pipe_num_packets()` with a `write_only` pipe. It seems especially unfortunate that the type of the implicit declaration varies depending on the access qualifier of the first use. https://reviews.llvm.org/D46015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r330842 - [Builtins] Fix typos in a comment. NFC
Author: ctopper Date: Wed Apr 25 09:57:46 2018 New Revision: 330842 URL: http://llvm.org/viewvc/llvm-project?rev=330842&view=rev Log: [Builtins] Fix typos in a comment. NFC Modified: cfe/trunk/include/clang/Basic/Builtins.h Modified: cfe/trunk/include/clang/Basic/Builtins.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.h?rev=330842&r1=330841&r2=330842&view=diff == --- cfe/trunk/include/clang/Basic/Builtins.h (original) +++ cfe/trunk/include/clang/Basic/Builtins.h Wed Apr 25 09:57:46 2018 @@ -211,7 +211,7 @@ public: return ID >= (Builtin::FirstTSBuiltin + TSRecords.size()); } - /// Return real buitin ID (i.e. ID it would have furing compilation + /// Return real builtin ID (i.e. ID it would have during compilation /// for AuxTarget). unsigned getAuxBuiltinID(unsigned ID) const { return ID - TSRecords.size(); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46019: [ASTImporter] Fix isa cast assert
szepet accepted this revision. szepet added a comment. Yepp, pretty straightforward check for something we were not aware previously (but unfortunately encountered it). Repository: rC Clang https://reviews.llvm.org/D46019 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46066: [analyzer] Add checker for underflowing unsigned integers
pfultz2 added a comment. > Isn't this case already covered by conversion checker? I was unaware of this. This looks like it only works for binary operators. So `f(-1)` won't get caught. Repository: rC Clang https://reviews.llvm.org/D46066 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode
svenvh updated this revision to Diff 143951. svenvh edited the summary of this revision. svenvh added a comment. Implemented most of the restrictions as parser or Sema checks instead. This results in nicer diagnostics too, thanks for the suggestion! For the address space qualifiers such as global / __global / local / ..., I still think we should differentiate them in the lexer, as "global", "local" etc. are not reserved keywords in OpenCL C++. https://reviews.llvm.org/D46022 Files: include/clang/Basic/DiagnosticCommonKinds.td include/clang/Basic/DiagnosticSemaKinds.td include/clang/Basic/TokenKinds.def include/clang/Sema/DeclSpec.h lib/Basic/IdentifierTable.cpp lib/Frontend/CompilerInvocation.cpp lib/Parse/ParseDecl.cpp lib/Parse/ParseStmtAsm.cpp lib/Sema/DeclSpec.cpp lib/Sema/SemaCast.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaStmt.cpp test/Parser/opencl-cl20.cl test/Parser/opencl-cxx-keywords.cl test/Parser/opencl-storage-class.cl test/SemaOpenCL/storageclass.cl test/SemaOpenCLCXX/restricted.cl Index: test/SemaOpenCLCXX/restricted.cl === --- /dev/null +++ test/SemaOpenCLCXX/restricted.cl @@ -0,0 +1,47 @@ +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify -fsyntax-only + +// This test checks that various C/C++/OpenCL C constructs are not available in +// OpenCL C++, according to OpenCL C++ 1.0 Specification Section 2.9. + +// Test that typeid is not available in OpenCL C++. +namespace std { + // Provide a dummy std::type_info so that we can use typeid. + class type_info { +int a; + }; +} +__constant std::type_info int_ti = typeid(int); +// expected-error@-1 {{'typeid' is not supported in OpenCL C++}} + +// Test that dynamic_cast is not available in OpenCL C++. +class A { +public: + int a; +}; + +class B : public A { + int b; +}; + +B *test_dynamic_cast(B *p) { + return dynamic_cast(p); + // expected-error@-1 {{'dynamic_cast' is not supported in OpenCL C++}} +} + +// Test storage class qualifiers. +kernel void test_storage_classes() { + register int x; + // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'register' storage class specifier}} + thread_local int y; + // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'thread_local' storage class specifier}} +} + +// Test other keywords that are not available in OpenCL C++. +kernel void test_misc() { + goto label; + // expected-error@-1 {{'goto' is not supported in OpenCL C++}} +label: + asm(""); + // expected-error@-1 {{'asm' is not supported in OpenCL C++}} + // expected-warning@-2 {{expression result unused}} +} Index: test/SemaOpenCL/storageclass.cl === --- test/SemaOpenCL/storageclass.cl +++ test/SemaOpenCL/storageclass.cl @@ -10,14 +10,14 @@ static global float g_global_static_var = 0; // expected-error {{program scope variable must reside in constant address space}} static local float g_local_static_var = 0; // expected-error {{program scope variable must reside in constant address space}} static private float g_private_static_var = 0; // expected-error {{program scope variable must reside in constant address space}} -static generic float g_generic_static_var = 0; // expected-error{{OpenCL version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}} +static generic float g_generic_static_var = 0; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}} extern float g_implicit_extern_var; // expected-error {{extern variable must reside in constant address space}} extern constant float g_constant_extern_var; extern global float g_global_extern_var; // expected-error {{extern variable must reside in constant address space}} extern local float g_local_extern_var; // expected-error {{extern variable must reside in constant address space}} extern private float g_private_extern_var; // expected-error {{extern variable must reside in constant address space}} -extern generic float g_generic_extern_var; // expected-error{{OpenCL version 1.2 does not support the 'generic' type qualifier}} // expected-error {{extern variable must reside in constant address space}} +extern generic float g_generic_extern_var; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{extern variable must reside in constant address space}} void kernel foo(int x) { // static is not allowed at local scope before CL2.0 @@ -32,7 +32,7 @@ constant int L1 = 42; // expected-error {{variables in the constant address space can only be declared in the outermost scope of a kernel function}} } - auto int L3 = 7;// expected-error{{OpenCL vers
Re: r329804 - [Sema] Fix built-in decrement operator overload resolution
On 12 April 2018 at 07:20, Jan Korous via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Hi Richard, > > Here you are: > https://reviews.llvm.org/D45569 > > I am now thinking if it makes sense to output this warning for pre-17 > standards: > > warning: incrementing expression of type bool is deprecated and > incompatible with C++17 > > Produced in: > > SemaExpr.cpp > > static QualType CheckIncrementDecrementOperand > > // Increment of bool sets it to true, but is deprecated. > S.Diag(OpLoc, S.getLangOpts().CPlusPlus17 ? diag::ext_increment_bool > : diag::warn_increment_bool) > > What do you think? > Seems like a good idea to me, thanks! > Jan > > On 11 Apr 2018, at 15:19, Richard Smith wrote: > > While you're here... ++ should not be available for bool in C++17 onwards. > :) > > On Wed, 11 Apr 2018, 14:39 Jan Korous via cfe-commits, < > cfe-commits@lists.llvm.org> wrote: > >> Author: jkorous >> Date: Wed Apr 11 06:36:29 2018 >> New Revision: 329804 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=329804&view=rev >> Log: >> [Sema] Fix built-in decrement operator overload resolution >> >> C++ [over.built] p4: >> >> "For every pair (T, VQ), where T is an arithmetic type other than bool, >> and VQ is either volatile or empty, there exist candidate operator >> functions of the form >> >> VQ T& operator--(VQ T&); >> T operator--(VQ T&, int); >> " >> The bool type is in position LastPromotedIntegralType in >> BuiltinOperatorOverloadBuilder::getArithmeticType::ArithmeticTypes, but >> addPlusPlusMinusMinusArithmeticOverloads() was expecting it at position >> 0. >> >> Differential Revision: https://reviews.llvm.org/D44988 >> >> rdar://problem/34255516 >> >> Modified: >> cfe/trunk/lib/Sema/SemaOverload.cpp >> cfe/trunk/test/SemaCXX/overloaded-builtin-operators.cpp >> >> Modified: cfe/trunk/lib/Sema/SemaOverload.cpp >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/ >> SemaOverload.cpp?rev=329804&r1=329803&r2=329804&view=diff >> >> == >> --- cfe/trunk/lib/Sema/SemaOverload.cpp (original) >> +++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Apr 11 06:36:29 2018 >> @@ -7796,10 +7796,12 @@ public: >> if (!HasArithmeticOrEnumeralCandidateType) >>return; >> >> -for (unsigned Arith = (Op == OO_PlusPlus? 0 : 1); >> - Arith < NumArithmeticTypes; ++Arith) { >> +for (unsigned Arith = 0; Arith < NumArithmeticTypes; ++Arith) { >> + const auto TypeOfT = ArithmeticTypes[Arith]; >> + if (Op == OO_MinusMinus && TypeOfT == S.Context.BoolTy) >> +continue; >>addPlusPlusMinusMinusStyleOverloads( >> -ArithmeticTypes[Arith], >> +TypeOfT, >> VisibleTypeConversionsQuals.hasVolatile(), >> VisibleTypeConversionsQuals.hasRestrict()); >> } >> >> Modified: cfe/trunk/test/SemaCXX/overloaded-builtin-operators.cpp >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ >> SemaCXX/overloaded-builtin-operators.cpp?rev=329804&r1= >> 329803&r2=329804&view=diff >> >> == >> --- cfe/trunk/test/SemaCXX/overloaded-builtin-operators.cpp (original) >> +++ cfe/trunk/test/SemaCXX/overloaded-builtin-operators.cpp Wed Apr 11 >> 06:36:29 2018 >> @@ -62,6 +62,10 @@ void f(Short s, Long l, Enum1 e1, Enum2 >>// FIXME: should pass (void)static_cast(islong(e1 % e2)); >> } >> >> +struct BoolRef { >> + operator bool&(); >> +}; >> + >> struct ShortRef { // expected-note{{candidate function (the implicit >> copy assignment operator) not viable}} >> #if __cplusplus >= 201103L // C++11 or later >> // expected-note@-2 {{candidate function (the implicit move assignment >> operator) not viable}} >> @@ -73,6 +77,10 @@ struct LongRef { >>operator volatile long&(); >> }; >> >> +struct FloatRef { >> + operator float&(); >> +}; >> + >> struct XpmfRef { // expected-note{{candidate function (the implicit copy >> assignment operator) not viable}} >> #if __cplusplus >= 201103L // C++11 or later >> // expected-note@-2 {{candidate function (the implicit move assignment >> operator) not viable}} >> @@ -84,13 +92,19 @@ struct E2Ref { >>operator E2&(); >> }; >> >> -void g(ShortRef sr, LongRef lr, E2Ref e2_ref, XpmfRef pmf_ref) { >> +void g(BoolRef br, ShortRef sr, LongRef lr, FloatRef fr, E2Ref e2_ref, >> XpmfRef pmf_ref) { >>// C++ [over.built]p3 >>short s1 = sr++; >> >> - // C++ [over.built]p3 >> + // C++ [over.built]p4 >>long l1 = lr--; >> >> + // C++ [over.built]p4 >> + float f1 = fr--; >> + >> + // C++ [over.built]p4 >> + bool b2 = br--; // expected-error{{cannot decrement value of type >> 'BoolRef'}} >> + >>// C++ [over.built]p18 >>short& sr1 = (sr *= lr); >>volatile long& lr1 = (lr *= sr); >> >> >> ___ >> cfe-commits mailing list >> cfe-commits@li
[PATCH] D45416: [analyzer] ExprEngine: model GCC inline asm rvalue cast outputs
a.sidorin updated this revision to Diff 143959. a.sidorin added a comment. Add a test for CFG dump; replace static_cast with an initialization. No test failures on check-all were observed. Repository: rC Clang https://reviews.llvm.org/D45416 Files: include/clang/Analysis/CFG.h lib/Analysis/CFG.cpp lib/StaticAnalyzer/Core/ExprEngine.cpp test/Analysis/asm.cpp test/Analysis/cfg.cpp Index: test/Analysis/cfg.cpp === --- test/Analysis/cfg.cpp +++ test/Analysis/cfg.cpp @@ -1,6 +1,6 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -analyzer-config cfg-temporary-dtors=true -std=c++11 -analyzer-config cfg-rich-constructors=false %s > %t 2>&1 +// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -fheinous-gnu-extensions -analyzer-config cfg-temporary-dtors=true -std=c++11 -analyzer-config cfg-rich-constructors=false %s > %t 2>&1 // RUN: FileCheck --input-file=%t -check-prefixes=CHECK,WARNINGS %s -// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -analyzer-config cfg-temporary-dtors=true -std=c++11 -analyzer-config cfg-rich-constructors=true %s > %t 2>&1 +// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -fheinous-gnu-extensions -analyzer-config cfg-temporary-dtors=true -std=c++11 -analyzer-config cfg-rich-constructors=true %s > %t 2>&1 // RUN: FileCheck --input-file=%t -check-prefixes=CHECK,ANALYZER %s // This file tests how we construct two different flavors of the Clang CFG - @@ -84,6 +84,23 @@ static_assert(1, "abc"); } + +// CHECK-LABEL: void checkGCCAsmRValueOutput() +// CHECK: [B2 (ENTRY)] +// CHECK-NEXT: Succs (1): B1 +// CHECK: [B1] +// CHECK-NEXT: 1: int arg +// CHECK-NEXT: 2: arg +// CHECK-NEXT: 3: asm ("" : "=r" ([B1.2])); +// CHECK-NEXT: 4: arg +// CHECK-NEXT: 5: asm ("" : "=r" ([B1.4])); +void checkGCCAsmRValueOutput() { + int arg; + __asm__("" : "=r"((int)arg)); // rvalue output operand + __asm__("" : "=r"(arg)); // lvalue output operand +} + + // CHECK-LABEL: void F(EmptyE e) // CHECK: ENTRY // CHECK-NEXT: Succs (1): B1 Index: test/Analysis/asm.cpp === --- /dev/null +++ test/Analysis/asm.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker debug.ExprInspection -fheinous-gnu-extensions -w %s -verify + +int clang_analyzer_eval(int); + +int global; +void testRValueOutput() { + int &ref = global; + ref = 1; + __asm__("" : "=r"((int)global)); // don't crash on rvalue output operand + clang_analyzer_eval(global == 1); // expected-warning{{UNKNOWN}} + clang_analyzer_eval(ref == 1);// expected-warning{{UNKNOWN}} +} Index: lib/StaticAnalyzer/Core/ExprEngine.cpp === --- lib/StaticAnalyzer/Core/ExprEngine.cpp +++ lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -3058,13 +3058,14 @@ // outputs. ProgramStateRef state = Pred->getState(); + const auto *LCtx = Pred->getLocationContext(); for (const Expr *O : A->outputs()) { -SVal X = state->getSVal(O, Pred->getLocationContext()); +SVal X = state->getSVal(O, LCtx); assert(!X.getAs()); // Should be an Lval, or unknown, undef. if (Optional LV = X.getAs()) - state = state->bindLoc(*LV, UnknownVal(), Pred->getLocationContext()); + state = state->bindLoc(*LV, UnknownVal(), LCtx); } Bldr.generateNode(A, Pred, state); Index: lib/Analysis/CFG.cpp === --- lib/Analysis/CFG.cpp +++ lib/Analysis/CFG.cpp @@ -548,6 +548,7 @@ CFGBlock *VisitDoStmt(DoStmt *D); CFGBlock *VisitExprWithCleanups(ExprWithCleanups *E, AddStmtChoice asc); CFGBlock *VisitForStmt(ForStmt *F); + CFGBlock *VisitGCCAsmStmt(GCCAsmStmt *GCCAsmS, AddStmtChoice asc); CFGBlock *VisitGotoStmt(GotoStmt *G); CFGBlock *VisitIfStmt(IfStmt *I); CFGBlock *VisitImplicitCastExpr(ImplicitCastExpr *E, AddStmtChoice asc); @@ -587,6 +588,16 @@ CFGBlock *VisitChildren(Stmt *S); CFGBlock *VisitNoRecurse(Expr *E, AddStmtChoice asc); + GCCAsmStmt *getOrCreateGCCAsmStmtWithoutGnuExtensions(GCCAsmStmt *GCCAsmS); + + template void *allocateMemForStmt() { +// Get the alignment of the new Stmt, padding out to >=8 bytes. +unsigned Align = std::max(alignof(StmtTy), size_t{8}); +// Allocate a new Stmt using the BumpPtrAllocator. It will get +// automatically freed with the CFG. +return cfg->getAllocator().Allocate(sizeof(StmtTy), Align); + } + void maybeAddScopeBeginForVarDecl(CFGBlock *B, const VarDecl *VD, const Stmt *S) { if (ScopePos && (VD == ScopePos.getFirstVarInScope())) @@ -2039,6 +2050,9 @@ case Stmt::ForStmtClass: return VisitForStmt(cast(S)); +case Stmt::GCCAsmStmtClass: + return VisitGCC
r330847 - [ASTImporter] FriendDecl importing improvements
Author: szepet Date: Wed Apr 25 10:28:03 2018 New Revision: 330847 URL: http://llvm.org/viewvc/llvm-project?rev=330847&view=rev Log: [ASTImporter] FriendDecl importing improvements There are only a few cases of importing a frienddecl which is currently supported. This patch aims to improve the friend import process. Set FriendObjectKind in case of decls, insert friend into the friend chain correctly, checks structurally equivalent in a more advanced manner. Test cases added as well. Modified: cfe/trunk/include/clang/AST/DeclBase.h cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td cfe/trunk/lib/AST/ASTImporter.cpp cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp cfe/trunk/test/ASTMerge/class/Inputs/class1.cpp cfe/trunk/test/ASTMerge/class/Inputs/class2.cpp cfe/trunk/test/ASTMerge/class/test.cpp Modified: cfe/trunk/include/clang/AST/DeclBase.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=330847&r1=330846&r2=330847&view=diff == --- cfe/trunk/include/clang/AST/DeclBase.h (original) +++ cfe/trunk/include/clang/AST/DeclBase.h Wed Apr 25 10:28:03 2018 @@ -309,6 +309,7 @@ private: protected: friend class ASTDeclReader; friend class ASTDeclWriter; + friend class ASTImporter; friend class ASTReader; friend class CXXClassMemberWrapper; friend class LinkageComputer; Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td?rev=330847&r1=330846&r2=330847&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td Wed Apr 25 10:28:03 2018 @@ -273,6 +273,8 @@ def note_odr_objc_synthesize_ivar_here : "property is synthesized to ivar %0 here">; // Importing C++ ASTs +def note_odr_friend : Note<"friend declared here">; +def note_odr_missing_friend : Note<"no corresponding friend here">; def err_odr_different_num_template_parameters : Error< "template parameter lists have a different number of parameters (%0 vs %1)">; def note_odr_template_parameter_list : Note< Modified: cfe/trunk/lib/AST/ASTImporter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=330847&r1=330846&r2=330847&view=diff == --- cfe/trunk/lib/AST/ASTImporter.cpp (original) +++ cfe/trunk/lib/AST/ASTImporter.cpp Wed Apr 25 10:28:03 2018 @@ -2709,9 +2709,14 @@ Decl *ASTNodeImporter::VisitFriendDecl(F // Not found. Create it. FriendDecl::FriendUnion ToFU; - if (NamedDecl *FriendD = D->getFriendDecl()) -ToFU = cast_or_null(Importer.Import(FriendD)); - else + if (NamedDecl *FriendD = D->getFriendDecl()) { +auto *ToFriendD = cast_or_null(Importer.Import(FriendD)); +if (ToFriendD && FriendD->getFriendObjectKind() != Decl::FOK_None && +!(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) + ToFriendD->setObjectOfFriendDecl(false); + +ToFU = ToFriendD; + } else // The friend is a type, not a decl. ToFU = Importer.Import(D->getFriendType()); if (!ToFU) return nullptr; @@ -2731,7 +2736,6 @@ Decl *ASTNodeImporter::VisitFriendDecl(F ToTPLists); Importer.Imported(D, FrD); - RD->pushFriendDecl(FrD); FrD->setAccess(D->getAccess()); FrD->setLexicalDeclContext(LexicalDC); @@ -6596,7 +6600,7 @@ Decl *ASTImporter::Import(Decl *FromD) { // Record the imported declaration. ImportedDecls[FromD] = ToD; - + ToD->IdentifierNamespace = FromD->IdentifierNamespace; return ToD; } Modified: cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp?rev=330847&r1=330846&r2=330847&view=diff == --- cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp (original) +++ cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp Wed Apr 25 10:28:03 2018 @@ -18,6 +18,7 @@ #include "clang/AST/Decl.h" #include "clang/AST/DeclBase.h" #include "clang/AST/DeclCXX.h" +#include "clang/AST/DeclFriend.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/NestedNameSpecifier.h" @@ -942,6 +943,44 @@ static bool IsStructurallyEquivalent(Str return false; } } + + // Check the friends for consistency. + CXXRecordDecl::friend_iterator Friend2 = D2CXX->friend_begin(), + Friend2End = D2CXX->friend_end(); + for (CXXRecordDecl::friend_iterator Friend1 = D1CXX->friend_begin(), + Friend1End = D1CXX->friend_end(); + Friend1 != Friend1End; ++Friend1, ++Friend2) { +if (Friend2 == Friend2End) {
[libclc] r330851 - relational/select: Condition types for half are short/ushort, not char/uchar
Author: jvesely Date: Wed Apr 25 10:36:36 2018 New Revision: 330851 URL: http://llvm.org/viewvc/llvm-project?rev=330851&view=rev Log: relational/select: Condition types for half are short/ushort, not char/uchar Signed-off-by: Jan Vesely Reviewed-by: Aaron Watry Modified: libclc/trunk/generic/include/clc/relational/select.inc Modified: libclc/trunk/generic/include/clc/relational/select.inc URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/relational/select.inc?rev=330851&r1=330850&r2=330851&view=diff == --- libclc/trunk/generic/include/clc/relational/select.inc (original) +++ libclc/trunk/generic/include/clc/relational/select.inc Wed Apr 25 10:36:36 2018 @@ -9,8 +9,8 @@ #define __CLC_S_GENTYPE __CLC_XCONCAT(int, __CLC_VECSIZE) #define __CLC_U_GENTYPE __CLC_XCONCAT(uint, __CLC_VECSIZE) #elif __CLC_FPSIZE == 16 -#define __CLC_S_GENTYPE __CLC_XCONCAT(char, __CLC_VECSIZE) -#define __CLC_U_GENTYPE __CLC_XCONCAT(uchar, __CLC_VECSIZE) +#define __CLC_S_GENTYPE __CLC_XCONCAT(short, __CLC_VECSIZE) +#define __CLC_U_GENTYPE __CLC_XCONCAT(ushort, __CLC_VECSIZE) #endif _CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE select(__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_S_GENTYPE z); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits