[PATCH] D55662: [Sema][ObjC] Do not warn about repeated uses of weak variables when the variables are accessed in an unevaluated context.

2018-12-14 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak marked an inline comment as done.
ahatanak added inline comments.



Comment at: lib/Sema/SemaType.cpp:8127
 QualType Sema::BuildDecltypeType(Expr *E, SourceLocation Loc,
  bool AsUnevaluated) {
   ExprResult ER = CheckPlaceholderExpr(E);

I couldn't assert here that `E` isn't a placeholder since there are several 
call sites that call this function and there are code paths that don't call 
`Sema::ActOnDecltypeExpression` before reaching this point.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55662



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


[PATCH] D55662: [Sema][ObjC] Do not warn about repeated uses of weak variables when the variables are accessed in an unevaluated context.

2018-12-14 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 178341.
ahatanak added a comment.

Call CheckPlaceholderExpr instead of pushing an unevaluated evaluation context.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55662

Files:
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaExprObjC.cpp
  lib/Sema/SemaType.cpp
  test/SemaObjC/arc-repeated-weak.mm


Index: test/SemaObjC/arc-repeated-weak.mm
===
--- test/SemaObjC/arc-repeated-weak.mm
+++ test/SemaObjC/arc-repeated-weak.mm
@@ -462,6 +462,9 @@
   NSString * t2 = NSBundle.foo2.prop;
   use(NSBundle.foo2.weakProp); // expected-warning{{weak property 'weakProp' 
may be accessed multiple times}}
   use(NSBundle2.foo2.weakProp); // expected-note{{also accessed here}}
+  decltype([NSBundle2.foo2 weakProp]) t3;
+  decltype(NSBundle2.foo2.weakProp) t4;
+  __typeof__(NSBundle2.foo2.weakProp) t5;
 }
 
 // This used to crash in the constructor of WeakObjectProfileTy when a
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -8040,9 +8040,7 @@
 }
 
 QualType Sema::BuildTypeofExprType(Expr *E, SourceLocation Loc) {
-  ExprResult ER = CheckPlaceholderExpr(E);
-  if (ER.isInvalid()) return QualType();
-  E = ER.get();
+  assert(!E->getType()->getAsPlaceholderType() && "unexpected placeholder");
 
   if (!getLangOpts().CPlusPlus && E->refersToBitField())
 Diag(E->getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield) << 2;
Index: lib/Sema/SemaExprObjC.cpp
===
--- lib/Sema/SemaExprObjC.cpp
+++ lib/Sema/SemaExprObjC.cpp
@@ -3140,7 +3140,7 @@
   Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_weak;
 if (!IsWeak && Sel.isUnarySelector())
   IsWeak = ReturnType.getObjCLifetime() & Qualifiers::OCL_Weak;
-if (IsWeak &&
+if (IsWeak && !isUnevaluatedContext() &&
 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, LBracLoc))
   getCurFunction()->recordUseOfWeak(Result, Prop);
   }
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -6539,6 +6539,11 @@
  ExpressionEvaluationContextRecord::EK_Decltype &&
  "not in a decltype expression");
 
+  ExprResult Result = CheckPlaceholderExpr(E);
+  if (Result.isInvalid())
+return ExprError();
+  E = Result.get();
+
   // C++11 [expr.call]p11:
   //   If a function call is a prvalue of object type,
   // -- if the function call is either
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -14552,6 +14552,10 @@
 }
 
 ExprResult Sema::HandleExprEvaluationContextForTypeof(Expr *E) {
+  ExprResult Result = CheckPlaceholderExpr(E);
+  if (Result.isInvalid())
+return ExprError();
+  E = Result.get();
   if (!E->getType()->isVariablyModifiedType())
 return E;
   return TransformToPotentiallyEvaluated(E);


Index: test/SemaObjC/arc-repeated-weak.mm
===
--- test/SemaObjC/arc-repeated-weak.mm
+++ test/SemaObjC/arc-repeated-weak.mm
@@ -462,6 +462,9 @@
   NSString * t2 = NSBundle.foo2.prop;
   use(NSBundle.foo2.weakProp); // expected-warning{{weak property 'weakProp' may be accessed multiple times}}
   use(NSBundle2.foo2.weakProp); // expected-note{{also accessed here}}
+  decltype([NSBundle2.foo2 weakProp]) t3;
+  decltype(NSBundle2.foo2.weakProp) t4;
+  __typeof__(NSBundle2.foo2.weakProp) t5;
 }
 
 // This used to crash in the constructor of WeakObjectProfileTy when a
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -8040,9 +8040,7 @@
 }
 
 QualType Sema::BuildTypeofExprType(Expr *E, SourceLocation Loc) {
-  ExprResult ER = CheckPlaceholderExpr(E);
-  if (ER.isInvalid()) return QualType();
-  E = ER.get();
+  assert(!E->getType()->getAsPlaceholderType() && "unexpected placeholder");
 
   if (!getLangOpts().CPlusPlus && E->refersToBitField())
 Diag(E->getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield) << 2;
Index: lib/Sema/SemaExprObjC.cpp
===
--- lib/Sema/SemaExprObjC.cpp
+++ lib/Sema/SemaExprObjC.cpp
@@ -3140,7 +3140,7 @@
   Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_weak;
 if (!IsWeak && Sel.isUnarySelector())
   IsWeak = ReturnType.getObjCLifetime() & Qualifiers::OCL_Weak;
-if (IsWeak &&
+if (IsWeak && !isUnevaluatedContext() &&
 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, LBracLoc))
   

[libunwind] r349249 - Creating release candidate final from release_701 branch

2018-12-14 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Fri Dec 14 20:32:13 2018
New Revision: 349249

URL: http://llvm.org/viewvc/llvm-project?rev=349249=rev
Log:
Creating release candidate final from release_701 branch

Added:
libunwind/tags/RELEASE_701/final/   (props changed)
  - copied from r349248, libunwind/branches/release_70/

Propchange: libunwind/tags/RELEASE_701/final/
--
svn:mergeinfo = /libunwind/trunk:339217


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


r349237 - Fix includes and dependencies for libclang

2018-12-14 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Fri Dec 14 20:25:19 2018
New Revision: 349237

URL: http://llvm.org/viewvc/llvm-project?rev=349237=rev
Log:
Fix includes and dependencies for libclang

Remove unneeded includes
Add needed include
Remove dependency on Serialization

Modified:
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
cfe/trunk/tools/libclang/CIndexDiagnostic.cpp
cfe/trunk/tools/libclang/CMakeLists.txt
cfe/trunk/tools/libclang/CXStoredDiagnostic.cpp

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=349237=349236=349237=diff
==
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Fri Dec 14 20:25:19 2018
@@ -31,14 +31,12 @@
 #include "clang/Basic/Version.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
-#include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Index/CodegenNameGenerator.h"
 #include "clang/Index/CommentToXML.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/PreprocessingRecord.h"
 #include "clang/Lex/Preprocessor.h"
-#include "clang/Serialization/SerializationDiagnostic.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSwitch.h"

Modified: cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp?rev=349237=349236=349237=diff
==
--- cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp Fri Dec 14 20:25:19 2018
@@ -26,7 +26,6 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
-#include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "clang/Sema/Sema.h"
 #include "llvm/ADT/SmallString.h"

Modified: cfe/trunk/tools/libclang/CIndexDiagnostic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexDiagnostic.cpp?rev=349237=349236=349237=diff
==
--- cfe/trunk/tools/libclang/CIndexDiagnostic.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexDiagnostic.cpp Fri Dec 14 20:25:19 2018
@@ -19,7 +19,6 @@
 #include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/DiagnosticRenderer.h"
-#include "clang/Frontend/FrontendDiagnostic.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/raw_ostream.h"
 

Modified: cfe/trunk/tools/libclang/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CMakeLists.txt?rev=349237=349236=349237=diff
==
--- cfe/trunk/tools/libclang/CMakeLists.txt (original)
+++ cfe/trunk/tools/libclang/CMakeLists.txt Fri Dec 14 20:25:19 2018
@@ -40,7 +40,6 @@ set(LIBS
   clangIndex
   clangLex
   clangSema
-  clangSerialization
   clangTooling
 )
 

Modified: cfe/trunk/tools/libclang/CXStoredDiagnostic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXStoredDiagnostic.cpp?rev=349237=349236=349237=diff
==
--- cfe/trunk/tools/libclang/CXStoredDiagnostic.cpp (original)
+++ cfe/trunk/tools/libclang/CXStoredDiagnostic.cpp Fri Dec 14 20:25:19 2018
@@ -17,8 +17,8 @@
 #include "CXSourceLocation.h"
 #include "CXString.h"
 
+#include "clang/Basic/DiagnosticIDs.h"
 #include "clang/Frontend/ASTUnit.h"
-#include "clang/Frontend/FrontendDiagnostic.h"
 #include "llvm/ADT/Twine.h"
 
 using namespace clang;


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


[PATCH] D55719: [OpenMP] parsing and sema support for 'close' map-type-modifier

2018-12-14 Thread Ahsan Saghir via Phabricator via cfe-commits
saghir updated this revision to Diff 178336.
saghir added a comment.

Made following changes:

- added more tests for checking diagnostic error messages.
- added initialization of modifiers' location in OMPMapClause.
- improved variable names to depict multiple modifiers as opposed to a single 
modifier.
- improved comments.


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

https://reviews.llvm.org/D55719

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/include/clang/Basic/OpenMPKinds.h
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/target_ast_print.cpp
  clang/test/OpenMP/target_data_ast_print.cpp
  clang/test/OpenMP/target_map_messages.cpp
  clang/test/OpenMP/target_parallel_for_map_messages.cpp
  clang/test/OpenMP/target_parallel_for_simd_map_messages.cpp
  clang/test/OpenMP/target_parallel_map_messages.cpp
  clang/test/OpenMP/target_simd_map_messages.cpp
  clang/test/OpenMP/target_teams_distribute_map_messages.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_map_messages.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_map_messages.cpp
  clang/test/OpenMP/target_teams_distribute_simd_map_messages.cpp
  clang/test/OpenMP/target_teams_map_messages.cpp

Index: clang/test/OpenMP/target_teams_map_messages.cpp
===
--- clang/test/OpenMP/target_teams_map_messages.cpp
+++ clang/test/OpenMP/target_teams_map_messages.cpp
@@ -454,7 +454,7 @@
 
 #pragma omp target data map(always, tofrom: x)
 #pragma omp target data map(always: x) // expected-error {{missing map type}}
-#pragma omp target data map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always'}} expected-error {{incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 'release', or 'delete'}}
+#pragma omp target data map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always' or 'close'}} expected-error {{missing map type}}
 #pragma omp target data map(always, tofrom: always, tofrom, x)
 #pragma omp target teams map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
   foo();
@@ -529,7 +529,7 @@
 
 #pragma omp target data map(always, tofrom: x)
 #pragma omp target data map(always: x) // expected-error {{missing map type}}
-#pragma omp target data map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always'}} expected-error {{incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 'release', or 'delete'}}
+#pragma omp target data map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always' or 'close'}} expected-error {{missing map type}}
 #pragma omp target data map(always, tofrom: always, tofrom, x)
 #pragma omp target teams map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
   foo();
Index: clang/test/OpenMP/target_teams_distribute_simd_map_messages.cpp
===
--- clang/test/OpenMP/target_teams_distribute_simd_map_messages.cpp
+++ clang/test/OpenMP/target_teams_distribute_simd_map_messages.cpp
@@ -163,7 +163,7 @@
   for (i = 0; i < argc; ++i) foo();
 #pragma omp target teams distribute simd map(always: x) // expected-error {{missing map type}}
   for (i = 0; i < argc; ++i) foo();
-#pragma omp target teams distribute simd map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always'}} expected-error {{incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 'release', or 'delete'}}
+#pragma omp target teams distribute simd map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always' or 'close'}} expected-error {{missing map type}}
   for (i = 0; i < argc; ++i) foo();
 #pragma omp target teams distribute simd map(always, tofrom: always, tofrom, x)
   for (i = 0; i < argc; ++i) foo();
@@ -271,7 +271,7 @@
   for (i = 0; i < argc; ++i) foo();
 #pragma omp target teams distribute simd map(always: x) // expected-error {{missing map type}}
   for (i = 0; i < argc; ++i) foo();
-#pragma omp target teams distribute simd map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always'}} expected-error {{incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 'release', or 'delete'}}
+#pragma omp target teams distribute simd map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always' or 'close'}} expected-error 

[PATCH] D55388: [analyzer] MoveChecker Pt.8: Add checks for dereferencing a smart pointer after move.

2018-12-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Reverted in rC349233  - fails on a Windows 
buildbot 
(http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/2642/steps/annotate/logs/stdio).

Surprisingly, the next build is fine, and the build after it is broken again. 
Probably some UB.

  
   TEST 'Clang :: Analysis/use-after-move.cpp' FAILED 

  Script:
  --
  : 'RUN: at line 1';   
c:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\clang.EXE -cc1 
-internal-isystem 
c:\b\slave\clang-x64-windows-msvc\build\build\stage1\lib\clang\8.0.0\include 
-nostdsysteminc -analyze -analyzer-constraints=range 
-analyzer-checker=alpha.cplusplus.Move -verify 
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\Analysis\use-after-move.cpp
  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false  
-analyzer-config exploration_strategy=unexplored_first_queue  -analyzer-checker 
debug.ExprInspection
  : 'RUN: at line 5';   
c:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\clang.EXE -cc1 
-internal-isystem 
c:\b\slave\clang-x64-windows-msvc\build\build\stage1\lib\clang\8.0.0\include 
-nostdsysteminc -analyze -analyzer-constraints=range 
-analyzer-checker=alpha.cplusplus.Move -verify 
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\Analysis\use-after-move.cpp
  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false  
-analyzer-config exploration_strategy=dfs -DDFS=1  -analyzer-checker 
debug.ExprInspection
  : 'RUN: at line 9';   
c:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\clang.EXE -cc1 
-internal-isystem 
c:\b\slave\clang-x64-windows-msvc\build\build\stage1\lib\clang\8.0.0\include 
-nostdsysteminc -analyze -analyzer-constraints=range 
-analyzer-checker=alpha.cplusplus.Move -verify 
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\Analysis\use-after-move.cpp
  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false  
-analyzer-config exploration_strategy=unexplored_first_queue  -analyzer-config 
alpha.cplusplus.Move:Aggressive=true -DAGGRESSIVE  -analyzer-checker 
debug.ExprInspection
  : 'RUN: at line 14';   
c:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\clang.EXE -cc1 
-internal-isystem 
c:\b\slave\clang-x64-windows-msvc\build\build\stage1\lib\clang\8.0.0\include 
-nostdsysteminc -analyze -analyzer-constraints=range 
-analyzer-checker=alpha.cplusplus.Move -verify 
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\Analysis\use-after-move.cpp
  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false  
-analyzer-config exploration_strategy=dfs -DDFS=1  -analyzer-config 
alpha.cplusplus.Move:Aggressive=true -DAGGRESSIVE  -analyzer-checker 
debug.ExprInspection
  --
  Exit Code: 1
  
  Command Output (stdout):
  --
  $ ":" "RUN: at line 1"
  $ "c:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\clang.EXE" "-cc1" 
"-internal-isystem" 
"c:\b\slave\clang-x64-windows-msvc\build\build\stage1\lib\clang\8.0.0\include" 
"-nostdsysteminc" "-analyze" "-analyzer-constraints=range" 
"-analyzer-checker=alpha.cplusplus.Move" "-verify" 
"C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\Analysis\use-after-move.cpp"
 "-std=c++11" "-analyzer-output=text" "-analyzer-config" "eagerly-assume=false" 
"-analyzer-config" "exploration_strategy=unexplored_first_queue" 
"-analyzer-checker" "debug.ExprInspection"
  # command stderr:
  error: 'warning' diagnostics expected but not seen: 
  
File 
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\Analysis\use-after-move.cpp
 Line 823 (directive at 
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\Analysis\use-after-move.cpp:825):
 Dereference of null smart pointer 'P' of type 'std::unique_ptr'
  
File 
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\Analysis\use-after-move.cpp
 Line 851: Dereference of null smart pointer 'P' of type 'std::unique_ptr'
  
  error: 'warning' diagnostics seen but not expected: 
  
File 
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\Analysis\use-after-move.cpp
 Line 831: REACHABLE
  
File 
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\Analysis\use-after-move.cpp
 Line 851: Method called on moved-from object 'P'
  
  error: 'note' diagnostics expected but not seen: 
  
File 
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\Analysis\use-after-move.cpp
 Line 812 (directive at 
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\Analysis\use-after-move.cpp:826):
 Smart pointer 'P' of type 'std::unique_ptr' is reset to null when moved from
  
File 
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\Analysis\use-after-move.cpp
 Line 823 (directive at 
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\Analysis\use-after-move.cpp:827):
 Dereference of null smart 

r349233 - Revert "[analyzer] MoveChecker: Add checks for dereferencing a smart pointer..."

2018-12-14 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Fri Dec 14 18:55:55 2018
New Revision: 349233

URL: http://llvm.org/viewvc/llvm-project?rev=349233=rev
Log:
Revert "[analyzer] MoveChecker: Add checks for dereferencing a smart pointer..."

This reverts commit r349226.

Fails on an MSVC buildbot.

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
cfe/trunk/test/Analysis/use-after-move.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp?rev=349233=349232=349233=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp Fri Dec 14 18:55:55 
2018
@@ -61,35 +61,19 @@ public:
   const char *NL, const char *Sep) const override;
 
 private:
-  enum MisuseKind { MK_FunCall, MK_Copy, MK_Move, MK_Dereference };
-  enum StdObjectKind { SK_NonStd, SK_Unsafe, SK_Safe, SK_SmartPtr };
-
-  static bool misuseCausesCrash(MisuseKind MK) {
-return MK == MK_Dereference;
-  }
+  enum MisuseKind { MK_FunCall, MK_Copy, MK_Move };
 
   struct ObjectKind {
-// Is this a local variable or a local rvalue reference?
-bool IsLocal : 1;
-// Is this an STL object? If so, of what kind?
-StdObjectKind StdKind : 2;
-  };
-
-  // STL smart pointers are automatically re-initialized to null when moved
-  // from. So we can't warn on many methods, but we can warn when it is
-  // dereferenced, which is UB even if the resulting lvalue never gets read.
-  const llvm::StringSet<> StdSmartPtrClasses = {
-  "shared_ptr",
-  "unique_ptr",
-  "weak_ptr",
+bool Local : 1; // Is this a local variable or a local rvalue reference?
+bool STL : 1; // Is this an object of a standard type?
   };
 
   // Not all of these are entirely move-safe, but they do provide *some*
   // guarantees, and it means that somebody is using them after move
   // in a valid manner.
-  // TODO: We can still try to identify *unsafe* use after move,
-  // like we did with smart pointers.
-  const llvm::StringSet<> StdSafeClasses = {
+  // TODO: We can still try to identify *unsafe* use after move, such as
+  // dereference of a moved-from smart pointer (which is guaranteed to be 
null).
+  const llvm::StringSet<> StandardMoveSafeClasses = {
   "basic_filebuf",
   "basic_ios",
   "future",
@@ -98,8 +82,11 @@ private:
   "promise",
   "shared_future",
   "shared_lock",
+  "shared_ptr",
   "thread",
+  "unique_ptr",
   "unique_lock",
+  "weak_ptr",
   };
 
   // Should we bother tracking the state of the object?
@@ -110,25 +97,10 @@ private:
 // their user to re-use the storage. The latter is possible because STL
 // objects are known to end up in a valid but unspecified state after the
 // move and their state-reset methods are also known, which allows us to
-// predict precisely when use-after-move is invalid.
-// Some STL objects are known to conform to additional contracts after 
move,
-// so they are not tracked. However, smart pointers specifically are 
tracked
-// because we can perform extra checking over them.
-// In aggressive mode, warn on any use-after-move because the user has
-// intentionally asked us to completely eliminate use-after-move
-// in his code.
-return IsAggressive || OK.IsLocal
-|| OK.StdKind == SK_Unsafe || OK.StdKind == 
SK_SmartPtr;
-  }
-
-  // Some objects only suffer from some kinds of misuses, but we need to track
-  // them anyway because we cannot know in advance what misuse will we find.
-  bool shouldWarnAbout(ObjectKind OK, MisuseKind MK) const {
-// Additionally, only warn on smart pointers when they are dereferenced (or
-// local or we are aggressive).
-return shouldBeTracked(OK) &&
-   (IsAggressive || OK.IsLocal
- || OK.StdKind != SK_SmartPtr || MK == MK_Dereference);
+// predict precisely when use-after-move is invalid. In aggressive mode,
+// warn on any use-after-move because the user has intentionally asked us
+// to completely eliminate use-after-move in his code.
+return IsAggressive || OK.Local || OK.STL;
   }
 
   // Obtains ObjectKind of an object. Because class declaration cannot always
@@ -136,17 +108,17 @@ private:
   ObjectKind classifyObject(const MemRegion *MR, const CXXRecordDecl *RD) 
const;
 
   // Classifies the object and dumps a user-friendly description string to
-  // the stream.
-  void explainObject(llvm::raw_ostream , const MemRegion *MR,
- const CXXRecordDecl *RD, MisuseKind MK) const;
+  // the stream. Return value is equivalent to classifyObject.
+  ObjectKind explainObject(llvm::raw_ostream ,
+   const MemRegion *MR, const CXXRecordDecl *RD) const;
 
-  bool belongsTo(const CXXRecordDecl 

[PATCH] D55731: [darwin][arm64] use the "cyclone" CPU for Darwin even when `-arch` is not specified

2018-12-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
arphaman added reviewers: ab, t.p.northover.
Herald added subscribers: dexonsmith, jkorous, kristof.beyls, javed.absar.

The `-target` option allows the user to specify the build target using LLVM 
triple. The triple includes the arch, and so the `-arch` option is redundant. 
This should work just as well without the `-arch`. However, the driver has a 
bug in which it doesn't target the "Cyclone" CPU for darwin if `-target` is 
used without `-arch`. This patch fixes this issue.

rdar://46743182


Repository:
  rC Clang

https://reviews.llvm.org/D55731

Files:
  lib/Driver/ToolChains/Arch/AArch64.cpp
  lib/Driver/ToolChains/Arch/AArch64.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/CommonArgs.cpp
  test/Driver/aarch64-cpus.c

Index: test/Driver/aarch64-cpus.c
===
--- test/Driver/aarch64-cpus.c
+++ test/Driver/aarch64-cpus.c
@@ -21,7 +21,10 @@
 // ARM64-NATIVE-NOT: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "native"
 
 // RUN: %clang -target arm64-apple-darwin -arch arm64 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-DARWIN %s
+// RUN: %clang -target arm64-apple-darwin -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-DARWIN %s
+// RUN: %clang -target arm64-apple-ios12.0 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-DARWIN %s
 // ARM64-DARWIN: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "cyclone"
+// ARM64-DARWIN-SAME: "-target-feature" "+aes"
 
 // RUN: %clang -target aarch64 -mcpu=cortex-a35 -### -c %s 2>&1 | FileCheck -check-prefix=CA35 %s
 // RUN: %clang -target aarch64 -mlittle-endian -mcpu=cortex-a35 -### -c %s 2>&1 | FileCheck -check-prefix=CA35 %s
Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -271,7 +271,7 @@
 
   case llvm::Triple::aarch64:
   case llvm::Triple::aarch64_be:
-return aarch64::getAArch64TargetCPU(Args, A);
+return aarch64::getAArch64TargetCPU(Args, T, A);
 
   case llvm::Triple::arm:
   case llvm::Triple::armeb:
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -341,7 +341,7 @@
 break;
   case llvm::Triple::aarch64:
   case llvm::Triple::aarch64_be:
-aarch64::getAArch64TargetFeatures(D, Args, Features);
+aarch64::getAArch64TargetFeatures(D, Triple, Args, Features);
 break;
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
Index: lib/Driver/ToolChains/Arch/AArch64.h
===
--- lib/Driver/ToolChains/Arch/AArch64.h
+++ lib/Driver/ToolChains/Arch/AArch64.h
@@ -21,11 +21,12 @@
 namespace tools {
 namespace aarch64 {
 
-void getAArch64TargetFeatures(const Driver , const llvm::opt::ArgList ,
+void getAArch64TargetFeatures(const Driver , const llvm::Triple ,
+  const llvm::opt::ArgList ,
   std::vector );
 
 std::string getAArch64TargetCPU(const llvm::opt::ArgList ,
-llvm::opt::Arg *);
+const llvm::Triple , llvm::opt::Arg *);
 
 } // end namespace aarch64
 } // end namespace target
Index: lib/Driver/ToolChains/Arch/AArch64.cpp
===
--- lib/Driver/ToolChains/Arch/AArch64.cpp
+++ lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -19,10 +19,17 @@
 using namespace clang;
 using namespace llvm::opt;
 
+/// \returns true if the given triple can determine the default CPU type even
+/// if -arch is not specified.
+static bool isCPUDeterminedByTriple(const llvm::Triple ) {
+  return Triple.isOSDarwin();
+}
+
 /// getAArch64TargetCPU - Get the (LLVM) name of the AArch64 cpu we are
 /// targeting. Set \p A to the Arg corresponding to the -mcpu argument if it is
 /// provided, or to nullptr otherwise.
-std::string aarch64::getAArch64TargetCPU(const ArgList , Arg *) {
+std::string aarch64::getAArch64TargetCPU(const ArgList ,
+ const llvm::Triple , Arg *) {
   std::string CPU;
   // If we have -mcpu, use that.
   if ((A = Args.getLastArg(options::OPT_mcpu_EQ))) {
@@ -36,9 +43,9 @@
   else if (CPU.size())
 return CPU;
 
-  // Make sure we pick "cyclone" if -arch is used.
-  // FIXME: Should this be picked by checking the target triple instead?
-  if (Args.getLastArg(options::OPT_arch))
+  // Make sure we pick "cyclone" if -arch is used or when targetting a Darwin
+  // OS.
+  if (Args.getLastArg(options::OPT_arch) || Triple.isOSDarwin())
 return "cyclone";
 
   return "generic";
@@ -152,7 +159,9 @@
   return getAArch64MicroArchFeaturesFromMtune(D, CPU, Args, Features);
 }
 
-void aarch64::getAArch64TargetFeatures(const Driver , const ArgList ,
+void aarch64::getAArch64TargetFeatures(const Driver 

r349230 - Move static analyzer core diagnostics to common.

2018-12-14 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Fri Dec 14 18:30:16 2018
New Revision: 349230

URL: http://llvm.org/viewvc/llvm-project?rev=349230=rev
Log:
Move static analyzer core diagnostics to common.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
cfe/trunk/lib/StaticAnalyzer/Core/CheckerRegistry.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td?rev=349230=349229=349230=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td Fri Dec 14 18:30:16 
2018
@@ -290,4 +290,10 @@ def err_openclcxx_not_supported : Error<
 // OpenMP
 def err_omp_more_one_clause : Error<
   "directive '#pragma omp %0' cannot contain more than one '%1' 
clause%select{| with '%3' name modifier| with 'source' dependence}2">;
+
+// Static Analyzer Core
+def err_unknown_analyzer_checker : Error<
+"no analyzer checkers are associated with '%0'">;
+def note_suggest_disabling_all_checkers : Note<
+"use -analyzer-disable-all-checks to disable all static analyzer 
checkers">;
 }

Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=349230=349229=349230=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Fri Dec 14 
18:30:16 2018
@@ -160,11 +160,6 @@ def warn_unknown_warning_specifier : War
 "unknown %0 warning specifier: '%1'">,
 InGroup;
 
-def err_unknown_analyzer_checker : Error<
-"no analyzer checkers are associated with '%0'">;
-def note_suggest_disabling_all_checkers : Note<
-"use -analyzer-disable-all-checks to disable all static analyzer 
checkers">;
-
 def warn_incompatible_analyzer_plugin_api : Warning<
 "checker plugin '%0' is not compatible with this version of the analyzer">,
 InGroup >;

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CheckerRegistry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CheckerRegistry.cpp?rev=349230=349229=349230=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/CheckerRegistry.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CheckerRegistry.cpp Fri Dec 14 18:30:16 
2018
@@ -10,7 +10,6 @@
 #include "clang/StaticAnalyzer/Core/CheckerRegistry.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/LLVM.h"
-#include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
 #include "llvm/ADT/STLExtras.h"


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


[PATCH] D55671: [analyzer] Don't pretend that unknown block calls have one null parameter.

2018-12-14 Thread Phabricator via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349229: [analyzer] Fix unknown block calls to have zero 
parameters. (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55671?vs=178130=178331#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55671

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
  cfe/trunk/test/Analysis/osobject-retain-release.cpp


Index: cfe/trunk/test/Analysis/osobject-retain-release.cpp
===
--- cfe/trunk/test/Analysis/osobject-retain-release.cpp
+++ cfe/trunk/test/Analysis/osobject-retain-release.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core,osx 
-analyzer-output=text -verify %s
+// RUN: %clang_analyze_cc1 -fblocks -analyze -analyzer-output=text\
+// RUN:-analyzer-checker=core,osx -verify %s
 
 struct OSMetaClass;
 
@@ -399,3 +400,11 @@
   arr->release(); // +0
   return arr->getCount();
 }
+
+OSObject *getObject();
+typedef bool (^Blk)(OSObject *);
+
+void test_escape_to_unknown_block(Blk blk) {
+  blk(getObject()); // no-crash
+}
+
Index: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -837,7 +837,7 @@
 ArrayRef BlockCall::parameters() const {
   const BlockDecl *D = getDecl();
   if (!D)
-return nullptr;
+return None;
   return D->parameters();
 }
 


Index: cfe/trunk/test/Analysis/osobject-retain-release.cpp
===
--- cfe/trunk/test/Analysis/osobject-retain-release.cpp
+++ cfe/trunk/test/Analysis/osobject-retain-release.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core,osx -analyzer-output=text -verify %s
+// RUN: %clang_analyze_cc1 -fblocks -analyze -analyzer-output=text\
+// RUN:-analyzer-checker=core,osx -verify %s
 
 struct OSMetaClass;
 
@@ -399,3 +400,11 @@
   arr->release(); // +0
   return arr->getCount();
 }
+
+OSObject *getObject();
+typedef bool (^Blk)(OSObject *);
+
+void test_escape_to_unknown_block(Blk blk) {
+  blk(getObject()); // no-crash
+}
+
Index: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -837,7 +837,7 @@
 ArrayRef BlockCall::parameters() const {
   const BlockDecl *D = getDecl();
   if (!D)
-return nullptr;
+return None;
   return D->parameters();
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55543: [CodeGen] Fix assertion on throwing object with inlined inherited constructor and non-trivial destructor.

2018-12-14 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

In D55543#1329288 , @vsapsai wrote:

> In D55543#1328025 , @rjmccall wrote:
>
> > Nice catch.  This also fixes problems where there might be cleanups entered 
> > by `EmitParmDecl`, e.g. in ObjC++ with a parameter of type `struct A { 
> > __strong id x; }`; could you please add a test for that and verify that the 
> > parameter is destroyed at an appropriate point in the inlined call?
>
>
> Aha, I see we have at least `EHStack.pushCleanup` in 
> `EmitParmDecl`. Will make sure to add a test that executes this code path.


The way I understand the comment, we cannot make a parameter of type `struct A` 
to have a cleanup specific to 
`CodeGenFunction::EmitInlinedInheritingCXXConstructorCall`. It calls 
`EmitParmDecl` but does it only for implicit parameters. And I am struggling to 
make `struct A` an implicit parameter.

Nevertheless, my change causes different exception-handling behaviour. Need to 
check further if it is ARC-related or inherited constructor-related.


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

https://reviews.llvm.org/D55543



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


r349229 - [analyzer] Fix unknown block calls to have zero parameters.

2018-12-14 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Fri Dec 14 18:13:26 2018
New Revision: 349229

URL: http://llvm.org/viewvc/llvm-project?rev=349229=rev
Log:
[analyzer] Fix unknown block calls to have zero parameters.

Right now they report to have one parameter with null decl,
because initializing an ArrayRef of pointers with a nullptr
yields an ArrayRef to an array of one null pointer.

Fixes a crash in the OSObject section of RetainCountChecker.

Differential Revision: https://reviews.llvm.org/D55671

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
cfe/trunk/test/Analysis/osobject-retain-release.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp?rev=349229=349228=349229=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp Fri Dec 14 18:13:26 2018
@@ -837,7 +837,7 @@ const BlockDataRegion *BlockCall::getBlo
 ArrayRef BlockCall::parameters() const {
   const BlockDecl *D = getDecl();
   if (!D)
-return nullptr;
+return None;
   return D->parameters();
 }
 

Modified: cfe/trunk/test/Analysis/osobject-retain-release.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/osobject-retain-release.cpp?rev=349229=349228=349229=diff
==
--- cfe/trunk/test/Analysis/osobject-retain-release.cpp (original)
+++ cfe/trunk/test/Analysis/osobject-retain-release.cpp Fri Dec 14 18:13:26 2018
@@ -1,4 +1,5 @@
-// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core,osx 
-analyzer-output=text -verify %s
+// RUN: %clang_analyze_cc1 -fblocks -analyze -analyzer-output=text\
+// RUN:-analyzer-checker=core,osx -verify %s
 
 struct OSMetaClass;
 
@@ -399,3 +400,11 @@ unsigned int ok_release_with_unknown_sou
   arr->release(); // +0
   return arr->getCount();
 }
+
+OSObject *getObject();
+typedef bool (^Blk)(OSObject *);
+
+void test_escape_to_unknown_block(Blk blk) {
+  blk(getObject()); // no-crash
+}
+


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


[PATCH] D55680: [analyzer] ObjCDealloc: Fix a crash when a class attempts to deallocate another class.

2018-12-14 Thread Phabricator via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349228: [analyzer] ObjCDealloc: Fix a crash when a class 
attempts to deallocate a class. (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55680?vs=178146=178330#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55680

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
  cfe/trunk/test/Analysis/MissingDealloc.m


Index: cfe/trunk/test/Analysis/MissingDealloc.m
===
--- cfe/trunk/test/Analysis/MissingDealloc.m
+++ cfe/trunk/test/Analysis/MissingDealloc.m
@@ -183,4 +183,17 @@
 @implementation NonNSObjectMissingDealloc
 @end
 
-// CHECK: 4 warnings generated.
+
+//======
+// Don't crash on calls to dealloc as a class method.
+
+@interface DeallocingClass : NSObject {}
+@end
+@implementation DeallocingClass
+- (void)dealloc {
+  [DeallocingClass dealloc]; // FIXME: Should we warn on this specifically?
+}
+#if NON_ARC
+// expected-warning@-2{{method possibly missing a [super dealloc] call}}
+#endif
+@end
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
@@ -715,6 +715,10 @@
 bool ObjCDeallocChecker::diagnoseMistakenDealloc(SymbolRef DeallocedValue,
  const ObjCMethodCall ,
  CheckerContext ) const {
+  // TODO: Apart from unknown/undefined receivers, this may happen when
+  // dealloc is called as a class method. Should we warn?
+  if (!DeallocedValue)
+return false;
 
   // Find the property backing the instance variable that M
   // is dealloc'ing.


Index: cfe/trunk/test/Analysis/MissingDealloc.m
===
--- cfe/trunk/test/Analysis/MissingDealloc.m
+++ cfe/trunk/test/Analysis/MissingDealloc.m
@@ -183,4 +183,17 @@
 @implementation NonNSObjectMissingDealloc
 @end
 
-// CHECK: 4 warnings generated.
+
+//======
+// Don't crash on calls to dealloc as a class method.
+
+@interface DeallocingClass : NSObject {}
+@end
+@implementation DeallocingClass
+- (void)dealloc {
+  [DeallocingClass dealloc]; // FIXME: Should we warn on this specifically?
+}
+#if NON_ARC
+// expected-warning@-2{{method possibly missing a [super dealloc] call}}
+#endif
+@end
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
@@ -715,6 +715,10 @@
 bool ObjCDeallocChecker::diagnoseMistakenDealloc(SymbolRef DeallocedValue,
  const ObjCMethodCall ,
  CheckerContext ) const {
+  // TODO: Apart from unknown/undefined receivers, this may happen when
+  // dealloc is called as a class method. Should we warn?
+  if (!DeallocedValue)
+return false;
 
   // Find the property backing the instance variable that M
   // is dealloc'ing.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r349228 - [analyzer] ObjCDealloc: Fix a crash when a class attempts to deallocate a class.

2018-12-14 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Fri Dec 14 18:09:02 2018
New Revision: 349228

URL: http://llvm.org/viewvc/llvm-project?rev=349228=rev
Log:
[analyzer] ObjCDealloc: Fix a crash when a class attempts to deallocate a class.

The checker wasn't prepared to see the dealloc message sent to the class itself
rather than to an instance, as if it was +dealloc.

Additionally, it wasn't prepared for pure-unknown or undefined self values.
The new guard covers that as well, but it is annoying to test because
both kinds of values shouldn't really appear and we generally want to
get rid of all of them (by modeling unknown values with symbols and
by warning on use of undefined values before they are used).

The CHECK: directive for FileCheck at the end of the test looks useless,
so i removed it.

Differential Revision: https://reviews.llvm.org/D55680

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
cfe/trunk/test/Analysis/MissingDealloc.m

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp?rev=349228=349227=349228=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp Fri Dec 14 
18:09:02 2018
@@ -715,6 +715,10 @@ bool ObjCDeallocChecker::diagnoseExtraRe
 bool ObjCDeallocChecker::diagnoseMistakenDealloc(SymbolRef DeallocedValue,
  const ObjCMethodCall ,
  CheckerContext ) const {
+  // TODO: Apart from unknown/undefined receivers, this may happen when
+  // dealloc is called as a class method. Should we warn?
+  if (!DeallocedValue)
+return false;
 
   // Find the property backing the instance variable that M
   // is dealloc'ing.

Modified: cfe/trunk/test/Analysis/MissingDealloc.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/MissingDealloc.m?rev=349228=349227=349228=diff
==
--- cfe/trunk/test/Analysis/MissingDealloc.m (original)
+++ cfe/trunk/test/Analysis/MissingDealloc.m Fri Dec 14 18:09:02 2018
@@ -183,4 +183,17 @@ __attribute__((objc_root_class))
 @implementation NonNSObjectMissingDealloc
 @end
 
-// CHECK: 4 warnings generated.
+
+//======
+// Don't crash on calls to dealloc as a class method.
+
+@interface DeallocingClass : NSObject {}
+@end
+@implementation DeallocingClass
+- (void)dealloc {
+  [DeallocingClass dealloc]; // FIXME: Should we warn on this specifically?
+}
+#if NON_ARC
+// expected-warning@-2{{method possibly missing a [super dealloc] call}}
+#endif
+@end


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


[PATCH] D55458: [analyzer] ObjCContainers: Track index values.

2018-12-14 Thread Phabricator via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349227: [analyzer] ObjCContainers: Track index values. 
(authored by dergachev, committed by ).

Repository:
  rC Clang

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

https://reviews.llvm.org/D55458

Files:
  lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp
  test/Analysis/CFContainers.mm

Index: test/Analysis/CFContainers.mm
===
--- test/Analysis/CFContainers.mm
+++ test/Analysis/CFContainers.mm
@@ -1,4 +1,7 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=osx.coreFoundation.containers.PointerSizedValues,osx.coreFoundation.containers.OutOfBounds -analyzer-store=region -triple x86_64-apple-darwin -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin -analyzer-output=text\
+// RUN: -analyzer-checker=osx.coreFoundation.containers.PointerSizedValues\
+// RUN: -analyzer-checker=osx.coreFoundation.containers.OutOfBounds\
+// RUN: -verify %s
 
 typedef const struct __CFAllocator * CFAllocatorRef;
 typedef const struct __CFString * CFStringRef;
@@ -94,17 +97,21 @@
 #define CFSTR(cStr)  ((CFStringRef) __builtin___CFStringMakeConstantString ("" cStr ""))
 #define NULL __null
 
-// Done with the headers. 
+// Done with the headers.
 // Test alpha.osx.cocoa.ContainerAPI checker.
 void testContainers(int **xNoWarn, CFIndex count) {
   int x[] = { 1, 2, 3 };
-  CFArrayRef foo = CFArrayCreate(kCFAllocatorDefault, (const void **) x, sizeof(x) / sizeof(x[0]), 0);// expected-warning {{The second argument to 'CFArrayCreate' must be a C array of pointer-sized}}
+  CFArrayRef foo = CFArrayCreate(kCFAllocatorDefault, (const void **) x, sizeof(x) / sizeof(x[0]), 0);
+  // expected-warning@-1 {{The second argument to 'CFArrayCreate' must be a C array of pointer-sized}}
+  // expected-note@-2{{The second argument to 'CFArrayCreate' must be a C array of pointer-sized}}
 
   CFArrayRef fooNoWarn = CFArrayCreate(kCFAllocatorDefault, (const void **) xNoWarn, sizeof(xNoWarn) / sizeof(xNoWarn[0]), 0); // no warning
   CFArrayRef fooNoWarn2 = CFArrayCreate(kCFAllocatorDefault, 0, sizeof(xNoWarn) / sizeof(xNoWarn[0]), 0);// no warning, passing in 0
   CFArrayRef fooNoWarn3 = CFArrayCreate(kCFAllocatorDefault, NULL, sizeof(xNoWarn) / sizeof(xNoWarn[0]), 0);// no warning, passing in NULL
 
-  CFSetRef set = CFSetCreate(NULL, (const void **)x, 3, ); // expected-warning {{The second argument to 'CFSetCreate' must be a C array of pointer-sized values}}
+  CFSetRef set = CFSetCreate(NULL, (const void **)x, 3, );
+  // expected-warning@-1 {{The second argument to 'CFSetCreate' must be a C array of pointer-sized values}}
+  // expected-note@-2{{The second argument to 'CFSetCreate' must be a C array of pointer-sized values}}
   CFArrayRef* pairs = new CFArrayRef[count];
   CFSetRef fSet = CFSetCreate(kCFAllocatorDefault, (const void**) pairs, count - 1, );// no warning
 }
@@ -126,8 +133,13 @@
   const CFDictionaryKeyCallBacks keyCB = kCFCopyStringDictionaryKeyCallBacks;
   const CFDictionaryValueCallBacks valCB = kCFTypeDictionaryValueCallBacks;
   CFDictionaryRef dict1 = CFDictionaryCreate(kCFAllocatorDefault, (const void**)keys, (const void**)values, numValues, , ); // no warning
-  CFDictionaryRef dict2 = CFDictionaryCreate(kCFAllocatorDefault, (const void**)elems[0], (const void**)values, numValues, , ); //expected-warning {{The second argument to 'CFDictionaryCreate' must be a C array of}} expected-warning {{cast to 'const void **' from smaller integer type 'int'}}
-  CFDictionaryRef dict3 = CFDictionaryCreate(kCFAllocatorDefault, (const void**)keys, (const void**)elems, numValues, , ); // expected-warning {{The third argument to 'CFDictionaryCreate' must be a C array of pointer-sized values}}
+  CFDictionaryRef dict2 = CFDictionaryCreate(kCFAllocatorDefault, (const void**)elems[0], (const void**)values, numValues, , );
+  // expected-warning@-1 {{The second argument to 'CFDictionaryCreate' must be a C array of}}
+  // expected-note@-2{{The second argument to 'CFDictionaryCreate' must be a C array of}}
+  // expected-warning@-3{{cast to 'const void **' from smaller integer type 'int'}}
+  CFDictionaryRef dict3 = CFDictionaryCreate(kCFAllocatorDefault, (const void**)keys, (const void**)elems, numValues, , );
+  // expected-warning@-1 {{The third argument to 'CFDictionaryCreate' must be a C array of pointer-sized values}}
+  // expected-note@-2{{The third argument to 'CFDictionaryCreate' must be a C array of pointer-sized values}}
 }
 
 void OutOfBoundsSymbolicOffByOne(const void ** input, CFIndex S) {
@@ -136,6 +148,7 @@
   const void *s1 = CFArrayGetValueAtIndex(array, 0);   // no warning
   const void *s2 = CFArrayGetValueAtIndex(array, S-1); // no warning
   const void *s3 = CFArrayGetValueAtIndex(array, S);   // expected-warning {{Index is out of 

r349227 - [analyzer] ObjCContainers: Track index values.

2018-12-14 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Fri Dec 14 18:06:13 2018
New Revision: 349227

URL: http://llvm.org/viewvc/llvm-project?rev=349227=rev
Log:
[analyzer] ObjCContainers: Track index values.

Use trackExpressionValue() (previously known as trackNullOrUndefValue())
to track index value in the report, so that the user knew
what Static Analyzer thinks the index is.

Additionally, implement printState() to help debugging the checker later.

Differential Revision: https://reviews.llvm.org/D55458

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp
cfe/trunk/test/Analysis/CFContainers.mm

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp?rev=349227=349226=349227=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp Fri Dec 14 
18:06:13 2018
@@ -57,6 +57,9 @@ public:
  const InvalidatedSymbols ,
  const CallEvent *Call,
  PointerEscapeKind Kind) const;
+
+  void printState(raw_ostream , ProgramStateRef State,
+  const char *NL, const char *Sep) const;
 };
 } // end anonymous namespace
 
@@ -144,6 +147,8 @@ void ObjCContainersChecker::checkPreStmt
   initBugType();
   auto R = llvm::make_unique(*BT, "Index is out of bounds", N);
   R->addRange(IdxExpr->getSourceRange());
+  bugreporter::trackExpressionValue(N, IdxExpr, *R,
+/*EnableNullFPSuppression=*/false);
   C.emitReport(std::move(R));
   return;
 }
@@ -166,6 +171,18 @@ ObjCContainersChecker::checkPointerEscap
   return State;
 }
 
+void ObjCContainersChecker::printState(raw_ostream , ProgramStateRef State,
+   const char *NL, const char *Sep) const {
+  ArraySizeMapTy Map = State->get();
+  if (Map.isEmpty())
+return;
+
+  OS << Sep << "ObjC container sizes :" << NL;
+  for (auto I : Map) {
+OS << I.first << " : " << I.second << NL;
+  }
+}
+
 /// Register checker.
 void ento::registerObjCContainersChecker(CheckerManager ) {
   mgr.registerChecker();

Modified: cfe/trunk/test/Analysis/CFContainers.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/CFContainers.mm?rev=349227=349226=349227=diff
==
--- cfe/trunk/test/Analysis/CFContainers.mm (original)
+++ cfe/trunk/test/Analysis/CFContainers.mm Fri Dec 14 18:06:13 2018
@@ -1,4 +1,7 @@
-// RUN: %clang_analyze_cc1 
-analyzer-checker=osx.coreFoundation.containers.PointerSizedValues,osx.coreFoundation.containers.OutOfBounds
 -analyzer-store=region -triple x86_64-apple-darwin -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin -analyzer-output=text\
+// RUN: -analyzer-checker=osx.coreFoundation.containers.PointerSizedValues\
+// RUN: -analyzer-checker=osx.coreFoundation.containers.OutOfBounds\
+// RUN: -verify %s
 
 typedef const struct __CFAllocator * CFAllocatorRef;
 typedef const struct __CFString * CFStringRef;
@@ -94,17 +97,21 @@ CFSetRef CFSetCreate(CFAllocatorRef allo
 #define CFSTR(cStr)  ((CFStringRef) __builtin___CFStringMakeConstantString ("" 
cStr ""))
 #define NULL __null
 
-// Done with the headers. 
+// Done with the headers.
 // Test alpha.osx.cocoa.ContainerAPI checker.
 void testContainers(int **xNoWarn, CFIndex count) {
   int x[] = { 1, 2, 3 };
-  CFArrayRef foo = CFArrayCreate(kCFAllocatorDefault, (const void **) x, 
sizeof(x) / sizeof(x[0]), 0);// expected-warning {{The second argument to 
'CFArrayCreate' must be a C array of pointer-sized}}
+  CFArrayRef foo = CFArrayCreate(kCFAllocatorDefault, (const void **) x, 
sizeof(x) / sizeof(x[0]), 0);
+  // expected-warning@-1 {{The second argument to 'CFArrayCreate' must be a C 
array of pointer-sized}}
+  // expected-note@-2{{The second argument to 'CFArrayCreate' must be a C 
array of pointer-sized}}
 
   CFArrayRef fooNoWarn = CFArrayCreate(kCFAllocatorDefault, (const void **) 
xNoWarn, sizeof(xNoWarn) / sizeof(xNoWarn[0]), 0); // no warning
   CFArrayRef fooNoWarn2 = CFArrayCreate(kCFAllocatorDefault, 0, 
sizeof(xNoWarn) / sizeof(xNoWarn[0]), 0);// no warning, passing in 0
   CFArrayRef fooNoWarn3 = CFArrayCreate(kCFAllocatorDefault, NULL, 
sizeof(xNoWarn) / sizeof(xNoWarn[0]), 0);// no warning, passing in NULL
 
