[libcxx] r280621 - [libcxx] Fix a data race in call_once
Author: kuba.brecka Date: Sun Sep 4 04:55:12 2016 New Revision: 280621 URL: http://llvm.org/viewvc/llvm-project?rev=280621&view=rev Log: [libcxx] Fix a data race in call_once call_once is using relaxed atomic load to perform double-checked locking, which contains a data race. The fast-path load has to be an acquire atomic load. Differential Revision: https://reviews.llvm.org/D24028 Modified: libcxx/trunk/include/memory libcxx/trunk/include/mutex libcxx/trunk/src/mutex.cpp Modified: libcxx/trunk/include/memory URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=280621&r1=280620&r2=280621&view=diff == --- libcxx/trunk/include/memory (original) +++ libcxx/trunk/include/memory Sun Sep 4 04:55:12 2016 @@ -663,6 +663,18 @@ _ValueType __libcpp_relaxed_load(_ValueT #endif } +template +inline _LIBCPP_ALWAYS_INLINE +_ValueType __libcpp_acquire_load(_ValueType const* __value) { +#if !defined(_LIBCPP_HAS_NO_THREADS) && \ +defined(__ATOMIC_ACQUIRE) &&\ +(__has_builtin(__atomic_load_n) || _GNUC_VER >= 407) +return __atomic_load_n(__value, __ATOMIC_ACQUIRE); +#else +return *__value; +#endif +} + // addressof moved to <__functional_base> template class allocator; Modified: libcxx/trunk/include/mutex URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/mutex?rev=280621&r1=280620&r2=280621&view=diff == --- libcxx/trunk/include/mutex (original) +++ libcxx/trunk/include/mutex Sun Sep 4 04:55:12 2016 @@ -574,7 +574,7 @@ inline _LIBCPP_INLINE_VISIBILITY void call_once(once_flag& __flag, _Callable&& __func, _Args&&... __args) { -if (__libcpp_relaxed_load(&__flag.__state_) != ~0ul) +if (__libcpp_acquire_load(&__flag.__state_) != ~0ul) { typedef tuple<_Callable&&, _Args&&...> _Gp; _Gp __f(_VSTD::forward<_Callable>(__func), _VSTD::forward<_Args>(__args)...); @@ -590,7 +590,7 @@ inline _LIBCPP_INLINE_VISIBILITY void call_once(once_flag& __flag, _Callable& __func) { -if (__libcpp_relaxed_load(&__flag.__state_) != ~0ul) +if (__libcpp_acquire_load(&__flag.__state_) != ~0ul) { __call_once_param<_Callable> __p(__func); __call_once(__flag.__state_, &__p, &__call_once_proxy<_Callable>); Modified: libcxx/trunk/src/mutex.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/mutex.cpp?rev=280621&r1=280620&r2=280621&view=diff == --- libcxx/trunk/src/mutex.cpp (original) +++ libcxx/trunk/src/mutex.cpp Sun Sep 4 04:55:12 2016 @@ -199,9 +199,6 @@ static __libcpp_mutex_t mut = _LIBCPP_MU static __libcpp_condvar_t cv = _LIBCPP_CONDVAR_INITIALIZER; #endif -/// NOTE: Changes to flag are done via relaxed atomic stores -/// even though the accesses are protected by a mutex because threads -/// just entering 'call_once` concurrently read from flag. void __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) { @@ -238,7 +235,7 @@ __call_once(volatile unsigned long& flag __libcpp_mutex_unlock(&mut); func(arg); __libcpp_mutex_lock(&mut); -__libcpp_relaxed_store(&flag, ~0ul); +__libcpp_atomic_store(&flag, ~0ul, _AO_Release); __libcpp_mutex_unlock(&mut); __libcpp_condvar_broadcast(&cv); #ifndef _LIBCPP_NO_EXCEPTIONS ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r280622 - Test case for r280607 to check presence and sanity of the *_LOCK_FREE
Author: joerg Date: Sun Sep 4 06:21:27 2016 New Revision: 280622 URL: http://llvm.org/viewvc/llvm-project?rev=280622&view=rev Log: Test case for r280607 to check presence and sanity of the *_LOCK_FREE macros. Added: cfe/trunk/test/Headers/stdatomic.c Added: cfe/trunk/test/Headers/stdatomic.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/stdatomic.c?rev=280622&view=auto == --- cfe/trunk/test/Headers/stdatomic.c (added) +++ cfe/trunk/test/Headers/stdatomic.c Sun Sep 4 06:21:27 2016 @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -std=c11 -E %s | FileCheck %s +#include + +int bool_lock_free = ATOMIC_BOOL_LOCK_FREE; +// CHECK: bool_lock_free = {{ *[012] *;}} + +int char_lock_free = ATOMIC_CHAR_LOCK_FREE; +// CHECK: char_lock_free = {{ *[012] *;}} + +int char16_t_lock_free = ATOMIC_CHAR16_T_LOCK_FREE; +// CHECK: char16_t_lock_free = {{ *[012] *;}} + +int char32_t_lock_free = ATOMIC_CHAR32_T_LOCK_FREE; +// CHECK: char32_t_lock_free = {{ *[012] *;}} + +int wchar_t_lock_free = ATOMIC_WCHAR_T_LOCK_FREE; +// CHECK: wchar_t_lock_free = {{ *[012] *;}} + +int short_lock_free = ATOMIC_SHORT_LOCK_FREE; +// CHECK: short_lock_free = {{ *[012] *;}} + +int int_lock_free = ATOMIC_INT_LOCK_FREE; +// CHECK: int_lock_free = {{ *[012] *;}} + +int long_lock_free = ATOMIC_LONG_LOCK_FREE; +// CHECK: long_lock_free = {{ *[012] *;}} + +int llong_lock_free = ATOMIC_LLONG_LOCK_FREE; +// CHECK: llong_lock_free = {{ *[012] *;}} + +int pointer_lock_free = ATOMIC_POINTER_LOCK_FREE; +// CHECK: pointer_lock_free = {{ *[012] *;}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24054: Do not validate pch when -fno-validate-pch is set
bader added a comment. Could you a regression test, please? https://reviews.llvm.org/D24054 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r280607 - PR 27200: Fix names of the atomic lock-free macros.
On Sat, Sep 03, 2016 at 10:06:48PM -0700, Richard Smith wrote: > Thanks for the fix. Can you add a simple test that we provide macros with > the right name? Other than that, it makes sense to me for this to go to the > release branches. Done. > (I'm not sure whether we're doing more 3.8 point releases > now that 3.9 is out though.) There are still downstream consumers of 3.8, so merging fixes generally make it easier for them. Joerg ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r280635 - [AVX-512] Remove 128-bit and 256-bit masked floating point add/sub/mul/div builtins and replace with native operations.
Author: ctopper Date: Sun Sep 4 13:30:17 2016 New Revision: 280635 URL: http://llvm.org/viewvc/llvm-project?rev=280635&view=rev Log: [AVX-512] Remove 128-bit and 256-bit masked floating point add/sub/mul/div builtins and replace with native operations. We can't do the 512-bit ones because they take a rounding mode argument that we can't represent. Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def cfe/trunk/lib/Headers/avx512vlintrin.h cfe/trunk/test/CodeGen/avx512vl-builtins.c Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=280635&r1=280634&r2=280635&view=diff == --- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original) +++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Sun Sep 4 13:30:17 2016 @@ -1224,10 +1224,6 @@ TARGET_BUILTIN(__builtin_ia32_subsd_roun TARGET_BUILTIN(__builtin_ia32_maxsd_round_mask, "V2dV2dV2dV2dUcIi", "", "avx512f") TARGET_BUILTIN(__builtin_ia32_minsd_round_mask, "V2dV2dV2dV2dUcIi", "", "avx512f") -TARGET_BUILTIN(__builtin_ia32_addpd128_mask, "V2dV2dV2dV2dUc", "", "avx512vl") -TARGET_BUILTIN(__builtin_ia32_addpd256_mask, "V4dV4dV4dV4dUc", "", "avx512vl") -TARGET_BUILTIN(__builtin_ia32_addps128_mask, "V4fV4fV4fV4fUc", "", "avx512vl") -TARGET_BUILTIN(__builtin_ia32_addps256_mask, "V8fV8fV8fV8fUc", "", "avx512vl") TARGET_BUILTIN(__builtin_ia32_compressdf128_mask, "V2dV2dV2dUc", "", "avx512vl") TARGET_BUILTIN(__builtin_ia32_compressdf256_mask, "V4dV4dV4dUc", "", "avx512vl") TARGET_BUILTIN(__builtin_ia32_compressdi128_mask, "V2LLiV2LLiV2LLiUc", "", "avx512vl") @@ -1272,10 +1268,6 @@ TARGET_BUILTIN(__builtin_ia32_cvtudq2pd1 TARGET_BUILTIN(__builtin_ia32_cvtudq2pd256_mask, "V4dV4iV4dUc", "", "avx512vl") TARGET_BUILTIN(__builtin_ia32_cvtudq2ps128_mask, "V4fV4iV4fUc", "", "avx512vl") TARGET_BUILTIN(__builtin_ia32_cvtudq2ps256_mask, "V8fV8iV8fUc", "", "avx512vl") -TARGET_BUILTIN(__builtin_ia32_divpd_mask, "V2dV2dV2dV2dUc", "", "avx512vl") -TARGET_BUILTIN(__builtin_ia32_divpd256_mask, "V4dV4dV4dV4dUc", "", "avx512vl") -TARGET_BUILTIN(__builtin_ia32_divps_mask, "V4fV4fV4fV4fUc", "", "avx512vl") -TARGET_BUILTIN(__builtin_ia32_divps256_mask, "V8fV8fV8fV8fUc", "", "avx512vl") TARGET_BUILTIN(__builtin_ia32_expanddf128_mask, "V2dV2dV2dUc", "", "avx512vl") TARGET_BUILTIN(__builtin_ia32_expanddf256_mask, "V4dV4dV4dUc", "", "avx512vl") TARGET_BUILTIN(__builtin_ia32_expanddi128_mask, "V2LLiV2LLiV2LLiUc", "", "avx512vl") @@ -1304,10 +1296,6 @@ TARGET_BUILTIN(__builtin_ia32_minpd_mask TARGET_BUILTIN(__builtin_ia32_minpd256_mask, "V4dV4dV4dV4dUc", "", "avx512vl") TARGET_BUILTIN(__builtin_ia32_minps_mask, "V4fV4fV4fV4fUc", "", "avx512vl") TARGET_BUILTIN(__builtin_ia32_minps256_mask, "V8fV8fV8fV8fUc", "", "avx512vl") -TARGET_BUILTIN(__builtin_ia32_mulpd_mask, "V2dV2dV2dV2dUc", "", "avx512vl") -TARGET_BUILTIN(__builtin_ia32_mulpd256_mask, "V4dV4dV4dV4dUc", "", "avx512vl") -TARGET_BUILTIN(__builtin_ia32_mulps_mask, "V4fV4fV4fV4fUc", "", "avx512vl") -TARGET_BUILTIN(__builtin_ia32_mulps256_mask, "V8fV8fV8fV8fUc", "", "avx512vl") TARGET_BUILTIN(__builtin_ia32_pabsd128_mask, "V4iV4iV4iUc", "", "avx512vl") TARGET_BUILTIN(__builtin_ia32_pabsd256_mask, "V8iV8iV8iUc", "", "avx512vl") TARGET_BUILTIN(__builtin_ia32_pabsq128_mask, "V2LLiV2LLiV2LLiUc", "", "avx512vl") @@ -1358,10 +1346,6 @@ TARGET_BUILTIN(__builtin_ia32_sqrtpd128_ TARGET_BUILTIN(__builtin_ia32_sqrtpd256_mask, "V4dV4dV4dUc", "", "avx512vl") TARGET_BUILTIN(__builtin_ia32_sqrtps128_mask, "V4fV4fV4fUc", "", "avx512vl") TARGET_BUILTIN(__builtin_ia32_sqrtps256_mask, "V8fV8fV8fUc", "", "avx512vl") -TARGET_BUILTIN(__builtin_ia32_subpd128_mask, "V2dV2dV2dV2dUc", "", "avx512vl") -TARGET_BUILTIN(__builtin_ia32_subpd256_mask, "V4dV4dV4dV4dUc", "", "avx512vl") -TARGET_BUILTIN(__builtin_ia32_subps128_mask, "V4fV4fV4fV4fUc", "", "avx512vl") -TARGET_BUILTIN(__builtin_ia32_subps256_mask, "V8fV8fV8fV8fUc", "", "avx512vl") TARGET_BUILTIN(__builtin_ia32_vpermi2vard128_mask, "V4iV4iV4iV4iUc", "", "avx512vl") TARGET_BUILTIN(__builtin_ia32_vpermi2vard256_mask, "V8iV8iV8iV8iUc", "", "avx512vl") TARGET_BUILTIN(__builtin_ia32_vpermi2varpd128_mask, "V2dV2dV2LLiV2dUc", "", "avx512vl") Modified: cfe/trunk/lib/Headers/avx512vlintrin.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512vlintrin.h?rev=280635&r1=280634&r2=280635&view=diff == --- cfe/trunk/lib/Headers/avx512vlintrin.h (original) +++ cfe/trunk/lib/Headers/avx512vlintrin.h Sun Sep 4 13:30:17 2016 @@ -1857,71 +1857,59 @@ _mm256_mask3_fnmsub_ps(__m256 __A, __m25 } static __inline__ __m128d __DEFAULT_FN_ATTRS -_mm_mask_add_pd (__m128d __W, __mmask8 __U, __m128d __A, __m128d __B) { - return (__m128d) __builtin_ia32_addpd128_mask ((__v2df) __A, - (__v2df) __B, - (__v2df) _
[clang-tools-extra] r280638 - [clang-rename] Fix Clang-tidy and IWYU warnings; other minor fixes
Author: omtcyfz Date: Sun Sep 4 17:19:52 2016 New Revision: 280638 URL: http://llvm.org/viewvc/llvm-project?rev=280638&view=rev Log: [clang-rename] Fix Clang-tidy and IWYU warnings; other minor fixes Patch by Eugene Zelenko! Differential Revision: https://reviews.llvm.org/D24178 Reviewers: omtcyfz Modified: clang-tools-extra/trunk/clang-rename/USRFinder.h Modified: clang-tools-extra/trunk/clang-rename/USRFinder.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-rename/USRFinder.h?rev=280638&r1=280637&r2=280638&view=diff == --- clang-tools-extra/trunk/clang-rename/USRFinder.h (original) +++ clang-tools-extra/trunk/clang-rename/USRFinder.h Sun Sep 4 17:19:52 2016 @@ -12,6 +12,7 @@ /// code. /// //===--===// + #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDER_H #define LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDER_H @@ -19,11 +20,13 @@ #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include +#include using namespace llvm; using namespace clang::ast_matchers; namespace clang { + class ASTContext; class Decl; class SourceLocation; @@ -64,7 +67,7 @@ private: Finder.addMatcher(NestedNameSpecifierLocMatcher, this); } - virtual void run(const MatchFinder::MatchResult &Result) { + void run(const MatchFinder::MatchResult &Result) override { const auto *NNS = Result.Nodes.getNodeAs( "nestedNameSpecifierLoc"); Locations.push_back(*NNS); @@ -74,7 +77,8 @@ private: std::vector Locations; MatchFinder Finder; }; -} -} + +} // namespace rename +} // namespace clang #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDER_H ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24178: [clang-rename] Fix some Clang-tidy modernize-use-override and Include What You Use warnings; other minor fixes
This revision was automatically updated to reflect the committed changes. Closed by commit rL280638: [clang-rename] Fix Clang-tidy and IWYU warnings; other minor fixes (authored by omtcyfz). Changed prior to commit: https://reviews.llvm.org/D24178?vs=70119&id=70293#toc Repository: rL LLVM https://reviews.llvm.org/D24178 Files: clang-tools-extra/trunk/clang-rename/USRFinder.h Index: clang-tools-extra/trunk/clang-rename/USRFinder.h === --- clang-tools-extra/trunk/clang-rename/USRFinder.h +++ clang-tools-extra/trunk/clang-rename/USRFinder.h @@ -12,18 +12,21 @@ /// code. /// //===--===// + #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDER_H #define LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDER_H #include "clang/AST/AST.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include +#include using namespace llvm; using namespace clang::ast_matchers; namespace clang { + class ASTContext; class Decl; class SourceLocation; @@ -64,7 +67,7 @@ Finder.addMatcher(NestedNameSpecifierLocMatcher, this); } - virtual void run(const MatchFinder::MatchResult &Result) { + void run(const MatchFinder::MatchResult &Result) override { const auto *NNS = Result.Nodes.getNodeAs( "nestedNameSpecifierLoc"); Locations.push_back(*NNS); @@ -74,7 +77,8 @@ std::vector Locations; MatchFinder Finder; }; -} -} + +} // namespace rename +} // namespace clang #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDER_H Index: clang-tools-extra/trunk/clang-rename/USRFinder.h === --- clang-tools-extra/trunk/clang-rename/USRFinder.h +++ clang-tools-extra/trunk/clang-rename/USRFinder.h @@ -12,18 +12,21 @@ /// code. /// //===--===// + #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDER_H #define LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDER_H #include "clang/AST/AST.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include +#include using namespace llvm; using namespace clang::ast_matchers; namespace clang { + class ASTContext; class Decl; class SourceLocation; @@ -64,7 +67,7 @@ Finder.addMatcher(NestedNameSpecifierLocMatcher, this); } - virtual void run(const MatchFinder::MatchResult &Result) { + void run(const MatchFinder::MatchResult &Result) override { const auto *NNS = Result.Nodes.getNodeAs( "nestedNameSpecifierLoc"); Locations.push_back(*NNS); @@ -74,7 +77,8 @@ std::vector Locations; MatchFinder Finder; }; -} -} + +} // namespace rename +} // namespace clang #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDER_H ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r280639 - [clang-rename] add failing test
Author: omtcyfz Date: Sun Sep 4 17:28:39 2016 New Revision: 280639 URL: http://llvm.org/viewvc/llvm-project?rev=280639&view=rev Log: [clang-rename] add failing test For some reason clang-rename fails to rename method of templated class. Add XFAIL test reproducing the issue. Added: clang-tools-extra/trunk/test/clang-rename/TemplatedClassFunction.cpp Added: clang-tools-extra/trunk/test/clang-rename/TemplatedClassFunction.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/TemplatedClassFunction.cpp?rev=280639&view=auto == --- clang-tools-extra/trunk/test/clang-rename/TemplatedClassFunction.cpp (added) +++ clang-tools-extra/trunk/test/clang-rename/TemplatedClassFunction.cpp Sun Sep 4 17:28:39 2016 @@ -0,0 +1,22 @@ +template +class A { +public: + void foo() /* Test 1 */ {} // CHECK: void bar() /* Test 1 */ {} +}; + +int main(int argc, char **argv) { + A a; + a.foo(); /* Test 2 */ // CHECK: a.bar() /* Test 2 */ + return 0; +} + +// Test 1. +// RUN: clang-refactor rename -offset=48 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-refactor rename -offset=162 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s +// +// Currently unsupported test. +// XFAIL: * + +// To find offsets after modifying the file, use: +// grep -Ubo 'foo.*' ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r280640 - [clang-rename] Enforce LLVM policy about braces around single line control flow statement body.
Author: omtcyfz Date: Sun Sep 4 17:50:41 2016 New Revision: 280640 URL: http://llvm.org/viewvc/llvm-project?rev=280640&view=rev Log: [clang-rename] Enforce LLVM policy about braces around single line control flow statement body. Although it is not explicitly stated in LLVM Coding Standards, LLVM developers prefer to omit braces around flow control statements with single line body. For example the following piece of code ``` if (condition) std::cout << "Hello, world!" << std::endl; ``` is preferred to ``` if (condition) { std::cout << "Hello, world!" << std::endl; } ``` So far clang-rename has ignored this. This patch makes clang-rename more "LLVM-ish". Modified: clang-tools-extra/trunk/clang-rename/RenamingAction.cpp clang-tools-extra/trunk/clang-rename/USRFinder.cpp clang-tools-extra/trunk/clang-rename/USRFindingAction.cpp clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp Modified: clang-tools-extra/trunk/clang-rename/RenamingAction.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-rename/RenamingAction.cpp?rev=280640&r1=280639&r2=280640&view=diff == --- clang-tools-extra/trunk/clang-rename/RenamingAction.cpp (original) +++ clang-tools-extra/trunk/clang-rename/RenamingAction.cpp Sun Sep 4 17:50:41 2016 @@ -44,9 +44,8 @@ public: FileToReplaces(FileToReplaces), PrintLocations(PrintLocations) {} void HandleTranslationUnit(ASTContext &Context) override { -for (unsigned I = 0; I < NewNames.size(); ++I) { +for (unsigned I = 0; I < NewNames.size(); ++I) HandleOneRename(Context, NewNames[I], PrevNames[I], USRList[I]); -} } void HandleOneRename(ASTContext &Context, const std::string &NewName, Modified: clang-tools-extra/trunk/clang-rename/USRFinder.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-rename/USRFinder.cpp?rev=280640&r1=280639&r2=280640&view=diff == --- clang-tools-extra/trunk/clang-rename/USRFinder.cpp (original) +++ clang-tools-extra/trunk/clang-rename/USRFinder.cpp Sun Sep 4 17:50:41 2016 @@ -78,9 +78,8 @@ public: const SourceLocation TypeEndLoc = Lexer::getLocForEndOfToken( TypeBeginLoc, 0, Context.getSourceManager(), Context.getLangOpts()); if (const auto *TemplateTypeParm = -dyn_cast(Loc.getType())) { +dyn_cast(Loc.getType())) return setResult(TemplateTypeParm->getDecl(), TypeBeginLoc, TypeEndLoc); -} if (const auto *TemplateSpecType = dyn_cast(Loc.getType())) { return setResult(TemplateSpecType->getTemplateName().getAsTemplateDecl(), @@ -92,18 +91,16 @@ public: bool VisitCXXConstructorDecl(clang::CXXConstructorDecl *ConstructorDecl) { for (const auto *Initializer : ConstructorDecl->inits()) { - if (!Initializer->isWritten()) { -// Ignore implicit initializers. + // Ignore implicit initializers. + if (!Initializer->isWritten()) continue; - } if (const clang::FieldDecl *FieldDecl = Initializer->getMember()) { const SourceLocation InitBeginLoc = Initializer->getSourceLocation(), InitEndLoc = Lexer::getLocForEndOfToken( InitBeginLoc, 0, Context.getSourceManager(), Context.getLangOpts()); -if (!setResult(FieldDecl, InitBeginLoc, InitEndLoc)) { +if (!setResult(FieldDecl, InitBeginLoc, InitEndLoc)) return false; -} } } return true; @@ -129,20 +126,17 @@ private: // \returns false on success. bool setResult(const NamedDecl *Decl, SourceLocation Start, SourceLocation End) { -if (!Decl) { +if (!Decl) return true; -} if (Name.empty()) { // Offset is used to find the declaration. if (!Start.isValid() || !Start.isFileID() || !End.isValid() || - !End.isFileID() || !isPointWithin(Start, End)) { + !End.isFileID() || !isPointWithin(Start, End)) return true; - } } else { // Fully qualified name is used to find the declaration. - if (Name != Decl->getQualifiedNameAsString()) { + if (Name != Decl->getQualifiedNameAsString()) return true; - } } Result = Decl; return false; @@ -182,15 +176,13 @@ const NamedDecl *getNamedDeclAt(const AS const SourceLocation FileLoc = CurrDecl->getLocStart(); StringRef FileName = Context.getSourceManager().getFilename(FileLoc); // FIXME: Add test. -if (FileName == SearchFile) { +if (FileName == SearchFile) Visitor.TraverseDecl(CurrDecl); -} } NestedNameSpecifierLocFinder Finder(const_cast(Context)); - for (const auto &Location : Finder.getNestedNameSpecifierLocations()) { + for (const auto &Location : Finder.getNestedNameSpecifierLocat
[PATCH] D24224: [clang-rename] Merge rename-{ at | all } and optimise USRFindingAction.
omtcyfz created this revision. omtcyfz added reviewers: alexfh, ioeric, vmiklos. omtcyfz added subscribers: cfe-commits, Eugene.Zelenko. Having both rename-at and rename-all both seems confusing and introduces unneeded difficulties. Allowing to use both -qualified-name and -offset at once while performing efficient renamings seems like a feature, too. Maintaining `main` function wrappers and custom `help` becomes redundant while CLI becomes less confusing. This is basically D23651 done right. This patch belongs to a sequence of patches needed for painless migration to clang-refactor, see D24192. https://reviews.llvm.org/D24224 Files: clang-rename/USRFindingAction.cpp clang-rename/USRFindingAction.h clang-rename/tool/ClangRename.cpp docs/clang-rename.rst test/clang-rename/ClassFindByName.cpp test/clang-rename/ClassTestMulti.cpp test/clang-rename/ClassTestMultiByName.cpp test/clang-rename/ClassTestMultiByNameYAML.cpp test/clang-rename/CouldNotFindSymbol.cpp test/clang-rename/FunctionWithClassFindByName.cpp test/clang-rename/Inputs/ClassTestMultiByNameYAMLRenameAll.yaml test/clang-rename/Inputs/ClassTestMultiByNameYAMLRenameAt.yaml test/clang-rename/Inputs/YAMLInputUseBoth.yaml test/clang-rename/Inputs/YAMLInputUseOffsets.yaml test/clang-rename/Inputs/YAMLInputUseQualifeidNames.yaml test/clang-rename/InvalidOldName.cpp test/clang-rename/NoNewName.cpp test/clang-rename/PassYAMLInput.cpp Index: test/clang-rename/PassYAMLInput.cpp === --- /dev/null +++ test/clang-rename/PassYAMLInput.cpp @@ -0,0 +1,12 @@ +class Foo1 { // CHECK: class Bar1 +}; + +class Foo2 { // CHECK: class Bar2 +}; + +// Test 1. +// RUN: clang-rename -input %S/Inputs/YAMLInputUseQualifeidNames.yaml %s -- | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-rename -input %S/Inputs/YAMLInputUseOffsets.yaml %s -- | sed 's,//.*,,' | FileCheck %s +// Test 3. +// RUN: clang-rename -input %S/Inputs/YAMLInputUseBoth.yaml %s -- | sed 's,//.*,,' | FileCheck %s Index: test/clang-rename/NoNewName.cpp === --- test/clang-rename/NoNewName.cpp +++ test/clang-rename/NoNewName.cpp @@ -1,4 +1,4 @@ // Check for an error while -new-name argument has not been passed to // clang-rename. // RUN: not clang-rename -offset=133 %s 2>&1 | FileCheck %s -// CHECK: clang-rename: for the -new-name option: must be specified +// CHECK: clang-rename: -new-name must be specified. Index: test/clang-rename/InvalidOldName.cpp === --- test/clang-rename/InvalidOldName.cpp +++ /dev/null @@ -1,2 +0,0 @@ -// RUN: not clang-rename rename-all -new-name=Foo -old-name=Bar %s -- 2>&1 | FileCheck %s -// CHECK: clang-rename: could not find symbol Bar. Index: test/clang-rename/Inputs/YAMLInputUseQualifeidNames.yaml === --- /dev/null +++ test/clang-rename/Inputs/YAMLInputUseQualifeidNames.yaml @@ -0,0 +1,6 @@ +--- +- QualifiedName: Foo1 + NewName:Bar1 +- QualifiedName: Foo2 + NewName:Bar2 +... Index: test/clang-rename/Inputs/YAMLInputUseOffsets.yaml === --- /dev/null +++ test/clang-rename/Inputs/YAMLInputUseOffsets.yaml @@ -0,0 +1,6 @@ +--- +- Offset: 6 + NewName:Bar1 +- Offset: 44 + NewName:Bar2 +... Index: test/clang-rename/Inputs/YAMLInputUseBoth.yaml === --- /dev/null +++ test/clang-rename/Inputs/YAMLInputUseBoth.yaml @@ -0,0 +1,6 @@ +--- +- Offset: 6 + NewName:Bar1 +- QualifiedName: Foo2 + NewName:Bar2 +... Index: test/clang-rename/Inputs/ClassTestMultiByNameYAMLRenameAt.yaml === --- test/clang-rename/Inputs/ClassTestMultiByNameYAMLRenameAt.yaml +++ /dev/null @@ -1,6 +0,0 @@ -- Offset: 6 - NewName:Bar1 -- Offset: 44 - NewName:Bar2 -... Index: test/clang-rename/Inputs/ClassTestMultiByNameYAMLRenameAll.yaml === --- test/clang-rename/Inputs/ClassTestMultiByNameYAMLRenameAll.yaml +++ /dev/null @@ -1,6 +0,0 @@ -- OldName:Foo1 - NewName:Bar1 -- OldName:Foo2 - NewName:Bar2 -... Index: test/clang-rename/FunctionWithClassFindByName.cpp === --- test/clang-rename/FunctionWithClassFindByName.cpp +++ test/clang-rename/FunctionWithClassFindByName.cpp @@ -9,4 +9,4 @@ return 0; } -// RUN: clang-rename rename-all -old-name=Foo -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s +// RUN: clang-rename -qualified-name=Foo -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s Index: test/clang-rename/CouldNotFindSymbol.cpp ==
Re: [PATCH] D24192: [clang-refactor] introducing clang-refactor
omtcyfz added a comment. In https://reviews.llvm.org/D24192#533233, @ioeric wrote: > It was not trivial to me why USREngine is so important to those tools. You > might want to address that in the design doc as well. And given the weight > USREngine carries in clang-refactor as you suggested, I think it deserves an > more detailed introduction in the design doc. Yes, I agree, it might be a little confusing. The only mention I have is: > The most important facility would allow lookup of symbol definitions and > usages (probably, based on Unified Symbol Resolutions, USR) But it doesn't get into too much details anyway. However, the idea of the design doc was not to focus on implementation details too much as they are a subject to change. Thus, I'm not sure whether I should elaborate details of USREngine there. Comment at: clang-refactor/driver/Rename.h:192 @@ +191,3 @@ + auto ID = Sources.translateFile(Entry); + Rewrite.getEditBuffer(ID).write(outs()); +} alexshap wrote: > if i am not mistaken if the file has not been modified this will print smth > like > "invalid source location" or similar. Pls, double check me. Sorry, can you please elaborate? Also, this might be unrelated to this exact patch, but if there is an issue it's good to fix it in another patch. Basically, this is not new code, it's been there in `clang-rename`. https://reviews.llvm.org/D24192 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24192: [clang-refactor] introducing clang-refactor
omtcyfz added a comment. In https://reviews.llvm.org/D24192#533220, @ioeric wrote: > Don't worry about a patch being small. Reviewers like small patches :) > > The reason that I suggested a dummy sub-tool is to lower the bar for > developers, especially those who have never developed a clang tool, so that > they can easily figure out how to set up a clang-refactor sub-tool. > > For a "swiss-army knife" tool like clang-refactor, I would worry more about > the extendibility of the infrastructure instead of functionality at this > stage. At least, I would expect it to be much easier to create a refactor > tool under clang-refactor than creating a standalone clang tool. For example, > it would be really nice if there is a tool base that a sub-module can derive > from so that I don't have to go through the whole process of creating a clang > tool and setting up unit/lit test environment :) Yes, you are absolutely right. This patch is just a mess, because I tried to push everything at once while most of the stuff is not related to clang-refactor part at all. I pushed 3 very basic cleanup patches (namely https://reviews.llvm.org/rL280638, https://reviews.llvm.org/rL280639 and https://reviews.llvm.org/rL280640), which don't really need reviewing (and also for the sake of development speed). And I also kept clang-rename improvements separate in https://reviews.llvm.org/D24224, which is up for review. I'll update this patch tomorrow. What I'm about to do after is to either: 1. Make two patches, one of which would basically create "empty" `clang-refactor` and introduce dummy submodule to show how it works (as you proposed), and the other would merge `clang-rename` as a submodule. 2. Make one patch, which both creates `clang-refactor` binary and merges `clang-rename` as a submodule. The first variant seems better to me while I see a couple of issues with that, which makes sticking to the second variant a bit less challenging. We can discuss it tomorr..today and come up with a solution. Thank you very much for your comments, Eric! https://reviews.llvm.org/D24192 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24183: A clang tool for changing surrouding namespaces of class/function definitions.
omtcyfz added inline comments. Comment at: change-namespace/ChangeNamespace.cpp:30 @@ +29,3 @@ + std::string Result = Namespaces.front(); + for (auto I = Namespaces.begin() + 1, E = Namespaces.end(); I != E; ++I) { +Result += ("::" + *I).str(); Braces around single-line statement inside control flow statement body is occasionally not welcome in LLVM Codebase. There are actually both many braces around single-line statement inside cfs body here and many cfs's without braces around single-line body inside a single file, which isn't good in terms of consistency at least inside the project. Comment at: change-namespace/ChangeNamespace.cpp:105 @@ +104,3 @@ + llvm::StringRef File = SM.getBufferData(LocInfo.first, &InvalidTemp); + if (InvalidTemp) +return SourceLocation(); Shouldn't this throw an error instead? https://reviews.llvm.org/D24183 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libcxx] r280643 - Fix Bug 30240 - std::string: append(first, last) error when aliasing. Add test cases for append/insert/assign/replace while we're at it, and fix a similar bug in insert.
Author: marshall Date: Sun Sep 4 20:54:30 2016 New Revision: 280643 URL: http://llvm.org/viewvc/llvm-project?rev=280643&view=rev Log: Fix Bug 30240 - std::string: append(first, last) error when aliasing. Add test cases for append/insert/assign/replace while we're at it, and fix a similar bug in insert. Modified: libcxx/trunk/include/string libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_iter_iter.pass.cpp libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer.pass.cpp libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer_size.pass.cpp Modified: libcxx/trunk/include/string URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=280643&r1=280642&r2=280643&view=diff == --- libcxx/trunk/include/string (original) +++ libcxx/trunk/include/string Sun Sep 4 20:54:30 2016 @@ -1998,7 +1998,7 @@ typename enable_if >::type basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last) { -basic_string __temp(__first, __last, __alloc()); +const basic_string __temp(__first, __last, __alloc()); assign(__temp.data(), __temp.size()); return *this; } @@ -2151,11 +2151,17 @@ typename enable_if >::type basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last) { -basic_string __temp (__first, __last, __alloc()); +const basic_string __temp (__first, __last, __alloc()); append(__temp.data(), __temp.size()); return *this; } +template +bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last) +{ +return __first <= __p && __p < __last; +} + template template typename enable_if @@ -2171,13 +2177,21 @@ basic_string<_CharT, _Traits, _Allocator size_type __n = static_cast(_VSTD::distance(__first, __last)); if (__n) { -if (__cap - __sz < __n) -__grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); -pointer __p = __get_pointer() + __sz; -for (; __first != __last; ++__p, ++__first) -traits_type::assign(*__p, *__first); -traits_type::assign(*__p, value_type()); -__set_size(__sz + __n); +if ( __ptr_in_range(&*__first, data(), data() + size())) +{ +const basic_string __temp (__first, __last, __alloc()); +append(__temp.data(), __temp.size()); +} +else +{ +if (__cap - __sz < __n) +__grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); +pointer __p = __get_pointer() + __sz; +for (; __first != __last; ++__p, ++__first) +traits_type::assign(*__p, *__first); +traits_type::assign(*__p, value_type()); +__set_size(__sz + __n); +} } return *this; } @@ -2299,7 +2313,7 @@ basic_string<_CharT, _Traits, _Allocator "string::insert(iterator, range) called with an iterator not" " referring to this string"); #endif -basic_string __temp(__first, __last, __alloc()); +const basic_string __temp(__first, __last, __alloc()); return insert(__pos, __temp.data(), __temp.data() + __temp.size()); } @@ -2319,11 +2333,17 @@ basic_string<_CharT, _Traits, _Allocator " referring to this string"); #endif size_type __ip = static_cast(__pos - begin()); -size_type __sz = size(); -size_type __cap = capacity(); size_type __n = static_cast(_VSTD::distance(__first, __last)); if (__n) { +if ( __ptr_in_range(&*__first, data(), data() + size())) +{ +const basic_string __temp(__first, __last, __alloc()); +return insert(__pos, __temp.data(), __temp.data() + __temp.size()); +} + +size_type __sz = size(); +size_type __cap = capacity(); value_type* __p; if (__cap - __sz >= __n) { @@ -2523,7 +2543,7 @@ typename enable_if basic_s