-  CFSetRef set = CFSetCreate(NULL, (const void **)x, 3, ); 
// expected-warning {{The second argument to 'CFSetCreate' must be a C array of 
pointer-sized values}}
+  CFSetRef set = CFSetCreate(NULL, (const void **)x, 3, );
+  // expected-warning@-1 {{The second argument to 'CFSetCreate' must be a C 
array of pointer-sized values}}
+  // expected-note@-2{{The second 

[PATCH] D55458: [analyzer] ObjCContainers: Track index values.

2018-12-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

These are boring, i guess i just commit.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55458



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


[PATCH] D55388: [analyzer] MoveChecker Pt.8: Add checks for dereferencing a smart pointer after move.

2018-12-14 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349226: [analyzer] MoveChecker: Add checks for dereferencing 
a smart pointer after move. (authored by dergachev, committed by ).

Repository:
  rC Clang

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

https://reviews.llvm.org/D55388

Files:
  lib/StaticAnalyzer/Checkers/MoveChecker.cpp
  test/Analysis/use-after-move.cpp

Index: test/Analysis/use-after-move.cpp
===
--- test/Analysis/use-after-move.cpp
+++ test/Analysis/use-after-move.cpp
@@ -1,20 +1,26 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.cplusplus.Move -verify %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
-// RUN:  -analyzer-config exploration_strategy=unexplored_first_queue
+// RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
+// RUN:  -analyzer-checker debug.ExprInspection
 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.cplusplus.Move -verify %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
-// RUN:  -analyzer-config exploration_strategy=dfs -DDFS=1
+// RUN:  -analyzer-config exploration_strategy=dfs -DDFS=1\
+// RUN:  -analyzer-checker debug.ExprInspection
 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.cplusplus.Move -verify %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
-// RUN:  -analyzer-config alpha.cplusplus.Move:Aggressive=true -DAGGRESSIVE
+// RUN:  -analyzer-config alpha.cplusplus.Move:Aggressive=true -DAGGRESSIVE\
+// RUN:  -analyzer-checker debug.ExprInspection
 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.cplusplus.Move -verify %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=dfs -DDFS=1\
-// RUN:  -analyzer-config alpha.cplusplus.Move:Aggressive=true -DAGGRESSIVE
+// RUN:  -analyzer-config alpha.cplusplus.Move:Aggressive=true -DAGGRESSIVE\
+// RUN:  -analyzer-checker debug.ExprInspection
 
 #include "Inputs/system-header-simulator-cxx.h"
 
+void clang_analyzer_warnIfReached();
+
 class B {
 public:
   B() = default;
@@ -810,7 +816,19 @@
 // expected-note@-4{{Object 'P' is moved}}
 // expected-note@-4{{Method called on moved-from object 'P'}}
 #endif
-*P += 1; // FIXME: Should warn that the pointer is null.
+
+// Because that well-defined state is null, dereference is still UB.
+// Note that in aggressive mode we already warned about 'P',
+// so no extra warning is generated.
+*P += 1;
+#ifndef AGGRESSIVE
+// expected-warning@-2{{Dereference of null smart pointer 'P' of type 'std::unique_ptr'}}
+// expected-note@-14{{Smart pointer 'P' of type 'std::unique_ptr' is reset to null when moved from}}
+// expected-note@-4{{Dereference of null smart pointer 'P' of type 'std::unique_ptr'}}
+#endif
+
+// The program should have crashed by now.
+clang_analyzer_warnIfReached(); // no-warning
   }
 };
 
@@ -827,3 +845,9 @@
   P.get(); // expected-warning{{Method called on moved-from object 'P'}}
// expected-note@-1{{Method called on moved-from object 'P'}}
 }
+
+void localUniquePtrWithArrow(std::unique_ptr P) {
+  std::unique_ptr Q = std::move(P); // expected-note{{Smart pointer 'P' of type 'std::unique_ptr' is reset to null when moved from}}
+  P->foo(); // expected-warning{{Dereference of null smart pointer 'P' of type 'std::unique_ptr'}}
+// expected-note@-1{{Dereference of null smart pointer 'P' of type 'std::unique_ptr'}}
+}
Index: lib/StaticAnalyzer/Checkers/MoveChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MoveChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MoveChecker.cpp
@@ -61,19 +61,35 @@
   const char *NL, const char *Sep) const override;
 
 private:
-  enum MisuseKind { MK_FunCall, MK_Copy, MK_Move };
+  enum MisuseKind { MK_FunCall, MK_Copy, MK_Move, MK_Dereference };
+  enum StdObjectKind { SK_NonStd, SK_Unsafe, SK_Safe, SK_SmartPtr };
+
+  static bool misuseCausesCrash(MisuseKind MK) {
+return MK == MK_Dereference;
+  }
 
   struct ObjectKind {
-bool Local : 1; // Is this a local variable or a local rvalue reference?
-bool STL : 1; // Is this an object of a standard type?
+// Is this a local variable or a local rvalue reference?
+bool IsLocal : 1;
+// Is this an STL object? If so, of what kind?
+StdObjectKind StdKind : 2;
+  };
+
+  // STL smart pointers are automatically re-initialized to null when moved
+  // from. So we can't warn on many methods, but we can warn when it is
+  // dereferenced, which is UB even if the resulting lvalue never gets read.
+  const llvm::StringSet<> StdSmartPtrClasses = {
+  "shared_ptr",
+  "unique_ptr",
+  "weak_ptr",
   };
 
  

r349226 - [analyzer] MoveChecker: Add checks for dereferencing a smart pointer after move.

2018-12-14 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Fri Dec 14 17:53:38 2018
New Revision: 349226

URL: http://llvm.org/viewvc/llvm-project?rev=349226=rev
Log:
[analyzer] MoveChecker: Add checks for dereferencing a smart pointer after move.

Calling operator*() or operator->() on a null STL smart pointer is
undefined behavior.

Smart pointers are specified to become null after being moved from.
So we can't warn on arbitrary method calls, but these two operators
definitely make no sense.

The new bug is fatal because it's an immediate UB,
unlike other use-after-move bugs.

The work on a more generic null smart pointer dereference checker
is still pending.

Differential Revision: https://reviews.llvm.org/D55388

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
cfe/trunk/test/Analysis/use-after-move.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp?rev=349226=349225=349226=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp Fri Dec 14 17:53:38 
2018
@@ -61,19 +61,35 @@ public:
   const char *NL, const char *Sep) const override;
 
 private:
-  enum MisuseKind { MK_FunCall, MK_Copy, MK_Move };
+  enum MisuseKind { MK_FunCall, MK_Copy, MK_Move, MK_Dereference };
+  enum StdObjectKind { SK_NonStd, SK_Unsafe, SK_Safe, SK_SmartPtr };
+
+  static bool misuseCausesCrash(MisuseKind MK) {
+return MK == MK_Dereference;
+  }
 
   struct ObjectKind {
-bool Local : 1; // Is this a local variable or a local rvalue reference?
-bool STL : 1; // Is this an object of a standard type?
+// Is this a local variable or a local rvalue reference?
+bool IsLocal : 1;
+// Is this an STL object? If so, of what kind?
+StdObjectKind StdKind : 2;
+  };
+
+  // STL smart pointers are automatically re-initialized to null when moved
+  // from. So we can't warn on many methods, but we can warn when it is
+  // dereferenced, which is UB even if the resulting lvalue never gets read.
+  const llvm::StringSet<> StdSmartPtrClasses = {
+  "shared_ptr",
+  "unique_ptr",
+  "weak_ptr",
   };
 
   // Not all of these are entirely move-safe, but they do provide *some*
   // guarantees, and it means that somebody is using them after move
   // in a valid manner.
-  // TODO: We can still try to identify *unsafe* use after move, such as
-  // dereference of a moved-from smart pointer (which is guaranteed to be 
null).
-  const llvm::StringSet<> StandardMoveSafeClasses = {
+  // TODO: We can still try to identify *unsafe* use after move,
+  // like we did with smart pointers.
+  const llvm::StringSet<> StdSafeClasses = {
   "basic_filebuf",
   "basic_ios",
   "future",
@@ -82,11 +98,8 @@ private:
   "promise",
   "shared_future",
   "shared_lock",
-  "shared_ptr",
   "thread",
-  "unique_ptr",
   "unique_lock",
-  "weak_ptr",
   };
 
   // Should we bother tracking the state of the object?
@@ -97,10 +110,25 @@ private:
 // their user to re-use the storage. The latter is possible because STL
 // objects are known to end up in a valid but unspecified state after the
 // move and their state-reset methods are also known, which allows us to
-// predict precisely when use-after-move is invalid. In aggressive mode,
-// warn on any use-after-move because the user has intentionally asked us
-// to completely eliminate use-after-move in his code.
-return IsAggressive || OK.Local || OK.STL;
+// predict precisely when use-after-move is invalid.
+// Some STL objects are known to conform to additional contracts after 
move,
+// so they are not tracked. However, smart pointers specifically are 
tracked
+// because we can perform extra checking over them.
+// In aggressive mode, warn on any use-after-move because the user has
+// intentionally asked us to completely eliminate use-after-move
+// in his code.
+return IsAggressive || OK.IsLocal
+|| OK.StdKind == SK_Unsafe || OK.StdKind == 
SK_SmartPtr;
+  }
+
+  // Some objects only suffer from some kinds of misuses, but we need to track
+  // them anyway because we cannot know in advance what misuse will we find.
+  bool shouldWarnAbout(ObjectKind OK, MisuseKind MK) const {
+// Additionally, only warn on smart pointers when they are dereferenced (or
+// local or we are aggressive).
+return shouldBeTracked(OK) &&
+   (IsAggressive || OK.IsLocal
+ || OK.StdKind != SK_SmartPtr || MK == MK_Dereference);
   }
 
   // Obtains ObjectKind of an object. Because class declaration cannot always
@@ -108,17 +136,17 @@ private:
   ObjectKind classifyObject(const MemRegion *MR, const CXXRecordDecl *RD) 
const;
 
   // Classifies the object and dumps 

r349225 - [analyzer] MoveChecker: NFC: De-duplicate a few checks.

2018-12-14 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Fri Dec 14 17:50:58 2018
New Revision: 349225

URL: http://llvm.org/viewvc/llvm-project?rev=349225=rev
Log:
[analyzer] MoveChecker: NFC: De-duplicate a few checks.

No functional change intended.

Differential Revision: https://reviews.llvm.org/D55387

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp?rev=349225=349224=349225=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp Fri Dec 14 17:50:58 
2018
@@ -89,6 +89,20 @@ private:
   "weak_ptr",
   };
 
+  // Should we bother tracking the state of the object?
+  bool shouldBeTracked(ObjectKind OK) const {
+// In non-aggressive mode, only warn on use-after-move of local variables
+// (or local rvalue references) and of STL objects. The former is possible
+// because local variables (or local rvalue references) are not tempting
+// their user to re-use the storage. The latter is possible because STL
+// objects are known to end up in a valid but unspecified state after the
+// move and their state-reset methods are also known, which allows us to
+// predict precisely when use-after-move is invalid. In aggressive mode,
+// warn on any use-after-move because the user has intentionally asked us
+// to completely eliminate use-after-move in his code.
+return IsAggressive || OK.Local || OK.STL;
+  }
+
   // Obtains ObjectKind of an object. Because class declaration cannot always
   // be easily obtained from the memory region, it is supplied separately.
   ObjectKind classifyObject(const MemRegion *MR, const CXXRecordDecl *RD) 
const;
@@ -136,8 +150,20 @@ public:
 
 private:
   mutable std::unique_ptr BT;
+
+  // Check if the given form of potential misuse of a given object
+  // should be reported. If so, get it reported. The callback from which
+  // this function was called should immediately return after the call
+  // because this function adds one or two transitions.
+  void modelUse(ProgramStateRef State, const MemRegion *Region,
+const CXXRecordDecl *RD, MisuseKind MK,
+CheckerContext ) const;
+
+  // Returns the exploded node against which the report was emitted.
+  // The caller *must* add any further transitions against this node.
   ExplodedNode *reportBug(const MemRegion *Region, const CXXRecordDecl *RD,
   CheckerContext , MisuseKind MK) const;
+
   bool isInMoveSafeContext(const LocationContext *LC) const;
   bool isStateResetMethod(const CXXMethodDecl *MethodDec) const;
   bool isMoveSafeMethod(const CXXMethodDecl *MethodDec) const;
@@ -236,6 +262,25 @@ const ExplodedNode *MoveChecker::getMove
   return MoveNode;
 }
 
+void MoveChecker::modelUse(ProgramStateRef State, const MemRegion *Region,
+   const CXXRecordDecl *RD, MisuseKind MK,
+   CheckerContext ) const {
+  assert(!C.isDifferent() && "No transitions should have been made by now");
+  const RegionState *RS = State->get(Region);
+
+  if (!RS || isAnyBaseRegionReported(State, Region)
+  || isInMoveSafeContext(C.getLocationContext())) {
+// Finalize changes made by the caller.
+C.addTransition(State);
+return;
+  }
+
+  ExplodedNode *N = reportBug(Region, RD, C, MK);
+
+  State = State->set(Region, RegionState::getReported());
+  C.addTransition(State, N);
+}
+
 ExplodedNode *MoveChecker::reportBug(const MemRegion *Region,
  const CXXRecordDecl *RD,
  CheckerContext ,
@@ -294,12 +339,10 @@ void MoveChecker::checkPostCall(const Ca
   if (!MethodDecl)
 return;
 
-  const auto *ConstructorDecl = dyn_cast(MethodDecl);
-
-  const auto *CC = dyn_cast_or_null();
   // Check if an object became moved-from.
   // Object can become moved from after a call to move assignment operator or
   // move constructor .
+  const auto *ConstructorDecl = dyn_cast(MethodDecl);
   if (ConstructorDecl && !ConstructorDecl->isMoveConstructor())
 return;
 
@@ -310,23 +353,11 @@ void MoveChecker::checkPostCall(const Ca
   if (!ArgRegion)
 return;
 
-  // In non-aggressive mode, only warn on use-after-move of local variables (or
-  // local rvalue references) and of STL objects. The former is possible 
because
-  // local variables (or local rvalue references) are not tempting their user 
to
-  // re-use the storage. The latter is possible because STL objects are known
-  // to end up in a valid but unspecified state after the move and their
-  // state-reset methods are also known, which allows us to predict
-  // precisely when use-after-move is invalid.
-  // In aggressive mode, warn on any use-after-move because 

[PATCH] D55387: [analyzer] MoveChecker Pt.7: NFC: Misc refactoring.

2018-12-14 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349225: [analyzer] MoveChecker: NFC: De-duplicate a few 
checks. (authored by dergachev, committed by ).

Repository:
  rC Clang

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

https://reviews.llvm.org/D55387

Files:
  lib/StaticAnalyzer/Checkers/MoveChecker.cpp

Index: lib/StaticAnalyzer/Checkers/MoveChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MoveChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MoveChecker.cpp
@@ -89,6 +89,20 @@
   "weak_ptr",
   };
 
+  // Should we bother tracking the state of the object?
+  bool shouldBeTracked(ObjectKind OK) const {
+// In non-aggressive mode, only warn on use-after-move of local variables
+// (or local rvalue references) and of STL objects. The former is possible
+// because local variables (or local rvalue references) are not tempting
+// their user to re-use the storage. The latter is possible because STL
+// objects are known to end up in a valid but unspecified state after the
+// move and their state-reset methods are also known, which allows us to
+// predict precisely when use-after-move is invalid. In aggressive mode,
+// warn on any use-after-move because the user has intentionally asked us
+// to completely eliminate use-after-move in his code.
+return IsAggressive || OK.Local || OK.STL;
+  }
+
   // Obtains ObjectKind of an object. Because class declaration cannot always
   // be easily obtained from the memory region, it is supplied separately.
   ObjectKind classifyObject(const MemRegion *MR, const CXXRecordDecl *RD) const;
@@ -136,8 +150,20 @@
 
 private:
   mutable std::unique_ptr BT;
+
+  // Check if the given form of potential misuse of a given object
+  // should be reported. If so, get it reported. The callback from which
+  // this function was called should immediately return after the call
+  // because this function adds one or two transitions.
+  void modelUse(ProgramStateRef State, const MemRegion *Region,
+const CXXRecordDecl *RD, MisuseKind MK,
+CheckerContext ) const;
+
+  // Returns the exploded node against which the report was emitted.
+  // The caller *must* add any further transitions against this node.
   ExplodedNode *reportBug(const MemRegion *Region, const CXXRecordDecl *RD,
   CheckerContext , MisuseKind MK) const;
+
   bool isInMoveSafeContext(const LocationContext *LC) const;
   bool isStateResetMethod(const CXXMethodDecl *MethodDec) const;
   bool isMoveSafeMethod(const CXXMethodDecl *MethodDec) const;
@@ -236,6 +262,25 @@
   return MoveNode;
 }
 
+void MoveChecker::modelUse(ProgramStateRef State, const MemRegion *Region,
+   const CXXRecordDecl *RD, MisuseKind MK,
+   CheckerContext ) const {
+  assert(!C.isDifferent() && "No transitions should have been made by now");
+  const RegionState *RS = State->get(Region);
+
+  if (!RS || isAnyBaseRegionReported(State, Region)
+  || isInMoveSafeContext(C.getLocationContext())) {
+// Finalize changes made by the caller.
+C.addTransition(State);
+return;
+  }
+
+  ExplodedNode *N = reportBug(Region, RD, C, MK);
+
+  State = State->set(Region, RegionState::getReported());
+  C.addTransition(State, N);
+}
+
 ExplodedNode *MoveChecker::reportBug(const MemRegion *Region,
  const CXXRecordDecl *RD,
  CheckerContext ,
@@ -294,12 +339,10 @@
   if (!MethodDecl)
 return;
 
-  const auto *ConstructorDecl = dyn_cast(MethodDecl);
-
-  const auto *CC = dyn_cast_or_null();
   // Check if an object became moved-from.
   // Object can become moved from after a call to move assignment operator or
   // move constructor .
+  const auto *ConstructorDecl = dyn_cast(MethodDecl);
   if (ConstructorDecl && !ConstructorDecl->isMoveConstructor())
 return;
 
@@ -310,23 +353,11 @@
   if (!ArgRegion)
 return;
 
-  // In non-aggressive mode, only warn on use-after-move of local variables (or
-  // local rvalue references) and of STL objects. The former is possible because
-  // local variables (or local rvalue references) are not tempting their user to
-  // re-use the storage. The latter is possible because STL objects are known
-  // to end up in a valid but unspecified state after the move and their
-  // state-reset methods are also known, which allows us to predict
-  // precisely when use-after-move is invalid.
-  // In aggressive mode, warn on any use-after-move because the user
-  // has intentionally asked us to completely eliminate use-after-move
-  // in his code.
-  ObjectKind OK = classifyObject(ArgRegion, MethodDecl->getParent());
-  if (!IsAggressive && !OK.Local && !OK.STL)
-return;
-
   // Skip moving the object to itself.
+  const auto *CC = dyn_cast_or_null();
   if (CC 

[PATCH] D38675: [analyzer] MoveChecker Pt.10: Move the checker out of alpha state.

2018-12-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 178324.
NoQ retitled this revision from "[analyzer] MisusedMovedObjectChecker: Moving 
the checker out of alpha state" to "[analyzer] MoveChecker Pt.10: Move the 
checker out of alpha state.".
NoQ added a comment.

Rebase!


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

https://reviews.llvm.org/D38675

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  test/Analysis/mismatched-iterator.cpp
  test/Analysis/use-after-move.cpp

Index: test/Analysis/use-after-move.cpp
===
--- test/Analysis/use-after-move.cpp
+++ test/Analysis/use-after-move.cpp
@@ -1,30 +1,30 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.cplusplus.Move -verify %s\
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
 // RUN:  -analyzer-checker debug.ExprInspection
-// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.cplusplus.Move -verify %s\
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=dfs -DDFS=1\
 // RUN:  -analyzer-checker debug.ExprInspection
-// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.cplusplus.Move -verify %s\
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
-// RUN:  -analyzer-config alpha.cplusplus.Move:WarnOn=KnownsOnly -DPEACEFUL\
+// RUN:  -analyzer-config cplusplus.Move:WarnOn=KnownsOnly -DPEACEFUL\
 // RUN:  -analyzer-checker debug.ExprInspection
-// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.cplusplus.Move -verify %s\
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=dfs -DDFS=1\
-// RUN:  -analyzer-config alpha.cplusplus.Move:WarnOn=KnownsOnly -DPEACEFUL\
+// RUN:  -analyzer-config cplusplus.Move:WarnOn=KnownsOnly -DPEACEFUL\
 // RUN:  -analyzer-checker debug.ExprInspection
-// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.cplusplus.Move -verify %s\
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
-// RUN:  -analyzer-config alpha.cplusplus.Move:WarnOn=All -DAGGRESSIVE\
+// RUN:  -analyzer-config cplusplus.Move:WarnOn=All -DAGGRESSIVE\
 // RUN:  -analyzer-checker debug.ExprInspection
-// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.cplusplus.Move -verify %s\
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=dfs -DDFS=1\
-// RUN:  -analyzer-config alpha.cplusplus.Move:WarnOn=All -DAGGRESSIVE\
+// RUN:  -analyzer-config cplusplus.Move:WarnOn=All -DAGGRESSIVE\
 // RUN:  -analyzer-checker debug.ExprInspection
 
 #include "Inputs/system-header-simulator-cxx.h"
Index: test/Analysis/mismatched-iterator.cpp
===
--- test/Analysis/mismatched-iterator.cpp
+++ test/Analysis/mismatched-iterator.cpp
@@ -100,7 +100,7 @@
 void good_move_find3(std::vector , std::vector , int n) {
   auto i0 = v2.cend();
   v1 = std::move(v2);
-  v2.push_back(n);
+  v2.push_back(n); // expected-warning{{Method called on moved-from object of type 'std::vector'}}
   std::find(v2.cbegin(), i0, n); // no-warning
 }
 
@@ -125,6 +125,7 @@
   auto i0 = v2.cbegin();
   v1 = std::move(v2);
   std::find(i0, v2.cend(), n); // expected-warning{{Iterators of different containers used where the same container is expected}}
+   // expected-warning@-1{{Method called on moved-from object of type 'std::vector'}}
 }
 
 void bad_insert_find(std::vector , std::vector , int n, int m) {
@@ -167,12 +168,14 @@
   const auto i0 = ++v2.cbegin();
   v1 = std::move(v2);
   v2.erase(i0); // expected-warning{{Container accessed using foreign iterator argument}}
+// expected-warning@-1{{Method called on moved-from object of type 'std::vector'}}
 }
 
 void bad_move_find2(std::vector , std::vector , int n) {
   auto i0 = --v2.cend();
   v1 = std::move(v2);
   std::find(i0, v2.cend(), n); // expected-warning{{Iterators of different containers used where the same container is expected}}
+   // expected-warning@-1{{Method called on moved-from object of type 'std::vector'}}
 }
 
 void bad_move_find3(std::vector , std::vector , int n) {

Re: r349212 - Mangle calling conventions into function pointer types where GCC does

2018-12-14 Thread Richard Smith via cfe-commits
Should this change be disableable by -fclang-abi-compat=7 or below?

On Fri, 14 Dec 2018, 15:46 Reid Kleckner via cfe-commits <
cfe-commits@lists.llvm.org wrote:

> Author: rnk
> Date: Fri Dec 14 15:42:59 2018
> New Revision: 349212
>
> URL: http://llvm.org/viewvc/llvm-project?rev=349212=rev
> Log:
> Mangle calling conventions into function pointer types where GCC does
>
> Summary:
> GCC 5.1 began mangling these Windows calling conventions into function
> types, since they can be used for overloading. They've always been
> mangled in the MS ABI, but they are new to the Itanium mangler. Note
> that the calling convention doesn't appear as part of the main
> declaration, it only appears on function parameter types and other
> types.
>
> Fixes PR39860
>
> Reviewers: rjmccall, efriedma
>
> Subscribers: cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D55672
>
> Added:
> cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp
> cfe/trunk/test/CodeGenCXX/mangle-win64-ccs.cpp
> Modified:
> cfe/trunk/lib/AST/ItaniumMangle.cpp
>
> Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=349212=349211=349212=diff
>
> ==
> --- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
> +++ cfe/trunk/lib/AST/ItaniumMangle.cpp Fri Dec 14 15:42:59 2018
> @@ -2648,13 +2648,8 @@ StringRef CXXNameMangler::getCallingConv
>case CC_C:
>  return "";
>
> -  case CC_X86StdCall:
> -  case CC_X86FastCall:
> -  case CC_X86ThisCall:
>case CC_X86VectorCall:
>case CC_X86Pascal:
> -  case CC_Win64:
> -  case CC_X86_64SysV:
>case CC_X86RegCall:
>case CC_AAPCS:
>case CC_AAPCS_VFP:
> @@ -2667,6 +2662,16 @@ StringRef CXXNameMangler::getCallingConv
>  // FIXME: we should be mangling all of the above.
>  return "";
>
> +  case CC_X86StdCall:
> +return "stdcall";
> +  case CC_X86FastCall:
> +return "fastcall";
> +  case CC_X86ThisCall:
> +return "thiscall";
> +  case CC_X86_64SysV:
> +return "sysv_abi";
> +  case CC_Win64:
> +return "ms_abi";
>case CC_Swift:
>  return "swiftcall";
>}
>
> Added: cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp?rev=349212=auto
>
> ==
> --- cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp (added)
> +++ cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp Fri Dec 14 15:42:59 2018
> @@ -0,0 +1,61 @@
> +// RUN: %clang_cc1 %s -emit-llvm -triple i686-windows-gnu -o - |
> FileCheck %s
> +// RUN: %clang_cc1 %s -emit-llvm -triple i686-windows-itanium -o - |
> FileCheck %s
> +
> +// GCC 5.1 began mangling these Windows calling conventions into function
> +// types, since they can be used for overloading. They've always been
> mangled
> +// in the MS ABI, but they are new to the Itanium mangler. Note that the
> main
> +// function definition does not use a calling convention. Only function
> types
> +// that appear later use it.
> +
> +template  static int func_as_ptr(Fn fn) { return int(fn); }
> +
> +void f_cdecl(int, int);
> +void __attribute__((stdcall)) f_stdcall(int, int);
> +void __attribute__((fastcall)) f_fastcall(int, int);
> +void __attribute__((thiscall)) f_thiscall(int, int);
> +
> +int as_cdecl() { return func_as_ptr(f_cdecl); }
> +int as_stdcall() { return func_as_ptr(f_stdcall); }
> +int as_fastcall() { return func_as_ptr(f_fastcall); }
> +int as_thiscall() { return func_as_ptr(f_thiscall); }
> +
> +// CHECK: define dso_local i32 @_Z8as_cdeclv()
> +// CHECK:   call i32 @_ZL11func_as_ptrIPFviiEEiT_(void (i32, i32)*
> @_Z7f_cdeclii)
> +
> +// CHECK: define dso_local i32 @_Z10as_stdcallv()
> +// CHECK:   call i32 @_ZL11func_as_ptrIPU7stdcallFviiEEiT_(void (i32,
> i32)* @"\01__Z9f_stdcallii@8")
> +
> +// CHECK: define dso_local i32 @_Z11as_fastcallv()
> +// CHECK:   call i32 @_ZL11func_as_ptrIPU8fastcallFviiEEiT_(void (i32,
> i32)* @"\01@_Z10f_fastcallii@8")
> +
> +// CHECK: define dso_local i32 @_Z11as_thiscallv()
> +// CHECK:   call i32 @_ZL11func_as_ptrIPU8thiscallFviiEEiT_(void (i32,
> i32)* @_Z10f_thiscallii)
> +
> +// CHECK: define dso_local void @_Z11funcRefTypeRU8fastcallFviiE(void
> (i32, i32)* %fr)
> +void funcRefType(void(__attribute__((fastcall)) & fr)(int, int)) {
> +  fr(1, 2);
> +}
> +
> +// CHECK: define dso_local void
> @_Z12memptrCCTypeR3FooMS_U8fastcallFviiE(%struct.Foo* {{.*}}, { i32, i32 }*
> byval{{.*}})
> +struct Foo { void bar(int, int); };
> +void memptrCCType(Foo , void (__attribute__((fastcall)) Foo::*mp)(int,
> int)) {
> +  (o.*mp)(1, 2);
> +}
> +
> +// CHECK: define dso_local i32 @_Z17useTemplateFnTypev()
> +// CHECK:   call i32 @_ZL14templateFnTypeIU8fastcallFviiEElPT_(void (i32,
> i32)* @"\01@_Z10f_fastcallii@8")
> +template  static long templateFnType(Fn *fn) { return
> long(fn); }
> +long useTemplateFnType() { 

[PATCH] D55544: Warning: objc-encodings-larger-than=

2018-12-14 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

The patch looks largely fine to me.




Comment at: include/clang/Basic/DiagnosticSemaKinds.td:6207
+def warn_objc_method_encoding_too_large : Warning<
+  "%0 method %1 encoding of size %2 is larger than %3 bytes">,
+  InGroup;

You can use '%select' to choose between "class" and "instance" for %0.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:6209
+  InGroup;
+def warn_objc_block_encoding_too_large : Warning<
+  "block argument encoding of size %0 is larger than %1 bytes">,

You can merge warn_objc_block_encoding_too_large and 
warn_objc_ivar_encoding_too_large using '%select'.



Comment at: test/SemaObjC/objc-large-encoding-warn.m:16
+  id idThatDoesntWarn;
+}
+@end

Can you add tests for properties and categories just to make sure clang prints 
the expected diagnostics?


Repository:
  rC Clang

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

https://reviews.llvm.org/D55544



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


[PATCH] D55388: [analyzer] MoveChecker Pt.8: Add checks for dereferencing a smart pointer after move.

2018-12-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: test/Analysis/use-after-move.cpp:239
 A a;
 for (int i = 0; i < bignum(); i++) { // expected-note {{Loop condition is 
false. Execution jumps to the end of the function}}
   rightRefCall(std::move(a));// no-warning

Ugh. Why are these diagnostic pieces incorrect? We're not jumping to the end of 
the function yet. At the very least, we should evaluate the next `A a;`.


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

https://reviews.llvm.org/D55388



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


[PATCH] D55673: [darwin] parse the SDK settings from SDKSettings.json if it exists and pass in the -target-sdk-version to the compiler and backend

2018-12-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 178309.
arphaman marked an inline comment as done.
arphaman added a comment.

Ensure test will pass on non-darwin.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55673

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Basic/TargetInfo.h
  include/clang/Basic/TargetOptions.h
  include/clang/Driver/CC1Options.td
  include/clang/Driver/DarwinSDKInfo.h
  lib/CodeGen/ModuleBuilder.cpp
  lib/Driver/CMakeLists.txt
  lib/Driver/DarwinSDKInfo.cpp
  lib/Driver/ToolChains/Darwin.cpp
  lib/Driver/ToolChains/Darwin.h
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/darwin-sdk-version.c
  test/Driver/Inputs/MacOSX10.14.sdk/SDKSettings.json
  test/Driver/darwin-sdk-version.c

Index: test/Driver/darwin-sdk-version.c
===
--- /dev/null
+++ test/Driver/darwin-sdk-version.c
@@ -0,0 +1,37 @@
+// RUN: %clang -target x86_64-apple-macosx10.13 -isysroot %S/Inputs/MacOSX10.14.sdk -c -### %s 2>&1 \
+// RUN:   | FileCheck %s
+// RUN: env SDKROOT=%S/Inputs/MacOSX10.14.sdk %clang -target x86_64-apple-macosx10.13 -c -### %s 2>&1 \
+// RUN:   | FileCheck %s
+//
+// RUN: rm -rf %t/SDKs/MacOSX10.10.sdk
+// RUN: mkdir -p %t/SDKs/MacOSX10.10.sdk
+// RUN: %clang -isysroot %t/SDKs/MacOSX10.10.sdk -c -### %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=INFER_SDK_VERSION %s
+// RUN: cp %S/Inputs/MacOSX10.14.sdk/SDKSettings.json %t/SDKs/MacOSX10.10.sdk
+// RUN: %clang -isysroot %t/SDKs/MacOSX10.10.sdk -c -### %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=INFER_DEPLOYMENT_TARGET_VERSION %s
+// REQUIRES: system-darwin && native
+//
+// RUN: rm -rf %t/SDKs/MacOSX10.14.sdk
+// RUN: mkdir -p %t/SDKs/MacOSX10.14.sdk
+// RUN: %clang -target x86_64-apple-macosx10.13 -isysroot %t/SDKs/MacOSX10.14.sdk -c -### %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=NO_VERSION %s
+//
+// RUN: rm -rf %t/SDKs/MacOSX10.14.sdk
+// RUN: mkdir -p %t/SDKs/MacOSX10.14.sdk
+// RUN: echo '{broken json' > %t/SDKs/MacOSX10.14.sdk/SDKSettings.json
+// RUN: %clang -target x86_64-apple-macosx10.13 -isysroot %t/SDKs/MacOSX10.14.sdk -c -### %s 2>&1 \
+// RUN:   | FileCheck --check-prefixes=NO_VERSION,ERROR %s
+//
+// RUN: rm -rf %t/SDKs/MacOSX10.14.sdk
+// RUN: mkdir -p %t/SDKs/MacOSX10.14.sdk
+// RUN: echo '{"Version":1}' > %t/SDKs/MacOSX10.14.sdk/SDKSettings.json
+// RUN: %clang -target x86_64-apple-macosx10.13 -isysroot %t/SDKs/MacOSX10.14.sdk -c -### %s 2>&1 \
+// RUN:   | FileCheck --check-prefixes=NO_VERSION,ERROR %s
+
+// CHECK: -target-sdk-version=10.14
+// INFER_SDK_VERSION: "-triple" "x86_64-apple-macosx10.10.0"
+// INFER_SDK_VERSION-SAME: -target-sdk-version=10.10
+// INFER_DEPLOYMENT_TARGET_VERSION: "-triple" "x86_64-apple-macosx10.14.0"
+// NO_VERSION-NOT: target-sdk-version
+// ERROR: warning: SDK settings were ignored as 'SDKSettings.json' could not be parsed
Index: test/Driver/Inputs/MacOSX10.14.sdk/SDKSettings.json
===
--- /dev/null
+++ test/Driver/Inputs/MacOSX10.14.sdk/SDKSettings.json
@@ -0,0 +1 @@
+{"Version":"10.14"}
Index: test/CodeGen/darwin-sdk-version.c
===
--- /dev/null
+++ test/CodeGen/darwin-sdk-version.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14 -target-sdk-version=10.14.1 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: !llvm.module.flags = !{!0
+// CHECK: !0 = !{i32 2, !"SDK Version", [3 x i32] [i32 10, i32 14, i32 1]}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -3192,6 +3192,14 @@
   Opts.ForceEnableInt128 = Args.hasArg(OPT_fforce_enable_int128);
   Opts.NVPTXUseShortPointers = Args.hasFlag(
   options::OPT_fcuda_short_ptr, options::OPT_fno_cuda_short_ptr, false);
+  if (Arg *A = Args.getLastArg(options::OPT_target_sdk_version_EQ)) {
+llvm::VersionTuple Version;
+if (Version.tryParse(A->getValue()))
+  Diags.Report(diag::err_drv_invalid_value)
+  << A->getAsString(Args) << A->getValue();
+else
+  Opts.SDKVersion = Version;
+  }
 }
 
 bool CompilerInvocation::CreateFromArgs(CompilerInvocation ,
Index: lib/Driver/ToolChains/Darwin.h
===
--- lib/Driver/ToolChains/Darwin.h
+++ lib/Driver/ToolChains/Darwin.h
@@ -11,9 +11,10 @@
 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_DARWIN_H
 
 #include "Cuda.h"
-#include "clang/Driver/XRayArgs.h"
+#include "clang/Driver/DarwinSDKInfo.h"
 #include "clang/Driver/Tool.h"
 #include "clang/Driver/ToolChain.h"
+#include "clang/Driver/XRayArgs.h"
 
 namespace clang {
 namespace driver {
@@ -288,6 +289,9 @@
   /// The OS version we are targeting.
   mutable VersionTuple TargetVersion;
 
+  /// The information about the darwin SDK that 

[PATCH] D55672: Mangle calling conventions into function pointer types where GCC does

2018-12-14 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349212: Mangle calling conventions into function pointer 
types where GCC does (authored by rnk, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55672?vs=178144=178308#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55672

Files:
  cfe/trunk/lib/AST/ItaniumMangle.cpp
  cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp
  cfe/trunk/test/CodeGenCXX/mangle-win64-ccs.cpp

Index: cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp
===
--- cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp
+++ cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 %s -emit-llvm -triple i686-windows-gnu -o - | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -triple i686-windows-itanium -o - | FileCheck %s
+
+// GCC 5.1 began mangling these Windows calling conventions into function
+// types, since they can be used for overloading. They've always been mangled
+// in the MS ABI, but they are new to the Itanium mangler. Note that the main
+// function definition does not use a calling convention. Only function types
+// that appear later use it.
+
+template  static int func_as_ptr(Fn fn) { return int(fn); }
+
+void f_cdecl(int, int);
+void __attribute__((stdcall)) f_stdcall(int, int);
+void __attribute__((fastcall)) f_fastcall(int, int);
+void __attribute__((thiscall)) f_thiscall(int, int);
+
+int as_cdecl() { return func_as_ptr(f_cdecl); }
+int as_stdcall() { return func_as_ptr(f_stdcall); }
+int as_fastcall() { return func_as_ptr(f_fastcall); }
+int as_thiscall() { return func_as_ptr(f_thiscall); }
+
+// CHECK: define dso_local i32 @_Z8as_cdeclv()
+// CHECK:   call i32 @_ZL11func_as_ptrIPFviiEEiT_(void (i32, i32)* @_Z7f_cdeclii)
+
+// CHECK: define dso_local i32 @_Z10as_stdcallv()
+// CHECK:   call i32 @_ZL11func_as_ptrIPU7stdcallFviiEEiT_(void (i32, i32)* @"\01__Z9f_stdcallii@8")
+
+// CHECK: define dso_local i32 @_Z11as_fastcallv()
+// CHECK:   call i32 @_ZL11func_as_ptrIPU8fastcallFviiEEiT_(void (i32, i32)* @"\01@_Z10f_fastcallii@8")
+
+// CHECK: define dso_local i32 @_Z11as_thiscallv()
+// CHECK:   call i32 @_ZL11func_as_ptrIPU8thiscallFviiEEiT_(void (i32, i32)* @_Z10f_thiscallii)
+
+// CHECK: define dso_local void @_Z11funcRefTypeRU8fastcallFviiE(void (i32, i32)* %fr)
+void funcRefType(void(__attribute__((fastcall)) & fr)(int, int)) {
+  fr(1, 2);
+}
+
+// CHECK: define dso_local void @_Z12memptrCCTypeR3FooMS_U8fastcallFviiE(%struct.Foo* {{.*}}, { i32, i32 }* byval{{.*}})
+struct Foo { void bar(int, int); };
+void memptrCCType(Foo , void (__attribute__((fastcall)) Foo::*mp)(int, int)) {
+  (o.*mp)(1, 2);
+}
+
+// CHECK: define dso_local i32 @_Z17useTemplateFnTypev()
+// CHECK:   call i32 @_ZL14templateFnTypeIU8fastcallFviiEElPT_(void (i32, i32)* @"\01@_Z10f_fastcallii@8")
+template  static long templateFnType(Fn *fn) { return long(fn); }
+long useTemplateFnType() { return templateFnType(f_fastcall); }
+
+// CHECK: define weak_odr dso_local x86_fastcallcc void @"\01@_Z10fnTemplateIsEvv@0"()
+// CHECK: define  dso_local x86_fastcallcc void @"\01@_Z10fnTemplateIiEvv@0"()
+template  void __attribute__((fastcall)) fnTemplate() {}
+template void __attribute__((fastcall)) fnTemplate();
+template <> void __attribute__((fastcall)) fnTemplate() {}
+
+// CHECK: define weak_odr dso_local x86_fastcallcc void (i32, i32)* @"\01@_Z12fnTempReturnIsEPU8fastcallFviiEv@0"()
+// CHECK: define  dso_local x86_fastcallcc void (i32, i32)* @"\01@_Z12fnTempReturnIiEPU8fastcallFviiEv@0"()
+typedef void (__attribute__((fastcall)) *fp_cc_t)(int, int);
+template  fp_cc_t __attribute__((fastcall)) fnTempReturn() { return nullptr; }
+template fp_cc_t __attribute__((fastcall)) fnTempReturn();
+template <> fp_cc_t __attribute__((fastcall)) fnTempReturn() { return nullptr; }
Index: cfe/trunk/test/CodeGenCXX/mangle-win64-ccs.cpp
===
--- cfe/trunk/test/CodeGenCXX/mangle-win64-ccs.cpp
+++ cfe/trunk/test/CodeGenCXX/mangle-win64-ccs.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple x86_64-windows-gnu -o - -emit-llvm %s | FileCheck %s -check-prefix CHECK-WIN
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -o - -emit-llvm %s | FileCheck %s -check-prefix CHECK-LIN
+
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+template  ptrdiff_t func_as_int(FTy *fp) { return ptrdiff_t(fp); }
+
+int f_plain(int);
+int __attribute__((sysv_abi)) f_sysvabi(int);
+int __attribute__((ms_abi)) f_msabi(int);
+ptrdiff_t useThem() {
+  ptrdiff_t rv = 0;
+  rv += func_as_int(f_plain);
+  rv += func_as_int(f_sysvabi);
+  rv += func_as_int(f_msabi);
+  return rv;
+}
+
+// CHECK-WIN: define dso_local i64 @_Z7useThemv()
+// CHECK-WIN:   call i64 @_Z11func_as_intIFiiEExPT_(i32 (i32)* @_Z7f_plaini)
+// CHECK-WIN:   call i64 

r349212 - Mangle calling conventions into function pointer types where GCC does

2018-12-14 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Fri Dec 14 15:42:59 2018
New Revision: 349212

URL: http://llvm.org/viewvc/llvm-project?rev=349212=rev
Log:
Mangle calling conventions into function pointer types where GCC does

Summary:
GCC 5.1 began mangling these Windows calling conventions into function
types, since they can be used for overloading. They've always been
mangled in the MS ABI, but they are new to the Itanium mangler. Note
that the calling convention doesn't appear as part of the main
declaration, it only appears on function parameter types and other
types.

Fixes PR39860

Reviewers: rjmccall, efriedma

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D55672

Added:
cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp
cfe/trunk/test/CodeGenCXX/mangle-win64-ccs.cpp
Modified:
cfe/trunk/lib/AST/ItaniumMangle.cpp

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=349212=349211=349212=diff
==
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Fri Dec 14 15:42:59 2018
@@ -2648,13 +2648,8 @@ StringRef CXXNameMangler::getCallingConv
   case CC_C:
 return "";
 
-  case CC_X86StdCall:
-  case CC_X86FastCall:
-  case CC_X86ThisCall:
   case CC_X86VectorCall:
   case CC_X86Pascal:
-  case CC_Win64:
-  case CC_X86_64SysV:
   case CC_X86RegCall:
   case CC_AAPCS:
   case CC_AAPCS_VFP:
@@ -2667,6 +2662,16 @@ StringRef CXXNameMangler::getCallingConv
 // FIXME: we should be mangling all of the above.
 return "";
 
+  case CC_X86StdCall:
+return "stdcall";
+  case CC_X86FastCall:
+return "fastcall";
+  case CC_X86ThisCall:
+return "thiscall";
+  case CC_X86_64SysV:
+return "sysv_abi";
+  case CC_Win64:
+return "ms_abi";
   case CC_Swift:
 return "swiftcall";
   }

Added: cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp?rev=349212=auto
==
--- cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp Fri Dec 14 15:42:59 2018
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 %s -emit-llvm -triple i686-windows-gnu -o - | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -triple i686-windows-itanium -o - | FileCheck 
%s
+
+// GCC 5.1 began mangling these Windows calling conventions into function
+// types, since they can be used for overloading. They've always been mangled
+// in the MS ABI, but they are new to the Itanium mangler. Note that the main
+// function definition does not use a calling convention. Only function types
+// that appear later use it.
+
+template  static int func_as_ptr(Fn fn) { return int(fn); }
+
+void f_cdecl(int, int);
+void __attribute__((stdcall)) f_stdcall(int, int);
+void __attribute__((fastcall)) f_fastcall(int, int);
+void __attribute__((thiscall)) f_thiscall(int, int);
+
+int as_cdecl() { return func_as_ptr(f_cdecl); }
+int as_stdcall() { return func_as_ptr(f_stdcall); }
+int as_fastcall() { return func_as_ptr(f_fastcall); }
+int as_thiscall() { return func_as_ptr(f_thiscall); }
+
+// CHECK: define dso_local i32 @_Z8as_cdeclv()
+// CHECK:   call i32 @_ZL11func_as_ptrIPFviiEEiT_(void (i32, i32)* 
@_Z7f_cdeclii)
+
+// CHECK: define dso_local i32 @_Z10as_stdcallv()
+// CHECK:   call i32 @_ZL11func_as_ptrIPU7stdcallFviiEEiT_(void (i32, i32)* 
@"\01__Z9f_stdcallii@8")
+
+// CHECK: define dso_local i32 @_Z11as_fastcallv()
+// CHECK:   call i32 @_ZL11func_as_ptrIPU8fastcallFviiEEiT_(void (i32, i32)* 
@"\01@_Z10f_fastcallii@8")
+
+// CHECK: define dso_local i32 @_Z11as_thiscallv()
+// CHECK:   call i32 @_ZL11func_as_ptrIPU8thiscallFviiEEiT_(void (i32, i32)* 
@_Z10f_thiscallii)
+
+// CHECK: define dso_local void @_Z11funcRefTypeRU8fastcallFviiE(void (i32, 
i32)* %fr)
+void funcRefType(void(__attribute__((fastcall)) & fr)(int, int)) {
+  fr(1, 2);
+}
+
+// CHECK: define dso_local void 
@_Z12memptrCCTypeR3FooMS_U8fastcallFviiE(%struct.Foo* {{.*}}, { i32, i32 }* 
byval{{.*}})
+struct Foo { void bar(int, int); };
+void memptrCCType(Foo , void (__attribute__((fastcall)) Foo::*mp)(int, int)) 
{
+  (o.*mp)(1, 2);
+}
+
+// CHECK: define dso_local i32 @_Z17useTemplateFnTypev()
+// CHECK:   call i32 @_ZL14templateFnTypeIU8fastcallFviiEElPT_(void (i32, 
i32)* @"\01@_Z10f_fastcallii@8")
+template  static long templateFnType(Fn *fn) { return long(fn); }
+long useTemplateFnType() { return templateFnType(f_fastcall); }
+
+// CHECK: define weak_odr dso_local x86_fastcallcc void 
@"\01@_Z10fnTemplateIsEvv@0"()
+// CHECK: define  dso_local x86_fastcallcc void 
@"\01@_Z10fnTemplateIiEvv@0"()
+template  void __attribute__((fastcall)) fnTemplate() {}
+template void __attribute__((fastcall)) fnTemplate();
+template <> void __attribute__((fastcall)) fnTemplate() {}
+
+// CHECK: define weak_odr 

[PATCH] D55673: [darwin] parse the SDK settings from SDKSettings.json if it exists and pass in the -target-sdk-version to the compiler and backend

2018-12-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman marked 2 inline comments as done.
arphaman added inline comments.



Comment at: lib/Driver/ToolChains/Darwin.cpp:2053
+return None;
+  }
+  return *SDKInfoOrErr;

steven_wu wrote:
> We also has this InferredFromSDK when we infer deployment target, which can 
> be used as a fallback method.
> 
> The result of parsing JSON should be available to InferredFromSDK in 
> deployment target setting.
> 
> Bonus point is to set "-sdk_version" flag passing to ld64.
Done.
We're not planning to pass it down to the linker.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55673



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


[PATCH] D55673: [darwin] parse the SDK settings from SDKSettings.json if it exists and pass in the -target-sdk-version to the compiler and backend

2018-12-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 178307.
arphaman added a comment.

Updated to infer deployment target version from SDK versions specified in the 
JSON file and to allow inferring the SDK version from the SDK path.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55673

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Basic/TargetInfo.h
  include/clang/Basic/TargetOptions.h
  include/clang/Driver/CC1Options.td
  include/clang/Driver/DarwinSDKInfo.h
  lib/CodeGen/ModuleBuilder.cpp
  lib/Driver/CMakeLists.txt
  lib/Driver/DarwinSDKInfo.cpp
  lib/Driver/ToolChains/Darwin.cpp
  lib/Driver/ToolChains/Darwin.h
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/darwin-sdk-version.c
  test/Driver/Inputs/MacOSX10.14.sdk/SDKSettings.json
  test/Driver/darwin-sdk-version.c

Index: test/Driver/darwin-sdk-version.c
===
--- /dev/null
+++ test/Driver/darwin-sdk-version.c
@@ -0,0 +1,36 @@
+// RUN: %clang -target x86_64-apple-macosx10.13 -isysroot %S/Inputs/MacOSX10.14.sdk -c -### %s 2>&1 \
+// RUN:   | FileCheck %s
+// RUN: env SDKROOT=%S/Inputs/MacOSX10.14.sdk %clang -target x86_64-apple-macosx10.13 -c -### %s 2>&1 \
+// RUN:   | FileCheck %s
+//
+// RUN: rm -rf %t/SDKs/MacOSX10.10.sdk
+// RUN: mkdir -p %t/SDKs/MacOSX10.10.sdk
+// RUN: %clang -isysroot %t/SDKs/MacOSX10.10.sdk -c -### %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=INFER_SDK_VERSION %s
+// RUN: cp %S/Inputs/MacOSX10.14.sdk/SDKSettings.json %t/SDKs/MacOSX10.10.sdk
+// RUN: %clang -isysroot %t/SDKs/MacOSX10.10.sdk -c -### %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=INFER_DEPLOYMENT_TARGET_VERSION %s
+//
+// RUN: rm -rf %t/SDKs/MacOSX10.14.sdk
+// RUN: mkdir -p %t/SDKs/MacOSX10.14.sdk
+// RUN: %clang -target x86_64-apple-macosx10.13 -isysroot %t/SDKs/MacOSX10.14.sdk -c -### %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=NO_VERSION %s
+//
+// RUN: rm -rf %t/SDKs/MacOSX10.14.sdk
+// RUN: mkdir -p %t/SDKs/MacOSX10.14.sdk
+// RUN: echo '{broken json' > %t/SDKs/MacOSX10.14.sdk/SDKSettings.json
+// RUN: %clang -target x86_64-apple-macosx10.13 -isysroot %t/SDKs/MacOSX10.14.sdk -c -### %s 2>&1 \
+// RUN:   | FileCheck --check-prefixes=NO_VERSION,ERROR %s
+//
+// RUN: rm -rf %t/SDKs/MacOSX10.14.sdk
+// RUN: mkdir -p %t/SDKs/MacOSX10.14.sdk
+// RUN: echo '{"Version":1}' > %t/SDKs/MacOSX10.14.sdk/SDKSettings.json
+// RUN: %clang -target x86_64-apple-macosx10.13 -isysroot %t/SDKs/MacOSX10.14.sdk -c -### %s 2>&1 \
+// RUN:   | FileCheck --check-prefixes=NO_VERSION,ERROR %s
+
+// CHECK: -target-sdk-version=10.14
+// INFER_SDK_VERSION: "-triple" "x86_64-apple-macosx10.10.0"
+// INFER_SDK_VERSION-SAME: -target-sdk-version=10.10
+// INFER_DEPLOYMENT_TARGET_VERSION: "-triple" "x86_64-apple-macosx10.14.0"
+// NO_VERSION-NOT: target-sdk-version
+// ERROR: warning: SDK settings were ignored as 'SDKSettings.json' could not be parsed
Index: test/Driver/Inputs/MacOSX10.14.sdk/SDKSettings.json
===
--- /dev/null
+++ test/Driver/Inputs/MacOSX10.14.sdk/SDKSettings.json
@@ -0,0 +1 @@
+{"Version":"10.14"}
Index: test/CodeGen/darwin-sdk-version.c
===
--- /dev/null
+++ test/CodeGen/darwin-sdk-version.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14 -target-sdk-version=10.14.1 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: !llvm.module.flags = !{!0
+// CHECK: !0 = !{i32 2, !"SDK Version", [3 x i32] [i32 10, i32 14, i32 1]}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -3192,6 +3192,14 @@
   Opts.ForceEnableInt128 = Args.hasArg(OPT_fforce_enable_int128);
   Opts.NVPTXUseShortPointers = Args.hasFlag(
   options::OPT_fcuda_short_ptr, options::OPT_fno_cuda_short_ptr, false);
+  if (Arg *A = Args.getLastArg(options::OPT_target_sdk_version_EQ)) {
+llvm::VersionTuple Version;
+if (Version.tryParse(A->getValue()))
+  Diags.Report(diag::err_drv_invalid_value)
+  << A->getAsString(Args) << A->getValue();
+else
+  Opts.SDKVersion = Version;
+  }
 }
 
 bool CompilerInvocation::CreateFromArgs(CompilerInvocation ,
Index: lib/Driver/ToolChains/Darwin.h
===
--- lib/Driver/ToolChains/Darwin.h
+++ lib/Driver/ToolChains/Darwin.h
@@ -11,9 +11,10 @@
 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_DARWIN_H
 
 #include "Cuda.h"
-#include "clang/Driver/XRayArgs.h"
+#include "clang/Driver/DarwinSDKInfo.h"
 #include "clang/Driver/Tool.h"
 #include "clang/Driver/ToolChain.h"
+#include "clang/Driver/XRayArgs.h"
 
 namespace clang {
 namespace driver {
@@ -288,6 +289,9 @@
   /// The OS version we are targeting.
   mutable VersionTuple TargetVersion;
 
+  /// The information 

[PATCH] D55698: [MinGW] Produce a vtable and RTTI for dllexported classes without a key function

2018-12-14 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


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

https://reviews.llvm.org/D55698



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


[PATCH] D55715: Add AddressSpace mangling to MS mode

2018-12-14 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349209: Add AddressSpace mangling to MS mode (authored by 
erichkeane, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55715?vs=178282=178305#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55715

Files:
  cfe/trunk/lib/AST/MicrosoftMangle.cpp
  cfe/trunk/test/CodeGenCXX/mangle-address-space.cpp

Index: cfe/trunk/test/CodeGenCXX/mangle-address-space.cpp
===
--- cfe/trunk/test/CodeGenCXX/mangle-address-space.cpp
+++ cfe/trunk/test/CodeGenCXX/mangle-address-space.cpp
@@ -1,15 +1,64 @@
-// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s --check-prefixes=CHECK,CHECKNOOCL
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-windows-msvc -o - %s | FileCheck %s --check-prefixes=WIN,WINNOOCL
+// RUN: %clang_cc1 -cl-std=c++ -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s --check-prefixes=CHECK,CHECKOCL
+// RUN: %clang_cc1 -cl-std=c++ -emit-llvm -triple x86_64-windows-msvc -o - %s | FileCheck %s --check-prefixes=WIN,WINOCL
 
-// CHECK-LABEL: define {{.*}}void @_Z2f0Pc
+// CHECKNOOCL-LABEL: define {{.*}}void @_Z2f0Pc
+// WINNOOCL-LABEL: define {{.*}}void @"?f0@@YAXPEAD@Z"
+// CHECKOCL-LABEL: define {{.*}}void @_Z2f0PU9CLgenericc
+// WINOCL-LABEL: define {{.*}}void @"?f0@@YAXPEAU?$_ASCLgeneric@$$CAD@__clang@@@Z" 
 void f0(char *p) { }
 // CHECK-LABEL: define {{.*}}void @_Z2f0PU3AS1c
+// WIN-LABEL: define {{.*}}void @"?f0@@YAXPEAU?$_AS@$00$$CAD@__clang@@@Z"
 void f0(char __attribute__((address_space(1))) *p) { }
 
 struct OpaqueType;
 typedef OpaqueType __attribute__((address_space(100))) * OpaqueTypePtr;
 
 // CHECK-LABEL: define {{.*}}void @_Z2f0PU5AS10010OpaqueType
+// WIN-LABEL: define {{.*}}void @"?f0@@YAXPEAU?$_AS@$0GE@$$CAUOpaqueType@@@__clang@@@Z"
 void f0(OpaqueTypePtr) { }
 
 // CHECK-LABEL: define {{.*}}void @_Z2f1PU3AS1Kc
-void f1(char __attribute__((address_space(1))) const *p) {}
\ No newline at end of file
+// WIN-LABEL: define {{.*}}void @"?f1@@YAXPEAU?$_AS@$00$$CBD@__clang@@@Z"
+void f1(char __attribute__((address_space(1))) const *p) {}
+
+// Ensure we can do return values, which change in MS mode.
+// CHECK-LABEL: define {{.*}}float addrspace(1)* @_Z2f1PU3AS2Kc
+// WIN-LABEL: define {{.*}}float addrspace(1)* @"?f1@@YAPEAU?$_AS@$00$$CAM@__clang@@PEAU?$_AS@$01$$CBD@2@@Z"
+__attribute__((address_space(1))) float *f1(char __attribute__((address_space(2))) const *p) { return 0;}
+
+#if !defined(__OPENCL_CPP_VERSION__)
+// Return value of address space without a pointer is invalid in opencl.
+// Ensure we skip return values, since non-pointers aren't supposed to have an AS.
+// CHECKNOOCL-LABEL: define {{.*}}float @_Z2f2PU3AS2Kc
+// WINNOOCL-LABEL: define {{.*}}float @"?f2@@YA?AMQEAU?$_AS@$01$$CBD@__clang@@@Z"
+__attribute__((address_space(1))) float f2(char __attribute__((address_space(2))) const * const p) { return 0;}
+#endif
+
+#ifdef __OPENCL_CPP_VERSION__
+// CHECKOCL-LABEL: define {{.*}}void @_Z6ocl_f0PU9CLprivatec
+// WINOCL-LABEL: define {{.*}}void @"?ocl_f0@@YAXPEAU?$_ASCLprivate@$$CAD@__clang@@@Z"
+void ocl_f0(char __private *p) { }
+
+struct ocl_OpaqueType;
+typedef ocl_OpaqueType __global * ocl_OpaqueTypePtr;
+
+// CHECKOCL-LABEL: define {{.*}}void @_Z6ocl_f0PU8CLglobal14ocl_OpaqueType
+// WINOCL-LABEL: define {{.*}}void @"?ocl_f0@@YAXPEAU?$_ASCLglobal@$$CAUocl_OpaqueType@@@__clang@@@Z"
+void ocl_f0(ocl_OpaqueTypePtr) { }
+
+// CHECKOCL-LABEL: define {{.*}}void @_Z6ocl_f1PU10CLconstantKc
+// WINOCL-LABEL: define {{.*}}void @"?ocl_f1@@YAXPEAU?$_ASCLconstant@$$CBD@__clang@@@Z"
+void ocl_f1(char __constant const *p) {}
+
+// Ensure we can do return values, which change in MS mode.
+// CHECKOCL-LABEL: define {{.*}}float* @_Z6ocl_f1PU9CLgenericKc
+// WINOCL-LABEL: define {{.*}}float* @"?ocl_f1@@YAPEAU?$_ASCLconstant@$$CAM@__clang@@PEAU?$_ASCLgeneric@$$CBD@2@@Z"
+__constant float *ocl_f1(char __generic const *p) { return 0;}
+
+// Ensure we skip return values, since non-pointers aren't supposed to have an AS.
+// CHECKOCL-LABEL: define {{.*}}float* @_Z6ocl_f2PU9CLgenericKc
+// WINOCL-LABEL: define {{.*}}float* @"?ocl_f2@@YAPEAU?$_ASCLgeneric@$$CAM@__clang@@QEAU?$_ASCLgeneric@$$CBD@2@@Z"
+__generic float *ocl_f2(__generic char const * const p) { return 0;}
+#endif
Index: cfe/trunk/lib/AST/MicrosoftMangle.cpp
===
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp
@@ -311,6 +311,7 @@
   void mangleTagTypeKind(TagTypeKind TK);
   void mangleArtificialTagType(TagTypeKind TK, StringRef UnqualifiedName,
   ArrayRef NestedNames = None);
+  void mangleAddressSpaceType(QualType T, 

r349209 - Add AddressSpace mangling to MS mode

2018-12-14 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Fri Dec 14 15:17:34 2018
New Revision: 349209

URL: http://llvm.org/viewvc/llvm-project?rev=349209=rev
Log:
Add AddressSpace mangling to MS mode

All of the symbols demangle on llvm-undname and demangler.com. This
address space qualifier is useful for when we want to use opencl C++ in
Windows mode. Additionally, C++ address-space using functions will now
be usable on windows.

Differential Revision: https://reviews.llvm.org/D55715

Change-Id: Ife4506613c3cce778a783456d62117fbf7d83c26

Modified:
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/test/CodeGenCXX/mangle-address-space.cpp

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=349209=349208=349209=diff
==
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Fri Dec 14 15:17:34 2018
@@ -311,6 +311,7 @@ public:
   void mangleTagTypeKind(TagTypeKind TK);
   void mangleArtificialTagType(TagTypeKind TK, StringRef UnqualifiedName,
   ArrayRef NestedNames = None);
+  void mangleAddressSpaceType(QualType T, Qualifiers Quals, SourceRange Range);
   void mangleType(QualType T, SourceRange Range,
   QualifierMangleMode QMM = QMM_Mangle);
   void mangleFunctionType(const FunctionType *T,
@@ -1777,12 +1778,77 @@ void MicrosoftCXXNameMangler::manglePass
   }
 }
 
+void MicrosoftCXXNameMangler::mangleAddressSpaceType(QualType T,
+ Qualifiers Quals,
+ SourceRange Range) {
+  // Address space is mangled as an unqualified templated type in the __clang
+  // namespace. The demangled version of this is:
+  // In the case of a language specific address space:
+  // __clang::struct _AS[language_addr_space]
+  // where:
+  //   ::=  | 
+  // ::= "CL" [ "global" | "local" | "constant" |
+  //"private"| "generic" ]
+  // ::= "CU" [ "device" | "constant" | "shared" ]
+  //Note that the above were chosen to match the Itanium mangling for this.
+  //
+  // In the case of a non-language specific address space:
+  //  __clang::struct _AS
+  assert(Quals.hasAddressSpace() && "Not valid without address space");
+  llvm::SmallString<32> ASMangling;
+  llvm::raw_svector_ostream Stream(ASMangling);
+  MicrosoftCXXNameMangler Extra(Context, Stream);
+  Stream << "?$";
+
+  LangAS AS = Quals.getAddressSpace();
+  if (Context.getASTContext().addressSpaceMapManglingFor(AS)) {
+unsigned TargetAS = Context.getASTContext().getTargetAddressSpace(AS);
+Extra.mangleSourceName("_AS");
+Extra.mangleIntegerLiteral(llvm::APSInt::getUnsigned(TargetAS),
+   /*IsBoolean*/ false);
+  } else {
+switch (AS) {
+default:
+  llvm_unreachable("Not a language specific address space");
+case LangAS::opencl_global:
+  Extra.mangleSourceName("_ASCLglobal");
+  break;
+case LangAS::opencl_local:
+  Extra.mangleSourceName("_ASCLlocal");
+  break;
+case LangAS::opencl_constant:
+  Extra.mangleSourceName("_ASCLconstant");
+  break;
+case LangAS::opencl_private:
+  Extra.mangleSourceName("_ASCLprivate");
+  break;
+case LangAS::opencl_generic:
+  Extra.mangleSourceName("_ASCLgeneric");
+  break;
+case LangAS::cuda_device:
+  Extra.mangleSourceName("_ASCUdevice");
+  break;
+case LangAS::cuda_constant:
+  Extra.mangleSourceName("_ASCUconstant");
+  break;
+case LangAS::cuda_shared:
+  Extra.mangleSourceName("_ASCUshared");
+  break;
+}
+  }
+
+  Extra.mangleType(T, Range, QMM_Escape);
+  mangleQualifiers(Qualifiers(), false);
+  mangleArtificialTagType(TTK_Struct, ASMangling, {"__clang"});
+}
+
 void MicrosoftCXXNameMangler::mangleType(QualType T, SourceRange Range,
  QualifierMangleMode QMM) {
   // Don't use the canonical types.  MSVC includes things like 'const' on
   // pointer arguments to function pointers that canonicalization strips away.
   T = T.getDesugaredType(getASTContext());
   Qualifiers Quals = T.getLocalQualifiers();
+
   if (const ArrayType *AT = getASTContext().getAsArrayType(T)) {
 // If there were any Quals, getAsArrayType() pushed them onto the array
 // element type.
@@ -2488,7 +2554,11 @@ void MicrosoftCXXNameMangler::mangleType
   QualType PointeeType = T->getPointeeType();
   manglePointerCVQualifiers(Quals);
   manglePointerExtQualifiers(Quals, PointeeType);
-  mangleType(PointeeType, Range);
+
+  if (PointeeType.getQualifiers().hasAddressSpace())
+mangleAddressSpaceType(PointeeType, PointeeType.getQualifiers(), Range);
+  else
+mangleType(PointeeType, Range);
 }
 
 void MicrosoftCXXNameMangler::mangleType(const ObjCObjectPointerType *T,

Modified: 

RE: r349053 - [CodeComplete] Fill preferred type on binary expressions

2018-12-14 Thread via cfe-commits
Hi, I think this test is still broken on Windows when you are building a cross 
compiler as we at Sony do. I have put the details in PR40033. Can somebody take 
a look?

Douglas Yung

From: cfe-commits  On Behalf Of Reid 
Kleckner via cfe-commits
Sent: Thursday, December 13, 2018 13:51
To: Ilya Biryukov 
Cc: cfe-commits 
Subject: Re: r349053 - [CodeComplete] Fill preferred type on binary expressions

r349086 should take care of it, but you may want to tweak it.

On Thu, Dec 13, 2018 at 1:30 PM Reid Kleckner 
mailto:r...@google.com>> wrote:
This new test doesn't pass on Windows. I think it's an LLP64-ness bug based on 
the output:
Note: Google Test filter = PreferredTypeTest.Binar*
[==] Running 1 test from 1 test case.
[--] Global test environment set-up.
[--] 1 test from PreferredTypeTest
[ RUN  ] PreferredTypeTest.BinaryExpr
test.cc:4:45: error: invalid operands to binary expression ('float' and 'int')
  x += 10; x -= 10; x *= 10; x /= 10; x %= 10;
  ~ ^  ~~
1 error generated.
test.cc:4:45: error: invalid operands to binary expression ('float' and 'int')
  x += 10; x -= 10; x *= 10; x /= 10; x %= 10;
  ~ ^  ~~
1 error generated.
test.cc:4:45: error: invalid operands to binary expression ('float' and 'int')
  x += 10; x -= 10; x *= 10; x /= 10; x %= 10;
  ~ ^  ~~
1 error generated.
test.cc:4:45: error: invalid operands to binary expression ('float' and 'int')
  x += 10; x -= 10; x *= 10; x /= 10; x %= 10;
  ~ ^  ~~
1 error generated.
test.cc:4:45: error: invalid operands to binary expression ('float' and 'int')
  x += 10; x -= 10; x *= 10; x /= 10; x %= 10;
  ~ ^  ~~
1 error generated.
C:\src\llvm-project\clang\unittests\Sema\CodeCompleteTest.cpp(216): error: 
Value of: collectPreferredTypes(Code)
Expected: only contains elements that is equal to "long"
  Actual: { "long long", "long long", "long long" }, whose element #0 doesn't 
match

On Thu, Dec 13, 2018 at 8:09 AM Ilya Biryukov via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:
Author: ibiryukov
Date: Thu Dec 13 08:06:11 2018
New Revision: 349053

URL: http://llvm.org/viewvc/llvm-project?rev=349053=rev
Log:
[CodeComplete] Fill preferred type on binary expressions

Reviewers: kadircet

Reviewed By: kadircet

Subscribers: arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D55648

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/test/Index/complete-exprs.c
cfe/trunk/unittests/Sema/CodeCompleteTest.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=349053=349052=349053=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Dec 13 08:06:11 2018
@@ -10350,7 +10350,7 @@ public:
   void CodeCompleteInitializer(Scope *S, Decl *D);
   void CodeCompleteReturn(Scope *S);
   void CodeCompleteAfterIf(Scope *S);
-  void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS);
+  void CodeCompleteBinaryRHS(Scope *S, Expr *LHS, tok::TokenKind Op);

   void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec ,
bool EnteringContext, QualType BaseType);

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=349053=349052=349053=diff
==
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Thu Dec 13 08:06:11 2018
@@ -393,10 +393,11 @@ Parser::ParseRHSOfBinaryExpression(ExprR
   }
 }

-// Code completion for the right-hand side of an assignment expression
-// goes through a special hook that takes the left-hand side into account.
-if (Tok.is(tok::code_completion) && NextTokPrec == prec::Assignment) {
-  Actions.CodeCompleteAssignmentRHS(getCurScope(), LHS.get());
+// Code completion for the right-hand side of a binary expression goes
+// through a special hook that takes the left-hand side into account.
+if (Tok.is(tok::code_completion)) {
+  Actions.CodeCompleteBinaryRHS(getCurScope(), LHS.get(),
+OpToken.getKind());
   cutOffParsing();
   return ExprError();
 }

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=349053=349052=349053=diff
==
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Thu Dec 13 08:06:11 

[PATCH] D55685: Update Microsoft name mangling scheme for exception specifiers in the type system

2018-12-14 Thread Zachary Henkel via Phabricator via cfe-commits
zahen added a comment.

In D55685#1331810 , @zturner wrote:

> BTW, as far as updating the demangler, as long as it doesn't crash or 
> generate an error on a valid `_E` mangling, that should be sufficient (with a 
> test).  If you want bonus points you can make it print out `noexcept` when 
> you see the `_E`, but I won't require it as it's a bit of extra work.  If you 
> decide not to do that, I'll just file a bug for it so that we don't forget.


I have the full set of demangler updates ready to go and will upload shortly 
(Monday at the latest due to travel)


Repository:
  rC Clang

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

https://reviews.llvm.org/D55685



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


[PATCH] D55715: Add AddressSpace mangling to MS mode

2018-12-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane marked an inline comment as done.
erichkeane added inline comments.



Comment at: test/CodeGenCXX/mangle-address-space.cpp:7
+// CHECKNOOCL-LABEL: define {{.*}}void @_Z2f0Pc
+// WINNOOCL-LABEL: define {{.*}}void @"?f0@@YAXPEAD@Z"
+// CHECKOCL-LABEL: define {{.*}}void @_Z2f0PU9CLgenericc

rnk wrote:
> erichkeane wrote:
> > rnk wrote:
> > > You know, now that we have a demangler, I wonder if we shouldn't add a 
> > > RUN line like this to test that these names really do demangle properly:
> > > `// RUN: %clang_cc1 %s ... -emit-bitcode -o - | llvm-nm -demangle - | 
> > > FileCheck %s --check-prefix=DEMANGLED`
> > I'm not sure how that would work, but I can take a look.
> Any thoughts on this? I see, llvm-nm -demangle doesn't call the microsoft 
> demangler.
I wasn't able to find a way that would call this.  Also, some of my test 
machines don't seem to default build llvm-undname always (which would be 
required for the windows ones).


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

https://reviews.llvm.org/D55715



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


[PATCH] D54604: Automatic variable initialization

2018-12-14 Thread JF Bastien via Phabricator via cfe-commits
jfb updated this revision to Diff 178304.
jfb added a comment.

- Rebase


Repository:
  rC Clang

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

https://reviews.llvm.org/D54604

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Basic/LangOptions.def
  include/clang/Basic/LangOptions.h
  include/clang/Driver/Options.td
  include/clang/Driver/ToolChain.h
  lib/CodeGen/CGDecl.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCXX/auto-var-init.cpp
  test/CodeGenCXX/trivial-auto-var-init-attribute.cpp
  test/CodeGenCXX/trivial-auto-var-init.cpp
  test/Driver/clang_f_opts.c
  test/Sema/attr-uninitialized.c
  test/Sema/uninit-variables.c

Index: test/Sema/uninit-variables.c
===
--- test/Sema/uninit-variables.c
+++ test/Sema/uninit-variables.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wuninitialized -Wconditional-uninitialized -fsyntax-only -fblocks %s -verify
+// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -Wconditional-uninitialized -ftrivial-auto-var-init=pattern -fsyntax-only -fblocks %s -verify
 
 typedef __typeof(sizeof(int)) size_t;
 void *malloc(size_t);
Index: test/Sema/attr-uninitialized.c
===
--- /dev/null
+++ test/Sema/attr-uninitialized.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+void good() {
+  int dont_initialize_me __attribute((uninitialized));
+}
+
+void bad() {
+  int im_bad __attribute((uninitialized("zero")));  // expected-error {{'uninitialized' attribute takes no arguments}}
+  static int im_baaad __attribute((uninitialized)); // expected-warning {{'uninitialized' attribute only applies to local variables}}
+}
+
+extern int come_on __attribute((uninitialized));// expected-warning {{'uninitialized' attribute only applies to local variables}}
+int you_know __attribute((uninitialized));  // expected-warning {{'uninitialized' attribute only applies to local variables}}
+static int and_the_whole_world_has_to __attribute((uninitialized)); // expected-warning {{'uninitialized' attribute only applies to local variables}}
+
+void answer_right_now() __attribute((uninitialized)) {}// expected-warning {{'uninitialized' attribute only applies to local variables}}
+void just_to_tell_you_once_again(__attribute((uninitialized)) int whos_bad) {} // expected-warning {{'uninitialized' attribute only applies to local variables}}
+
+struct TheWordIsOut {
+  __attribute((uninitialized)) int youre_doin_wrong; // expected-warning {{'uninitialized' attribute only applies to local variables}}
+} __attribute((uninitialized));  // expected-warning {{'uninitialized' attribute only applies to local variables}}
Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -557,3 +557,12 @@
 // CHECK-RECORD-GCC-SWITCHES: "-record-command-line"
 // CHECK-NO-RECORD-GCC-SWITCHES-NOT: "-record-command-line"
 // CHECK-RECORD-GCC-SWITCHES-ERROR: error: unsupported option '-frecord-command-line' for target
+
+// RUN: %clang -### -S -ftrivial-auto-var-init=uninitialized %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-UNINIT %s
+// RUN: %clang -### -S -ftrivial-auto-var-init=pattern %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-PATTERN %s
+// RUN: %clang -### -S -ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-ZERO-GOOD %s
+// RUN: %clang -### -S -ftrivial-auto-var-init=zero %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-ZERO-BAD %s
+// CHECK-TRIVIAL-UNINIT-NOT: hasn't been enabled
+// CHECK-TRIVIAL-PATTERN-NOT: hasn't been enabled
+// CHECK-TRIVIAL-ZERO-GOOD-NOT: hasn't been enabled
+// CHECK-TRIVIAL-ZERO-BAD: hasn't been enabled
Index: test/CodeGenCXX/trivial-auto-var-init.cpp
===
--- /dev/null
+++ test/CodeGenCXX/trivial-auto-var-init.cpp
@@ -0,0 +1,216 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks %s -emit-llvm -o - | FileCheck %s -check-prefix=UNINIT
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks -ftrivial-auto-var-init=pattern %s -emit-llvm -o - | FileCheck %s -check-prefix=PATTERN
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks -ftrivial-auto-var-init=zero %s -emit-llvm -o - | FileCheck %s -check-prefix=ZERO
+
+// None of the synthesized globals should contain `undef`.
+// PATTERN-NOT: undef
+// ZERO-NOT: undef
+
+template void used(T &) noexcept;
+
+extern "C" {
+
+// UNINIT-LABEL:  test_selfinit(
+// ZERO-LABEL:test_selfinit(
+// ZERO: store i32 0, i32* %self, align 4
+// PATTERN-LABEL: 

[PATCH] D55685: Update Microsoft name mangling scheme for exception specifiers in the type system

2018-12-14 Thread Zachary Turner via Phabricator via cfe-commits
zturner added a comment.

BTW, as far as updating the demangler, as long as it doesn't crash or generate 
an error on a valid `_E` mangling, that should be sufficient (with a test).  If 
you want bonus points you can make it print out `noexcept` when you see the 
`_E`, but I won't require it as it's a bit of extra work.  If you decide not to 
do that, I'll just file a bug for it so that we don't forget.




Comment at: lib/AST/MicrosoftMangle.cpp:2311-2314
+  if (FT->canThrow())
+Out << 'Z';
+  else
+Out << "_E";

rnk wrote:
> zahen wrote:
> > zturner wrote:
> > > I knew that the mangling changed whenever a pointer to a `noexcept` 
> > > function is passed as an argument, and we don't yet handle that, but I'm 
> > > surprised to hear that they changed an existing mangling, since it's a 
> > > hard ABI break.
> > > 
> > > Do you know the major and minor version numbers that this changed in?  
> > > I'd like to test it out for starters, but also since this is an ABI break 
> > > we would need to put it behind `-fms-compatibility-version` and only 
> > > mangle using the new scheme when the compatibility version is 
> > > sufficiently high.
> > It's only when a function is used as a type.  My original rathole was 
> > trying to enumerate all of the places where that could be, but instead I 
> > settled on "everywhere but the initial definition".  It's why false is 
> > passed in the 4th parameter on line 516.
> > 
> > I've confirmed this changed in 15.5 so I'll use that as the compat version.
> I see existing code that uses this pattern: 
> `getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2015)`
> 
> The MSVCMajorVersion enum is symbolic, so I think you might have to multiply 
> it by a hundred and modify LangOptions::isCompatibleWithMSVC to multiply by 
> two fewer places.
> 
> I guess to fit with the existing enums we'd say MSVC2017_5, even though that 
> conflates VS and VC version numbers.
Ok, I see it now.  That should be fine.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55685



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


[PATCH] D55715: Add AddressSpace mangling to MS mode

2018-12-14 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm




Comment at: test/CodeGenCXX/mangle-address-space.cpp:7
+// CHECKNOOCL-LABEL: define {{.*}}void @_Z2f0Pc
+// WINNOOCL-LABEL: define {{.*}}void @"?f0@@YAXPEAD@Z"
+// CHECKOCL-LABEL: define {{.*}}void @_Z2f0PU9CLgenericc

erichkeane wrote:
> rnk wrote:
> > You know, now that we have a demangler, I wonder if we shouldn't add a RUN 
> > line like this to test that these names really do demangle properly:
> > `// RUN: %clang_cc1 %s ... -emit-bitcode -o - | llvm-nm -demangle - | 
> > FileCheck %s --check-prefix=DEMANGLED`
> I'm not sure how that would work, but I can take a look.
Any thoughts on this? I see, llvm-nm -demangle doesn't call the microsoft 
demangler.


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

https://reviews.llvm.org/D55715



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


[PATCH] D53713: Add extension to always default-initialize nullptr_t.

2018-12-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: test/Analysis/nullptr.cpp:136
-invokeF(p); // expected-warning{{1st function call argument is an 
uninitialized value}}
-// expected-note@-1{{1st function call argument is an 
uninitialized value}}
   if (getSymbol()) // expected-note   {{Assuming the condition is false}}

rsmith wrote:
> This bug is already fixed in trunk.
Never mind, the fix was reverted in r346065.


Repository:
  rC Clang

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

https://reviews.llvm.org/D53713



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


RE: r349201 - Add extension to always default-initialize nullptr_t.

2018-12-14 Thread Keane, Erich via cfe-commits
Thanks!  I’ll take a look in a bit!
-Erich

From: Richard Smith [mailto:rich...@metafoo.co.uk]
Sent: Friday, December 14, 2018 2:55 PM
To: Keane, Erich 
Cc: cfe-commits 
Subject: Re: r349201 - Add extension to always default-initialize nullptr_t.

Attached. With the functional part of your change reverted and this applied, 
the modified tests still pass except

error: 'note' diagnostics expected but not seen:
  File 
/usr/local/google/home/richardsmith/llvm-git-1/src/tools/clang/test/Analysis/nullptr.cpp
 Line 128: 'p' initialized to a null pointer value
error: 'note' diagnostics seen but not expected:
  File 
/usr/local/google/home/richardsmith/llvm-git-1/src/tools/clang/test/Analysis/nullptr.cpp
 Line 128: 'p' declared without an initial value

... which seems accurate (but perhaps not useful).

On Fri, 14 Dec 2018 at 14:47, Richard Smith 
mailto:rich...@metafoo.co.uk>> wrote:
I have a patch I put together a while back as an attempt to fix a different 
bug, that creates a new CastKind for this operation (didn't work out there, but 
it might do so here). I'll dig it out and mail it to you in case it's a useful 
starting point.

On Fri, 14 Dec 2018 at 14:42, Keane, Erich via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:
Alright, no problem.  I’ll push a revert in a few minutes and give it another 
try.  Perhaps I can suppress the creation of a CK_LValueToRValue in the case 
where it’s a read from nullptr_t


From: Richard Smith [mailto:rich...@metafoo.co.uk]
Sent: Friday, December 14, 2018 2:41 PM
To: Keane, Erich mailto:erich.ke...@intel.com>>
Cc: cfe-commits mailto:cfe-commits@lists.llvm.org>>
Subject: Re: r349201 - Add extension to always default-initialize nullptr_t.

Sorry, I was late with my review comment. I think this is the wrong way to 
approach this problem. This does not "fix all situations where nullptr_t would 
seem uninitialized", and it makes our AST representation lose source fidelity.

On Fri, 14 Dec 2018 at 14:25, Erich Keane via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:
Author: erichkeane
Date: Fri Dec 14 14:22:29 2018
New Revision: 349201

URL: http://llvm.org/viewvc/llvm-project?rev=349201=rev
Log:
Add extension to always default-initialize nullptr_t.

Core issue 1013 suggests that having an uninitialied std::nullptr_t be
UB is a bit foolish, since there is only a single valid value. This DR
reports that DR616 fixes it, which does so by making lvalue-to-rvalue
conversions from nullptr_t be equal to nullptr.

However, just implementing that results in warnings/etc in many places.
In order to fix all situations where nullptr_t would seem uninitialized,
this patch instead (as an otherwise transparent extension) default
initializes uninitialized VarDecls of nullptr_t.

Differential Revision: https://reviews.llvm.org/D53713

Change-Id: I84d72a9290054fa55341e8cbdac43c8e7f25b885

Added:
cfe/trunk/test/SemaCXX/nullptr_t-init.cpp   (with props)
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/Analysis/nullptr.cpp
cfe/trunk/test/SemaCXX/ast-print-crash.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=349201=349200=349201=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Dec 14 14:22:29 2018
@@ -4881,6 +4881,13 @@ static void TryDefaultInitialization(Sem
 return;
   }

+  // As an extension, and to fix Core issue 1013, zero initialize nullptr_t.
+  // Since there is only 1 valid value of nullptr_t, we can just use that.
+  if (DestType->isNullPtrType()) {
+Sequence.AddZeroInitializationStep(Entity.getType());
+return;
+  }
+
   // - otherwise, no initialization is performed.

   //   If a program calls for the default initialization of an object of

Modified: cfe/trunk/test/Analysis/nullptr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/nullptr.cpp?rev=349201=349200=349201=diff
==
--- cfe/trunk/test/Analysis/nullptr.cpp (original)
+++ cfe/trunk/test/Analysis/nullptr.cpp Fri Dec 14 14:22:29 2018
@@ -125,21 +125,16 @@ struct Type {
 };

 void shouldNotCrash() {
-  decltype(nullptr) p; // expected-note{{'p' declared without an initial 
value}}
-  if (getSymbol()) // expected-note   {{Assuming the condition is false}}
-   // expected-note@-1{{Taking false branch}}
-   // expected-note@-2{{Assuming the condition is false}}
-   // expected-note@-3{{Taking false branch}}
-   // expected-note@-4{{Assuming the condition is true}}
-   // expected-note@-5{{Taking true branch}}
-invokeF(p); // expected-warning{{1st function call argument is an 
uninitialized value}}
-// expected-note@-1{{1st function call argument is an 

[PATCH] D54604: Automatic variable initialization

2018-12-14 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

In D54604#1331711 , @pcc wrote:

> Mostly looking good, a few style nits.


Thanks! I think I addressed all of your comments.


Repository:
  rC Clang

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

https://reviews.llvm.org/D54604



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


[PATCH] D54604: Automatic variable initialization

2018-12-14 Thread JF Bastien via Phabricator via cfe-commits
jfb updated this revision to Diff 178301.
jfb marked 6 inline comments as done.
jfb added a comment.

- Address @pcc's comments.


Repository:
  rC Clang

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

https://reviews.llvm.org/D54604

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Basic/LangOptions.def
  include/clang/Basic/LangOptions.h
  include/clang/Driver/Options.td
  include/clang/Driver/ToolChain.h
  lib/CodeGen/CGDecl.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCXX/auto-var-init.cpp
  test/CodeGenCXX/trivial-auto-var-init-attribute.cpp
  test/CodeGenCXX/trivial-auto-var-init.cpp
  test/Driver/clang_f_opts.c
  test/Sema/attr-uninitialized.c
  test/Sema/uninit-variables.c

Index: test/Sema/uninit-variables.c
===
--- test/Sema/uninit-variables.c
+++ test/Sema/uninit-variables.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wuninitialized -Wconditional-uninitialized -fsyntax-only -fblocks %s -verify
+// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -Wconditional-uninitialized -ftrivial-auto-var-init=pattern -fsyntax-only -fblocks %s -verify
 
 typedef __typeof(sizeof(int)) size_t;
 void *malloc(size_t);
Index: test/Sema/attr-uninitialized.c
===
--- /dev/null
+++ test/Sema/attr-uninitialized.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+void good() {
+  int dont_initialize_me __attribute((uninitialized));
+}
+
+void bad() {
+  int im_bad __attribute((uninitialized("zero")));  // expected-error {{'uninitialized' attribute takes no arguments}}
+  static int im_baaad __attribute((uninitialized)); // expected-warning {{'uninitialized' attribute only applies to local variables}}
+}
+
+extern int come_on __attribute((uninitialized));// expected-warning {{'uninitialized' attribute only applies to local variables}}
+int you_know __attribute((uninitialized));  // expected-warning {{'uninitialized' attribute only applies to local variables}}
+static int and_the_whole_world_has_to __attribute((uninitialized)); // expected-warning {{'uninitialized' attribute only applies to local variables}}
+
+void answer_right_now() __attribute((uninitialized)) {}// expected-warning {{'uninitialized' attribute only applies to local variables}}
+void just_to_tell_you_once_again(__attribute((uninitialized)) int whos_bad) {} // expected-warning {{'uninitialized' attribute only applies to local variables}}
+
+struct TheWordIsOut {
+  __attribute((uninitialized)) int youre_doin_wrong; // expected-warning {{'uninitialized' attribute only applies to local variables}}
+} __attribute((uninitialized));  // expected-warning {{'uninitialized' attribute only applies to local variables}}
Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -542,3 +542,12 @@
 // RUN: %clang -### -S -fomit-frame-pointer -fno-omit-frame-pointer -pg %s 2>&1 | FileCheck -check-prefix=CHECK-MIX-NO-OMIT-FP-PG %s
 // CHECK-NO-MIX-OMIT-FP-PG: '-fomit-frame-pointer' not allowed with '-pg'
 // CHECK-MIX-NO-OMIT-FP-PG-NOT: '-fomit-frame-pointer' not allowed with '-pg'
+
+// RUN: %clang -### -S -ftrivial-auto-var-init=uninitialized %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-UNINIT %s
+// RUN: %clang -### -S -ftrivial-auto-var-init=pattern %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-PATTERN %s
+// RUN: %clang -### -S -ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-ZERO-GOOD %s
+// RUN: %clang -### -S -ftrivial-auto-var-init=zero %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-ZERO-BAD %s
+// CHECK-TRIVIAL-UNINIT-NOT: hasn't been enabled
+// CHECK-TRIVIAL-PATTERN-NOT: hasn't been enabled
+// CHECK-TRIVIAL-ZERO-GOOD-NOT: hasn't been enabled
+// CHECK-TRIVIAL-ZERO-BAD: hasn't been enabled
Index: test/CodeGenCXX/trivial-auto-var-init.cpp
===
--- /dev/null
+++ test/CodeGenCXX/trivial-auto-var-init.cpp
@@ -0,0 +1,216 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks %s -emit-llvm -o - | FileCheck %s -check-prefix=UNINIT
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks -ftrivial-auto-var-init=pattern %s -emit-llvm -o - | FileCheck %s -check-prefix=PATTERN
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks -ftrivial-auto-var-init=zero %s -emit-llvm -o - | FileCheck %s -check-prefix=ZERO
+
+// None of the synthesized globals should contain `undef`.
+// PATTERN-NOT: undef
+// ZERO-NOT: undef
+
+template void used(T &) noexcept;
+
+extern "C" {
+
+// 

Re: r349201 - Add extension to always default-initialize nullptr_t.

2018-12-14 Thread Richard Smith via cfe-commits
Attached. With the functional part of your change reverted and this
applied, the modified tests still pass except

error: 'note' diagnostics expected but not seen:
  File
/usr/local/google/home/richardsmith/llvm-git-1/src/tools/clang/test/Analysis/nullptr.cpp
Line 128: 'p' initialized to a null pointer value
error: 'note' diagnostics seen but not expected:
  File
/usr/local/google/home/richardsmith/llvm-git-1/src/tools/clang/test/Analysis/nullptr.cpp
Line 128: 'p' declared without an initial value

... which seems accurate (but perhaps not useful).

On Fri, 14 Dec 2018 at 14:47, Richard Smith  wrote:

> I have a patch I put together a while back as an attempt to fix a
> different bug, that creates a new CastKind for this operation (didn't work
> out there, but it might do so here). I'll dig it out and mail it to you in
> case it's a useful starting point.
>
> On Fri, 14 Dec 2018 at 14:42, Keane, Erich via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Alright, no problem.  I’ll push a revert in a few minutes and give it
>> another try.  Perhaps I can suppress the creation of a CK_LValueToRValue in
>> the case where it’s a read from nullptr_t
>>
>>
>>
>>
>>
>> *From:* Richard Smith [mailto:rich...@metafoo.co.uk]
>> *Sent:* Friday, December 14, 2018 2:41 PM
>> *To:* Keane, Erich 
>> *Cc:* cfe-commits 
>> *Subject:* Re: r349201 - Add extension to always default-initialize
>> nullptr_t.
>>
>>
>>
>> Sorry, I was late with my review comment. I think this is the wrong way
>> to approach this problem. This does not "fix all situations where nullptr_t
>> would seem uninitialized", and it makes our AST representation lose source
>> fidelity.
>>
>>
>>
>> On Fri, 14 Dec 2018 at 14:25, Erich Keane via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>> Author: erichkeane
>> Date: Fri Dec 14 14:22:29 2018
>> New Revision: 349201
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=349201=rev
>> Log:
>> Add extension to always default-initialize nullptr_t.
>>
>> Core issue 1013 suggests that having an uninitialied std::nullptr_t be
>> UB is a bit foolish, since there is only a single valid value. This DR
>> reports that DR616 fixes it, which does so by making lvalue-to-rvalue
>> conversions from nullptr_t be equal to nullptr.
>>
>> However, just implementing that results in warnings/etc in many places.
>> In order to fix all situations where nullptr_t would seem uninitialized,
>> this patch instead (as an otherwise transparent extension) default
>> initializes uninitialized VarDecls of nullptr_t.
>>
>> Differential Revision: https://reviews.llvm.org/D53713
>>
>> Change-Id: I84d72a9290054fa55341e8cbdac43c8e7f25b885
>>
>> Added:
>> cfe/trunk/test/SemaCXX/nullptr_t-init.cpp   (with props)
>> Modified:
>> cfe/trunk/lib/Sema/SemaInit.cpp
>> cfe/trunk/test/Analysis/nullptr.cpp
>> cfe/trunk/test/SemaCXX/ast-print-crash.cpp
>>
>> Modified: cfe/trunk/lib/Sema/SemaInit.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=349201=349200=349201=diff
>>
>> ==
>> --- cfe/trunk/lib/Sema/SemaInit.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Dec 14 14:22:29 2018
>> @@ -4881,6 +4881,13 @@ static void TryDefaultInitialization(Sem
>>  return;
>>}
>>
>> +  // As an extension, and to fix Core issue 1013, zero initialize
>> nullptr_t.
>> +  // Since there is only 1 valid value of nullptr_t, we can just use
>> that.
>> +  if (DestType->isNullPtrType()) {
>> +Sequence.AddZeroInitializationStep(Entity.getType());
>> +return;
>> +  }
>> +
>>// - otherwise, no initialization is performed.
>>
>>//   If a program calls for the default initialization of an object of
>>
>> Modified: cfe/trunk/test/Analysis/nullptr.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/nullptr.cpp?rev=349201=349200=349201=diff
>>
>> ==
>> --- cfe/trunk/test/Analysis/nullptr.cpp (original)
>> +++ cfe/trunk/test/Analysis/nullptr.cpp Fri Dec 14 14:22:29 2018
>> @@ -125,21 +125,16 @@ struct Type {
>>  };
>>
>>  void shouldNotCrash() {
>> -  decltype(nullptr) p; // expected-note{{'p' declared without an initial
>> value}}
>> -  if (getSymbol()) // expected-note   {{Assuming the condition is false}}
>> -   // expected-note@-1{{Taking false branch}}
>> -   // expected-note@-2{{Assuming the condition is
>> false}}
>> -   // expected-note@-3{{Taking false branch}}
>> -   // expected-note@-4{{Assuming the condition is true}}
>> -   // expected-note@-5{{Taking true branch}}
>> -invokeF(p); // expected-warning{{1st function call argument is an
>> uninitialized value}}
>> -// expected-note@-1{{1st function call argument is an
>> uninitialized value}}
>> +  decltype(nullptr) p; // expected-note{{'p' initialized to 

[PATCH] D55685: Update Microsoft name mangling scheme for exception specifiers in the type system

2018-12-14 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: lib/AST/MicrosoftMangle.cpp:2311-2314
+  if (FT->canThrow())
+Out << 'Z';
+  else
+Out << "_E";

zahen wrote:
> zturner wrote:
> > I knew that the mangling changed whenever a pointer to a `noexcept` 
> > function is passed as an argument, and we don't yet handle that, but I'm 
> > surprised to hear that they changed an existing mangling, since it's a hard 
> > ABI break.
> > 
> > Do you know the major and minor version numbers that this changed in?  I'd 
> > like to test it out for starters, but also since this is an ABI break we 
> > would need to put it behind `-fms-compatibility-version` and only mangle 
> > using the new scheme when the compatibility version is sufficiently high.
> It's only when a function is used as a type.  My original rathole was trying 
> to enumerate all of the places where that could be, but instead I settled on 
> "everywhere but the initial definition".  It's why false is passed in the 4th 
> parameter on line 516.
> 
> I've confirmed this changed in 15.5 so I'll use that as the compat version.
I see existing code that uses this pattern: 
`getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2015)`

The MSVCMajorVersion enum is symbolic, so I think you might have to multiply it 
by a hundred and modify LangOptions::isCompatibleWithMSVC to multiply by two 
fewer places.

I guess to fit with the existing enums we'd say MSVC2017_5, even though that 
conflates VS and VC version numbers.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55685



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


Re: r349201 - Add extension to always default-initialize nullptr_t.

2018-12-14 Thread Richard Smith via cfe-commits
I have a patch I put together a while back as an attempt to fix a different
bug, that creates a new CastKind for this operation (didn't work out there,
but it might do so here). I'll dig it out and mail it to you in case it's a
useful starting point.

On Fri, 14 Dec 2018 at 14:42, Keane, Erich via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Alright, no problem.  I’ll push a revert in a few minutes and give it
> another try.  Perhaps I can suppress the creation of a CK_LValueToRValue in
> the case where it’s a read from nullptr_t
>
>
>
>
>
> *From:* Richard Smith [mailto:rich...@metafoo.co.uk]
> *Sent:* Friday, December 14, 2018 2:41 PM
> *To:* Keane, Erich 
> *Cc:* cfe-commits 
> *Subject:* Re: r349201 - Add extension to always default-initialize
> nullptr_t.
>
>
>
> Sorry, I was late with my review comment. I think this is the wrong way to
> approach this problem. This does not "fix all situations where nullptr_t
> would seem uninitialized", and it makes our AST representation lose source
> fidelity.
>
>
>
> On Fri, 14 Dec 2018 at 14:25, Erich Keane via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> Author: erichkeane
> Date: Fri Dec 14 14:22:29 2018
> New Revision: 349201
>
> URL: http://llvm.org/viewvc/llvm-project?rev=349201=rev
> Log:
> Add extension to always default-initialize nullptr_t.
>
> Core issue 1013 suggests that having an uninitialied std::nullptr_t be
> UB is a bit foolish, since there is only a single valid value. This DR
> reports that DR616 fixes it, which does so by making lvalue-to-rvalue
> conversions from nullptr_t be equal to nullptr.
>
> However, just implementing that results in warnings/etc in many places.
> In order to fix all situations where nullptr_t would seem uninitialized,
> this patch instead (as an otherwise transparent extension) default
> initializes uninitialized VarDecls of nullptr_t.
>
> Differential Revision: https://reviews.llvm.org/D53713
>
> Change-Id: I84d72a9290054fa55341e8cbdac43c8e7f25b885
>
> Added:
> cfe/trunk/test/SemaCXX/nullptr_t-init.cpp   (with props)
> Modified:
> cfe/trunk/lib/Sema/SemaInit.cpp
> cfe/trunk/test/Analysis/nullptr.cpp
> cfe/trunk/test/SemaCXX/ast-print-crash.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaInit.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=349201=349200=349201=diff
>
> ==
> --- cfe/trunk/lib/Sema/SemaInit.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Dec 14 14:22:29 2018
> @@ -4881,6 +4881,13 @@ static void TryDefaultInitialization(Sem
>  return;
>}
>
> +  // As an extension, and to fix Core issue 1013, zero initialize
> nullptr_t.
> +  // Since there is only 1 valid value of nullptr_t, we can just use that.
> +  if (DestType->isNullPtrType()) {
> +Sequence.AddZeroInitializationStep(Entity.getType());
> +return;
> +  }
> +
>// - otherwise, no initialization is performed.
>
>//   If a program calls for the default initialization of an object of
>
> Modified: cfe/trunk/test/Analysis/nullptr.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/nullptr.cpp?rev=349201=349200=349201=diff
>
> ==
> --- cfe/trunk/test/Analysis/nullptr.cpp (original)
> +++ cfe/trunk/test/Analysis/nullptr.cpp Fri Dec 14 14:22:29 2018
> @@ -125,21 +125,16 @@ struct Type {
>  };
>
>  void shouldNotCrash() {
> -  decltype(nullptr) p; // expected-note{{'p' declared without an initial
> value}}
> -  if (getSymbol()) // expected-note   {{Assuming the condition is false}}
> -   // expected-note@-1{{Taking false branch}}
> -   // expected-note@-2{{Assuming the condition is false}}
> -   // expected-note@-3{{Taking false branch}}
> -   // expected-note@-4{{Assuming the condition is true}}
> -   // expected-note@-5{{Taking true branch}}
> -invokeF(p); // expected-warning{{1st function call argument is an
> uninitialized value}}
> -// expected-note@-1{{1st function call argument is an
> uninitialized value}}
> +  decltype(nullptr) p; // expected-note{{'p' initialized to a null
> pointer value}}
>if (getSymbol()) // expected-note   {{Assuming the condition is false}}
> // expected-note@-1{{Taking false branch}}
> // expected-note@-2{{Assuming the condition is true}}
> // expected-note@-3{{Taking true branch}}
> -invokeF(nullptr); // expected-note   {{Calling 'invokeF'}}
> -  // expected-note@-1{{Passing null pointer value
> via 1st parameter 'x'}}
> +invokeF(p); // expected-note{{Passing null pointer value via 1st
> parameter 'x'}}
> +// expected-note@-1{{Calling 'invokeF'}}
> +  if (getSymbol()) // expected-note   {{Assuming the condition is false}}
> +   // 

[PATCH] D55685: Update Microsoft name mangling scheme for exception specifiers in the type system

2018-12-14 Thread Zachary Henkel via Phabricator via cfe-commits
zahen added a comment.

In D55685#1330717 , @zturner wrote:

> Also we still need to put this behind `-fms-compatibility-version`.  Finally, 
> it would be nice if you could also update the demangler 
> (`llvm/lib/Demangle/MicrosoftDemangle.cpp`)


This was introduced in 15.5 (1912).  What's the preferred way to represent that 
in clang code?




Comment at: lib/AST/MicrosoftMangle.cpp:2311-2314
+  if (FT->canThrow())
+Out << 'Z';
+  else
+Out << "_E";

zturner wrote:
> I knew that the mangling changed whenever a pointer to a `noexcept` function 
> is passed as an argument, and we don't yet handle that, but I'm surprised to 
> hear that they changed an existing mangling, since it's a hard ABI break.
> 
> Do you know the major and minor version numbers that this changed in?  I'd 
> like to test it out for starters, but also since this is an ABI break we 
> would need to put it behind `-fms-compatibility-version` and only mangle 
> using the new scheme when the compatibility version is sufficiently high.
It's only when a function is used as a type.  My original rathole was trying to 
enumerate all of the places where that could be, but instead I settled on 
"everywhere but the initial definition".  It's why false is passed in the 4th 
parameter on line 516.

I've confirmed this changed in 15.5 so I'll use that as the compat version.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55685



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


r349206 - Revert "Add extension to always default-initialize nullptr_t."

2018-12-14 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Fri Dec 14 14:41:18 2018
New Revision: 349206

URL: http://llvm.org/viewvc/llvm-project?rev=349206=rev
Log:
Revert "Add extension to always default-initialize nullptr_t."

This reverts commit 46efdf2ccc2a80aefebf8433dbf9c7c959f6e629.

Richard Smith commented just after I submitted this that this is the
wrong solution.  Reverting so that I can fix differently.

Removed:
cfe/trunk/test/SemaCXX/nullptr_t-init.cpp
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/Analysis/nullptr.cpp
cfe/trunk/test/SemaCXX/ast-print-crash.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=349206=349205=349206=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Dec 14 14:41:18 2018
@@ -4881,13 +4881,6 @@ static void TryDefaultInitialization(Sem
 return;
   }
 
-  // As an extension, and to fix Core issue 1013, zero initialize nullptr_t.
-  // Since there is only 1 valid value of nullptr_t, we can just use that.
-  if (DestType->isNullPtrType()) {
-Sequence.AddZeroInitializationStep(Entity.getType());
-return;
-  }
-
   // - otherwise, no initialization is performed.
 
   //   If a program calls for the default initialization of an object of

Modified: cfe/trunk/test/Analysis/nullptr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/nullptr.cpp?rev=349206=349205=349206=diff
==
--- cfe/trunk/test/Analysis/nullptr.cpp (original)
+++ cfe/trunk/test/Analysis/nullptr.cpp Fri Dec 14 14:41:18 2018
@@ -125,16 +125,21 @@ struct Type {
 };
 
 void shouldNotCrash() {
-  decltype(nullptr) p; // expected-note{{'p' initialized to a null pointer 
value}}
+  decltype(nullptr) p; // expected-note{{'p' declared without an initial 
value}}
   if (getSymbol()) // expected-note   {{Assuming the condition is false}}
// expected-note@-1{{Taking false branch}}
-   // expected-note@-2{{Assuming the condition is true}}
-   // expected-note@-3{{Taking true branch}}
-invokeF(p); // expected-note{{Passing null pointer value via 1st parameter 
'x'}}
-// expected-note@-1{{Calling 'invokeF'}}
+   // expected-note@-2{{Assuming the condition is false}}
+   // expected-note@-3{{Taking false branch}}
+   // expected-note@-4{{Assuming the condition is true}}
+   // expected-note@-5{{Taking true branch}}
+invokeF(p); // expected-warning{{1st function call argument is an 
uninitialized value}}
+// expected-note@-1{{1st function call argument is an 
uninitialized value}}
   if (getSymbol()) // expected-note   {{Assuming the condition is false}}
// expected-note@-1{{Taking false branch}}
-invokeF(nullptr);
+   // expected-note@-2{{Assuming the condition is true}}
+   // expected-note@-3{{Taking true branch}}
+invokeF(nullptr); // expected-note   {{Calling 'invokeF'}}
+  // expected-note@-1{{Passing null pointer value via 1st 
parameter 'x'}}
   if (getSymbol()) {  // expected-note  {{Assuming the condition is true}}
   // expected-note@-1{{Taking true branch}}
 X *xx = Type().x; // expected-note   {{Null pointer value stored to field 
'x'}}

Modified: cfe/trunk/test/SemaCXX/ast-print-crash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ast-print-crash.cpp?rev=349206=349205=349206=diff
==
--- cfe/trunk/test/SemaCXX/ast-print-crash.cpp (original)
+++ cfe/trunk/test/SemaCXX/ast-print-crash.cpp Fri Dec 14 14:41:18 2018
@@ -7,6 +7,6 @@
 
 // CHECK:  struct {
 // CHECK-NEXT: } dont_crash_on_syntax_error;
-// CHECK-NEXT: decltype(nullptr) p(/*implicit*/(decltype(nullptr))0);
+// CHECK-NEXT: decltype(nullptr) p;
 struct {
 } dont_crash_on_syntax_error /* missing ; */ decltype(nullptr) p;

Removed: cfe/trunk/test/SemaCXX/nullptr_t-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nullptr_t-init.cpp?rev=349205=auto
==
--- cfe/trunk/test/SemaCXX/nullptr_t-init.cpp (original)
+++ cfe/trunk/test/SemaCXX/nullptr_t-init.cpp (removed)
@@ -1,10 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -ffreestanding 
-Wuninitialized %s
-// expected-no-diagnostics
-typedef decltype(nullptr) nullptr_t;
-
-// Ensure no 'uninitialized when used here' warnings (Wuninitialized), for 
-// nullptr_t always-initialized extension.
-nullptr_t default_init() {
-  nullptr_t a;
-  return a;
-}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org

RE: r349201 - Add extension to always default-initialize nullptr_t.

2018-12-14 Thread Keane, Erich via cfe-commits
Reverted in r349206.

From: Richard Smith [mailto:rich...@metafoo.co.uk]
Sent: Friday, December 14, 2018 2:41 PM
To: Keane, Erich 
Cc: cfe-commits 
Subject: Re: r349201 - Add extension to always default-initialize nullptr_t.

Sorry, I was late with my review comment. I think this is the wrong way to 
approach this problem. This does not "fix all situations where nullptr_t would 
seem uninitialized", and it makes our AST representation lose source fidelity.

On Fri, 14 Dec 2018 at 14:25, Erich Keane via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:
Author: erichkeane
Date: Fri Dec 14 14:22:29 2018
New Revision: 349201

URL: http://llvm.org/viewvc/llvm-project?rev=349201=rev
Log:
Add extension to always default-initialize nullptr_t.

Core issue 1013 suggests that having an uninitialied std::nullptr_t be
UB is a bit foolish, since there is only a single valid value. This DR
reports that DR616 fixes it, which does so by making lvalue-to-rvalue
conversions from nullptr_t be equal to nullptr.

However, just implementing that results in warnings/etc in many places.
In order to fix all situations where nullptr_t would seem uninitialized,
this patch instead (as an otherwise transparent extension) default
initializes uninitialized VarDecls of nullptr_t.

Differential Revision: https://reviews.llvm.org/D53713

Change-Id: I84d72a9290054fa55341e8cbdac43c8e7f25b885

Added:
cfe/trunk/test/SemaCXX/nullptr_t-init.cpp   (with props)
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/Analysis/nullptr.cpp
cfe/trunk/test/SemaCXX/ast-print-crash.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=349201=349200=349201=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Dec 14 14:22:29 2018
@@ -4881,6 +4881,13 @@ static void TryDefaultInitialization(Sem
 return;
   }

+  // As an extension, and to fix Core issue 1013, zero initialize nullptr_t.
+  // Since there is only 1 valid value of nullptr_t, we can just use that.
+  if (DestType->isNullPtrType()) {
+Sequence.AddZeroInitializationStep(Entity.getType());
+return;
+  }
+
   // - otherwise, no initialization is performed.

   //   If a program calls for the default initialization of an object of

Modified: cfe/trunk/test/Analysis/nullptr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/nullptr.cpp?rev=349201=349200=349201=diff
==
--- cfe/trunk/test/Analysis/nullptr.cpp (original)
+++ cfe/trunk/test/Analysis/nullptr.cpp Fri Dec 14 14:22:29 2018
@@ -125,21 +125,16 @@ struct Type {
 };

 void shouldNotCrash() {
-  decltype(nullptr) p; // expected-note{{'p' declared without an initial 
value}}
-  if (getSymbol()) // expected-note   {{Assuming the condition is false}}
-   // expected-note@-1{{Taking false branch}}
-   // expected-note@-2{{Assuming the condition is false}}
-   // expected-note@-3{{Taking false branch}}
-   // expected-note@-4{{Assuming the condition is true}}
-   // expected-note@-5{{Taking true branch}}
-invokeF(p); // expected-warning{{1st function call argument is an 
uninitialized value}}
-// expected-note@-1{{1st function call argument is an 
uninitialized value}}
+  decltype(nullptr) p; // expected-note{{'p' initialized to a null pointer 
value}}
   if (getSymbol()) // expected-note   {{Assuming the condition is false}}
// expected-note@-1{{Taking false branch}}
// expected-note@-2{{Assuming the condition is true}}
// expected-note@-3{{Taking true branch}}
-invokeF(nullptr); // expected-note   {{Calling 'invokeF'}}
-  // expected-note@-1{{Passing null pointer value via 1st 
parameter 'x'}}
+invokeF(p); // expected-note{{Passing null pointer value via 1st parameter 
'x'}}
+// expected-note@-1{{Calling 'invokeF'}}
+  if (getSymbol()) // expected-note   {{Assuming the condition is false}}
+   // expected-note@-1{{Taking false branch}}
+invokeF(nullptr);
   if (getSymbol()) {  // expected-note  {{Assuming the condition is true}}
   // expected-note@-1{{Taking true branch}}
 X *xx = Type().x; // expected-note   {{Null pointer value stored to field 
'x'}}

Modified: cfe/trunk/test/SemaCXX/ast-print-crash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ast-print-crash.cpp?rev=349201=349200=349201=diff
==
--- cfe/trunk/test/SemaCXX/ast-print-crash.cpp (original)
+++ cfe/trunk/test/SemaCXX/ast-print-crash.cpp Fri Dec 14 14:22:29 2018
@@ -7,6 +7,6 @@

 // CHECK:  struct {
 // CHECK-NEXT: } 

[PATCH] D53713: Add extension to always default-initialize nullptr_t.

2018-12-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

As stated in CFE commits (in response to Richard's comments):

`I’ll push a revert in a few minutes and give it another try.  Perhaps I can 
suppress the creation of a CK_LValueToRValue in the case where it’s a read from 
nullptr_t


Repository:
  rC Clang

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

https://reviews.llvm.org/D53713



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


RE: r349201 - Add extension to always default-initialize nullptr_t.

2018-12-14 Thread Keane, Erich via cfe-commits
Alright, no problem.  I’ll push a revert in a few minutes and give it another 
try.  Perhaps I can suppress the creation of a CK_LValueToRValue in the case 
where it’s a read from nullptr_t


From: Richard Smith [mailto:rich...@metafoo.co.uk]
Sent: Friday, December 14, 2018 2:41 PM
To: Keane, Erich 
Cc: cfe-commits 
Subject: Re: r349201 - Add extension to always default-initialize nullptr_t.

Sorry, I was late with my review comment. I think this is the wrong way to 
approach this problem. This does not "fix all situations where nullptr_t would 
seem uninitialized", and it makes our AST representation lose source fidelity.

On Fri, 14 Dec 2018 at 14:25, Erich Keane via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:
Author: erichkeane
Date: Fri Dec 14 14:22:29 2018
New Revision: 349201

URL: http://llvm.org/viewvc/llvm-project?rev=349201=rev
Log:
Add extension to always default-initialize nullptr_t.

Core issue 1013 suggests that having an uninitialied std::nullptr_t be
UB is a bit foolish, since there is only a single valid value. This DR
reports that DR616 fixes it, which does so by making lvalue-to-rvalue
conversions from nullptr_t be equal to nullptr.

However, just implementing that results in warnings/etc in many places.
In order to fix all situations where nullptr_t would seem uninitialized,
this patch instead (as an otherwise transparent extension) default
initializes uninitialized VarDecls of nullptr_t.

Differential Revision: https://reviews.llvm.org/D53713

Change-Id: I84d72a9290054fa55341e8cbdac43c8e7f25b885

Added:
cfe/trunk/test/SemaCXX/nullptr_t-init.cpp   (with props)
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/Analysis/nullptr.cpp
cfe/trunk/test/SemaCXX/ast-print-crash.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=349201=349200=349201=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Dec 14 14:22:29 2018
@@ -4881,6 +4881,13 @@ static void TryDefaultInitialization(Sem
 return;
   }

+  // As an extension, and to fix Core issue 1013, zero initialize nullptr_t.
+  // Since there is only 1 valid value of nullptr_t, we can just use that.
+  if (DestType->isNullPtrType()) {
+Sequence.AddZeroInitializationStep(Entity.getType());
+return;
+  }
+
   // - otherwise, no initialization is performed.

   //   If a program calls for the default initialization of an object of

Modified: cfe/trunk/test/Analysis/nullptr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/nullptr.cpp?rev=349201=349200=349201=diff
==
--- cfe/trunk/test/Analysis/nullptr.cpp (original)
+++ cfe/trunk/test/Analysis/nullptr.cpp Fri Dec 14 14:22:29 2018
@@ -125,21 +125,16 @@ struct Type {
 };

 void shouldNotCrash() {
-  decltype(nullptr) p; // expected-note{{'p' declared without an initial 
value}}
-  if (getSymbol()) // expected-note   {{Assuming the condition is false}}
-   // expected-note@-1{{Taking false branch}}
-   // expected-note@-2{{Assuming the condition is false}}
-   // expected-note@-3{{Taking false branch}}
-   // expected-note@-4{{Assuming the condition is true}}
-   // expected-note@-5{{Taking true branch}}
-invokeF(p); // expected-warning{{1st function call argument is an 
uninitialized value}}
-// expected-note@-1{{1st function call argument is an 
uninitialized value}}
+  decltype(nullptr) p; // expected-note{{'p' initialized to a null pointer 
value}}
   if (getSymbol()) // expected-note   {{Assuming the condition is false}}
// expected-note@-1{{Taking false branch}}
// expected-note@-2{{Assuming the condition is true}}
// expected-note@-3{{Taking true branch}}
-invokeF(nullptr); // expected-note   {{Calling 'invokeF'}}
-  // expected-note@-1{{Passing null pointer value via 1st 
parameter 'x'}}
+invokeF(p); // expected-note{{Passing null pointer value via 1st parameter 
'x'}}
+// expected-note@-1{{Calling 'invokeF'}}
+  if (getSymbol()) // expected-note   {{Assuming the condition is false}}
+   // expected-note@-1{{Taking false branch}}
+invokeF(nullptr);
   if (getSymbol()) {  // expected-note  {{Assuming the condition is true}}
   // expected-note@-1{{Taking true branch}}
 X *xx = Type().x; // expected-note   {{Null pointer value stored to field 
'x'}}

Modified: cfe/trunk/test/SemaCXX/ast-print-crash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ast-print-crash.cpp?rev=349201=349200=349201=diff
==
--- 

Re: r349201 - Add extension to always default-initialize nullptr_t.

2018-12-14 Thread Richard Smith via cfe-commits
Sorry, I was late with my review comment. I think this is the wrong way to
approach this problem. This does not "fix all situations where nullptr_t
would seem uninitialized", and it makes our AST representation lose source
fidelity.

On Fri, 14 Dec 2018 at 14:25, Erich Keane via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: erichkeane
> Date: Fri Dec 14 14:22:29 2018
> New Revision: 349201
>
> URL: http://llvm.org/viewvc/llvm-project?rev=349201=rev
> Log:
> Add extension to always default-initialize nullptr_t.
>
> Core issue 1013 suggests that having an uninitialied std::nullptr_t be
> UB is a bit foolish, since there is only a single valid value. This DR
> reports that DR616 fixes it, which does so by making lvalue-to-rvalue
> conversions from nullptr_t be equal to nullptr.
>
> However, just implementing that results in warnings/etc in many places.
> In order to fix all situations where nullptr_t would seem uninitialized,
> this patch instead (as an otherwise transparent extension) default
> initializes uninitialized VarDecls of nullptr_t.
>
> Differential Revision: https://reviews.llvm.org/D53713
>
> Change-Id: I84d72a9290054fa55341e8cbdac43c8e7f25b885
>
> Added:
> cfe/trunk/test/SemaCXX/nullptr_t-init.cpp   (with props)
> Modified:
> cfe/trunk/lib/Sema/SemaInit.cpp
> cfe/trunk/test/Analysis/nullptr.cpp
> cfe/trunk/test/SemaCXX/ast-print-crash.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaInit.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=349201=349200=349201=diff
>
> ==
> --- cfe/trunk/lib/Sema/SemaInit.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Dec 14 14:22:29 2018
> @@ -4881,6 +4881,13 @@ static void TryDefaultInitialization(Sem
>  return;
>}
>
> +  // As an extension, and to fix Core issue 1013, zero initialize
> nullptr_t.
> +  // Since there is only 1 valid value of nullptr_t, we can just use that.
> +  if (DestType->isNullPtrType()) {
> +Sequence.AddZeroInitializationStep(Entity.getType());
> +return;
> +  }
> +
>// - otherwise, no initialization is performed.
>
>//   If a program calls for the default initialization of an object of
>
> Modified: cfe/trunk/test/Analysis/nullptr.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/nullptr.cpp?rev=349201=349200=349201=diff
>
> ==
> --- cfe/trunk/test/Analysis/nullptr.cpp (original)
> +++ cfe/trunk/test/Analysis/nullptr.cpp Fri Dec 14 14:22:29 2018
> @@ -125,21 +125,16 @@ struct Type {
>  };
>
>  void shouldNotCrash() {
> -  decltype(nullptr) p; // expected-note{{'p' declared without an initial
> value}}
> -  if (getSymbol()) // expected-note   {{Assuming the condition is false}}
> -   // expected-note@-1{{Taking false branch}}
> -   // expected-note@-2{{Assuming the condition is false}}
> -   // expected-note@-3{{Taking false branch}}
> -   // expected-note@-4{{Assuming the condition is true}}
> -   // expected-note@-5{{Taking true branch}}
> -invokeF(p); // expected-warning{{1st function call argument is an
> uninitialized value}}
> -// expected-note@-1{{1st function call argument is an
> uninitialized value}}
> +  decltype(nullptr) p; // expected-note{{'p' initialized to a null
> pointer value}}
>if (getSymbol()) // expected-note   {{Assuming the condition is false}}
> // expected-note@-1{{Taking false branch}}
> // expected-note@-2{{Assuming the condition is true}}
> // expected-note@-3{{Taking true branch}}
> -invokeF(nullptr); // expected-note   {{Calling 'invokeF'}}
> -  // expected-note@-1{{Passing null pointer value
> via 1st parameter 'x'}}
> +invokeF(p); // expected-note{{Passing null pointer value via 1st
> parameter 'x'}}
> +// expected-note@-1{{Calling 'invokeF'}}
> +  if (getSymbol()) // expected-note   {{Assuming the condition is false}}
> +   // expected-note@-1{{Taking false branch}}
> +invokeF(nullptr);
>if (getSymbol()) {  // expected-note  {{Assuming the condition is true}}
>// expected-note@-1{{Taking true branch}}
>  X *xx = Type().x; // expected-note   {{Null pointer value stored to
> field 'x'}}
>
> Modified: cfe/trunk/test/SemaCXX/ast-print-crash.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ast-print-crash.cpp?rev=349201=349200=349201=diff
>
> ==
> --- cfe/trunk/test/SemaCXX/ast-print-crash.cpp (original)
> +++ cfe/trunk/test/SemaCXX/ast-print-crash.cpp Fri Dec 14 14:22:29 2018
> @@ -7,6 +7,6 @@
>
>  // CHECK:  struct {
>  // CHECK-NEXT: } dont_crash_on_syntax_error;
> -// CHECK-NEXT: 

[PATCH] D55443: [test] Capture stderr from 'tar --version' call as well

2018-12-14 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349204: [test] Capture stderr from tar --version 
call as well (authored by mgorny, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D55443?vs=177265=178296#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55443

Files:
  lld/trunk/test/lit.cfg.py


Index: lld/trunk/test/lit.cfg.py
===
--- lld/trunk/test/lit.cfg.py
+++ lld/trunk/test/lit.cfg.py
@@ -94,7 +94,10 @@
 tar_executable = lit.util.which('tar', config.environment['PATH'])
 if tar_executable:
 tar_version = subprocess.Popen(
-[tar_executable, '--version'], stdout=subprocess.PIPE, env={'LANG': 
'C'})
-if 'GNU tar' in tar_version.stdout.read().decode():
+[tar_executable, '--version'],
+stdout=subprocess.PIPE,
+stderr=subprocess.PIPE,
+env={'LANG': 'C'})
+sout, _ = tar_version.communicate()
+if 'GNU tar' in sout.decode():
 config.available_features.add('gnutar')
-tar_version.wait()


Index: lld/trunk/test/lit.cfg.py
===
--- lld/trunk/test/lit.cfg.py
+++ lld/trunk/test/lit.cfg.py
@@ -94,7 +94,10 @@
 tar_executable = lit.util.which('tar', config.environment['PATH'])
 if tar_executable:
 tar_version = subprocess.Popen(
-[tar_executable, '--version'], stdout=subprocess.PIPE, env={'LANG': 'C'})
-if 'GNU tar' in tar_version.stdout.read().decode():
+[tar_executable, '--version'],
+stdout=subprocess.PIPE,
+stderr=subprocess.PIPE,
+env={'LANG': 'C'})
+sout, _ = tar_version.communicate()
+if 'GNU tar' in sout.decode():
 config.available_features.add('gnutar')
-tar_version.wait()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55443: [test] Capture stderr from 'tar --version' call as well

2018-12-14 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu accepted this revision.
ruiu added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D55443



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


[PATCH] D53713: Add extension to always default-initialize nullptr_t.

2018-12-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

I'm concerned that this will hide real bugs by suppressing the bogus warnings 
in (only) the simple cases. There is no "read a value from memory" operation on 
type `nullptr_t` (just like for, say, class types), and any warning that 
believes there is is incorrect. For example, given

  alignas(nullptr_t) char buffer[sizeof(nullptr_t)];
  nullptr_t *p = (nullptr_t*)buffer;
  nullptr_t q = *p;

... there is no uninitialized use, but this patch will do nothing to make 
static analysis (etc) aware of that.

I think the real problem here is that our AST representation is wrong. We use 
`CK_LValueToRValue` to model a read from memory, but we also use it in examples 
like the above where there is no read from memory.




Comment at: test/Analysis/nullptr.cpp:136
-invokeF(p); // expected-warning{{1st function call argument is an 
uninitialized value}}
-// expected-note@-1{{1st function call argument is an 
uninitialized value}}
   if (getSymbol()) // expected-note   {{Assuming the condition is false}}

This bug is already fixed in trunk.


Repository:
  rC Clang

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

https://reviews.llvm.org/D53713



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


[PATCH] D54604: Automatic variable initialization

2018-12-14 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added a comment.

Mostly looking good, a few style nits.




Comment at: include/clang/Basic/DiagnosticDriverKinds.td:409
+
+def err_drv_trivial_auto_var_init_zero_disabled : Warning<
+  "-ftrivial-auto-var-init=zero hasn't been enabled. Enable it at your own 
peril for benchmarking purpose only with "

`s/Warning/Error/` here? Then I think you won't need to adjust the list of 
warnings without warning flags.



Comment at: lib/CodeGen/CGDecl.cpp:993
+Ty, llvm::APInt::getSplat(BitWidth, llvm::APInt(64, LargeValue)));
+  } else if (Ty->isPtrOrPtrVectorTy()) {
+auto *PtrTy = cast(

No else after return (same below)



Comment at: lib/CodeGen/CGDecl.cpp:1037
+  llvm::SmallVector Struct(StructTy->getNumElements());
+  for (unsigned El = 0; El != Struct.size(); ++El) {
+Struct[El] = patternFor(CGM, StructTy->getElementType(El));

Remove braces



Comment at: lib/CodeGen/CGDecl.cpp:1183
+return llvm::ConstantStruct::get(cast(Ty), Values);
+  } else if (Ty->isArrayTy()) {
+return llvm::ConstantArray::get(cast(Ty), Values);

No else after return, no braces.



Comment at: test/CodeGenCXX/trivial-auto-var-init.cpp:180
+// PATTERN-LABEL: test_huge_uninit(
+// PATTTERN: call void @llvm.memset{{.*}}, i8 -86, i64 65536,
+void test_huge_uninit() {

`PATTERN:`



Comment at: test/CodeGenCXX/trivial-auto-var-init.cpp:196
+// PATTERN-LABEL: test_huge_small_init(
+// PATTTERN: call void @llvm.memset{{.*}}, i8 -86, i64 65536,
+// PATTERN: store i8 97,

`PATTERN:`


Repository:
  rC Clang

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

https://reviews.llvm.org/D54604



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


[PATCH] D53847: [C++2a] P0634r3: Down with typename!

2018-12-14 Thread Nicolas Lesser via Phabricator via cfe-commits
Rakete updated this revision to Diff 178289.
Rakete added a comment.

@rsmith do you have any more comments?

ping/rebase.


Repository:
  rC Clang

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

https://reviews.llvm.org/D53847

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Parse/Parser.h
  include/clang/Sema/DeclSpec.h
  include/clang/Sema/Sema.h
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Parse/ParseTemplate.cpp
  lib/Parse/ParseTentative.cpp
  lib/Parse/Parser.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaTemplate.cpp
  test/CXX/drs/dr1xx.cpp
  test/CXX/drs/dr2xx.cpp
  test/CXX/drs/dr4xx.cpp
  test/CXX/drs/dr5xx.cpp
  test/CXX/temp/temp.res/temp.dep/temp.dep.type/p1.cpp
  test/FixIt/fixit.cpp
  test/Parser/cxx-member-initializers.cpp
  test/Parser/editor-placeholder-recovery.cpp
  test/SemaCXX/MicrosoftCompatibility.cpp
  test/SemaCXX/MicrosoftExtensions.cpp
  test/SemaCXX/MicrosoftSuper.cpp
  test/SemaCXX/unknown-type-name.cpp

Index: test/SemaCXX/unknown-type-name.cpp
===
--- test/SemaCXX/unknown-type-name.cpp
+++ test/SemaCXX/unknown-type-name.cpp
@@ -36,15 +36,15 @@
 
   static int n;
   static type m;
-  static int h(T::type, int); // expected-error{{missing 'typename'}}
-  static int h(T::type x, char); // expected-error{{missing 'typename'}}
+  static int h(T::type, int); // expected-warning{{implicit 'typename' is a C++2a extension}}
+  static int h(T::type x, char); // expected-warning{{implicit 'typename' is a C++2a extension}}
 };
 
 template
-A::type g(T t) { return t; } // expected-error{{missing 'typename'}}
+A::type g(T t) { return t; } // expected-warning{{implicit 'typename' is a C++2a extension}}
 
 template
-A::type A::f() { return type(); } // expected-error{{missing 'typename'}}
+A::type A::f() { return type(); } // expected-warning{{implicit 'typename' is a C++2a extension}}
 
 template
 void f(T::type) { } // expected-error{{missing 'typename'}}
@@ -72,9 +72,7 @@
 
 int *p;
 
-// FIXME: We should assume that 'undeclared' is a type, not a parameter name
-//here, and produce an 'unknown type name' diagnostic instead.
-int f1(undeclared, int); // expected-error{{requires a type specifier}}
+int f1(undeclared, int); // expected-error{{unknown type name 'undeclared'}}
 
 int f2(undeclared, 0); // expected-error{{undeclared identifier}}
 
@@ -86,11 +84,11 @@
 
 template int A::n(T::value); // ok
 template
-A::type // expected-error{{missing 'typename'}}
+A::type // expected-warning {{implicit 'typename' is a C++2a extension}}
 A::m(T::value, 0); // ok
 
-template int A::h(T::type, int) {} // expected-error{{missing 'typename'}}
-template int A::h(T::type x, char) {} // expected-error{{missing 'typename'}}
+template int A::h(T::type, int) {} // expected-warning{{implicit 'typename' is a C++2a extension}}
+template int A::h(T::type x, char) {} // expected-warning{{implicit 'typename' is a C++2a extension}}
 
 template int h(T::type, int); // expected-error{{missing 'typename'}}
 template int h(T::type x, char); // expected-error{{missing 'typename'}}
@@ -118,4 +116,5 @@
 // FIXME: We know which type specifier should have been specified here. Provide
 //a fix-it to add 'typename A::type'
 template
-A::g() { } // expected-error{{requires a type specifier}}
+A::g() { } // expected-error{{expected unqualified-id}}
+// expected-warning@-1{{implicit 'typename' is a C++2a extension}}
Index: test/SemaCXX/MicrosoftSuper.cpp
===
--- test/SemaCXX/MicrosoftSuper.cpp
+++ test/SemaCXX/MicrosoftSuper.cpp
@@ -108,8 +108,8 @@
   typename __super::XXX a;
   typedef typename __super::XXX b;
 
-  __super::XXX c; // expected-error {{missing 'typename'}}
-  typedef __super::XXX d; // expected-error {{missing 'typename'}}
+  __super::XXX c; // expected-warning {{implicit 'typename' is a C++2a extension}}
+  typedef __super::XXX d; // expected-warning {{implicit 'typename' is a C++2a extension}}
 
   void foo() {
 typename __super::XXX e;
@@ -127,8 +127,8 @@
   typename __super::XXX a;
   typedef typename __super::XXX b;
 
-  __super::XXX c; // expected-error {{missing 'typename'}}
-  typedef __super::XXX d; // expected-error {{missing 'typename'}}
+  __super::XXX c; // expected-warning {{implicit 'typename' is a C++2a extension}}
+  typedef __super::XXX d; // expected-warning {{implicit 'typename' is a C++2a extension}}
 
   void foo() {
 typename __super::XXX e;
Index: test/SemaCXX/MicrosoftExtensions.cpp
===
--- test/SemaCXX/MicrosoftExtensions.cpp
+++ test/SemaCXX/MicrosoftExtensions.cpp
@@ -526,7 +526,7 @@
 
 namespace PR32750 {
 template struct A {};
-template struct B : A> { A::C::D d; }; // expected-error {{missing 'typename' 

[PATCH] D53713: Add extension to always default-initialize nullptr_t.

2018-12-14 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349201: Add extension to always default-initialize 
nullptr_t. (authored by erichkeane, committed by ).

Repository:
  rC Clang

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

https://reviews.llvm.org/D53713

Files:
  lib/Sema/SemaInit.cpp
  test/Analysis/nullptr.cpp
  test/SemaCXX/ast-print-crash.cpp
  test/SemaCXX/nullptr_t-init.cpp


Index: test/Analysis/nullptr.cpp
===
--- test/Analysis/nullptr.cpp
+++ test/Analysis/nullptr.cpp
@@ -125,21 +125,16 @@
 };
 
 void shouldNotCrash() {
-  decltype(nullptr) p; // expected-note{{'p' declared without an initial 
value}}
-  if (getSymbol()) // expected-note   {{Assuming the condition is false}}
-   // expected-note@-1{{Taking false branch}}
-   // expected-note@-2{{Assuming the condition is false}}
-   // expected-note@-3{{Taking false branch}}
-   // expected-note@-4{{Assuming the condition is true}}
-   // expected-note@-5{{Taking true branch}}
-invokeF(p); // expected-warning{{1st function call argument is an 
uninitialized value}}
-// expected-note@-1{{1st function call argument is an 
uninitialized value}}
+  decltype(nullptr) p; // expected-note{{'p' initialized to a null pointer 
value}}
   if (getSymbol()) // expected-note   {{Assuming the condition is false}}
// expected-note@-1{{Taking false branch}}
// expected-note@-2{{Assuming the condition is true}}
// expected-note@-3{{Taking true branch}}
-invokeF(nullptr); // expected-note   {{Calling 'invokeF'}}
-  // expected-note@-1{{Passing null pointer value via 1st 
parameter 'x'}}
+invokeF(p); // expected-note{{Passing null pointer value via 1st parameter 
'x'}}
+// expected-note@-1{{Calling 'invokeF'}}
+  if (getSymbol()) // expected-note   {{Assuming the condition is false}}
+   // expected-note@-1{{Taking false branch}}
+invokeF(nullptr);
   if (getSymbol()) {  // expected-note  {{Assuming the condition is true}}
   // expected-note@-1{{Taking true branch}}
 X *xx = Type().x; // expected-note   {{Null pointer value stored to field 
'x'}}
Index: test/SemaCXX/ast-print-crash.cpp
===
--- test/SemaCXX/ast-print-crash.cpp
+++ test/SemaCXX/ast-print-crash.cpp
@@ -7,6 +7,6 @@
 
 // CHECK:  struct {
 // CHECK-NEXT: } dont_crash_on_syntax_error;
-// CHECK-NEXT: decltype(nullptr) p;
+// CHECK-NEXT: decltype(nullptr) p(/*implicit*/(decltype(nullptr))0);
 struct {
 } dont_crash_on_syntax_error /* missing ; */ decltype(nullptr) p;
Index: test/SemaCXX/nullptr_t-init.cpp
===
--- test/SemaCXX/nullptr_t-init.cpp
+++ test/SemaCXX/nullptr_t-init.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -ffreestanding 
-Wuninitialized %s
+// expected-no-diagnostics
+typedef decltype(nullptr) nullptr_t;
+
+// Ensure no 'uninitialized when used here' warnings (Wuninitialized), for 
+// nullptr_t always-initialized extension.
+nullptr_t default_init() {
+  nullptr_t a;
+  return a;
+}
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -4881,6 +4881,13 @@
 return;
   }
 
+  // As an extension, and to fix Core issue 1013, zero initialize nullptr_t.
+  // Since there is only 1 valid value of nullptr_t, we can just use that.
+  if (DestType->isNullPtrType()) {
+Sequence.AddZeroInitializationStep(Entity.getType());
+return;
+  }
+
   // - otherwise, no initialization is performed.
 
   //   If a program calls for the default initialization of an object of


Index: test/Analysis/nullptr.cpp
===
--- test/Analysis/nullptr.cpp
+++ test/Analysis/nullptr.cpp
@@ -125,21 +125,16 @@
 };
 
 void shouldNotCrash() {
-  decltype(nullptr) p; // expected-note{{'p' declared without an initial value}}
-  if (getSymbol()) // expected-note   {{Assuming the condition is false}}
-   // expected-note@-1{{Taking false branch}}
-   // expected-note@-2{{Assuming the condition is false}}
-   // expected-note@-3{{Taking false branch}}
-   // expected-note@-4{{Assuming the condition is true}}
-   // expected-note@-5{{Taking true branch}}
-invokeF(p); // expected-warning{{1st function call argument is an uninitialized value}}
-// expected-note@-1{{1st function call argument is an uninitialized value}}
+  decltype(nullptr) p; // expected-note{{'p' initialized to a null pointer value}}
   if (getSymbol()) // expected-note  

[PATCH] D55697: [analyzer] Assume that we always have a SubEngine available

2018-12-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D55697#1331001 , @Szelethus wrote:

> We could also add an assert to getOwningEngine I guess.


Or make it return a reference, like everything else.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55697



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


r349201 - Add extension to always default-initialize nullptr_t.

2018-12-14 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Fri Dec 14 14:22:29 2018
New Revision: 349201

URL: http://llvm.org/viewvc/llvm-project?rev=349201=rev
Log:
Add extension to always default-initialize nullptr_t.

Core issue 1013 suggests that having an uninitialied std::nullptr_t be
UB is a bit foolish, since there is only a single valid value. This DR
reports that DR616 fixes it, which does so by making lvalue-to-rvalue
conversions from nullptr_t be equal to nullptr.

However, just implementing that results in warnings/etc in many places.
In order to fix all situations where nullptr_t would seem uninitialized,
this patch instead (as an otherwise transparent extension) default
initializes uninitialized VarDecls of nullptr_t.

Differential Revision: https://reviews.llvm.org/D53713

Change-Id: I84d72a9290054fa55341e8cbdac43c8e7f25b885

Added:
cfe/trunk/test/SemaCXX/nullptr_t-init.cpp   (with props)
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/Analysis/nullptr.cpp
cfe/trunk/test/SemaCXX/ast-print-crash.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=349201=349200=349201=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Dec 14 14:22:29 2018
@@ -4881,6 +4881,13 @@ static void TryDefaultInitialization(Sem
 return;
   }
 
+  // As an extension, and to fix Core issue 1013, zero initialize nullptr_t.
+  // Since there is only 1 valid value of nullptr_t, we can just use that.
+  if (DestType->isNullPtrType()) {
+Sequence.AddZeroInitializationStep(Entity.getType());
+return;
+  }
+
   // - otherwise, no initialization is performed.
 
   //   If a program calls for the default initialization of an object of

Modified: cfe/trunk/test/Analysis/nullptr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/nullptr.cpp?rev=349201=349200=349201=diff
==
--- cfe/trunk/test/Analysis/nullptr.cpp (original)
+++ cfe/trunk/test/Analysis/nullptr.cpp Fri Dec 14 14:22:29 2018
@@ -125,21 +125,16 @@ struct Type {
 };
 
 void shouldNotCrash() {
-  decltype(nullptr) p; // expected-note{{'p' declared without an initial 
value}}
-  if (getSymbol()) // expected-note   {{Assuming the condition is false}}
-   // expected-note@-1{{Taking false branch}}
-   // expected-note@-2{{Assuming the condition is false}}
-   // expected-note@-3{{Taking false branch}}
-   // expected-note@-4{{Assuming the condition is true}}
-   // expected-note@-5{{Taking true branch}}
-invokeF(p); // expected-warning{{1st function call argument is an 
uninitialized value}}
-// expected-note@-1{{1st function call argument is an 
uninitialized value}}
+  decltype(nullptr) p; // expected-note{{'p' initialized to a null pointer 
value}}
   if (getSymbol()) // expected-note   {{Assuming the condition is false}}
// expected-note@-1{{Taking false branch}}
// expected-note@-2{{Assuming the condition is true}}
// expected-note@-3{{Taking true branch}}
-invokeF(nullptr); // expected-note   {{Calling 'invokeF'}}
-  // expected-note@-1{{Passing null pointer value via 1st 
parameter 'x'}}
+invokeF(p); // expected-note{{Passing null pointer value via 1st parameter 
'x'}}
+// expected-note@-1{{Calling 'invokeF'}}
+  if (getSymbol()) // expected-note   {{Assuming the condition is false}}
+   // expected-note@-1{{Taking false branch}}
+invokeF(nullptr);
   if (getSymbol()) {  // expected-note  {{Assuming the condition is true}}
   // expected-note@-1{{Taking true branch}}
 X *xx = Type().x; // expected-note   {{Null pointer value stored to field 
'x'}}

Modified: cfe/trunk/test/SemaCXX/ast-print-crash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ast-print-crash.cpp?rev=349201=349200=349201=diff
==
--- cfe/trunk/test/SemaCXX/ast-print-crash.cpp (original)
+++ cfe/trunk/test/SemaCXX/ast-print-crash.cpp Fri Dec 14 14:22:29 2018
@@ -7,6 +7,6 @@
 
 // CHECK:  struct {
 // CHECK-NEXT: } dont_crash_on_syntax_error;
-// CHECK-NEXT: decltype(nullptr) p;
+// CHECK-NEXT: decltype(nullptr) p(/*implicit*/(decltype(nullptr))0);
 struct {
 } dont_crash_on_syntax_error /* missing ; */ decltype(nullptr) p;

Added: cfe/trunk/test/SemaCXX/nullptr_t-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nullptr_t-init.cpp?rev=349201=auto
==
--- cfe/trunk/test/SemaCXX/nullptr_t-init.cpp (added)
+++ cfe/trunk/test/SemaCXX/nullptr_t-init.cpp Fri Dec 14 14:22:29 2018

[PATCH] D55697: [analyzer] Assume that we always have a SubEngine available

2018-12-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Yup, squash these! Even if there was a plan to use `ProgramState` separately 
for some other sort of analysis that doesn't involve a sub-engine, it is 
currently long forgotten.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55697



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


[PATCH] D55701: [analyzer] Pass the correct loc Expr from VisitIncDecOp to evalStore

2018-12-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Thanks! Neat test.

Can we now `assert(LocationE->isGLValue())` in `evalStore()`? What about 
`evalLoad()`?

Also, were no other checkers affected? Like, will null pointer dereference 
checker now warn upon something like `(*0)++` or `++(*0)`?

You can commit the patch, but i would also love to see these questions 
investigated.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55701



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


[PATCH] D55715: Add AddressSpace mangling to MS mode

2018-12-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 178282.
erichkeane added a comment.

Should catch me up on all comments except @zturner's llvm-undname feature 
request :)


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

https://reviews.llvm.org/D55715

Files:
  lib/AST/MicrosoftMangle.cpp
  test/CodeGenCXX/mangle-address-space.cpp

Index: test/CodeGenCXX/mangle-address-space.cpp
===
--- test/CodeGenCXX/mangle-address-space.cpp
+++ test/CodeGenCXX/mangle-address-space.cpp
@@ -1,15 +1,64 @@
-// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s --check-prefixes=CHECK,CHECKNOOCL
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-windows-msvc -o - %s | FileCheck %s --check-prefixes=WIN,WINNOOCL
+// RUN: %clang_cc1 -cl-std=c++ -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s --check-prefixes=CHECK,CHECKOCL
+// RUN: %clang_cc1 -cl-std=c++ -emit-llvm -triple x86_64-windows-msvc -o - %s | FileCheck %s --check-prefixes=WIN,WINOCL
 
-// CHECK-LABEL: define {{.*}}void @_Z2f0Pc
+// CHECKNOOCL-LABEL: define {{.*}}void @_Z2f0Pc
+// WINNOOCL-LABEL: define {{.*}}void @"?f0@@YAXPEAD@Z"
+// CHECKOCL-LABEL: define {{.*}}void @_Z2f0PU9CLgenericc
+// WINOCL-LABEL: define {{.*}}void @"?f0@@YAXPEAU?$_ASCLgeneric@$$CAD@__clang@@@Z" 
 void f0(char *p) { }
 // CHECK-LABEL: define {{.*}}void @_Z2f0PU3AS1c
+// WIN-LABEL: define {{.*}}void @"?f0@@YAXPEAU?$_AS@$00$$CAD@__clang@@@Z"
 void f0(char __attribute__((address_space(1))) *p) { }
 
 struct OpaqueType;
 typedef OpaqueType __attribute__((address_space(100))) * OpaqueTypePtr;
 
 // CHECK-LABEL: define {{.*}}void @_Z2f0PU5AS10010OpaqueType
+// WIN-LABEL: define {{.*}}void @"?f0@@YAXPEAU?$_AS@$0GE@$$CAUOpaqueType@@@__clang@@@Z"
 void f0(OpaqueTypePtr) { }
 
 // CHECK-LABEL: define {{.*}}void @_Z2f1PU3AS1Kc
-void f1(char __attribute__((address_space(1))) const *p) {}
\ No newline at end of file
+// WIN-LABEL: define {{.*}}void @"?f1@@YAXPEAU?$_AS@$00$$CBD@__clang@@@Z"
+void f1(char __attribute__((address_space(1))) const *p) {}
+
+// Ensure we can do return values, which change in MS mode.
+// CHECK-LABEL: define {{.*}}float addrspace(1)* @_Z2f1PU3AS2Kc
+// WIN-LABEL: define {{.*}}float addrspace(1)* @"?f1@@YAPEAU?$_AS@$00$$CAM@__clang@@PEAU?$_AS@$01$$CBD@2@@Z"
+__attribute__((address_space(1))) float *f1(char __attribute__((address_space(2))) const *p) { return 0;}
+
+#if !defined(__OPENCL_CPP_VERSION__)
+// Return value of address space without a pointer is invalid in opencl.
+// Ensure we skip return values, since non-pointers aren't supposed to have an AS.
+// CHECKNOOCL-LABEL: define {{.*}}float @_Z2f2PU3AS2Kc
+// WINNOOCL-LABEL: define {{.*}}float @"?f2@@YA?AMQEAU?$_AS@$01$$CBD@__clang@@@Z"
+__attribute__((address_space(1))) float f2(char __attribute__((address_space(2))) const * const p) { return 0;}
+#endif
+
+#ifdef __OPENCL_CPP_VERSION__
+// CHECKOCL-LABEL: define {{.*}}void @_Z6ocl_f0PU9CLprivatec
+// WINOCL-LABEL: define {{.*}}void @"?ocl_f0@@YAXPEAU?$_ASCLprivate@$$CAD@__clang@@@Z"
+void ocl_f0(char __private *p) { }
+
+struct ocl_OpaqueType;
+typedef ocl_OpaqueType __global * ocl_OpaqueTypePtr;
+
+// CHECKOCL-LABEL: define {{.*}}void @_Z6ocl_f0PU8CLglobal14ocl_OpaqueType
+// WINOCL-LABEL: define {{.*}}void @"?ocl_f0@@YAXPEAU?$_ASCLglobal@$$CAUocl_OpaqueType@@@__clang@@@Z"
+void ocl_f0(ocl_OpaqueTypePtr) { }
+
+// CHECKOCL-LABEL: define {{.*}}void @_Z6ocl_f1PU10CLconstantKc
+// WINOCL-LABEL: define {{.*}}void @"?ocl_f1@@YAXPEAU?$_ASCLconstant@$$CBD@__clang@@@Z"
+void ocl_f1(char __constant const *p) {}
+
+// Ensure we can do return values, which change in MS mode.
+// CHECKOCL-LABEL: define {{.*}}float* @_Z6ocl_f1PU9CLgenericKc
+// WINOCL-LABEL: define {{.*}}float* @"?ocl_f1@@YAPEAU?$_ASCLconstant@$$CAM@__clang@@PEAU?$_ASCLgeneric@$$CBD@2@@Z"
+__constant float *ocl_f1(char __generic const *p) { return 0;}
+
+// Ensure we skip return values, since non-pointers aren't supposed to have an AS.
+// CHECKOCL-LABEL: define {{.*}}float* @_Z6ocl_f2PU9CLgenericKc
+// WINOCL-LABEL: define {{.*}}float* @"?ocl_f2@@YAPEAU?$_ASCLgeneric@$$CAM@__clang@@QEAU?$_ASCLgeneric@$$CBD@2@@Z"
+__generic float *ocl_f2(__generic char const * const p) { return 0;}
+#endif
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -311,6 +311,7 @@
   void mangleTagTypeKind(TagTypeKind TK);
   void mangleArtificialTagType(TagTypeKind TK, StringRef UnqualifiedName,
   ArrayRef NestedNames = None);
+  void mangleAddressSpaceType(QualType T, Qualifiers Quals, SourceRange Range);
   void mangleType(QualType T, SourceRange Range,
   QualifierMangleMode QMM = QMM_Mangle);
   void mangleFunctionType(const FunctionType *T,
@@ -1777,12 +1778,77 @@
   }
 }
 
+void 

[PATCH] D55719: [OpenMP] parsing and sema support for 'close' map-type-modifier

2018-12-14 Thread Ahsan Saghir via Phabricator via cfe-commits
saghir created this revision.
saghir added reviewers: ABataev, kkwli0, Hahnfeld, RaviNarayanaswamy, mikerice, 
hfinkel, gtbercea.
saghir added a project: clang.
Herald added subscribers: cfe-commits, guansong.

A map clause with the close map-type-modifier is a hint to prefer that the 
variables are mapped using a copy into faster memory.

Reference: TR7 Section 2.15.8 and 2.22.7.1


Repository:
  rC Clang

https://reviews.llvm.org/D55719

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/include/clang/Basic/OpenMPKinds.h
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/target_ast_print.cpp
  clang/test/OpenMP/target_data_ast_print.cpp
  clang/test/OpenMP/target_map_messages.cpp
  clang/test/OpenMP/target_parallel_for_map_messages.cpp
  clang/test/OpenMP/target_parallel_for_simd_map_messages.cpp
  clang/test/OpenMP/target_parallel_map_messages.cpp
  clang/test/OpenMP/target_simd_map_messages.cpp
  clang/test/OpenMP/target_teams_distribute_map_messages.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_map_messages.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_map_messages.cpp
  clang/test/OpenMP/target_teams_distribute_simd_map_messages.cpp
  clang/test/OpenMP/target_teams_map_messages.cpp

Index: clang/test/OpenMP/target_teams_map_messages.cpp
===
--- clang/test/OpenMP/target_teams_map_messages.cpp
+++ clang/test/OpenMP/target_teams_map_messages.cpp
@@ -454,7 +454,7 @@
 
 #pragma omp target data map(always, tofrom: x)
 #pragma omp target data map(always: x) // expected-error {{missing map type}}
-#pragma omp target data map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always'}} expected-error {{incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 'release', or 'delete'}}
+#pragma omp target data map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always' or 'close'}} expected-error {{missing map type}}
 #pragma omp target data map(always, tofrom: always, tofrom, x)
 #pragma omp target teams map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
   foo();
@@ -529,7 +529,7 @@
 
 #pragma omp target data map(always, tofrom: x)
 #pragma omp target data map(always: x) // expected-error {{missing map type}}
-#pragma omp target data map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always'}} expected-error {{incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 'release', or 'delete'}}
+#pragma omp target data map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always' or 'close'}} expected-error {{missing map type}}
 #pragma omp target data map(always, tofrom: always, tofrom, x)
 #pragma omp target teams map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
   foo();
Index: clang/test/OpenMP/target_teams_distribute_simd_map_messages.cpp
===
--- clang/test/OpenMP/target_teams_distribute_simd_map_messages.cpp
+++ clang/test/OpenMP/target_teams_distribute_simd_map_messages.cpp
@@ -163,7 +163,7 @@
   for (i = 0; i < argc; ++i) foo();
 #pragma omp target teams distribute simd map(always: x) // expected-error {{missing map type}}
   for (i = 0; i < argc; ++i) foo();
-#pragma omp target teams distribute simd map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always'}} expected-error {{incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 'release', or 'delete'}}
+#pragma omp target teams distribute simd map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always' or 'close'}} expected-error {{missing map type}}
   for (i = 0; i < argc; ++i) foo();
 #pragma omp target teams distribute simd map(always, tofrom: always, tofrom, x)
   for (i = 0; i < argc; ++i) foo();
@@ -271,7 +271,7 @@
   for (i = 0; i < argc; ++i) foo();
 #pragma omp target teams distribute simd map(always: x) // expected-error {{missing map type}}
   for (i = 0; i < argc; ++i) foo();
-#pragma omp target teams distribute simd map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always'}} expected-error {{incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 'release', or 'delete'}}
+#pragma omp target teams distribute simd map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always' or 

[PATCH] D55715: Add AddressSpace mangling to MS mode

2018-12-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane marked 2 inline comments as done.
erichkeane added inline comments.



Comment at: lib/AST/MicrosoftMangle.cpp:1806-1836
+Extra.mangleSourceName("AS_");
+Extra.mangleIntegerLiteral(llvm::APSInt::getUnsigned(TargetAS),
+   /*IsBoolean*/ false);
+  } else {
+switch (AS) {
+default:
+  llvm_unreachable("Not a language specific address space");

rnk wrote:
> majnemer wrote:
> > Don't these need to be _AS_Foobar to avoid collisions with normal code?
> I think we're in __clang::, so it's OK? In any case, it's what's done for 
> Itanium, IIUC. It's also not like we have to worry about conflicts with user 
> macros.
Right, we're in __clang (thus cannot conflict), and cannot be replaced with 
macros or anything (since this is a mangling name), so I opted to save the char 
instead.  

However, I'll make it _AS_CU just cause.



Comment at: test/CodeGenOpenCL/address-spaces-mangling.cl:7
+// RUN: %clang_cc1 %s -ffake-address-space-map 
-faddress-space-map-mangling=yes -triple x86_64-windows-pc -emit-llvm -o - | 
FileCheck -check-prefixes=MS_ASMANG,MS_ASMAN10 %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map 
-faddress-space-map-mangling=yes -triple x86_64-windows-pc -emit-llvm -o - | 
FileCheck -check-prefixes=MS_ASMANG,MS_ASMAN20 %s
+// RUN: %clang_cc1 %s -ffake-address-space-map -faddress-space-map-mangling=no 
-triple x86_64-windows-pc -emit-llvm -o - | FileCheck 
-check-prefixes=MS_NOASMANG,MS_NOASMAN10 %s

rnk wrote:
> erichkeane wrote:
> > erichkeane wrote:
> > > rnk wrote:
> > > > I would replace `-triple x86_64-windows-pc` here and everywhere with 
> > > > `-triple x86_64-windows-itanium` (or gnu instead of itanium) to test 
> > > > the Itanium mangling on Windows. I don't think `x86_64-windows-pc` 
> > > > parses into a real triple. After all, "pc" is parsed as the vendor, 
> > > > which is supposed to be second.
> > > Woops! I didn't mean to check this file in.  It has some other nasty 
> > > problems that need to be fixed up, so I tested this feature in the 
> > > mangle-address-space.  I'll still do this above.
> > @rnk I tried this, but it changes off of the MicrosoftMangler and switches 
> > back to the Itanium mangling.  Is there a better triple for testing 
> > microsoft mangling?
> Tacking on "-msvc" or "-itanium" or "-gnu" is the more explicit way to the 
> C++ ABI. I guess I was confused, it looks like this file expects Itanium 
> manglings from the -pc triple.
Ah, yeah, I should have figured that out.  I was originally looking to do the 
opencl-c++ test in this file but it has some bigger problems that cause issues 
(so I never finished it).

Somehow it stayed in my workspace when I stashed.

I'll update this whole patch as soon as my build passes.


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

https://reviews.llvm.org/D55715



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


[PATCH] D55698: [MinGW] Produce a vtable and RTTI for dllexported classes without a key function

2018-12-14 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo updated this revision to Diff 178275.
mstorsjo added a comment.

Moved the code to work on DelayedDllExportClasses instead, as suggested, which 
still works for the testcase. (I've yet to test that approach on a larger 
codebase though.)


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

https://reviews.llvm.org/D55698

Files:
  lib/Sema/SemaDeclCXX.cpp
  test/CodeGenCXX/dllexport-missing-key.cpp


Index: test/CodeGenCXX/dllexport-missing-key.cpp
===
--- /dev/null
+++ test/CodeGenCXX/dllexport-missing-key.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-windows-gnu -emit-llvm -std=c++11 -o - %s | 
FileCheck --check-prefix=GNU %s
+
+class __declspec(dllexport) QAbstractLayoutStyleInfo {
+public:
+  QAbstractLayoutStyleInfo() : m_isWindow(false) {}
+  virtual ~QAbstractLayoutStyleInfo() {}
+
+  virtual bool hasChangedCore() const { return false; }
+
+  virtual void invalidate() {}
+
+  virtual double windowMargin(bool orientation) const = 0;
+
+  bool isWindow() const { return m_isWindow; }
+
+protected:
+  bool m_isWindow;
+};
+
+// GNU-DAG: @_ZTV24QAbstractLayoutStyleInfo = weak_odr dso_local dllexport
+// GNU-DAG: @_ZTS24QAbstractLayoutStyleInfo = linkonce_odr
+// GNU-DAG: @_ZTI24QAbstractLayoutStyleInfo = linkonce_odr
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -5493,6 +5493,9 @@
 // declaration.
 return;
 
+  if (S.Context.getTargetInfo().getTriple().isWindowsGNUEnvironment())
+S.MarkVTableUsed(Class->getLocation(), Class, true);
+
   for (Decl *Member : Class->decls()) {
 // Defined static variables that are members of an exported base
 // class must be marked export too.


Index: test/CodeGenCXX/dllexport-missing-key.cpp
===
--- /dev/null
+++ test/CodeGenCXX/dllexport-missing-key.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-windows-gnu -emit-llvm -std=c++11 -o - %s | FileCheck --check-prefix=GNU %s
+
+class __declspec(dllexport) QAbstractLayoutStyleInfo {
+public:
+  QAbstractLayoutStyleInfo() : m_isWindow(false) {}
+  virtual ~QAbstractLayoutStyleInfo() {}
+
+  virtual bool hasChangedCore() const { return false; }
+
+  virtual void invalidate() {}
+
+  virtual double windowMargin(bool orientation) const = 0;
+
+  bool isWindow() const { return m_isWindow; }
+
+protected:
+  bool m_isWindow;
+};
+
+// GNU-DAG: @_ZTV24QAbstractLayoutStyleInfo = weak_odr dso_local dllexport
+// GNU-DAG: @_ZTS24QAbstractLayoutStyleInfo = linkonce_odr
+// GNU-DAG: @_ZTI24QAbstractLayoutStyleInfo = linkonce_odr
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -5493,6 +5493,9 @@
 // declaration.
 return;
 
+  if (S.Context.getTargetInfo().getTriple().isWindowsGNUEnvironment())
+S.MarkVTableUsed(Class->getLocation(), Class, true);
+
   for (Decl *Member : Class->decls()) {
 // Defined static variables that are members of an exported base
 // class must be marked export too.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55698: [MinGW] Produce a vtable and RTTI for dllexported classes without a key function

2018-12-14 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo marked 2 inline comments as done.
mstorsjo added inline comments.



Comment at: lib/Sema/SemaDeclCXX.cpp:5754-5756
+  if (ClassExported &&
+  Context.getTargetInfo().getTriple().isWindowsGNUEnvironment())
+MarkVTableUsed(Class->getLocation(), Class, true);

rnk wrote:
> This may be too early, you can get into situations like this if you start 
> emitting the vtable (which will emit inline methods) before we get to the end 
> of the outermost class. See this bug for example:
> https://bugs.llvm.org/show_bug.cgi?id=40006
> 
> Maybe if you have a dllexported nested class with a virtual method that 
> references the constructor of the outer class which has a late-parsed member 
> initializer... you can get things to go wrong as in the bug above.
> 
> I think the fix will be to touch the vtable when we process delayed 
> dllexported classes from the list just above this line.
Ok, will upload a new version of the patch.


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

https://reviews.llvm.org/D55698



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


[PATCH] D55388: [analyzer] MoveChecker Pt.8: Add checks for dereferencing a smart pointer after move.

2018-12-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 178273.
NoQ added a comment.

Rebase.


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

https://reviews.llvm.org/D55388

Files:
  lib/StaticAnalyzer/Checkers/MoveChecker.cpp
  test/Analysis/use-after-move.cpp

Index: test/Analysis/use-after-move.cpp
===
--- test/Analysis/use-after-move.cpp
+++ test/Analysis/use-after-move.cpp
@@ -1,20 +1,26 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.cplusplus.Move -verify %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
-// RUN:  -analyzer-config exploration_strategy=unexplored_first_queue
+// RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
+// RUN:  -analyzer-checker debug.ExprInspection
 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.cplusplus.Move -verify %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
-// RUN:  -analyzer-config exploration_strategy=dfs -DDFS=1
+// RUN:  -analyzer-config exploration_strategy=dfs -DDFS=1\
+// RUN:  -analyzer-checker debug.ExprInspection
 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.cplusplus.Move -verify %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
-// RUN:  -analyzer-config alpha.cplusplus.Move:Aggressive=true -DAGGRESSIVE
+// RUN:  -analyzer-config alpha.cplusplus.Move:Aggressive=true -DAGGRESSIVE\
+// RUN:  -analyzer-checker debug.ExprInspection
 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.cplusplus.Move -verify %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=dfs -DDFS=1\
-// RUN:  -analyzer-config alpha.cplusplus.Move:Aggressive=true -DAGGRESSIVE
+// RUN:  -analyzer-config alpha.cplusplus.Move:Aggressive=true -DAGGRESSIVE\
+// RUN:  -analyzer-checker debug.ExprInspection
 
 #include "Inputs/system-header-simulator-cxx.h"
 
+void clang_analyzer_warnIfReached();
+
 class B {
 public:
   B() = default;
@@ -810,7 +816,19 @@
 // expected-note@-4{{Object 'P' is moved}}
 // expected-note@-4{{Method called on moved-from object 'P'}}
 #endif
-*P += 1; // FIXME: Should warn that the pointer is null.
+
+// Because that well-defined state is null, dereference is still UB.
+// Note that in aggressive mode we already warned about 'P',
+// so no extra warning is generated.
+*P += 1;
+#ifndef AGGRESSIVE
+// expected-warning@-2{{Dereference of null smart pointer 'P' of type 'std::unique_ptr'}}
+// expected-note@-14{{Smart pointer 'P' of type 'std::unique_ptr' is reset to null when moved from}}
+// expected-note@-4{{Dereference of null smart pointer 'P' of type 'std::unique_ptr'}}
+#endif
+
+// The program should have crashed by now.
+clang_analyzer_warnIfReached(); // no-warning
   }
 };
 
@@ -827,3 +845,9 @@
   P.get(); // expected-warning{{Method called on moved-from object 'P'}}
// expected-note@-1{{Method called on moved-from object 'P'}}
 }
+
+void localUniquePtrWithArrow(std::unique_ptr P) {
+  std::unique_ptr Q = std::move(P); // expected-note{{Smart pointer 'P' of type 'std::unique_ptr' is reset to null when moved from}}
+  P->foo(); // expected-warning{{Dereference of null smart pointer 'P' of type 'std::unique_ptr'}}
+// expected-note@-1{{Dereference of null smart pointer 'P' of type 'std::unique_ptr'}}
+}
Index: lib/StaticAnalyzer/Checkers/MoveChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MoveChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MoveChecker.cpp
@@ -61,19 +61,35 @@
   const char *NL, const char *Sep) const override;
 
 private:
-  enum MisuseKind { MK_FunCall, MK_Copy, MK_Move };
+  enum MisuseKind { MK_FunCall, MK_Copy, MK_Move, MK_Dereference };
+  enum StdObjectKind { SK_NonStd, SK_Unsafe, SK_Safe, SK_SmartPtr };
+
+  static bool misuseCausesCrash(MisuseKind MK) {
+return MK == MK_Dereference;
+  }
 
   struct ObjectKind {
-bool Local : 1; // Is this a local variable or a local rvalue reference?
-bool STL : 1; // Is this an object of a standard type?
+// Is this a local variable or a local rvalue reference?
+bool IsLocal : 1;
+// Is this an STL object? If so, of what kind?
+StdObjectKind StdKind : 2;
+  };
+
+  // STL smart pointers are automatically re-initialized to null when moved
+  // from. So we can't warn on many methods, but we can warn when it is
+  // dereferenced, which is UB even if the resulting lvalue never gets read.
+  const llvm::StringSet<> StdSmartPtrClasses = {
+  "shared_ptr",
+  "unique_ptr",
+  "weak_ptr",
   };
 
   // Not all of these are entirely move-safe, but they do provide *some*
   // guarantees, and it means that somebody is using them after move
   // in a valid manner.
-  // 

[PATCH] D55387: [analyzer] MoveChecker Pt.7: NFC: Misc refactoring.

2018-12-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/MoveChecker.cpp:265
 
+void MoveChecker::checkUse(ProgramStateRef State, const MemRegion *Region,
+   const CXXRecordDecl *RD, MisuseKind MK,

a_sidorin wrote:
> I think that if the function is named "checkUse()", committing State changes 
> is not what is really expected from it. Should we rename it or change the 
> logic somehow? For example, return true if a report was emitted and add 
> transition in the caller?
Good point. Renamed to `modelUse()` because the `addTransition()` logic becomes 
more complicated in the next patch, so i didn't want to duplicate it on all 
those call sites.



Comment at: lib/StaticAnalyzer/Checkers/MoveChecker.cpp:272
+  if (!RS || isAnyBaseRegionReported(State, Region)
+  || isInMoveSafeContext(C.getLocationContext())) {
+// Finalize changes made by the caller.

a_sidorin wrote:
> This formatting is different from what clang-format does.
This gets overwritten in the next patch anyway. But imho this is more fancy 
than what clang-format does.


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

https://reviews.llvm.org/D55387



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


[PATCH] D55387: [analyzer] MoveChecker Pt.7: NFC: Misc refactoring.

2018-12-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 178272.
NoQ marked 4 inline comments as done.
NoQ added a comment.

Fxd.


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

https://reviews.llvm.org/D55387

Files:
  lib/StaticAnalyzer/Checkers/MoveChecker.cpp

Index: lib/StaticAnalyzer/Checkers/MoveChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MoveChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MoveChecker.cpp
@@ -89,6 +89,20 @@
   "weak_ptr",
   };
 
+  // Should we bother tracking the state of the object?
+  bool shouldBeTracked(ObjectKind OK) const {
+// In non-aggressive mode, only warn on use-after-move of local variables
+// (or local rvalue references) and of STL objects. The former is possible
+// because local variables (or local rvalue references) are not tempting
+// their user to re-use the storage. The latter is possible because STL
+// objects are known to end up in a valid but unspecified state after the
+// move and their state-reset methods are also known, which allows us to
+// predict precisely when use-after-move is invalid. In aggressive mode,
+// warn on any use-after-move because the user has intentionally asked us
+// to completely eliminate use-after-move in his code.
+return IsAggressive || OK.Local || OK.STL;
+  }
+
   // Obtains ObjectKind of an object. Because class declaration cannot always
   // be easily obtained from the memory region, it is supplied separately.
   ObjectKind classifyObject(const MemRegion *MR, const CXXRecordDecl *RD) const;
@@ -136,8 +150,20 @@
 
 private:
   mutable std::unique_ptr BT;
+
+  // Check if the given form of potential misuse of a given object
+  // should be reported. If so, get it reported. The callback from which
+  // this function was called should immediately return after the call
+  // because this function adds one or two transitions.
+  void modelUse(ProgramStateRef State, const MemRegion *Region,
+const CXXRecordDecl *RD, MisuseKind MK,
+CheckerContext ) const;
+
+  // Returns the exploded node against which the report was emitted.
+  // The caller *must* add any further transitions against this node.
   ExplodedNode *reportBug(const MemRegion *Region, const CXXRecordDecl *RD,
   CheckerContext , MisuseKind MK) const;
+
   bool isInMoveSafeContext(const LocationContext *LC) const;
   bool isStateResetMethod(const CXXMethodDecl *MethodDec) const;
   bool isMoveSafeMethod(const CXXMethodDecl *MethodDec) const;
@@ -236,6 +262,25 @@
   return MoveNode;
 }
 
+void MoveChecker::modelUse(ProgramStateRef State, const MemRegion *Region,
+   const CXXRecordDecl *RD, MisuseKind MK,
+   CheckerContext ) const {
+  assert(!C.isDifferent() && "No transitions should have been made by now");
+  const RegionState *RS = State->get(Region);
+
+  if (!RS || isAnyBaseRegionReported(State, Region)
+  || isInMoveSafeContext(C.getLocationContext())) {
+// Finalize changes made by the caller.
+C.addTransition(State);
+return;
+  }
+
+  ExplodedNode *N = reportBug(Region, RD, C, MK);
+
+  State = State->set(Region, RegionState::getReported());
+  C.addTransition(State, N);
+}
+
 ExplodedNode *MoveChecker::reportBug(const MemRegion *Region,
  const CXXRecordDecl *RD,
  CheckerContext ,
@@ -294,12 +339,10 @@
   if (!MethodDecl)
 return;
 
-  const auto *ConstructorDecl = dyn_cast(MethodDecl);
-
-  const auto *CC = dyn_cast_or_null();
   // Check if an object became moved-from.
   // Object can become moved from after a call to move assignment operator or
   // move constructor .
+  const auto *ConstructorDecl = dyn_cast(MethodDecl);
   if (ConstructorDecl && !ConstructorDecl->isMoveConstructor())
 return;
 
@@ -310,23 +353,11 @@
   if (!ArgRegion)
 return;
 
-  // In non-aggressive mode, only warn on use-after-move of local variables (or
-  // local rvalue references) and of STL objects. The former is possible because
-  // local variables (or local rvalue references) are not tempting their user to
-  // re-use the storage. The latter is possible because STL objects are known
-  // to end up in a valid but unspecified state after the move and their
-  // state-reset methods are also known, which allows us to predict
-  // precisely when use-after-move is invalid.
-  // In aggressive mode, warn on any use-after-move because the user
-  // has intentionally asked us to completely eliminate use-after-move
-  // in his code.
-  ObjectKind OK = classifyObject(ArgRegion, MethodDecl->getParent());
-  if (!IsAggressive && !OK.Local && !OK.STL)
-return;
-
   // Skip moving the object to itself.
+  const auto *CC = dyn_cast_or_null();
   if (CC && CC->getCXXThisVal().getAsRegion() == ArgRegion)
 return;
+
   if (const auto *IC = dyn_cast(AFC))
 if 

r349197 - Using llvm::find_if() instead of a range-based for loop; NFC.

2018-12-14 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri Dec 14 13:14:44 2018
New Revision: 349197

URL: http://llvm.org/viewvc/llvm-project?rev=349197=rev
Log:
Using llvm::find_if() instead of a range-based for loop; NFC.

This addresses post-commit review feedback from r349188.

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp?rev=349197=349196=349197=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp Fri Dec 14 13:14:44 
2018
@@ -123,24 +123,21 @@ static json::Object createFileLocation(c
   std::string FileURI = fileNameToURI(getFileName(FE));
 
   // See if the Files array contains this URI already. If it does not, create
-  // a new file object to add to the array. Calculate the index within the file
-  // location array so it can be stored in the JSON object.
-  unsigned Index = 0;
-  for (const json::Value  : Files) {
+  // a new file object to add to the array.
+  auto I = llvm::find_if(Files, [&](const json::Value ) {
 if (const json::Object *Obj = File.getAsObject()) {
   if (const json::Object *FileLoc = Obj->getObject("fileLocation")) {
 Optional URI = FileLoc->getString("uri");
-if (URI && URI->equals(FileURI))
-  break;
+return URI && URI->equals(FileURI);
   }
 }
-++Index;
-  }
+return false;
+  });
 
-  // If we reached the end of the array, then add the file to the list of files
-  // we're tracking; Index then points to the last element of the array. Note
-  // that an empty file lists always causes a file to be added.
-  if (Files.empty() || Index == Files.size())
+  // Calculate the index within the file location array so it can be stored in
+  // the JSON object.
+  auto Index = static_cast(std::distance(Files.begin(), I));
+  if (I == Files.end())
 Files.push_back(createFile(FE));
 
   return json::Object{{"uri", FileURI}, {"fileIndex", Index}};


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


[PATCH] D55707: Update to SARIF 11-28

2018-12-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman marked an inline comment as done.
aaron.ballman added inline comments.



Comment at: lib/StaticAnalyzer/Core/SarifDiagnostics.cpp:129
+  unsigned Index = 0;
+  for (const json::Value  : Files) {
+if (const json::Object *Obj = File.getAsObject()) {

NoQ wrote:
> aaron.ballman wrote:
> > NoQ wrote:
> > > This sounds like `find_if` to me.
> > The problem is: we need the `Index`. It felt a bit weird to have 
> > `llvm::find_if()` (a const operation) also mutating a locally-captured 
> > variable. WDYT?
> The way i see it:
> 
> ```
> auto I = std::find_if(Files.begin(), Files.end(), [&](const json::Value  
> {
>   if (const json::Object *Obj = File.getAsObject())
> if (const json::Object *FileLoc = Obj->getObject("fileLocation")) {
>   Optional URI = FileLoc->getString("uri");
>   return URI && URI->equals(FileURI);
> }
>   return false;
> });
> 
> if (I == Files.end())
>   Files.push_back(createFile(FE));
> 
> return std::distance(Files.begin(), I);
> ```
> 
> Or pre-compute the index before `push_back` if the container invalidates 
> iterators upon `push_back`.
> 
I dig it! Implemented in r349197.


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

https://reviews.llvm.org/D55707



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


r349195 - [Clang] Add __builtin_launder

2018-12-14 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Fri Dec 14 13:11:28 2018
New Revision: 349195

URL: http://llvm.org/viewvc/llvm-project?rev=349195=rev
Log:
[Clang] Add __builtin_launder

Summary:
This patch adds `__builtin_launder`, which is required to implement 
`std::launder`. Additionally GCC provides `__builtin_launder`, so thing brings 
Clang in-line with GCC.

I'm not exactly sure what magic `__builtin_launder` requires, but  based on 
previous discussions this patch applies a `@llvm.invariant.group.barrier`. As 
noted in previous discussions, this may not be enough to correctly handle 
vtables.

Reviewers: rnk, majnemer, rsmith

Reviewed By: rsmith

Subscribers: kristina, Romain-Geissler-1A, erichkeane, amharc, jroelofs, 
cfe-commits, Prazek

Differential Revision: https://reviews.llvm.org/D40218

Added:
cfe/trunk/test/CodeGenCXX/builtin-launder.cpp
Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/CodeGen/builtins.c
cfe/trunk/test/Preprocessor/feature_tests.c
cfe/trunk/test/Sema/builtins.c
cfe/trunk/test/SemaCXX/builtins.cpp

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=349195=349194=349195=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Fri Dec 14 13:11:28 2018
@@ -498,6 +498,7 @@ BUILTIN(__builtin_snprintf, "ic*zcC*.",
 BUILTIN(__builtin_vsprintf, "ic*cC*a", "nFP:1:")
 BUILTIN(__builtin_vsnprintf, "ic*zcC*a", "nFP:2:")
 BUILTIN(__builtin_thread_pointer, "v*", "nc")
+BUILTIN(__builtin_launder, "v*v*", "nt")
 
 // GCC exception builtins
 BUILTIN(__builtin_eh_return, "vzv*", "r") // FIXME: Takes intptr_t, not size_t!

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=349195=349194=349195=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Dec 14 13:11:28 
2018
@@ -9475,4 +9475,8 @@ def warn_noderef_on_non_pointer_or_array
 def warn_noderef_to_dereferenceable_pointer : Warning<
   "casting to dereferenceable pointer removes 'noderef' attribute">, 
InGroup;
 
+def err_builtin_launder_invalid_arg : Error<
+  "%select{non-pointer|function pointer|void pointer}0 argument to "
+  "'__builtin_launder' is not allowed">;
+
 } // end of sema component.

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=349195=349194=349195=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Dec 14 13:11:28 2018
@@ -6112,7 +6112,8 @@ bool PointerExprEvaluator::VisitBuiltinC
 
 return true;
   }
-
+  case Builtin::BI__builtin_launder:
+return evaluatePointer(E->getArg(0), Result);
   case Builtin::BIstrchr:
   case Builtin::BIwcschr:
   case Builtin::BImemchr:

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=349195=349194=349195=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Dec 14 13:11:28 2018
@@ -25,6 +25,7 @@
 #include "clang/Basic/TargetBuiltins.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/IR/CallSite.h"
 #include "llvm/IR/DataLayout.h"
@@ -1409,6 +1410,42 @@ static llvm::Value *dumpRecord(CodeGenFu
   return Res;
 }
 
+static bool
+TypeRequiresBuiltinLaunderImp(const ASTContext , QualType Ty,
+  llvm::SmallPtrSetImpl ) {
+  if (const auto *Arr = Ctx.getAsArrayType(Ty))
+Ty = Ctx.getBaseElementType(Arr);
+
+  const auto *Record = Ty->getAsCXXRecordDecl();
+  if (!Record)
+return false;
+
+  // We've already checked this type, or are in the process of checking it.
+  if (!Seen.insert(Record).second)
+return false;
+
+  assert(Record->hasDefinition() &&
+ "Incomplete types should already be diagnosed");
+
+  if (Record->isDynamicClass())
+return true;
+
+  for (FieldDecl *F : Record->fields()) {
+if (TypeRequiresBuiltinLaunderImp(Ctx, F->getType(), Seen))
+  return true;
+  }
+  return false;
+}
+
+/// Determine if the specified type requires laundering by checking if it is a
+/// dynamic class type or contains a subobject which is a 

[PATCH] D40218: [Clang] Add __builtin_launder

2018-12-14 Thread Eric Fiselier via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349195: [Clang] Add __builtin_launder (authored by EricWF, 
committed by ).

Repository:
  rC Clang

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

https://reviews.llvm.org/D40218

Files:
  include/clang/Basic/Builtins.def
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/Sema/SemaChecking.cpp
  test/CodeGen/builtins.c
  test/CodeGenCXX/builtin-launder.cpp
  test/Preprocessor/feature_tests.c
  test/Sema/builtins.c
  test/SemaCXX/builtins.cpp

Index: test/SemaCXX/builtins.cpp
===
--- test/SemaCXX/builtins.cpp
+++ test/SemaCXX/builtins.cpp
@@ -53,3 +53,95 @@
 void synchronize_args() {
   __sync_synchronize(0); // expected-error {{too many arguments}}
 }
+
+namespace test_launder {
+#define TEST_TYPE(Ptr, Type) \
+  static_assert(__is_same(decltype(__builtin_launder(Ptr)), Type), "expected same type")
+
+struct Dummy {};
+
+using FnType = int(char);
+using MemFnType = int (Dummy::*)(char);
+using ConstMemFnType = int (Dummy::*)() const;
+
+void foo() {}
+
+void test_builtin_launder_diags(void *vp, const void *cvp, FnType *fnp,
+MemFnType mfp, ConstMemFnType cmfp, int ()[5]) {
+  __builtin_launder(vp);   // expected-error {{void pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(cvp);  // expected-error {{void pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(fnp);  // expected-error {{function pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(mfp);  // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(cmfp); // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+  (void)__builtin_launder();
+  __builtin_launder(42);  // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(nullptr); // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(foo); // expected-error {{function pointer argument to '__builtin_launder' is not allowed}}
+  (void)__builtin_launder(Arr);
+}
+
+void test_builtin_launder(char *p, const volatile int *ip, const float *,
+  double *__restrict dp) {
+  int x;
+  __builtin_launder(x); // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+
+  TEST_TYPE(p, char*);
+  TEST_TYPE(ip, const volatile int*);
+  TEST_TYPE(fp, const float*);
+  TEST_TYPE(dp, double *__restrict);
+
+  char *d = __builtin_launder(p);
+  const volatile int *id = __builtin_launder(ip);
+  int *id2 = __builtin_launder(ip); // expected-error {{cannot initialize a variable of type 'int *' with an rvalue of type 'const volatile int *'}}
+  const float* fd = __builtin_launder(fp);
+}
+
+void test_launder_return_type(const int ()[101], int ()[42][13],
+  void (**)()) {
+  TEST_TYPE(ArrayRef, const int *);
+  TEST_TYPE(MArrRef, int(*)[13]);
+  TEST_TYPE(FuncPtrRef, void (**)());
+}
+
+template 
+constexpr Tp *test_constexpr_launder(Tp *tp) {
+  return __builtin_launder(tp);
+}
+constexpr int const_int = 42;
+constexpr int const_int2 = 101;
+constexpr const int *const_ptr = test_constexpr_launder(_int);
+static_assert(_int == const_ptr, "");
+static_assert(const_ptr != test_constexpr_launder(_int2), "");
+
+void test_non_constexpr() {
+  constexpr int i = 42;// expected-note {{declared here}}
+  constexpr const int *ip = __builtin_launder(); // expected-error {{constexpr variable 'ip' must be initialized by a constant expression}}
+  // expected-note@-1 {{pointer to 'i' is not a constant expression}}
+}
+
+constexpr bool test_in_constexpr(const int ) {
+  return (__builtin_launder() == );
+}
+
+static_assert(test_in_constexpr(const_int), "");
+void f() {
+  constexpr int i = 42;
+  static_assert(test_in_constexpr(i), "");
+}
+
+struct Incomplete; // expected-note {{forward declaration}}
+struct IncompleteMember {
+  Incomplete 
+};
+void test_incomplete(Incomplete *i, IncompleteMember *im) {
+  // expected-error@+1 {{incomplete type 'test_launder::Incomplete' where a complete type is required}}
+  __builtin_launder(i);
+  __builtin_launder(); // OK
+  __builtin_launder(im); // OK
+}
+
+void test_noexcept(int *i) {
+  static_assert(noexcept(__builtin_launder(i)), "");
+}
+#undef TEST_TYPE
+} // end namespace test_launder
Index: test/CodeGen/builtins.c
===
--- test/CodeGen/builtins.c
+++ test/CodeGen/builtins.c
@@ -132,6 +132,8 @@
   R(extract_return_addr, ());
   P(signbit, (1.0));
 
+  R(launder, ());
+
   return 0;
 }
 
@@ -396,6 +398,15 @@
   return __builtin_readcyclecounter();
 }
 
+/// __builtin_launder should be a NOP in C since there are no 

[PATCH] D40218: [Clang] Add __builtin_launder

2018-12-14 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 178267.
EricWF added a comment.

Merging with upstream. Preparing to commit.


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

https://reviews.llvm.org/D40218

Files:
  include/clang/Basic/Builtins.def
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/Sema/SemaChecking.cpp
  test/CodeGen/builtins.c
  test/CodeGenCXX/builtin-launder.cpp
  test/Preprocessor/feature_tests.c
  test/Sema/builtins.c
  test/SemaCXX/builtins.cpp

Index: test/SemaCXX/builtins.cpp
===
--- test/SemaCXX/builtins.cpp
+++ test/SemaCXX/builtins.cpp
@@ -53,3 +53,95 @@
 void synchronize_args() {
   __sync_synchronize(0); // expected-error {{too many arguments}}
 }
+
+namespace test_launder {
+#define TEST_TYPE(Ptr, Type) \
+  static_assert(__is_same(decltype(__builtin_launder(Ptr)), Type), "expected same type")
+
+struct Dummy {};
+
+using FnType = int(char);
+using MemFnType = int (Dummy::*)(char);
+using ConstMemFnType = int (Dummy::*)() const;
+
+void foo() {}
+
+void test_builtin_launder_diags(void *vp, const void *cvp, FnType *fnp,
+MemFnType mfp, ConstMemFnType cmfp, int ()[5]) {
+  __builtin_launder(vp);   // expected-error {{void pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(cvp);  // expected-error {{void pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(fnp);  // expected-error {{function pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(mfp);  // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(cmfp); // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+  (void)__builtin_launder();
+  __builtin_launder(42);  // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(nullptr); // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(foo); // expected-error {{function pointer argument to '__builtin_launder' is not allowed}}
+  (void)__builtin_launder(Arr);
+}
+
+void test_builtin_launder(char *p, const volatile int *ip, const float *,
+  double *__restrict dp) {
+  int x;
+  __builtin_launder(x); // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+
+  TEST_TYPE(p, char*);
+  TEST_TYPE(ip, const volatile int*);
+  TEST_TYPE(fp, const float*);
+  TEST_TYPE(dp, double *__restrict);
+
+  char *d = __builtin_launder(p);
+  const volatile int *id = __builtin_launder(ip);
+  int *id2 = __builtin_launder(ip); // expected-error {{cannot initialize a variable of type 'int *' with an rvalue of type 'const volatile int *'}}
+  const float* fd = __builtin_launder(fp);
+}
+
+void test_launder_return_type(const int ()[101], int ()[42][13],
+  void (**)()) {
+  TEST_TYPE(ArrayRef, const int *);
+  TEST_TYPE(MArrRef, int(*)[13]);
+  TEST_TYPE(FuncPtrRef, void (**)());
+}
+
+template 
+constexpr Tp *test_constexpr_launder(Tp *tp) {
+  return __builtin_launder(tp);
+}
+constexpr int const_int = 42;
+constexpr int const_int2 = 101;
+constexpr const int *const_ptr = test_constexpr_launder(_int);
+static_assert(_int == const_ptr, "");
+static_assert(const_ptr != test_constexpr_launder(_int2), "");
+
+void test_non_constexpr() {
+  constexpr int i = 42;// expected-note {{declared here}}
+  constexpr const int *ip = __builtin_launder(); // expected-error {{constexpr variable 'ip' must be initialized by a constant expression}}
+  // expected-note@-1 {{pointer to 'i' is not a constant expression}}
+}
+
+constexpr bool test_in_constexpr(const int ) {
+  return (__builtin_launder() == );
+}
+
+static_assert(test_in_constexpr(const_int), "");
+void f() {
+  constexpr int i = 42;
+  static_assert(test_in_constexpr(i), "");
+}
+
+struct Incomplete; // expected-note {{forward declaration}}
+struct IncompleteMember {
+  Incomplete 
+};
+void test_incomplete(Incomplete *i, IncompleteMember *im) {
+  // expected-error@+1 {{incomplete type 'test_launder::Incomplete' where a complete type is required}}
+  __builtin_launder(i);
+  __builtin_launder(); // OK
+  __builtin_launder(im); // OK
+}
+
+void test_noexcept(int *i) {
+  static_assert(noexcept(__builtin_launder(i)), "");
+}
+#undef TEST_TYPE
+} // end namespace test_launder
Index: test/Sema/builtins.c
===
--- test/Sema/builtins.c
+++ test/Sema/builtins.c
@@ -258,6 +258,24 @@
 return buf;
 }
 
+typedef void (fn_t)(int);
+
+void test_builtin_launder(char *p, void *vp, const void *cvp,
+  const volatile int *ip, float *restrict fp,
+  fn_t *fn) {
+  __builtin_launder(); // expected-error {{too few arguments to function call, 

r349192 - [OPENMP][NVPTX]Improved interwarp copy function.

2018-12-14 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Dec 14 13:00:58 2018
New Revision: 349192

URL: http://llvm.org/viewvc/llvm-project?rev=349192=rev
Log:
[OPENMP][NVPTX]Improved interwarp copy function.

Inlined runtime with the current implementation of the interwarp copy
function leads to the undefined behavior because of the not quite
correct implementation of the barriers. Start using generic
__kmpc_barier function instead of the custom made barriers.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_teams_reduction_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=349192=349191=349192=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Fri Dec 14 13:00:58 2018
@@ -189,13 +189,6 @@ enum MachineConfiguration : unsigned {
   SharedMemorySize = 128,
 };
 
-enum NamedBarrier : unsigned {
-  /// Synchronize on this barrier #ID using a named barrier primitive.
-  /// Only the subset of active threads in a parallel region arrive at the
-  /// barrier.
-  NB_Parallel = 1,
-};
-
 static const ValueDecl *getPrivateItem(const Expr *RefExpr) {
   RefExpr = RefExpr->IgnoreParens();
   if (const auto *ASE = dyn_cast(RefExpr)) {
@@ -655,26 +648,9 @@ static void getNVPTXCTABarrier(CodeGenFu
   CGF.EmitRuntimeCall(F);
 }
 
-/// Get barrier #ID to synchronize selected (multiple of warp size) threads in
-/// a CTA.
-static void getNVPTXBarrier(CodeGenFunction , int ID,
-llvm::Value *NumThreads) {
-  CGBuilderTy  = CGF.Builder;
-  llvm::Value *Args[] = {Bld.getInt32(ID), NumThreads};
-  llvm::Function *F = llvm::Intrinsic::getDeclaration(
-  (), llvm::Intrinsic::nvvm_barrier);
-  F->addFnAttr(llvm::Attribute::Convergent);
-  CGF.EmitRuntimeCall(F, Args);
-}
-
 /// Synchronize all GPU threads in a block.
 static void syncCTAThreads(CodeGenFunction ) { getNVPTXCTABarrier(CGF); }
 
-/// Synchronize worker threads in a parallel region.
-static void syncParallelThreads(CodeGenFunction , llvm::Value *NumThreads) 
{
-  return getNVPTXBarrier(CGF, NB_Parallel, NumThreads);
-}
-
 /// Get the value of the thread_limit clause in the teams directive.
 /// For the 'generic' execution mode, the runtime encodes thread_limit in
 /// the launch parameters, always starting thread_limit+warpSize threads per
@@ -3272,14 +3248,10 @@ static llvm::Value *emitInterWarpCopyFun
 
   CGF.EmitBlock(MergeBB);
 
-  Address AddrNumWarpsArg = CGF.GetAddrOfLocalVar();
-  llvm::Value *NumWarpsVal = CGF.EmitLoadOfScalar(
-  AddrNumWarpsArg, /*Volatile=*/false, C.IntTy, Loc);
-
-  llvm::Value *NumActiveThreads = Bld.CreateNSWMul(
-  NumWarpsVal, getNVPTXWarpSize(CGF), "num_active_threads");
-  // named_barrier_sync(ParallelBarrierID, num_active_threads)
-  syncParallelThreads(CGF, NumActiveThreads);
+  // kmpc_barrier.
+  CGM.getOpenMPRuntime().emitBarrierCall(CGF, Loc, OMPD_unknown,
+ /*EmitChecks=*/false,
+ /*ForceSimpleCall=*/true);
 
   //
   // Warp 0 copies reduce element from transfer medium.
@@ -3288,6 +3260,10 @@ static llvm::Value *emitInterWarpCopyFun
   llvm::BasicBlock *W0ElseBB = CGF.createBasicBlock("else");
   llvm::BasicBlock *W0MergeBB = CGF.createBasicBlock("ifcont");
 
+  Address AddrNumWarpsArg = CGF.GetAddrOfLocalVar();
+  llvm::Value *NumWarpsVal = CGF.EmitLoadOfScalar(
+  AddrNumWarpsArg, /*Volatile=*/false, C.IntTy, Loc);
+
   // Up to 32 threads in warp 0 are active.
   llvm::Value *IsActiveThread =
   Bld.CreateICmpULT(ThreadID, NumWarpsVal, "is_active_thread");
@@ -3329,7 +3305,10 @@ static llvm::Value *emitInterWarpCopyFun
 
   // While warp 0 copies values from transfer medium, all other warps must
   // wait.
-  syncParallelThreads(CGF, NumActiveThreads);
+  // kmpc_barrier.
+  CGM.getOpenMPRuntime().emitBarrierCall(CGF, Loc, OMPD_unknown,
+ /*EmitChecks=*/false,
+ /*ForceSimpleCall=*/true);
   if (NumIters > 1) {
 Cnt = Bld.CreateNSWAdd(Cnt, llvm::ConstantInt::get(CGM.IntTy, 
/*V=*/1));
 CGF.EmitStoreOfScalar(Cnt, CntAddr, /*Volatile=*/false, C.IntTy);

Modified: cfe/trunk/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp?rev=349192=349191=349192=diff
==
--- cfe/trunk/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp (original)
+++ 

[PATCH] D55628: Add support for "labels" on push/pop directives in #pragma clang attribute

2018-12-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: clang/test/Sema/pragma-attribute-label.c:15
+// Out of order!
+#pragma clang attribute pop MY_LABEL
+

aaron.ballman wrote:
> dexonsmith wrote:
> > erik.pilkington wrote:
> > > aaron.ballman wrote:
> > > > dexonsmith wrote:
> > > > > aaron.ballman wrote:
> > > > > > I feel like this should be diagnosed, perhaps even as an error. The 
> > > > > > user provided labels but then got the push and pop order wrong when 
> > > > > > explicitly saying what to pop. That seems more likely to be a logic 
> > > > > > error on the user's part.
> > > > > On the contrary, the user is using two differently-named and 
> > > > > independent macro pairs (A_BEGIN/A_END vs B_BEGIN/B_END) and has no 
> > > > > idea they are implemented with _Pragma(“clang attribute ...”) under 
> > > > > the hood.  The point is to give the same result as two independent 
> > > > > pragma pairs, whose regions do not need to be nested.
> > > > > On the contrary, the user is using two differently-named and 
> > > > > independent macro pairs (A_BEGIN/A_END vs B_BEGIN/B_END) 
> > > > 
> > > > I don't think this is a safe assumption to make, and in this case, is 
> > > > false. There are no macros anywhere in this test case.
> > > > 
> > > > > The point is to give the same result as two independent pragma pairs, 
> > > > > whose regions do not need to be nested.
> > > > 
> > > > I don't find this to be intuitive behavior. These are stack 
> > > > manipulations with the names push and pop -- pretending that they're 
> > > > overlapping rather than a stack in the presence of labels is confusing. 
> > > > If I saw the code from this test case during a code review, I would 
> > > > flag it as being incorrect because the labels do not match -- I don't 
> > > > think I'd be the only one.
> > > I think the labels only really makes sense if you're writing macros that 
> > > hide the pragma attribute stack (like ASSUME_X_BEGIN/END, for instance), 
> > > which for better or for worse people do write, and in fact was the 
> > > intended use case for #pragma clang attribute. I think if we were to 
> > > write this feature again, we'd forgo the stack entirly and require every 
> > > `push` to have a label and be in its own namespace. But this is the best 
> > > we can do now.
> > > 
> > > I don't really think that anyone should write a push label outside of a 
> > > macro definition, since I agree that the semantics are a bit surprising 
> > > when you're writing the #pragmas yourself without macros. I'll update 
> > > this test case and the documentation to stress this point more. If you 
> > > think this is going to be a potential pain point, maybe we can even warn 
> > > on using a label outside of a macro definition. 
> > >> The point is to give the same result as two independent pragma pairs, 
> > >> whose regions do not need to be nested.
> > > I don't find this to be intuitive behavior. These are stack manipulations 
> > > with the names push and pop -- pretending that they're overlapping rather 
> > > than a stack in the presence of labels is confusing. If I saw the code 
> > > from this test case during a code review, I would flag it as being 
> > > incorrect because the labels do not match -- I don't think I'd be the 
> > > only one.
> > 
> > As Erik says, the intention is that these are only used by macros.
> > 
> > Stepping back, the goal of this pragma (which we added in 
> > https://reviews.llvm.org/D30009) is to avoid adding a new region-based 
> > pragma every time we want to apply an attribute within a region.  Clang has 
> > a lot of these pragmas, in order to support independent macros like this:
> > ```
> > #define A_BEGIN _Pragma("clang a push")
> > #define A_END   _Pragma("clang a pop")
> > #define B_BEGIN _Pragma("clang b push")
> > #define B_END   _Pragma("clang b pop")
> > #define C_BEGIN _Pragma("clang c push")
> > #define C_END   _Pragma("clang c pop")
> > ```
> > 
> > @arphaman came up with the idea of introduce "one pragma to rule them all", 
> > `pragma clang attribute`, so that we didn't need to introduce a new pragma 
> > each time we wanted an independent region:
> > ```
> > #define A_BEGIN _Pragma("clang attribute push(a)")
> > #define A_END   _Pragma("clang attribute pop")
> > #define B_BEGIN _Pragma("clang attribute push(b)")
> > #define B_END   _Pragma("clang attribute pop")
> > #define C_BEGIN _Pragma("clang attribute push(c)")
> > #define C_END   _Pragma("clang attribute pop")
> > ```
> > 
> > However, we've realized that there is a major design flaw: these macros are 
> > not independent, because they're using the same stack.  @erik.pilkington 
> > has come up with this solution using identifiers to namespace the attribute 
> > stacks, allowing the macros to be independent (like they were before, when 
> > each had a dedicated pragma):
> > ```
> > #define A_BEGIN _Pragma("clang attribute push A (a)")
> > #define A_END   _Pragma("clang attribute 

r349191 - [analyzer] MoveChecker Pt.6: Suppress the warning for the move-safe STL classes.

2018-12-14 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Fri Dec 14 12:52:57 2018
New Revision: 349191

URL: http://llvm.org/viewvc/llvm-project?rev=349191=rev
Log:
[analyzer] MoveChecker Pt.6: Suppress the warning for the move-safe STL classes.

Some C++ standard library classes provide additional guarantees about their
state after move. Suppress warnings on such classes until a more precise
behavior is implemented. Warnings for locals are not suppressed anyway
because it's still most likely a bug.

Differential Revision: https://reviews.llvm.org/D55307

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h
cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp
cfe/trunk/test/Analysis/use-after-move.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp?rev=349191=349190=349191=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp Fri Dec 14 12:52:57 
2018
@@ -20,6 +20,7 @@
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "llvm/ADT/StringSet.h"
 
 using namespace clang;
 using namespace ento;
@@ -67,20 +68,43 @@ private:
 bool STL : 1; // Is this an object of a standard type?
   };
 
+  // Not all of these are entirely move-safe, but they do provide *some*
+  // guarantees, and it means that somebody is using them after move
+  // in a valid manner.
+  // TODO: We can still try to identify *unsafe* use after move, such as
+  // dereference of a moved-from smart pointer (which is guaranteed to be 
null).
+  const llvm::StringSet<> StandardMoveSafeClasses = {
+  "basic_filebuf",
+  "basic_ios",
+  "future",
+  "optional",
+  "packaged_task"
+  "promise",
+  "shared_future",
+  "shared_lock",
+  "shared_ptr",
+  "thread",
+  "unique_ptr",
+  "unique_lock",
+  "weak_ptr",
+  };
+
   // Obtains ObjectKind of an object. Because class declaration cannot always
   // be easily obtained from the memory region, it is supplied separately.
-  static ObjectKind classifyObject(const MemRegion *MR,
-   const CXXRecordDecl *RD);
+  ObjectKind classifyObject(const MemRegion *MR, const CXXRecordDecl *RD) 
const;
 
   // Classifies the object and dumps a user-friendly description string to
   // the stream. Return value is equivalent to classifyObject.
-  static ObjectKind explainObject(llvm::raw_ostream ,
-  const MemRegion *MR, const CXXRecordDecl 
*RD);
+  ObjectKind explainObject(llvm::raw_ostream ,
+   const MemRegion *MR, const CXXRecordDecl *RD) const;
+
+  bool isStandardMoveSafeClass(const CXXRecordDecl *RD) const;
 
   class MovedBugVisitor : public BugReporterVisitor {
   public:
-MovedBugVisitor(const MemRegion *R, const CXXRecordDecl *RD)
-: Region(R), RD(RD), Found(false) {}
+MovedBugVisitor(const MoveChecker ,
+const MemRegion *R, const CXXRecordDecl *RD)
+: Chk(Chk), Region(R), RD(RD), Found(false) {}
 
 void Profile(llvm::FoldingSetNodeID ) const override {
   static int X = 0;
@@ -97,6 +121,7 @@ private:
BugReport ) override;
 
   private:
+const MoveChecker 
 // The tracked region.
 const MemRegion *Region;
 // The class of the tracked object.
@@ -157,7 +182,7 @@ static const MemRegion *unwrapRValueRefe
 
 std::shared_ptr
 MoveChecker::MovedBugVisitor::VisitNode(const ExplodedNode *N,
-BugReporterContext , BugReport &) {
+BugReporterContext , BugReport 
) {
   // We need only the last move of the reported object's region.
   // The visitor walks the ExplodedGraph backwards.
   if (Found)
@@ -182,7 +207,7 @@ MoveChecker::MovedBugVisitor::VisitNode(
   llvm::raw_svector_ostream OS(Str);
 
   OS << "Object";
-  ObjectKind OK = explainObject(OS, Region, RD);
+  ObjectKind OK = Chk.explainObject(OS, Region, RD);
   if (OK.STL)
 OS << " is left in a valid but unspecified state after move";
   else
@@ -251,7 +276,7 @@ ExplodedNode *MoveChecker::reportBug(con
 auto R =
 llvm::make_unique(*BT, OS.str(), N, LocUsedForUniqueing,
  
MoveNode->getLocationContext()->getDecl());
-R->addVisitor(llvm::make_unique(Region, RD));
+R->addVisitor(llvm::make_unique(*this, Region, RD));
 C.emitReport(std::move(R));
 return N;
   }
@@ -370,20 +395,30 @@ bool MoveChecker::isInMoveSafeContext(co
   return false;
 }
 
-MoveChecker::ObjectKind 

[PATCH] D55307: [analyzer] MoveChecker Pt.6: Suppress the warning for the few move-safe STL classes.

2018-12-14 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349191: [analyzer] MoveChecker Pt.6: Suppress the warning 
for the move-safe STL classes. (authored by dergachev, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D55307?vs=177048=178266#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D55307

Files:
  lib/StaticAnalyzer/Checkers/MoveChecker.cpp
  test/Analysis/Inputs/system-header-simulator-cxx.h
  test/Analysis/diagnostics/explicit-suppression.cpp
  test/Analysis/use-after-move.cpp

Index: test/Analysis/diagnostics/explicit-suppression.cpp
===
--- test/Analysis/diagnostics/explicit-suppression.cpp
+++ test/Analysis/diagnostics/explicit-suppression.cpp
@@ -19,6 +19,6 @@
 void testCopyNull(C *I, C *E) {
   std::copy(I, E, (C *)0);
 #ifndef SUPPRESSED
-  // expected-warning@../Inputs/system-header-simulator-cxx.h:670 {{Called C++ object pointer is null}}
+  // expected-warning@../Inputs/system-header-simulator-cxx.h:677 {{Called C++ object pointer is null}}
 #endif
 }
Index: test/Analysis/Inputs/system-header-simulator-cxx.h
===
--- test/Analysis/Inputs/system-header-simulator-cxx.h
+++ test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -237,6 +237,13 @@
 return static_cast(a);
   }
 
+  template 
+  void swap(T , T ) {
+T c(std::move(a));
+a = std::move(b);
+b = std::move(c);
+  }
+
   template
   class vector {
 typedef T value_type;
@@ -770,6 +777,22 @@
 
 }
 
+#if __cplusplus >= 201103L
+namespace std {
+  template  // TODO: Implement the stub for deleter.
+  class unique_ptr {
+  public:
+unique_ptr(const unique_ptr &) = delete;
+unique_ptr(unique_ptr &&);
+
+T *get() const;
+
+typename std::add_lvalue_reference::type operator*() const;
+T *operator->() const;
+  };
+}
+#endif
+
 #ifdef TEST_INLINABLE_ALLOCATORS
 namespace std {
   void *malloc(size_t);
Index: test/Analysis/use-after-move.cpp
===
--- test/Analysis/use-after-move.cpp
+++ test/Analysis/use-after-move.cpp
@@ -13,47 +13,7 @@
 // RUN:  -analyzer-config exploration_strategy=dfs -DDFS=1\
 // RUN:  -analyzer-config alpha.cplusplus.Move:Aggressive=true -DAGGRESSIVE
 
-namespace std {
-
-typedef __typeof(sizeof(int)) size_t;
-
-template 
-struct remove_reference;
-
-template 
-struct remove_reference { typedef _Tp type; };
-
-template 
-struct remove_reference<_Tp &> { typedef _Tp type; };
-
-template 
-struct remove_reference<_Tp &&> { typedef _Tp type; };
-
-template 
-typename remove_reference<_Tp>::type &(_Tp &&__t) {
-  return static_cast::type &&>(__t);
-}
-
-template 
-_Tp &(typename remove_reference<_Tp>::type &__t) noexcept {
-  return static_cast<_Tp &&>(__t);
-}
-
-template 
-void swap(T , T ) {
-  T c(std::move(a));
-  a = std::move(b);
-  b = std::move(c);
-}
-
-template 
-class vector {
-public:
-  vector();
-  void push_back(const T );
-};
-
-} // namespace std
+#include "Inputs/system-header-simulator-cxx.h"
 
 class B {
 public:
@@ -832,13 +792,26 @@
 
 class HasSTLField {
   std::vector V;
-  void foo() {
+  void testVector() {
 // Warn even in non-aggressive mode when it comes to STL, because
 // in STL the object is left in "valid but unspecified state" after move.
 std::vector W = std::move(V); // expected-note{{Object 'V' of type 'std::vector' is left in a valid but unspecified state after move}}
 V.push_back(123); // expected-warning{{Method called on moved-from object 'V'}}
   // expected-note@-1{{Method called on moved-from object 'V'}}
   }
+
+  std::unique_ptr P;
+  void testUniquePtr() {
+// unique_ptr remains in a well-defined state after move.
+std::unique_ptr Q = std::move(P);
+P.get();
+#ifdef AGGRESSIVE
+// expected-warning@-2{{Method called on moved-from object 'P'}}
+// expected-note@-4{{Object 'P' is moved}}
+// expected-note@-4{{Method called on moved-from object 'P'}}
+#endif
+*P += 1; // FIXME: Should warn that the pointer is null.
+  }
 };
 
 void localRValueMove(A &) {
@@ -846,3 +819,11 @@
   a.foo(); // expected-warning{{Method called on moved-from object 'a'}}
// expected-note@-1{{Method called on moved-from object 'a'}}
 }
+
+void localUniquePtr(std::unique_ptr P) {
+  // Even though unique_ptr is safe to use after move,
+  // reusing a local variable this way usually indicates a bug.
+  std::unique_ptr Q = std::move(P); // expected-note{{Object 'P' is moved}}
+  P.get(); // expected-warning{{Method called on moved-from object 'P'}}
+   // expected-note@-1{{Method called on moved-from object 'P'}}
+}
Index: lib/StaticAnalyzer/Checkers/MoveChecker.cpp
===
--- 

[PATCH] D55307: [analyzer] MoveChecker Pt.6: Suppress the warning for the few move-safe STL classes.

2018-12-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ marked 2 inline comments as done.
NoQ added inline comments.



Comment at: test/Analysis/Inputs/system-header-simulator-cxx.h:782
+namespace std {
+  template // TODO: Implement the stub for deleter.
+  class unique_ptr {

a_sidorin wrote:
> Nit: our coding rules require a space before template lbrace.
Fxd.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55307



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


[PATCH] D55289: [analyzer] MoveChecker Pt.5: Improve invalidation policies.

2018-12-14 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349190: [analyzer] MoveChecker: Improve invalidation 
policies. (authored by dergachev, committed by ).

Repository:
  rC Clang

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

https://reviews.llvm.org/D55289

Files:
  lib/StaticAnalyzer/Checkers/MoveChecker.cpp
  test/Analysis/use-after-move.cpp

Index: test/Analysis/use-after-move.cpp
===
--- test/Analysis/use-after-move.cpp
+++ test/Analysis/use-after-move.cpp
@@ -116,6 +116,19 @@
   bool empty() const;
   bool isEmpty() const;
   operator bool() const;
+
+  void testUpdateField() {
+A a;
+A b = std::move(a);
+a.i = 1;
+a.foo(); // no-warning
+  }
+  void testUpdateFieldDouble() {
+A a;
+A b = std::move(a);
+a.d = 1.0;
+a.foo(); // no-warning
+  }
 };
 
 int bignum();
@@ -594,24 +607,50 @@
   foobar(a.getI(), std::move(a)); //no-warning
 }
 
-void not_known(A );
-void not_known(A *a);
+void not_known_pass_by_ref(A );
+void not_known_pass_by_const_ref(const A );
+void not_known_pass_by_rvalue_ref(A &);
+void not_known_pass_by_ptr(A *a);
+void not_known_pass_by_const_ptr(const A *a);
 
 void regionAndPointerEscapeTest() {
   {
 A a;
 A b;
 b = std::move(a);
-not_known(a);
-a.foo(); //no-warning
+not_known_pass_by_ref(a);
+a.foo(); // no-warning
+  }
+  {
+A a;
+A b;
+b = std::move(a); // expected-note{{Object 'a' is moved}}
+not_known_pass_by_const_ref(a);
+a.foo(); // expected-warning{{Method called on moved-from object 'a'}}
+ // expected-note@-1{{Method called on moved-from object 'a'}}
+  }
+  {
+A a;
+A b;
+b = std::move(a);
+not_known_pass_by_rvalue_ref(std::move(a));
+a.foo(); // no-warning
   }
   {
 A a;
 A b;
 b = std::move(a);
-not_known();
+not_known_pass_by_ptr();
 a.foo(); // no-warning
   }
+  {
+A a;
+A b;
+b = std::move(a); // expected-note{{Object 'a' is moved}}
+not_known_pass_by_const_ptr();
+a.foo(); // expected-warning{{Method called on moved-from object 'a'}}
+ // expected-note@-1{{Method called on moved-from object 'a'}}
+  }
 }
 
 // A declaration statement containing multiple declarations sequences the
Index: lib/StaticAnalyzer/Checkers/MoveChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MoveChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MoveChecker.cpp
@@ -53,8 +53,8 @@
   ProgramStateRef
   checkRegionChanges(ProgramStateRef State,
  const InvalidatedSymbols *Invalidated,
- ArrayRef ExplicitRegions,
- ArrayRef Regions,
+ ArrayRef RequestedRegions,
+ ArrayRef InvalidatedRegions,
  const LocationContext *LCtx, const CallEvent *Call) const;
   void printState(raw_ostream , ProgramStateRef State,
   const char *NL, const char *Sep) const override;
@@ -525,19 +525,35 @@
 
 ProgramStateRef MoveChecker::checkRegionChanges(
 ProgramStateRef State, const InvalidatedSymbols *Invalidated,
-ArrayRef ExplicitRegions,
-ArrayRef Regions, const LocationContext *LCtx,
-const CallEvent *Call) const {
-  // In case of an InstanceCall don't remove the ThisRegion from the GDM since
-  // it is handled in checkPreCall and checkPostCall.
-  const MemRegion *ThisRegion = nullptr;
-  if (const auto *IC = dyn_cast_or_null(Call)) {
-ThisRegion = IC->getCXXThisVal().getAsRegion();
-  }
-
-  for (const auto *Region : ExplicitRegions) {
-if (ThisRegion != Region)
-  State = removeFromState(State, Region);
+ArrayRef RequestedRegions,
+ArrayRef InvalidatedRegions,
+const LocationContext *LCtx, const CallEvent *Call) const {
+  if (Call) {
+// Relax invalidation upon function calls: only invalidate parameters
+// that are passed directly via non-const pointers or non-const references
+// or rvalue references.
+// In case of an InstanceCall don't invalidate the this-region since
+// it is fully handled in checkPreCall and checkPostCall.
+const MemRegion *ThisRegion = nullptr;
+if (const auto *IC = dyn_cast(Call))
+  ThisRegion = IC->getCXXThisVal().getAsRegion();
+
+// Requested ("explicit") regions are the regions passed into the call
+// directly, but not all of them end up being invalidated.
+// But when they do, they appear in the InvalidatedRegions array as well.
+for (const auto *Region : RequestedRegions) {
+  if (ThisRegion != Region) {
+if (llvm::find(InvalidatedRegions, Region) !=
+std::end(InvalidatedRegions)) {
+  State = removeFromState(State, Region);
+}
+  }
+}
+  } else {
+// For invalidations that aren't caused by calls, assume nothing. In
+// particular, direct write into 

r349190 - [analyzer] MoveChecker: Improve invalidation policies.

2018-12-14 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Fri Dec 14 12:47:58 2018
New Revision: 349190

URL: http://llvm.org/viewvc/llvm-project?rev=349190=rev
Log:
[analyzer] MoveChecker: Improve invalidation policies.

If a moved-from object is passed into a conservatively evaluated function
by pointer or by reference, we assume that the function may reset its state.

Make sure it doesn't apply to const pointers and const references. Add a test
that demonstrates that it does apply to rvalue references.

Additionally, make sure that the object is invalidated when its contents change
for reasons other than invalidation caused by evaluating a call conservatively.
In particular, when the object's fields are manipulated directly, we should
assume that some sort of reset may be happening.

Differential Revision: https://reviews.llvm.org/D55289

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
cfe/trunk/test/Analysis/use-after-move.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp?rev=349190=349189=349190=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp Fri Dec 14 12:47:58 
2018
@@ -53,8 +53,8 @@ public:
   ProgramStateRef
   checkRegionChanges(ProgramStateRef State,
  const InvalidatedSymbols *Invalidated,
- ArrayRef ExplicitRegions,
- ArrayRef Regions,
+ ArrayRef RequestedRegions,
+ ArrayRef InvalidatedRegions,
  const LocationContext *LCtx, const CallEvent *Call) const;
   void printState(raw_ostream , ProgramStateRef State,
   const char *NL, const char *Sep) const override;
@@ -525,19 +525,35 @@ void MoveChecker::checkDeadSymbols(Symbo
 
 ProgramStateRef MoveChecker::checkRegionChanges(
 ProgramStateRef State, const InvalidatedSymbols *Invalidated,
-ArrayRef ExplicitRegions,
-ArrayRef Regions, const LocationContext *LCtx,
-const CallEvent *Call) const {
-  // In case of an InstanceCall don't remove the ThisRegion from the GDM since
-  // it is handled in checkPreCall and checkPostCall.
-  const MemRegion *ThisRegion = nullptr;
-  if (const auto *IC = dyn_cast_or_null(Call)) {
-ThisRegion = IC->getCXXThisVal().getAsRegion();
-  }
-
-  for (const auto *Region : ExplicitRegions) {
-if (ThisRegion != Region)
-  State = removeFromState(State, Region);
+ArrayRef RequestedRegions,
+ArrayRef InvalidatedRegions,
+const LocationContext *LCtx, const CallEvent *Call) const {
+  if (Call) {
+// Relax invalidation upon function calls: only invalidate parameters
+// that are passed directly via non-const pointers or non-const references
+// or rvalue references.
+// In case of an InstanceCall don't invalidate the this-region since
+// it is fully handled in checkPreCall and checkPostCall.
+const MemRegion *ThisRegion = nullptr;
+if (const auto *IC = dyn_cast(Call))
+  ThisRegion = IC->getCXXThisVal().getAsRegion();
+
+// Requested ("explicit") regions are the regions passed into the call
+// directly, but not all of them end up being invalidated.
+// But when they do, they appear in the InvalidatedRegions array as well.
+for (const auto *Region : RequestedRegions) {
+  if (ThisRegion != Region) {
+if (llvm::find(InvalidatedRegions, Region) !=
+std::end(InvalidatedRegions)) {
+  State = removeFromState(State, Region);
+}
+  }
+}
+  } else {
+// For invalidations that aren't caused by calls, assume nothing. In
+// particular, direct write into an object's field invalidates the status.
+for (const auto *Region : InvalidatedRegions)
+  State = removeFromState(State, Region->getBaseRegion());
   }
 
   return State;

Modified: cfe/trunk/test/Analysis/use-after-move.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/use-after-move.cpp?rev=349190=349189=349190=diff
==
--- cfe/trunk/test/Analysis/use-after-move.cpp (original)
+++ cfe/trunk/test/Analysis/use-after-move.cpp Fri Dec 14 12:47:58 2018
@@ -116,6 +116,19 @@ public:
   bool empty() const;
   bool isEmpty() const;
   operator bool() const;
+
+  void testUpdateField() {
+A a;
+A b = std::move(a);
+a.i = 1;
+a.foo(); // no-warning
+  }
+  void testUpdateFieldDouble() {
+A a;
+A b = std::move(a);
+a.d = 1.0;
+a.foo(); // no-warning
+  }
 };
 
 int bignum();
@@ -594,24 +607,50 @@ void paramEvaluateOrderTest() {
   foobar(a.getI(), std::move(a)); //no-warning
 }
 
-void not_known(A );
-void not_known(A *a);
+void not_known_pass_by_ref(A );
+void not_known_pass_by_const_ref(const A );
+void 

[PATCH] D53713: Add extension to always default-initialize nullptr_t.

2018-12-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

I approve this for Static Analyzer. As long as this is the correct thing to do 
in the compiler, Static Analyzer should ideally behave similarly to the 
compiler. Exposing portability bugs that would show up on other compilers is 
generally less important than behaving similarly to Clang itself.


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

https://reviews.llvm.org/D53713



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


[PATCH] D55707: Update to SARIF 11-28

2018-12-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Sure, np.




Comment at: lib/StaticAnalyzer/Core/SarifDiagnostics.cpp:129
+  unsigned Index = 0;
+  for (const json::Value  : Files) {
+if (const json::Object *Obj = File.getAsObject()) {

aaron.ballman wrote:
> NoQ wrote:
> > This sounds like `find_if` to me.
> The problem is: we need the `Index`. It felt a bit weird to have 
> `llvm::find_if()` (a const operation) also mutating a locally-captured 
> variable. WDYT?
The way i see it:

```
auto I = std::find_if(Files.begin(), Files.end(), [&](const json::Value  {
  if (const json::Object *Obj = File.getAsObject())
if (const json::Object *FileLoc = Obj->getObject("fileLocation")) {
  Optional URI = FileLoc->getString("uri");
  return URI && URI->equals(FileURI);
}
  return false;
});

if (I == Files.end())
  Files.push_back(createFile(FE));

return std::distance(Files.begin(), I);
```

Or pre-compute the index before `push_back` if the container invalidates 
iterators upon `push_back`.



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

https://reviews.llvm.org/D55707



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


[PATCH] D51211: [Sema] Emit -Wformat properly for bitfield promotions.

2018-12-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: lib/Sema/SemaChecking.cpp:7725-7726
+return true;
+  // Look through vector types, since we do default argument promotion for
+  // those in OpenCL.
+  if (const ExtVectorType *VecTy = From->getAs())

Looking at `Sema::DefaultArgumentPromotion()`, it seems there is some special 
logic there for _Float16 vs half/fp16. Do we need to deal with that here as 
well?



Comment at: lib/Sema/SemaChecking.cpp:7727
+  // those in OpenCL.
+  if (const ExtVectorType *VecTy = From->getAs())
+From = VecTy->getElementType();

Should use `const auto *` here and below.


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

https://reviews.llvm.org/D51211



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


[PATCH] D55707: Update to SARIF 11-28

2018-12-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

Committed in r349188.

(@NoQ -- if you'd like to see a switch to `llvm::find_if()`, I'm happy to 
handle it post-commit.)


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

https://reviews.llvm.org/D55707



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


r349188 - Update our SARIF support from 10-10 to 11-28.

2018-12-14 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri Dec 14 12:34:23 2018
New Revision: 349188

URL: http://llvm.org/viewvc/llvm-project?rev=349188=rev
Log:
Update our SARIF support from 10-10 to 11-28.

Functional changes include:

* The run.files property is now an array instead of a mapping.
* fileLocation objects now have a fileIndex property specifying the array index 
into run.files.
* The resource.rules property is now an array instead of a mapping.
* The result object was given a ruleIndex property that is an index into the 
resource.rules array.
* rule objects now have their "id" field filled out in addition to the name 
field.
* Updated the schema and spec version numbers to 11-28.

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp

cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif

cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif

Modified: cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp?rev=349188=349187=349188=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp Fri Dec 14 12:34:23 
2018
@@ -17,6 +17,7 @@
 #include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
 #include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/Path.h"
 
@@ -77,7 +78,7 @@ static std::string fileNameToURI(StringR
   if (Root.startswith("//")) {
 // There is an authority, so add it to the URI.
 Ret += Root.drop_front(2).str();
-  } else {
+  } else if (!Root.empty()) {
 // There is no authority, so end the component and add the root to the URI.
 Ret += Twine("/" + Root).str();
   }
@@ -118,12 +119,31 @@ static json::Object createFile(const Fil
 }
 
 static json::Object createFileLocation(const FileEntry ,
-   json::Object ) {
+   json::Array ) {
   std::string FileURI = fileNameToURI(getFileName(FE));
-  if (!Files.get(FileURI))
-Files[FileURI] = createFile(FE);
 
-  return json::Object{{"uri", FileURI}};
+  // See if the Files array contains this URI already. If it does not, create
+  // a new file object to add to the array. Calculate the index within the file
+  // location array so it can be stored in the JSON object.
+  unsigned Index = 0;
+  for (const json::Value  : Files) {
+if (const json::Object *Obj = File.getAsObject()) {
+  if (const json::Object *FileLoc = Obj->getObject("fileLocation")) {
+Optional URI = FileLoc->getString("uri");
+if (URI && URI->equals(FileURI))
+  break;
+  }
+}
+++Index;
+  }
+
+  // If we reached the end of the array, then add the file to the list of files
+  // we're tracking; Index then points to the last element of the array. Note
+  // that an empty file lists always causes a file to be added.
+  if (Files.empty() || Index == Files.size())
+Files.push_back(createFile(FE));
+
+  return json::Object{{"uri", FileURI}, {"fileIndex", Index}};
 }
 
 static json::Object createTextRegion(SourceRange R, const SourceManager ) {
@@ -136,7 +156,7 @@ static json::Object createTextRegion(Sou
 
 static json::Object createPhysicalLocation(SourceRange R, const FileEntry ,
const SourceManager ,
-   json::Object ) {
+   json::Array ) {
   return json::Object{{{"fileLocation", createFileLocation(FE, Files)},
{"region", createTextRegion(R, SMgr)}}};
 }
@@ -190,7 +210,7 @@ static Importance calculateImportance(co
 }
 
 static json::Object createThreadFlow(const PathPieces ,
- json::Object ) {
+ json::Array ) {
   const SourceManager  = Pieces.front()->getLocation().getManager();
   json::Array Locations;
   for (const auto  : Pieces) {
@@ -206,7 +226,7 @@ static json::Object createThreadFlow(con
 }
 
 static json::Object createCodeFlow(const PathPieces ,
-   json::Object ) {
+   json::Array ) {
   return json::Object{
   {"threadFlows", json::Array{createThreadFlow(Pieces, Files)}}};
 }
@@ -218,11 +238,14 @@ static json::Object createTool() {
   {"version", getClangFullVersion()}};
 }
 
-static json::Object createResult(const PathDiagnostic ,
- json::Object ) {
+static json::Object createResult(const PathDiagnostic , json::Array 
,
+ const StringMap ) {
   const PathPieces  = Diag.path.flatten(false);
   const 

[PATCH] D55707: Update to SARIF 11-28

2018-12-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman marked 4 inline comments as done.
aaron.ballman added inline comments.



Comment at: lib/StaticAnalyzer/Core/SarifDiagnostics.cpp:129
+  unsigned Index = 0;
+  for (const json::Value  : Files) {
+if (const json::Object *Obj = File.getAsObject()) {

NoQ wrote:
> This sounds like `find_if` to me.
The problem is: we need the `Index`. It felt a bit weird to have 
`llvm::find_if()` (a const operation) also mutating a locally-captured 
variable. WDYT?



Comment at: lib/StaticAnalyzer/Core/SarifDiagnostics.cpp:143
+  // that an empty file lists always causes a file to be added.
+  if (Files.empty() || Index == Files.size())
+Files.push_back(createFile(FE));

NoQ wrote:
> I suspect that the LHS of `||` implies the RHS of `||` and is therefore 
> redundant.
Nope, this is needed for a boundary condition. In the case where `Files` is 
empty, we don't loop over anything in the range-based for loop, and so `Index` 
is zero, which means `Index == Files.size()`. On the other end of that 
boundary, if `Files` is nonempty but `FE` hasn't been added to it yet, you'll 
loop over the entire list of `Files` in the range-based for loop, which also 
triggers `Index == Files.size()`.



Comment at: lib/StaticAnalyzer/Core/SarifDiagnostics.cpp:289
+if (P.second) {
+  RuleMapping[RuleID] = Rules.size(); // Maps RuleID to an Array Index.
+  Rules.push_back(createRule(*D));

NoQ wrote:
> Aha, ok, so now instead of an alphabetical order we have the order in which 
> reports of the respective checkers are squeezed into the consumer. Which is 
> probably deterministic, so it's fine. I just enjoy talking to myself on 
> phabricator sometimes.
Yes, this should be deterministic -- good thought to check!



Comment at: lib/StaticAnalyzer/Core/SarifDiagnostics.cpp:318
 void SarifDiagnostics::FlushDiagnosticsImpl(
 std::vector , FilesMade *) {
   // We currently overwrite the file if it already exists. However, it may be

NoQ wrote:
> I wonder why we didn't mark `Diags` as `const &` in this callback.
It would be a nice refactoring for someday. :-)


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

https://reviews.llvm.org/D55707



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


[PATCH] D55707: Update to SARIF 11-28

2018-12-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Yup, looks good, and i keep passively cheering for this project to be 
successful.




Comment at: lib/StaticAnalyzer/Core/SarifDiagnostics.cpp:129
+  unsigned Index = 0;
+  for (const json::Value  : Files) {
+if (const json::Object *Obj = File.getAsObject()) {

This sounds like `find_if` to me.



Comment at: lib/StaticAnalyzer/Core/SarifDiagnostics.cpp:143
+  // that an empty file lists always causes a file to be added.
+  if (Files.empty() || Index == Files.size())
+Files.push_back(createFile(FE));

I suspect that the LHS of `||` implies the RHS of `||` and is therefore 
redundant.



Comment at: lib/StaticAnalyzer/Core/SarifDiagnostics.cpp:289
+if (P.second) {
+  RuleMapping[RuleID] = Rules.size(); // Maps RuleID to an Array Index.
+  Rules.push_back(createRule(*D));

Aha, ok, so now instead of an alphabetical order we have the order in which 
reports of the respective checkers are squeezed into the consumer. Which is 
probably deterministic, so it's fine. I just enjoy talking to myself on 
phabricator sometimes.



Comment at: lib/StaticAnalyzer/Core/SarifDiagnostics.cpp:318
 void SarifDiagnostics::FlushDiagnosticsImpl(
 std::vector , FilesMade *) {
   // We currently overwrite the file if it already exists. However, it may be

I wonder why we didn't mark `Diags` as `const &` in this callback.


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

https://reviews.llvm.org/D55707



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


[PATCH] D55710: add pragmas to control Software Pipelining optimisation

2018-12-14 Thread Alexey Lapshin via Phabricator via cfe-commits
alexey.lapshin updated this revision to Diff 178264.
alexey.lapshin added a comment.

deleted small typo in CGLoopInfo.cpp


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

https://reviews.llvm.org/D55710

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticParseKinds.td
  lib/CodeGen/CGLoopInfo.cpp
  lib/CodeGen/CGLoopInfo.h
  lib/Parse/ParsePragma.cpp
  lib/Sema/SemaStmtAttr.cpp
  test/CodeGenCXX/pragma-pipeline.cpp
  test/Parser/pragma-loop.cpp
  test/Parser/pragma-pipeline.cpp
  test/Parser/pragma-unroll-and-jam.cpp

Index: test/Parser/pragma-unroll-and-jam.cpp
===
--- test/Parser/pragma-unroll-and-jam.cpp
+++ test/Parser/pragma-unroll-and-jam.cpp
@@ -67,7 +67,7 @@
   }
 
 // pragma clang unroll_and_jam is disabled for the moment
-/* expected-error {{invalid option 'unroll_and_jam'; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, or distribute}} */ #pragma clang loop unroll_and_jam(4)
+/* expected-error {{invalid option 'unroll_and_jam'; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_ii_count or distribute}} */ #pragma clang loop unroll_and_jam(4)
   for (int i = 0; i < Length; i++) {
 for (int j = 0; j < Length; j++) {
   List[i * Length + j] = Value;
Index: test/Parser/pragma-pipeline.cpp
===
--- /dev/null
+++ test/Parser/pragma-pipeline.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s
+
+// Note that this puts the expected lines before the directives to work around
+// limitations in the -verify mode.
+
+void test(int *List, int Length, int Value) {
+  int i = 0;
+
+#pragma clang loop pipeline(disable) 
+  for (int i = 0; i < Length; i++) {
+  List[i] = Value;
+  }
+
+#pragma clang loop pipeline_ii_count(10) 
+  for (int i = 0; i < Length; i++) {
+  List[i] = Value;
+  }
+
+/* expected-error {{expected ')'}} */ #pragma clang loop pipeline(disable
+/* expected-error {{invalid argument; expected 'disable'}} */ #pragma clang loop pipeline(enable)
+/* expected-error {{invalid argument; expected 'disable'}} */ #pragma clang loop pipeline(error)
+/* expected-error {{missing argument; expected an integer value}} */ #pragma clang loop pipeline_ii_count()
+/* expected-error {{use of undeclared identifier 'error'}} */ #pragma clang loop pipeline_ii_count(error)
+/* expected-error {{expected '('}} */ #pragma clang loop pipeline_ii_count 1 2
+  for (int i = 0; i < Length; i++) {
+for (int j = 0; j < Length; j++) {
+  List[i * Length + j] = Value;
+}
+  }
+
+#pragma clang loop pipeline(disable) 
+/* expected-error {{expected a for, while, or do-while loop to follow '#pragma clang loop'}} */ int j = Length;
+#pragma clang loop pipeline_ii_count(4) 
+/* expected-error {{expected a for, while, or do-while loop to follow '#pragma clang loop'}} */ int k = Length;
+
+#pragma clang loop pipeline(disable)
+#pragma clang loop pipeline_ii_count(4) /* expected-error {{incompatible directives 'pipeline(disable)' and 'pipeline_ii_count(4)'}} */
+  for (int i = 0; i < Length; i++) {
+  List[i] = Value;
+  }
+
+#pragma clang loop pipeline(disable) 
+/* expected-error {{expected statement}} */ }
Index: test/Parser/pragma-loop.cpp
===
--- test/Parser/pragma-loop.cpp
+++ test/Parser/pragma-loop.cpp
@@ -147,7 +147,7 @@
 /* expected-error {{missing argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll()
 /* expected-error {{missing argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute()
 
-/* expected-error {{missing option; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, or distribute}} */ #pragma clang loop
+/* expected-error {{missing option; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_ii_count or distribute}} */ #pragma clang loop
 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword
 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword(enable)
 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop vectorize(enable) badkeyword(4)
Index: test/CodeGenCXX/pragma-pipeline.cpp
===
--- /dev/null
+++ test/CodeGenCXX/pragma-pipeline.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple hexagon -std=c++11 -emit-llvm -o - %s | FileCheck %s
+
+void pipeline_disabled(int *List, int Length, int Value) {
+  // CHECK-LABEL: define {{.*}} @_Z17pipeline_disabled 
+#pragma clang loop pipeline(disable) 
+  for (int i = 0; i < Length; i++) {
+  // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_1:.*]]
+  List[i] = Value;
+  }
+}
+
+void 

[PATCH] D55628: Add support for "labels" on push/pop directives in #pragma clang attribute

2018-12-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/Sema/pragma-attribute-label.c:15
+// Out of order!
+#pragma clang attribute pop MY_LABEL
+

dexonsmith wrote:
> erik.pilkington wrote:
> > aaron.ballman wrote:
> > > dexonsmith wrote:
> > > > aaron.ballman wrote:
> > > > > I feel like this should be diagnosed, perhaps even as an error. The 
> > > > > user provided labels but then got the push and pop order wrong when 
> > > > > explicitly saying what to pop. That seems more likely to be a logic 
> > > > > error on the user's part.
> > > > On the contrary, the user is using two differently-named and 
> > > > independent macro pairs (A_BEGIN/A_END vs B_BEGIN/B_END) and has no 
> > > > idea they are implemented with _Pragma(“clang attribute ...”) under the 
> > > > hood.  The point is to give the same result as two independent pragma 
> > > > pairs, whose regions do not need to be nested.
> > > > On the contrary, the user is using two differently-named and 
> > > > independent macro pairs (A_BEGIN/A_END vs B_BEGIN/B_END) 
> > > 
> > > I don't think this is a safe assumption to make, and in this case, is 
> > > false. There are no macros anywhere in this test case.
> > > 
> > > > The point is to give the same result as two independent pragma pairs, 
> > > > whose regions do not need to be nested.
> > > 
> > > I don't find this to be intuitive behavior. These are stack manipulations 
> > > with the names push and pop -- pretending that they're overlapping rather 
> > > than a stack in the presence of labels is confusing. If I saw the code 
> > > from this test case during a code review, I would flag it as being 
> > > incorrect because the labels do not match -- I don't think I'd be the 
> > > only one.
> > I think the labels only really makes sense if you're writing macros that 
> > hide the pragma attribute stack (like ASSUME_X_BEGIN/END, for instance), 
> > which for better or for worse people do write, and in fact was the intended 
> > use case for #pragma clang attribute. I think if we were to write this 
> > feature again, we'd forgo the stack entirly and require every `push` to 
> > have a label and be in its own namespace. But this is the best we can do 
> > now.
> > 
> > I don't really think that anyone should write a push label outside of a 
> > macro definition, since I agree that the semantics are a bit surprising 
> > when you're writing the #pragmas yourself without macros. I'll update this 
> > test case and the documentation to stress this point more. If you think 
> > this is going to be a potential pain point, maybe we can even warn on using 
> > a label outside of a macro definition. 
> >> The point is to give the same result as two independent pragma pairs, 
> >> whose regions do not need to be nested.
> > I don't find this to be intuitive behavior. These are stack manipulations 
> > with the names push and pop -- pretending that they're overlapping rather 
> > than a stack in the presence of labels is confusing. If I saw the code from 
> > this test case during a code review, I would flag it as being incorrect 
> > because the labels do not match -- I don't think I'd be the only one.
> 
> As Erik says, the intention is that these are only used by macros.
> 
> Stepping back, the goal of this pragma (which we added in 
> https://reviews.llvm.org/D30009) is to avoid adding a new region-based pragma 
> every time we want to apply an attribute within a region.  Clang has a lot of 
> these pragmas, in order to support independent macros like this:
> ```
> #define A_BEGIN _Pragma("clang a push")
> #define A_END   _Pragma("clang a pop")
> #define B_BEGIN _Pragma("clang b push")
> #define B_END   _Pragma("clang b pop")
> #define C_BEGIN _Pragma("clang c push")
> #define C_END   _Pragma("clang c pop")
> ```
> 
> @arphaman came up with the idea of introduce "one pragma to rule them all", 
> `pragma clang attribute`, so that we didn't need to introduce a new pragma 
> each time we wanted an independent region:
> ```
> #define A_BEGIN _Pragma("clang attribute push(a)")
> #define A_END   _Pragma("clang attribute pop")
> #define B_BEGIN _Pragma("clang attribute push(b)")
> #define B_END   _Pragma("clang attribute pop")
> #define C_BEGIN _Pragma("clang attribute push(c)")
> #define C_END   _Pragma("clang attribute pop")
> ```
> 
> However, we've realized that there is a major design flaw: these macros are 
> not independent, because they're using the same stack.  @erik.pilkington has 
> come up with this solution using identifiers to namespace the attribute 
> stacks, allowing the macros to be independent (like they were before, when 
> each had a dedicated pragma):
> ```
> #define A_BEGIN _Pragma("clang attribute push A (a)")
> #define A_END   _Pragma("clang attribute pop  A")
> #define B_BEGIN _Pragma("clang attribute push B (b)")
> #define B_END   _Pragma("clang attribute pop  B")
> #define C_BEGIN _Pragma("clang attribute push C (c)")
> #define C_END   

[PATCH] D55698: [MinGW] Produce a vtable and RTTI for dllexported classes without a key function

2018-12-14 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: lib/Sema/SemaDeclCXX.cpp:5754-5756
+  if (ClassExported &&
+  Context.getTargetInfo().getTriple().isWindowsGNUEnvironment())
+MarkVTableUsed(Class->getLocation(), Class, true);

This may be too early, you can get into situations like this if you start 
emitting the vtable (which will emit inline methods) before we get to the end 
of the outermost class. See this bug for example:
https://bugs.llvm.org/show_bug.cgi?id=40006

Maybe if you have a dllexported nested class with a virtual method that 
references the constructor of the outer class which has a late-parsed member 
initializer... you can get things to go wrong as in the bug above.

I think the fix will be to touch the vtable when we process delayed dllexported 
classes from the list just above this line.



Comment at: test/CodeGenCXX/dllexport-missing-key.cpp:20
+
+// GNU-DAG: @_ZTV24QAbstractLayoutStyleInfo = weak_odr dso_local dllexport
+// GNU-DAG: @_ZTS24QAbstractLayoutStyleInfo = linkonce_odr

OK, good, I was going to ask if it became weak_odr, but looks like it all works.


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

https://reviews.llvm.org/D55698



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


[PATCH] D46421: [analyzer][CrossTU] Extend CTU to VarDecls with initializer

2018-12-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D46421#1121080 , @r.stahl wrote:

> It seems like a good idea to not do that, since non-const values are not 
> used. It might become useful if we ever do some kind of straight line 
> execution from static initialization to main.
>  However for structs it is enough if one of their fields is declared const.


Aaand in C++ there's also the `mutable` keyword that can cancel the effect of 
the surrounding `const` keyword, at least for the purposes of precise memory 
contents modeling in `RegionStore`.

The idea looks great to me. It was far from obvious to me that importing 
variables manually was necessary, nice catch.

I definitely wish for a more direct test for this, i.e. "CTU analysis avoids 
that specific false positive due to the new functionality".


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

https://reviews.llvm.org/D46421



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


[PATCH] D55715: Add AddressSpace mangling to MS mode

2018-12-14 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: lib/AST/MicrosoftMangle.cpp:1806-1836
+Extra.mangleSourceName("AS_");
+Extra.mangleIntegerLiteral(llvm::APSInt::getUnsigned(TargetAS),
+   /*IsBoolean*/ false);
+  } else {
+switch (AS) {
+default:
+  llvm_unreachable("Not a language specific address space");

majnemer wrote:
> Don't these need to be _AS_Foobar to avoid collisions with normal code?
I think we're in __clang::, so it's OK? In any case, it's what's done for 
Itanium, IIUC. It's also not like we have to worry about conflicts with user 
macros.



Comment at: test/CodeGenOpenCL/address-spaces-mangling.cl:7
+// RUN: %clang_cc1 %s -ffake-address-space-map 
-faddress-space-map-mangling=yes -triple x86_64-windows-pc -emit-llvm -o - | 
FileCheck -check-prefixes=MS_ASMANG,MS_ASMAN10 %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map 
-faddress-space-map-mangling=yes -triple x86_64-windows-pc -emit-llvm -o - | 
FileCheck -check-prefixes=MS_ASMANG,MS_ASMAN20 %s
+// RUN: %clang_cc1 %s -ffake-address-space-map -faddress-space-map-mangling=no 
-triple x86_64-windows-pc -emit-llvm -o - | FileCheck 
-check-prefixes=MS_NOASMANG,MS_NOASMAN10 %s

erichkeane wrote:
> erichkeane wrote:
> > rnk wrote:
> > > I would replace `-triple x86_64-windows-pc` here and everywhere with 
> > > `-triple x86_64-windows-itanium` (or gnu instead of itanium) to test the 
> > > Itanium mangling on Windows. I don't think `x86_64-windows-pc` parses 
> > > into a real triple. After all, "pc" is parsed as the vendor, which is 
> > > supposed to be second.
> > Woops! I didn't mean to check this file in.  It has some other nasty 
> > problems that need to be fixed up, so I tested this feature in the 
> > mangle-address-space.  I'll still do this above.
> @rnk I tried this, but it changes off of the MicrosoftMangler and switches 
> back to the Itanium mangling.  Is there a better triple for testing microsoft 
> mangling?
Tacking on "-msvc" or "-itanium" or "-gnu" is the more explicit way to the C++ 
ABI. I guess I was confused, it looks like this file expects Itanium manglings 
from the -pc triple.


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

https://reviews.llvm.org/D55715



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


[PATCH] D55628: Add support for "labels" on push/pop directives in #pragma clang attribute

2018-12-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: clang/test/Sema/pragma-attribute-label.c:7
+
+#pragma clang attribute pop // expected-error{{'#pragma clang attribute pop' 
with no matching '#pragma clang attribute push'}}
+#pragma clang attribute pop NOT_MY_LABEL // expected-error{{'#pragma clang 
attribute pop NOT_MY_LABEL' with no matching '#pragma clang attribute push 
NOT_MY_LABEL'}}

erik.pilkington wrote:
> aaron.ballman wrote:
> > dexonsmith wrote:
> > > aaron.ballman wrote:
> > > > Should we really treat this as an error? It seems to me that this 
> > > > should be a warning because pop without a label could be viewed as "I 
> > > > don't care what I'm popping, just pop it". Still worth warning about, 
> > > > but maybe not worth stopping a build over.
> > > IMO this is most likely to be an implementation error on the part of a 
> > > macro author, where the END macro is missing the label used in BEGIN.  
> > > This makes the macro pair unsafe to mix with other macros.  If the macro 
> > > author doesn’t want safety, why use a label in the BEGIN macro at all?
> > > 
> > > I see you’re envisioning this being used directly by an end-user, which I 
> > > suppose is plausible, but I think the same logic applies.  Why add a 
> > > label to push if you don’t want to be precise about pop?
> > > Why add a label to push if you don’t want to be precise about pop?
> > 
> > Why is this important enough to fail everyone's build over it as opposed to 
> > warning users that they've done something that could be a bad code smell 
> > and let -Werror usage decide whether to fail the build or not? It seems 
> > like an extreme measure for something that has explicable "fallback" 
> > behavior.
> My implicit assumption (which I should have been more clear about!) was that 
> you'd only really ever write a label on a `push` in a BEGIN/END macro. In 
> that world, you'd only ever see this case if 1) you're interacting with 
> another macro that doesn't use the label convention, or 2) if you're 
> interacting with manual push/pop code. In both of those cases, you'd end up 
> popping the wrong attribute group and start applying attributes onto 
> declarations that the programmer didn't intend.
> 
> I'm fine with downgrading this to a warning, but IMO an error seems more 
> appropriate. If we wanted to force 1) or 2) through the compiler then we'd 
> also need to downgrade `pop UNPUSHED_LABEL` to a warning, which doesn't seem 
> like the end of the world either.
I'm not fine with this just being a warning.  The entire point is that the 
stacks are independent; having them suddenly mixed here would be super 
confusing.  @aaron.ballman, please see my other comment for a longer 
explanation.



Comment at: clang/test/Sema/pragma-attribute-label.c:15
+// Out of order!
+#pragma clang attribute pop MY_LABEL
+

erik.pilkington wrote:
> aaron.ballman wrote:
> > dexonsmith wrote:
> > > aaron.ballman wrote:
> > > > I feel like this should be diagnosed, perhaps even as an error. The 
> > > > user provided labels but then got the push and pop order wrong when 
> > > > explicitly saying what to pop. That seems more likely to be a logic 
> > > > error on the user's part.
> > > On the contrary, the user is using two differently-named and independent 
> > > macro pairs (A_BEGIN/A_END vs B_BEGIN/B_END) and has no idea they are 
> > > implemented with _Pragma(“clang attribute ...”) under the hood.  The 
> > > point is to give the same result as two independent pragma pairs, whose 
> > > regions do not need to be nested.
> > > On the contrary, the user is using two differently-named and independent 
> > > macro pairs (A_BEGIN/A_END vs B_BEGIN/B_END) 
> > 
> > I don't think this is a safe assumption to make, and in this case, is 
> > false. There are no macros anywhere in this test case.
> > 
> > > The point is to give the same result as two independent pragma pairs, 
> > > whose regions do not need to be nested.
> > 
> > I don't find this to be intuitive behavior. These are stack manipulations 
> > with the names push and pop -- pretending that they're overlapping rather 
> > than a stack in the presence of labels is confusing. If I saw the code from 
> > this test case during a code review, I would flag it as being incorrect 
> > because the labels do not match -- I don't think I'd be the only one.
> I think the labels only really makes sense if you're writing macros that hide 
> the pragma attribute stack (like ASSUME_X_BEGIN/END, for instance), which for 
> better or for worse people do write, and in fact was the intended use case 
> for #pragma clang attribute. I think if we were to write this feature again, 
> we'd forgo the stack entirly and require every `push` to have a label and be 
> in its own namespace. But this is the best we can do now.
> 
> I don't really think that anyone should write a push label outside of a macro 
> definition, since I agree that the 

[PATCH] D55715: Add AddressSpace mangling to MS mode

2018-12-14 Thread David Majnemer via Phabricator via cfe-commits
majnemer added inline comments.



Comment at: lib/AST/MicrosoftMangle.cpp:1806-1836
+Extra.mangleSourceName("AS_");
+Extra.mangleIntegerLiteral(llvm::APSInt::getUnsigned(TargetAS),
+   /*IsBoolean*/ false);
+  } else {
+switch (AS) {
+default:
+  llvm_unreachable("Not a language specific address space");

Don't these need to be _AS_Foobar to avoid collisions with normal code?


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

https://reviews.llvm.org/D55715



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


[PATCH] D55715: Add AddressSpace mangling to MS mode

2018-12-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane marked 2 inline comments as done.
erichkeane added inline comments.



Comment at: test/CodeGenOpenCL/address-spaces-mangling.cl:7
+// RUN: %clang_cc1 %s -ffake-address-space-map 
-faddress-space-map-mangling=yes -triple x86_64-windows-pc -emit-llvm -o - | 
FileCheck -check-prefixes=MS_ASMANG,MS_ASMAN10 %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map 
-faddress-space-map-mangling=yes -triple x86_64-windows-pc -emit-llvm -o - | 
FileCheck -check-prefixes=MS_ASMANG,MS_ASMAN20 %s
+// RUN: %clang_cc1 %s -ffake-address-space-map -faddress-space-map-mangling=no 
-triple x86_64-windows-pc -emit-llvm -o - | FileCheck 
-check-prefixes=MS_NOASMANG,MS_NOASMAN10 %s

erichkeane wrote:
> rnk wrote:
> > I would replace `-triple x86_64-windows-pc` here and everywhere with 
> > `-triple x86_64-windows-itanium` (or gnu instead of itanium) to test the 
> > Itanium mangling on Windows. I don't think `x86_64-windows-pc` parses into 
> > a real triple. After all, "pc" is parsed as the vendor, which is supposed 
> > to be second.
> Woops! I didn't mean to check this file in.  It has some other nasty problems 
> that need to be fixed up, so I tested this feature in the 
> mangle-address-space.  I'll still do this above.
@rnk I tried this, but it changes off of the MicrosoftMangler and switches back 
to the Itanium mangling.  Is there a better triple for testing microsoft 
mangling?


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

https://reviews.llvm.org/D55715



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


[PATCH] D55715: Add AddressSpace mangling to MS mode

2018-12-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane marked 4 inline comments as done.
erichkeane added inline comments.



Comment at: test/CodeGenCXX/mangle-address-space.cpp:7
+// CHECKNOOCL-LABEL: define {{.*}}void @_Z2f0Pc
+// WINNOOCL-LABEL: define {{.*}}void @"?f0@@YAXPEAD@Z"
+// CHECKOCL-LABEL: define {{.*}}void @_Z2f0PU9CLgenericc

rnk wrote:
> You know, now that we have a demangler, I wonder if we shouldn't add a RUN 
> line like this to test that these names really do demangle properly:
> `// RUN: %clang_cc1 %s ... -emit-bitcode -o - | llvm-nm -demangle - | 
> FileCheck %s --check-prefix=DEMANGLED`
I'm not sure how that would work, but I can take a look.



Comment at: test/CodeGenOpenCL/address-spaces-mangling.cl:7
+// RUN: %clang_cc1 %s -ffake-address-space-map 
-faddress-space-map-mangling=yes -triple x86_64-windows-pc -emit-llvm -o - | 
FileCheck -check-prefixes=MS_ASMANG,MS_ASMAN10 %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map 
-faddress-space-map-mangling=yes -triple x86_64-windows-pc -emit-llvm -o - | 
FileCheck -check-prefixes=MS_ASMANG,MS_ASMAN20 %s
+// RUN: %clang_cc1 %s -ffake-address-space-map -faddress-space-map-mangling=no 
-triple x86_64-windows-pc -emit-llvm -o - | FileCheck 
-check-prefixes=MS_NOASMANG,MS_NOASMAN10 %s

rnk wrote:
> I would replace `-triple x86_64-windows-pc` here and everywhere with `-triple 
> x86_64-windows-itanium` (or gnu instead of itanium) to test the Itanium 
> mangling on Windows. I don't think `x86_64-windows-pc` parses into a real 
> triple. After all, "pc" is parsed as the vendor, which is supposed to be 
> second.
Woops! I didn't mean to check this file in.  It has some other nasty problems 
that need to be fixed up, so I tested this feature in the mangle-address-space. 
 I'll still do this above.


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

https://reviews.llvm.org/D55715



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


[PATCH] D55715: Add AddressSpace mangling to MS mode

2018-12-14 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: test/CodeGenCXX/mangle-address-space.cpp:7
+// CHECKNOOCL-LABEL: define {{.*}}void @_Z2f0Pc
+// WINNOOCL-LABEL: define {{.*}}void @"?f0@@YAXPEAD@Z"
+// CHECKOCL-LABEL: define {{.*}}void @_Z2f0PU9CLgenericc

You know, now that we have a demangler, I wonder if we shouldn't add a RUN line 
like this to test that these names really do demangle properly:
`// RUN: %clang_cc1 %s ... -emit-bitcode -o - | llvm-nm -demangle - | FileCheck 
%s --check-prefix=DEMANGLED`



Comment at: test/CodeGenOpenCL/address-spaces-mangling.cl:7
+// RUN: %clang_cc1 %s -ffake-address-space-map 
-faddress-space-map-mangling=yes -triple x86_64-windows-pc -emit-llvm -o - | 
FileCheck -check-prefixes=MS_ASMANG,MS_ASMAN10 %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map 
-faddress-space-map-mangling=yes -triple x86_64-windows-pc -emit-llvm -o - | 
FileCheck -check-prefixes=MS_ASMANG,MS_ASMAN20 %s
+// RUN: %clang_cc1 %s -ffake-address-space-map -faddress-space-map-mangling=no 
-triple x86_64-windows-pc -emit-llvm -o - | FileCheck 
-check-prefixes=MS_NOASMANG,MS_NOASMAN10 %s

I would replace `-triple x86_64-windows-pc` here and everywhere with `-triple 
x86_64-windows-itanium` (or gnu instead of itanium) to test the Itanium 
mangling on Windows. I don't think `x86_64-windows-pc` parses into a real 
triple. After all, "pc" is parsed as the vendor, which is supposed to be second.



Comment at: test/CodeGenOpenCL/address-spaces-mangling.cl:24
 // NOASMANG20: @_Z2ffPU9CLgenerici
+// MS_ASMANG10: @_Z2ffPi
+// MS_ASMANG20: @_Z2ffPU3AS4i

Why "MS_"? This isn't the MSVC environment, this is using the Itanium C++ ABI 
mangling. Maybe WIN_ instead would be better?


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

https://reviews.llvm.org/D55715



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


[PATCH] D55715: Add AddressSpace mangling to MS mode

2018-12-14 Thread Zachary Turner via Phabricator via cfe-commits
zturner added a comment.

It would be interesting to teach `llvm-undname` to demangle this more 
naturally.  Right for this mangling: `?f1@@YAXPEAU?$AS_@$00$$CBD@__clang@@@Z` I 
see this demangling: `void __cdecl f1(struct __clang::AS_<1, char const> *)`.  
That's an accurate representation of the underlying structure, but it would be 
cool if we had special cases for things in the `__clang` namespace, so that we 
could display this as `void __cdecl f1(char __attribute__((address_space(1))) 
const *) {}`
`


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

https://reviews.llvm.org/D55715



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


  1   2   >