Re: [PATCH] D12445: [Static Analyzer] Remove sinks from nullability checks.

2015-09-03 Thread Anna Zaks via cfe-commits
zaks.anna accepted this revision.
zaks.anna added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks!
Anna.


http://reviews.llvm.org/D12445



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


Re: [PATCH] D11279: Initial patch for PS4 toolchain

2015-09-03 Thread Katya Romanova via cfe-commits
kromanova added inline comments.


Comment at: lib/Driver/Tools.cpp:3590-3591
@@ -3580,4 +3589,4 @@
   Args.ClaimAllArgs(options::OPT_g_flags_Group);
   if (Args.hasFlag(options::OPT_gcolumn_info, options::OPT_gno_column_info,
-   /*Default*/ true))
+   /*Default*/ !Triple.isPS4CPU()))
 CmdArgs.push_back("-dwarf-column-info");

echristo wrote:
> filcab wrote:
> > echristo wrote:
> > > Hmm?
> > We have different defaults from other platforms.
> *nod* disabling column info yes? I have "opinions" on this, but it's not my 
> platform. Needs a comment.
Our debugger doesn't use column information. Though it's not too much, unused 
column information adds to the total size of DI.
We will add a comment.


Comment at: lib/Driver/Tools.cpp:3613
@@ -3603,3 +3612,3 @@
   // backend.
-  if (Args.hasArg(options::OPT_gdwarf_aranges)) {
+  if (Args.hasArg(options::OPT_gdwarf_aranges) || Triple.isPS4CPU()) {
 CmdArgs.push_back("-backend-option");

echristo wrote:
> filcab wrote:
> > echristo wrote:
> > > Ditto.
> > Ditto, different defaults.
> > But I guess I can hoist out the Triple.isPS4CPU() on both cases, if you 
> > prefer, like it's done for other toolchains like:
> >   bool IsWindowsMSVC = 
> > getToolChain().getTriple().isWindowsMSVCEnvironment();
> Probably better to just handle it the same way as the column info I'd think. 
> Also, this is all terrible and needs to change, that said, not your problem. 
> :)
We could do exactly the same for aranges as it we did for the column info. 
Though it seems that we will have to add 'gno_dwarf_aranges' if we want to use 
hasFlag function here too. Is it worth doing it?


http://reviews.llvm.org/D11279



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


r246747 - [OPENMP 4.1] Parsing/sema analysis for extended format of 'if' clause.

2015-09-03 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Sep  3 02:23:48 2015
New Revision: 246747

URL: http://llvm.org/viewvc/llvm-project?rev=246747&view=rev
Log:
[OPENMP 4.1] Parsing/sema analysis for extended format of 'if' clause.
OpenMP 4.1 added special 'directive-name-modifier' to the 'if' clause.
Format of 'if' clause is as follows:
```
if([ directive-name-modifier :] scalar-logical-expression)
```

The restriction rules are also changed.
1. If any 'if' clause on the directive includes a 'directive-name-modifier' 
then all 'if' clauses on the directive must include a 'directive-name-modifier'.
2. At most one 'if' clause without a 'directive-name-modifier' can appear on 
the directive.
3. At most one 'if' clause with some particular 'directive-name-modifier' can 
appear on the directive.

'directive-name-modifier' is important for combined directives and allows to 
separate conditions in 'if' clause for simple sub-directives in combined 
directive. This 'directive-name-modifier' identifies the sub-directive to which 
this 'if' clause must be applied.


Modified:
cfe/trunk/include/clang/AST/OpenMPClause.h
cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/Parse/ParseOpenMP.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/test/OpenMP/for_schedule_messages.cpp
cfe/trunk/test/OpenMP/for_simd_schedule_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_if_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_schedule_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_if_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_schedule_messages.cpp
cfe/trunk/test/OpenMP/parallel_if_messages.cpp
cfe/trunk/test/OpenMP/parallel_sections_if_messages.cpp
cfe/trunk/test/OpenMP/target_data_if_messages.cpp
cfe/trunk/test/OpenMP/target_if_messages.cpp
cfe/trunk/test/OpenMP/task_if_messages.cpp

Modified: cfe/trunk/include/clang/AST/OpenMPClause.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=246747&r1=246746&r2=246747&view=diff
==
--- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
+++ cfe/trunk/include/clang/AST/OpenMPClause.h Thu Sep  3 02:23:48 2015
@@ -152,10 +152,10 @@ public:
 /// \brief This represents 'if' clause in the '#pragma omp ...' directive.
 ///
 /// \code
-/// #pragma omp parallel if(a > 5)
+/// #pragma omp parallel if(parallel:a > 5)
 /// \endcode
-/// In this example directive '#pragma omp parallel' has simple 'if'
-/// clause with condition 'a > 5'.
+/// In this example directive '#pragma omp parallel' has simple 'if' clause 
with
+/// condition 'a > 5' and directive name modifier 'parallel'.
 ///
 class OMPIfClause : public OMPClause {
   friend class OMPClauseReader;
@@ -163,37 +163,67 @@ class OMPIfClause : public OMPClause {
   SourceLocation LParenLoc;
   /// \brief Condition of the 'if' clause.
   Stmt *Condition;
+  /// \brief Location of ':' (if any).
+  SourceLocation ColonLoc;
+  /// \brief Directive name modifier for the clause.
+  OpenMPDirectiveKind NameModifier;
+  /// \brief Name modifier location.
+  SourceLocation NameModifierLoc;
 
   /// \brief Set condition.
   ///
   void setCondition(Expr *Cond) { Condition = Cond; }
+  /// \brief Set directive name modifier for the clause.
+  ///
+  void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
+  /// \brief Set location of directive name modifier for the clause.
+  ///
+  void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
+  /// \brief Set location of ':'.
+  ///
+  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
 
 public:
   /// \brief Build 'if' clause with condition \a Cond.
   ///
+  /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
+  /// \param Cond Condition of the clause.
   /// \param StartLoc Starting location of the clause.
   /// \param LParenLoc Location of '('.
-  /// \param Cond Condition of the clause.
+  /// \param NameModifierLoc Location of directive name modifier.
+  /// \param ColonLoc [OpenMP 4.1] Location of ':'.
   /// \param EndLoc Ending location of the clause.
   ///
-  OMPIfClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
+  OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond,
+  SourceLocation StartLoc, SourceLocation LParenLoc,
+  SourceLocation NameModifierLoc, SourceLocation ColonLoc,
   SourceLocation EndLoc)
   : OMPClause(OMPC_if, StartLoc, EndLoc), LParenLoc(LParenLoc),
-Condition(Cond) {}
+Condition(Cond), ColonLoc(ColonLoc), NameModifier(NameModifier),
+Na

Re: [PATCH] D12358: [Analyzer] Handling constant bound loops

2015-09-03 Thread Sean Eveson via cfe-commits
seaneveson updated this revision to Diff 33906.
seaneveson added a comment.

Refactored into a new file: LoopWidening.cpp (and LoopWidening.h).
Added an analyzer-config option, which defaults to false: 
widen-constant-bound-loops=false
Modified analyzer-config tests to check for the new option.
Added code to invalidate the stack locals, stack arguments and global regions 
(WIP).
Added a test to check variables are unknown after a widened loop, which 
currently fails.


http://reviews.llvm.org/D12358

Files:
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  include/clang/StaticAnalyzer/Core/PathSensitive/LoopWidening.h
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/CMakeLists.txt
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/LoopWidening.cpp
  test/Analysis/analyzer-config.c
  test/Analysis/analyzer-config.cpp
  test/Analysis/constant-bound-loops.c

Index: test/Analysis/constant-bound-loops.c
===
--- test/Analysis/constant-bound-loops.c
+++ test/Analysis/constant-bound-loops.c
@@ -0,0 +1,178 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-store=region -analyzer-max-loop 4 -analyzer-config widen-constant-bound-loops=true -verify %s
+
+extern void clang_analyzer_eval(_Bool);
+
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+
+void incr_for_loop() {
+int i;
+for (i = 0; i < 10; ++i) {}
+clang_analyzer_eval(i == 10); // expected-warning {{TRUE}}
+char *m = (char*)malloc(12);
+} // expected-warning {{Potential leak of memory pointed to by 'm'}}
+
+void decr_for_loop() {
+int i;
+for (i = 10; i > 0; --i) {}
+clang_analyzer_eval(i == 0); // expected-warning {{TRUE}}
+char *m = (char*)malloc(12);
+} // expected-warning {{Potential leak of memory pointed to by 'm'}}
+
+void incr_while_loop() {
+int i = 0;
+while (i < 10) {++i;}
+clang_analyzer_eval(i == 10); // expected-warning {{TRUE}}
+char *m = (char*)malloc(12);
+} // expected-warning {{Potential leak of memory pointed to by 'm'}}
+
+void decr_while_loop() {
+int i = 10;
+while (i > 0) {--i;}
+clang_analyzer_eval(i == 0); // expected-warning {{TRUE}}
+char *m = (char*)malloc(12);
+} // expected-warning {{Potential leak of memory pointed to by 'm'}}
+
+void incr_do_while_loop() {
+int i = 0;
+do {++i;} while (i < 10);
+clang_analyzer_eval(i == 10); // expected-warning {{TRUE}}
+char *m = (char*)malloc(12);
+} // expected-warning {{Potential leak of memory pointed to by 'm'}}
+
+void decr_do_while_loop() {
+int i = 10;
+do {--i;} while (i > 0);
+clang_analyzer_eval(i == 0); // expected-warning {{TRUE}}
+char *m = (char*)malloc(12);
+} // expected-warning {{Potential leak of memory pointed to by 'm'}}
+
+void negative_incr_for_loop() {
+int i;
+for (i = -10; i < 5 - 10; ++i) {}
+clang_analyzer_eval(i == -5); // expected-warning {{TRUE}}
+char *m = (char*)malloc(12);
+} // expected-warning {{Potential leak of memory pointed to by 'm'}}
+
+void negative_decr_for_loop() {
+int i;
+for (i = 5 - 10; i > -20; --i) {}
+clang_analyzer_eval(i == -20); // expected-warning {{TRUE}}
+char *m = (char*)malloc(12);
+} // expected-warning {{Potential leak of memory pointed to by 'm'}}
+
+void larger_incr_for_loop() {
+int i;
+for (i = 0; i < 20; i += 3) {}
+char *m = (char*)malloc(12);
+} // expected-warning {{Potential leak of memory pointed to by 'm'}}
+
+void larger_decr_for_loop() {
+int i;
+for (i = 20; i > 0; i -= 3) {}
+char *m = (char*)malloc(12);
+} // expected-warning {{Potential leak of memory pointed to by 'm'}}
+
+void unsigned_incr_for_loop() {
+unsigned i;
+for (i = 0; i < 10; ++i) {}
+clang_analyzer_eval(i == 10); // expected-warning {{TRUE}}
+char *m = (char*)malloc(12);
+} // expected-warning {{Potential leak of memory pointed to by 'm'}}
+
+void unsigned_decr_for_loop() {
+unsigned i;
+for (i = 10; i > 0; --i) {}
+clang_analyzer_eval(i == 0); // expected-warning {{TRUE}}
+char *m = (char*)malloc(12);
+} // expected-warning {{Potential leak of memory pointed to by 'm'}}
+
+void short_for_loop() {
+short i;
+for (i = 0; i < 10; ++i) {}
+clang_analyzer_eval(i == 10); // expected-warning {{TRUE}}
+char *m = (char*)malloc(12);
+} // expected-warning {{Potential leak of memory pointed to by 'm'}}
+
+void lte_for_loop() {
+int i;
+for (i = 0; i <= 10; ++i) {}
+clang_analyzer_eval(i == 11); // expected-warning {{TRUE}}
+char *m = (char*)malloc(12);
+} // expected-warning {{Potential leak of memory pointed to by 'm'}}
+
+void gte_for_loop() {
+int i;
+for (i = 10; i >= 0; --i) {}
+clang_analyzer_eval(i == -1); // expected-warning {{TRUE}}
+char *m = (char*)malloc(12);
+} // expected-warning {{Potential leak of memory pointed to by 'm'}}
+
+void incr_ne_for_loop() {

Re: [PATCH] D10833: Retrieve BinaryOperator::getOpcode and BinaryOperator::getOpcodeStr via libclang and its python interface

2015-09-03 Thread guibufolo+l...@gmail.com via cfe-commits
RedX2501 added a comment.

Ping


http://reviews.llvm.org/D10833



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


Re: [PATCH] D10834: Added functions to retrieve information about variable storage in libclang and its python bindings.

2015-09-03 Thread guibufolo+l...@gmail.com via cfe-commits
RedX2501 added a comment.

Ping


http://reviews.llvm.org/D10834



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


libtooling and ast matchers owners

2015-09-03 Thread Manuel Klimek via cfe-commits
After Aaron updated the clang-tools-extra owners, I looked at the clang
owners and noticed that I'm not in there for libtooling and ast matchers.
Doug suggested 3 years back that I should be in there, but apparently I
forgot to update it. Anybody raising objections to me putting myself in for
libtooling and ast matchers?

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


r246748 - [OPENMP 4.1] Codegen for extended format of 'if' clause.

2015-09-03 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Sep  3 03:45:56 2015
New Revision: 246748

URL: http://llvm.org/viewvc/llvm-project?rev=246748&view=rev
Log:
[OPENMP 4.1] Codegen for extended format of 'if' clause.
Fixed codegen for extended format of 'if' clauses with special 
'directive-name-modifier' + ast-print tests for extended format of 'if' clause.

Modified:
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/test/OpenMP/parallel_ast_print.cpp
cfe/trunk/test/OpenMP/parallel_for_ast_print.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_ast_print.cpp
cfe/trunk/test/OpenMP/parallel_if_codegen.cpp
cfe/trunk/test/OpenMP/parallel_sections_ast_print.cpp
cfe/trunk/test/OpenMP/target_ast_print.cpp
cfe/trunk/test/OpenMP/target_data_ast_print.cpp
cfe/trunk/test/OpenMP/task_ast_print.cpp
cfe/trunk/test/OpenMP/task_if_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=246748&r1=246747&r2=246748&view=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Thu Sep  3 03:45:56 2015
@@ -475,8 +475,12 @@ static void emitCommonOMPParallelDirecti
 CGF, ProcBindClause->getProcBindKind(), ProcBindClause->getLocStart());
   }
   const Expr *IfCond = nullptr;
-  if (const auto *C = S.getSingleClause()) {
-IfCond = C->getCondition();
+  for (const auto *C : S.getClausesOfKind()) {
+if (C->getNameModifier() == OMPD_unknown ||
+C->getNameModifier() == OMPD_parallel) {
+  IfCond = C->getCondition();
+  break;
+}
   }
   CGF.CGM.getOpenMPRuntime().emitParallelCall(CGF, S.getLocStart(), OutlinedFn,
   CapturedStruct, IfCond);
@@ -1605,8 +1609,12 @@ void CodeGenFunction::EmitOMPTaskDirecti
   }
   auto SharedsTy = getContext().getRecordType(CS->getCapturedRecordDecl());
   const Expr *IfCond = nullptr;
-  if (const auto *C = S.getSingleClause()) {
-IfCond = C->getCondition();
+  for (const auto *C : S.getClausesOfKind()) {
+if (C->getNameModifier() == OMPD_unknown ||
+C->getNameModifier() == OMPD_task) {
+  IfCond = C->getCondition();
+  break;
+}
   }
   CGM.getOpenMPRuntime().emitTaskCall(
   *this, S.getLocStart(), S, Tied, Final, OutlinedFn, SharedsTy,

Modified: cfe/trunk/test/OpenMP/parallel_ast_print.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_ast_print.cpp?rev=246748&r1=246747&r2=246748&view=diff
==
--- cfe/trunk/test/OpenMP/parallel_ast_print.cpp (original)
+++ cfe/trunk/test/OpenMP/parallel_ast_print.cpp Thu Sep  3 03:45:56 2015
@@ -35,7 +35,7 @@ T tmain(T argc, T *argv) {
   S s;
 #pragma omp parallel
   a=2;
-#pragma omp parallel default(none), private(argc,b) firstprivate(argv) shared 
(d) if (argc > 0) num_threads(C) copyin(S::TS) proc_bind(master) 
reduction(+:c) reduction(max:e)
+#pragma omp parallel default(none), private(argc,b) firstprivate(argv) shared 
(d) if (parallel:argc > 0) num_threads(C) copyin(S::TS) proc_bind(master) 
reduction(+:c) reduction(max:e)
   foo();
 #pragma omp parallel if (C) num_threads(s) proc_bind(close) reduction(^:e, f) 
reduction(&& : g)
   foo();
@@ -48,7 +48,7 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: S s;
 // CHECK-NEXT: #pragma omp parallel
 // CHECK-NEXT: a = 2;
-// CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) 
firstprivate(argv) shared(d) if(argc > 0) num_threads(5) copyin(S::TS) 
proc_bind(master) reduction(+: c) reduction(max: e)
+// CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) 
firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(5) 
copyin(S::TS) proc_bind(master) reduction(+: c) reduction(max: e)
 // CHECK-NEXT: foo()
 // CHECK-NEXT: #pragma omp parallel if(5) num_threads(s) proc_bind(close) 
reduction(^: e,f) reduction(&&: g)
 // CHECK-NEXT: foo()
@@ -58,7 +58,7 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: S s;
 // CHECK-NEXT: #pragma omp parallel
 // CHECK-NEXT: a = 2;
-// CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) 
firstprivate(argv) shared(d) if(argc > 0) num_threads(1) copyin(S::TS) 
proc_bind(master) reduction(+: c) reduction(max: e)
+// CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) 
firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(1) 
copyin(S::TS) proc_bind(master) reduction(+: c) reduction(max: e)
 // CHECK-NEXT: foo()
 // CHECK-NEXT: #pragma omp parallel if(1) num_threads(s) proc_bind(close) 
reduction(^: e,f) reduction(&&: g)
 // CHECK-NEXT: foo()
@@ -68,7 +68,7 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: S s;
 // CHECK-NEXT: #pragma omp parallel
 // CHECK-NEXT: a = 2;
-// CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) 
firstprivate(argv) shared(d) if(argc > 0) num_threads(C) copyin(S::TS) 
proc_b

Re: [PATCH] D12244: Implement ACLE 2.0 macros of chapters 6.4 and 6.5 for [ARM] and [Aarch64] targets

2015-09-03 Thread Renato Golin via cfe-commits
rengolin added a comment.

Hi Alexandros,

Sorry, I was on holidays. Apart from my comment, everything else looks good.

cheers,
--renato



Comment at: lib/Basic/Targets.cpp:4790
@@ +4789,3 @@
+  Builder.defineMacro("__ARM_FEATURE_SAT", "1");
+  Builder.defineMacro("__ARM_FEATURE_QBIT", "1");
+}

Isn't there a combination where you'll emit this macro twice?


http://reviews.llvm.org/D12244



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


Re: [PATCH] D12244: Implement ACLE 2.0 macros of chapters 6.4 and 6.5 for [ARM] and [Aarch64] targets

2015-09-03 Thread Renato Golin via cfe-commits
rengolin added a comment.

Also, the target parser code has changed, please make sure it still works with 
the new version.


http://reviews.llvm.org/D12244



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


Re: [PATCH] D12148: [ARM] Allow passing/returning of __fp16 arguments

2015-09-03 Thread Renato Golin via cfe-commits
rengolin accepted this revision.
rengolin added a reviewer: rengolin.
rengolin added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


http://reviews.llvm.org/D12148



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


Re: [PATCH] D12148: [ARM] Allow passing/returning of __fp16 arguments

2015-09-03 Thread Oliver Stannard via cfe-commits
olista01 closed this revision.
olista01 added a comment.

Thanks, committed as r246755.


http://reviews.llvm.org/D12148



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


r246755 - [ARM] Allow passing/returning of __fp16 arguments

2015-09-03 Thread Oliver Stannard via cfe-commits
Author: olista01
Date: Thu Sep  3 04:34:53 2015
New Revision: 246755

URL: http://llvm.org/viewvc/llvm-project?rev=246755&view=rev
Log:
[ARM] Allow passing/returning of __fp16 arguments

The ACLE (ARM C Language Extensions) 2.0 allows the __fp16 type to be
used as a functon argument or return type (ACLE 1.1 did not).

The current public release of the AAPCS (2.09) states that __fp16 values
should be converted to single-precision before being passed or returned,
but AAPCS 2.10 (to be released shortly) changes this, so that they are
passed in the least-significant 16 bits of either a GPR (for base AAPCS)
or a single-precision register (for AAPCS-VFP). This does not change how
arguments are passed if they get passed on the stack.

This patch brings clang up to compliance with the latest versions of
both of these specs.

We can now set the __ARM_FP16_ARGS ACLE predefine, and we have always
been able to set the __ARM_FP16_FORMAT_IEEE predefine (we do not support
the alternative format).

Added:
cfe/trunk/test/CodeGen/arm-fp16-arguments.c
Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Preprocessor/arm-acle-6.5.c
cfe/trunk/test/Preprocessor/arm-target-features.c

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=246755&r1=246754&r2=246755&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Sep  3 04:34:53 2015
@@ -4568,6 +4568,10 @@ public:
 // ACLE predefines.
 Builder.defineMacro("__ARM_ACLE", "200");
 
+// FP16 support (we currently only support IEEE format).
+Builder.defineMacro("__ARM_FP16_FORMAT_IEEE", "1");
+Builder.defineMacro("__ARM_FP16_ARGS", "1");
+
 // Subtarget options.
 
 // FIXME: It's more complicated than this and we don't really support

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=246755&r1=246754&r2=246755&view=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Thu Sep  3 04:34:53 2015
@@ -4714,6 +4714,15 @@ ABIArgInfo ARMABIInfo::classifyArgumentT
 return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
   }
 
+  // __fp16 gets passed as if it were an int or float, but with the top 16 bits
+  // unspecified.
+  if (Ty->isHalfType()) {
+llvm::Type *ResType = IsEffectivelyAAPCS_VFP ?
+  llvm::Type::getFloatTy(getVMContext()) :
+  llvm::Type::getInt32Ty(getVMContext());
+return ABIArgInfo::getDirect(ResType);
+  }
+
   if (!isAggregateTypeForABI(Ty)) {
 // Treat an enum type as its underlying type.
 if (const EnumType *EnumTy = Ty->getAs()) {
@@ -4872,6 +4881,15 @@ ABIArgInfo ARMABIInfo::classifyReturnTyp
 return ABIArgInfo::getIndirect(0);
   }
 
+  // __fp16 gets returned as if it were an int or float, but with the top 16
+  // bits unspecified.
+  if (RetTy->isHalfType()) {
+llvm::Type *ResType = IsEffectivelyAAPCS_VFP ?
+  llvm::Type::getFloatTy(getVMContext()) :
+  llvm::Type::getInt32Ty(getVMContext());
+return ABIArgInfo::getDirect(ResType);
+  }
+
   if (!isAggregateTypeForABI(RetTy)) {
 // Treat an enum type as its underlying type.
 if (const EnumType *EnumTy = RetTy->getAs())

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=246755&r1=246754&r2=246755&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Sep  3 04:34:53 2015
@@ -4293,9 +4293,19 @@ void Clang::ConstructJob(Compilation &C,
   CmdArgs.push_back("-mstack-probe-size=0");
   }
 
-  if (getToolChain().getArch() == llvm::Triple::aarch64 ||
-  getToolChain().getArch() == llvm::Triple::aarch64_be)
+  switch (getToolChain().getArch()) {
+  case llvm::Triple::aarch64:
+  case llvm::Triple::aarch64_be:
+  case llvm::Triple::arm:
+  case llvm::Triple::armeb:
+  case llvm::Triple::thumb:
+  case llvm::Triple::thumbeb:
 CmdArgs.push_back("-fallow-half-arguments-and-returns");
+break;
+
+  default:
+break;
+  }
 
   if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it,
options::OPT_mno_restrict_it)) {

Added: cfe/trunk/test/CodeGen/arm-fp16-arguments.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm-fp16-arguments.c?rev=246755&view=auto
==
--- cfe/trunk/test/CodeGen/arm-fp16-arguments.c (added)
+++ cfe/trunk/test/CodeGen/arm-fp16-arguments.c Thu Sep  3 04:34:53 2015
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple armv7a--none-ea

Re: [PATCH] D11832: [Patch] [Analyzer] false positive: Potential leak connected with memcpy (PR 22954)

2015-09-03 Thread pierre gousseau via cfe-commits
pgousseau added a comment.

In http://reviews.llvm.org/D11832#237110, @pgousseau wrote:

> In http://reviews.llvm.org/D11832#236672, @xazax.hun wrote:
>
> > I reverted the commit until this assertion is fixed.
> >
> > Steps to reproduce:
> >  Download the following preprocessed file: F804743: clang_crash_7QnDaH.i 
> > 
> >  Execute the analyzer on that one: clang -cc1 -analyze 
> > -analyzer-checker=core -analyzer-checker=unix -fblocks clang_crash_7QnDaH.i
>
>
> Thanks for the reproducible and revert, I will have a look !


I have now uploaded a patch for this at http://reviews.llvm.org/D12571


Repository:
  rL LLVM

http://reviews.llvm.org/D11832



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


Re: [PATCH] D12400: Fix store detection for return value in CGCall

2015-09-03 Thread Jakub Kuderski via cfe-commits
kuhar updated this revision to Diff 33919.
kuhar added a comment.

Some refactoring + comments added.


Repository:
  rL LLVM

http://reviews.llvm.org/D12400

Files:
  lib/CodeGen/CGCall.cpp
  test/CodeGen/arm_function_epilog.cpp

Index: test/CodeGen/arm_function_epilog.cpp
===
--- /dev/null
+++ test/CodeGen/arm_function_epilog.cpp
@@ -0,0 +1,17 @@
+// REQUIRES: arm-registered-target
+// RUN: %clang_cc1 -triple armv7-none-linux-androideabi -target-abi 
aapcs-linux -mfloat-abi hard -x c++ -emit-llvm %s -o - | FileCheck %s
+
+struct Vec2 {
+union { struct { float x, y; };
+float data[2];
+};
+};
+
+// CHECK: define arm_aapcs_vfpcc %struct.Vec2 @_Z7getVec2v()
+// CHECK: ret %struct.Vec2
+Vec2 getVec2() {
+Vec2 out;
+union { Vec2* v; unsigned char* u; } x;
+x.v = &out;
+return out;
+}
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -2277,6 +2277,18 @@
 
 /// Heuristically search for a dominating store to the return-value slot.
 static llvm::StoreInst *findDominatingStoreToReturnValue(CodeGenFunction &CGF) 
{
+  // Check if a User is a store which pointerOperand is the ReturnValue.
+  // We are looking for stores to the ReturnValue, not for stores of the
+  // ReturnValue to some other location.
+  auto getStoreIfValid = [&CGF](llvm::User *U) -> llvm::StoreInst * {
+auto *SI = dyn_cast(U);
+if (!SI || SI->getPointerOperand() != CGF.ReturnValue)
+  return nullptr;
+// These aren't actually possible for non-coerced returns, and we
+// only care about non-coerced returns on this code path.
+assert(!SI->isAtomic() && !SI->isVolatile());
+return SI;
+  };
   // If there are multiple uses of the return-value slot, just check
   // for something immediately preceding the IP.  Sometimes this can
   // happen with how we generate implicit-returns; it can also happen
@@ -2305,21 +2317,12 @@
   break;
 }
 
-llvm::StoreInst *store = dyn_cast(I);
-if (!store) return nullptr;
-if (store->getPointerOperand() != CGF.ReturnValue) return nullptr;
-assert(!store->isAtomic() && !store->isVolatile()); // see below
-return store;
+return getStoreIfValid(I);
   }
 
-  llvm::StoreInst *store =
-dyn_cast(CGF.ReturnValue->user_back());
+  llvm::StoreInst *store = getStoreIfValid(CGF.ReturnValue->user_back());
   if (!store) return nullptr;
 
-  // These aren't actually possible for non-coerced returns, and we
-  // only care about non-coerced returns on this code path.
-  assert(!store->isAtomic() && !store->isVolatile());
-
   // Now do a first-and-dirty dominance check: just walk up the
   // single-predecessors chain from the current insertion point.
   llvm::BasicBlock *StoreBB = store->getParent();


Index: test/CodeGen/arm_function_epilog.cpp
===
--- /dev/null
+++ test/CodeGen/arm_function_epilog.cpp
@@ -0,0 +1,17 @@
+// REQUIRES: arm-registered-target
+// RUN: %clang_cc1 -triple armv7-none-linux-androideabi -target-abi aapcs-linux -mfloat-abi hard -x c++ -emit-llvm %s -o - | FileCheck %s
+
+struct Vec2 {
+union { struct { float x, y; };
+float data[2];
+};
+};
+
+// CHECK: define arm_aapcs_vfpcc %struct.Vec2 @_Z7getVec2v()
+// CHECK: ret %struct.Vec2
+Vec2 getVec2() {
+Vec2 out;
+union { Vec2* v; unsigned char* u; } x;
+x.v = &out;
+return out;
+}
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -2277,6 +2277,18 @@
 
 /// Heuristically search for a dominating store to the return-value slot.
 static llvm::StoreInst *findDominatingStoreToReturnValue(CodeGenFunction &CGF) {
+  // Check if a User is a store which pointerOperand is the ReturnValue.
+  // We are looking for stores to the ReturnValue, not for stores of the
+  // ReturnValue to some other location.
+  auto getStoreIfValid = [&CGF](llvm::User *U) -> llvm::StoreInst * {
+auto *SI = dyn_cast(U);
+if (!SI || SI->getPointerOperand() != CGF.ReturnValue)
+  return nullptr;
+// These aren't actually possible for non-coerced returns, and we
+// only care about non-coerced returns on this code path.
+assert(!SI->isAtomic() && !SI->isVolatile());
+return SI;
+  };
   // If there are multiple uses of the return-value slot, just check
   // for something immediately preceding the IP.  Sometimes this can
   // happen with how we generate implicit-returns; it can also happen
@@ -2305,21 +2317,12 @@
   break;
 }
 
-llvm::StoreInst *store = dyn_cast(I);
-if (!store) return nullptr;
-if (store->getPointerOperand() != CGF.ReturnValue) return nullptr;
-assert(!store->isAtomic() && !store->isVolatile()); // see below
-return store;
+return getStoreIfValid(I);
   }

Re: [PATCH] D12400: Fix store detection for return value in CGCall

2015-09-03 Thread Jakub Kuderski via cfe-commits
kuhar marked 2 inline comments as done.
kuhar added a comment.

Repository:
  rL LLVM

http://reviews.llvm.org/D12400



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


Re: [PATCH] D12400: Fix store detection for return value in CGCall

2015-09-03 Thread Jakub Kuderski via cfe-commits
kuhar updated this revision to Diff 33921.

Repository:
  rL LLVM

http://reviews.llvm.org/D12400

Files:
  lib/CodeGen/CGCall.cpp
  test/CodeGen/arm_function_epilog.cpp

Index: test/CodeGen/arm_function_epilog.cpp
===
--- /dev/null
+++ test/CodeGen/arm_function_epilog.cpp
@@ -0,0 +1,17 @@
+// REQUIRES: arm-registered-target
+// RUN: %clang_cc1 -triple armv7-none-linux-androideabi -target-abi 
aapcs-linux -mfloat-abi hard -x c++ -emit-llvm %s -o - | FileCheck %s
+
+struct Vec2 {
+union { struct { float x, y; };
+float data[2];
+};
+};
+
+// CHECK: define arm_aapcs_vfpcc %struct.Vec2 @_Z7getVec2v()
+// CHECK: ret %struct.Vec2
+Vec2 getVec2() {
+Vec2 out;
+union { Vec2* v; unsigned char* u; } x;
+x.v = &out;
+return out;
+}
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -2277,6 +2277,18 @@
 
 /// Heuristically search for a dominating store to the return-value slot.
 static llvm::StoreInst *findDominatingStoreToReturnValue(CodeGenFunction &CGF) 
{
+  // Check if a User is a store which pointerOperand is the ReturnValue.
+  // We are looking for stores to the ReturnValue, not for stores of the
+  // ReturnValue to some other location.
+  auto GetStoreIfValid = [&CGF](llvm::User *U) -> llvm::StoreInst * {
+auto *SI = dyn_cast(U);
+if (!SI || SI->getPointerOperand() != CGF.ReturnValue)
+  return nullptr;
+// These aren't actually possible for non-coerced returns, and we
+// only care about non-coerced returns on this code path.
+assert(!SI->isAtomic() && !SI->isVolatile());
+return SI;
+  };
   // If there are multiple uses of the return-value slot, just check
   // for something immediately preceding the IP.  Sometimes this can
   // happen with how we generate implicit-returns; it can also happen
@@ -2305,21 +2317,12 @@
   break;
 }
 
-llvm::StoreInst *store = dyn_cast(I);
-if (!store) return nullptr;
-if (store->getPointerOperand() != CGF.ReturnValue) return nullptr;
-assert(!store->isAtomic() && !store->isVolatile()); // see below
-return store;
+return GetStoreIfValid(I);
   }
 
-  llvm::StoreInst *store =
-dyn_cast(CGF.ReturnValue->user_back());
+  llvm::StoreInst *store = GetStoreIfValid(CGF.ReturnValue->user_back());
   if (!store) return nullptr;
 
-  // These aren't actually possible for non-coerced returns, and we
-  // only care about non-coerced returns on this code path.
-  assert(!store->isAtomic() && !store->isVolatile());
-
   // Now do a first-and-dirty dominance check: just walk up the
   // single-predecessors chain from the current insertion point.
   llvm::BasicBlock *StoreBB = store->getParent();


Index: test/CodeGen/arm_function_epilog.cpp
===
--- /dev/null
+++ test/CodeGen/arm_function_epilog.cpp
@@ -0,0 +1,17 @@
+// REQUIRES: arm-registered-target
+// RUN: %clang_cc1 -triple armv7-none-linux-androideabi -target-abi aapcs-linux -mfloat-abi hard -x c++ -emit-llvm %s -o - | FileCheck %s
+
+struct Vec2 {
+union { struct { float x, y; };
+float data[2];
+};
+};
+
+// CHECK: define arm_aapcs_vfpcc %struct.Vec2 @_Z7getVec2v()
+// CHECK: ret %struct.Vec2
+Vec2 getVec2() {
+Vec2 out;
+union { Vec2* v; unsigned char* u; } x;
+x.v = &out;
+return out;
+}
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -2277,6 +2277,18 @@
 
 /// Heuristically search for a dominating store to the return-value slot.
 static llvm::StoreInst *findDominatingStoreToReturnValue(CodeGenFunction &CGF) {
+  // Check if a User is a store which pointerOperand is the ReturnValue.
+  // We are looking for stores to the ReturnValue, not for stores of the
+  // ReturnValue to some other location.
+  auto GetStoreIfValid = [&CGF](llvm::User *U) -> llvm::StoreInst * {
+auto *SI = dyn_cast(U);
+if (!SI || SI->getPointerOperand() != CGF.ReturnValue)
+  return nullptr;
+// These aren't actually possible for non-coerced returns, and we
+// only care about non-coerced returns on this code path.
+assert(!SI->isAtomic() && !SI->isVolatile());
+return SI;
+  };
   // If there are multiple uses of the return-value slot, just check
   // for something immediately preceding the IP.  Sometimes this can
   // happen with how we generate implicit-returns; it can also happen
@@ -2305,21 +2317,12 @@
   break;
 }
 
-llvm::StoreInst *store = dyn_cast(I);
-if (!store) return nullptr;
-if (store->getPointerOperand() != CGF.ReturnValue) return nullptr;
-assert(!store->isAtomic() && !store->isVolatile()); // see below
-return store;
+return GetStoreIfValid(I);
   }
 
-  llvm::StoreInst *store =
-dyn_cast(CGF.ReturnValue-

r246757 - [OPENMP] Fix for http://llvm.org/PR24687: ICE on compilation of R package TPmsm.

2015-09-03 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Sep  3 05:21:46 2015
New Revision: 246757

URL: http://llvm.org/viewvc/llvm-project?rev=246757&view=rev
Log:
[OPENMP] Fix for http://llvm.org/PR24687: ICE on compilation of R package TPmsm.
Fixed capturing of VLAs in 'private' clause of the OpenMP directives.

Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/OpenMP/parallel_for_codegen.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=246757&r1=246756&r2=246757&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep  3 05:21:46 2015
@@ -13000,21 +13000,6 @@ bool Sema::tryCaptureVariable(
 if (isVariableAlreadyCapturedInScopeInfo(CSI, Var, Nested, CaptureType, 
  DeclRefType)) 
   break;
-if (getLangOpts().OpenMP) {
-  if (auto *RSI = dyn_cast(CSI)) {
-// OpenMP private variables should not be captured in outer scope, so
-// just break here.
-if (RSI->CapRegionKind == CR_OpenMP) {
-  if (isOpenMPPrivateVar(Var, OpenMPLevel)) {
-Nested = true;
-DeclRefType = DeclRefType.getUnqualifiedType();
-CaptureType = Context.getLValueReferenceType(DeclRefType);
-break;
-  }
-  ++OpenMPLevel;
-}
-  }
-}
 // If we are instantiating a generic lambda call operator body, 
 // we do not want to capture new variables.  What was captured
 // during either a lambdas transformation or initial parsing
@@ -13160,6 +13145,21 @@ bool Sema::tryCaptureVariable(
   } while (!QTy.isNull() && QTy->isVariablyModifiedType());
 }
 
+if (getLangOpts().OpenMP) {
+  if (auto *RSI = dyn_cast(CSI)) {
+// OpenMP private variables should not be captured in outer scope, so
+// just break here.
+if (RSI->CapRegionKind == CR_OpenMP) {
+  if (isOpenMPPrivateVar(Var, OpenMPLevel)) {
+Nested = true;
+DeclRefType = DeclRefType.getUnqualifiedType();
+CaptureType = Context.getLValueReferenceType(DeclRefType);
+break;
+  }
+  ++OpenMPLevel;
+}
+  }
+}
 if (CSI->ImpCaptureStyle == CapturingScopeInfo::ImpCap_None && !Explicit) {
   // No capture-default, and this is not an explicit capture 
   // so cannot capture this variable.  

Modified: cfe/trunk/test/OpenMP/parallel_for_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_for_codegen.cpp?rev=246757&r1=246756&r2=246757&view=diff
==
--- cfe/trunk/test/OpenMP/parallel_for_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/parallel_for_codegen.cpp Thu Sep  3 05:21:46 2015
@@ -378,8 +378,9 @@ int foo() {return 0;};
 
 // TERM_DEBUG-LABEL: parallel_for
 // CLEANUP: parallel_for
-void parallel_for(float *a) {
-#pragma omp parallel for schedule(static, 5)
+void parallel_for(float *a, int n) {
+  float arr[n];
+#pragma omp parallel for schedule(static, 5) private(arr)
   // TERM_DEBUG-NOT: __kmpc_global_thread_num
   // TERM_DEBUG: call void @__kmpc_for_static_init_4u({{.+}}), !dbg 
[[DBG_LOC_START:![0-9]+]]
   // TERM_DEBUG: invoke i32 {{.*}}foo{{.*}}()
@@ -395,7 +396,7 @@ void parallel_for(float *a) {
   // CLEANUP: call void @__kmpc_for_static_fini({{.+}})
   // CLEANUP: call {{.+}} @__kmpc_barrier({{.+}})
   for (unsigned i = 131071; i <= 2147483647; i += 127)
-a[i] += foo();
+a[i] += foo() + arr[i];
 }
 // Check source line corresponds to "#pragma omp parallel for schedule(static, 
5)" above:
 // TERM_DEBUG-DAG: [[DBG_LOC_START]] = !DILocation(line: [[@LINE-4]],


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


[PATCH] D12594: [X86-64] Allow additional register names in inline assembler.

2015-09-03 Thread Alexey Bataev via cfe-commits
ABataev created this revision.
ABataev added reviewers: rjmccall, echristo.
ABataev added a subscriber: cfe-commits.

Patch allows to recognize additional registers x8d, x8b, x8w - x15d, x15b, x15w 
in inline assembler, already recognized by backend

http://reviews.llvm.org/D12594

Files:
  lib/Basic/Targets.cpp
  test/CodeGen/asm_64.c

Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -2022,6 +2022,14 @@
   { { "edi", "rdi" }, 5 },
   { { "esp", "rsp" }, 7 },
   { { "ebp", "rbp" }, 6 },
+  { { "r8d", "r8w", "r8b" }, 38 },
+  { { "r9d", "r9w", "r9b" }, 39 },
+  { { "r10d", "r10w", "r10b" }, 40 },
+  { { "r11d", "r11w", "r11b" }, 41 },
+  { { "r12d", "r12w", "r12b" }, 42 },
+  { { "r13d", "r13w", "r13b" }, 43 },
+  { { "r14d", "r14w", "r14b" }, 44 },
+  { { "r15d", "r15w", "r15b" }, 45 },
 };
 
 // X86 target abstract base class; x86-32 and x86-64 are very close, so
Index: test/CodeGen/asm_64.c
===
--- test/CodeGen/asm_64.c
+++ test/CodeGen/asm_64.c
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm %s -o - | 
FileCheck %s
+
+// CHECK-LABEL: @t1
+void t1() {
+  __asm__ ("mov r8w, 100;");
+  __asm__ ("mov r8d, 100;");
+  __asm__ ("mov r8b, 100;");
+  __asm__ ("mov r9w, 100;");
+  __asm__ ("mov r9d, 100;");
+  __asm__ ("mov r9b, 100;");
+  __asm__ ("mov r10w, 100;");
+  __asm__ ("mov r10d, 100;");
+  __asm__ ("mov r10b, 100;");
+  __asm__ ("mov r11w, 100;");
+  __asm__ ("mov r11d, 100;");
+  __asm__ ("mov r11b, 100;");
+  __asm__ ("mov r12w, 100;");
+  __asm__ ("mov r12d, 100;");
+  __asm__ ("mov r12b, 100;");
+  __asm__ ("mov r13w, 100;");
+  __asm__ ("mov r13d, 100;");
+  __asm__ ("mov r13b, 100;");
+  __asm__ ("mov r14w, 100;");
+  __asm__ ("mov r14d, 100;");
+  __asm__ ("mov r14b, 100;");
+  __asm__ ("mov r15w, 100;");
+  __asm__ ("mov r15d, 100;");
+  __asm__ ("mov r15b, 100;");
+  // CHECK: call void asm sideeffect "mov r8w, 100;"
+  // CHECK: call void asm sideeffect "mov r8d, 100;"
+  // CHECK: call void asm sideeffect "mov r8b, 100;"
+  // CHECK: call void asm sideeffect "mov r9w, 100;"
+  // CHECK: call void asm sideeffect "mov r9d, 100;"
+  // CHECK: call void asm sideeffect "mov r9b, 100;"
+  // CHECK: call void asm sideeffect "mov r10w, 100;"
+  // CHECK: call void asm sideeffect "mov r10d, 100;"
+  // CHECK: call void asm sideeffect "mov r10b, 100;"
+  // CHECK: call void asm sideeffect "mov r11w, 100;"
+  // CHECK: call void asm sideeffect "mov r11d, 100;"
+  // CHECK: call void asm sideeffect "mov r11b, 100;"
+  // CHECK: call void asm sideeffect "mov r12w, 100;"
+  // CHECK: call void asm sideeffect "mov r12d, 100;"
+  // CHECK: call void asm sideeffect "mov r12b, 100;"
+  // CHECK: call void asm sideeffect "mov r13w, 100;"
+  // CHECK: call void asm sideeffect "mov r13d, 100;"
+  // CHECK: call void asm sideeffect "mov r13b, 100;"
+  // CHECK: call void asm sideeffect "mov r14w, 100;"
+  // CHECK: call void asm sideeffect "mov r14d, 100;"
+  // CHECK: call void asm sideeffect "mov r14b, 100;"
+  // CHECK: call void asm sideeffect "mov r15w, 100;"
+  // CHECK: call void asm sideeffect "mov r15d, 100;"
+  // CHECK: call void asm sideeffect "mov r15b, 100;"
+}


Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -2022,6 +2022,14 @@
   { { "edi", "rdi" }, 5 },
   { { "esp", "rsp" }, 7 },
   { { "ebp", "rbp" }, 6 },
+  { { "r8d", "r8w", "r8b" }, 38 },
+  { { "r9d", "r9w", "r9b" }, 39 },
+  { { "r10d", "r10w", "r10b" }, 40 },
+  { { "r11d", "r11w", "r11b" }, 41 },
+  { { "r12d", "r12w", "r12b" }, 42 },
+  { { "r13d", "r13w", "r13b" }, 43 },
+  { { "r14d", "r14w", "r14b" }, 44 },
+  { { "r15d", "r15w", "r15b" }, 45 },
 };
 
 // X86 target abstract base class; x86-32 and x86-64 are very close, so
Index: test/CodeGen/asm_64.c
===
--- test/CodeGen/asm_64.c
+++ test/CodeGen/asm_64.c
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+
+// CHECK-LABEL: @t1
+void t1() {
+  __asm__ ("mov r8w, 100;");
+  __asm__ ("mov r8d, 100;");
+  __asm__ ("mov r8b, 100;");
+  __asm__ ("mov r9w, 100;");
+  __asm__ ("mov r9d, 100;");
+  __asm__ ("mov r9b, 100;");
+  __asm__ ("mov r10w, 100;");
+  __asm__ ("mov r10d, 100;");
+  __asm__ ("mov r10b, 100;");
+  __asm__ ("mov r11w, 100;");
+  __asm__ ("mov r11d, 100;");
+  __asm__ ("mov r11b, 100;");
+  __asm__ ("mov r12w, 100;");
+  __asm__ ("mov r12d, 100;");
+  __asm__ ("mov r12b, 100;");
+  __asm__ ("mov r13w, 100;");
+  __asm__ ("mov r13d, 100;");
+  __asm__ ("mov r13b, 100;");
+  __asm__ ("mov r14w, 100;");
+  __asm__ ("mov r14d, 100;");
+  __asm__ ("mov r14b, 100;");
+  __asm__ ("mov r15w, 100;");
+  __asm__ ("mov r15d, 100;");
+  __asm__ ("mov r15b, 100;");
+  // CH

Re: r246755 - [ARM] Allow passing/returning of __fp16 arguments

2015-09-03 Thread Renato Golin via cfe-commits
On 3 September 2015 at 10:34, Oliver Stannard via cfe-commits
 wrote:
> Author: olista01
> Date: Thu Sep  3 04:34:53 2015
> New Revision: 246755
>
> URL: http://llvm.org/viewvc/llvm-project?rev=246755&view=rev
> Log:
> [ARM] Allow passing/returning of __fp16 arguments
>
> The ACLE (ARM C Language Extensions) 2.0 allows the __fp16 type to be
> used as a functon argument or return type (ACLE 1.1 did not).

This looks like has something to do with FP16:

http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-a15/builds/5546/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Ahalf.cl

I'm also seeing on the NEON bot:

http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost-neon/builds/3291

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


r246760 - Revert 246755 as it breaks buildbots

2015-09-03 Thread Oliver Stannard via cfe-commits
Author: olista01
Date: Thu Sep  3 06:46:24 2015
New Revision: 246760

URL: http://llvm.org/viewvc/llvm-project?rev=246760&view=rev
Log:
Revert 246755 as it breaks buildbots

Original commit message:
[ARM] Allow passing/returning of __fp16 arguments

The ACLE (ARM C Language Extensions) 2.0 allows the __fp16 type to be
used as a functon argument or return type (ACLE 1.1 did not).

The current public release of the AAPCS (2.09) states that __fp16 values
should be converted to single-precision before being passed or returned,
but AAPCS 2.10 (to be released shortly) changes this, so that they are
passed in the least-significant 16 bits of either a GPR (for base AAPCS)
or a single-precision register (for AAPCS-VFP). This does not change how
arguments are passed if they get passed on the stack.

This patch brings clang up to compliance with the latest versions of
both of these specs.

We can now set the __ARM_FP16_ARGS ACLE predefine, and we have always
been able to set the __ARM_FP16_FORMAT_IEEE predefine (we do not support
the alternative format).


Removed:
cfe/trunk/test/CodeGen/arm-fp16-arguments.c
Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Preprocessor/arm-acle-6.5.c
cfe/trunk/test/Preprocessor/arm-target-features.c

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=246760&r1=246759&r2=246760&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Sep  3 06:46:24 2015
@@ -4568,10 +4568,6 @@ public:
 // ACLE predefines.
 Builder.defineMacro("__ARM_ACLE", "200");
 
-// FP16 support (we currently only support IEEE format).
-Builder.defineMacro("__ARM_FP16_FORMAT_IEEE", "1");
-Builder.defineMacro("__ARM_FP16_ARGS", "1");
-
 // Subtarget options.
 
 // FIXME: It's more complicated than this and we don't really support

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=246760&r1=246759&r2=246760&view=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Thu Sep  3 06:46:24 2015
@@ -4714,15 +4714,6 @@ ABIArgInfo ARMABIInfo::classifyArgumentT
 return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
   }
 
-  // __fp16 gets passed as if it were an int or float, but with the top 16 bits
-  // unspecified.
-  if (Ty->isHalfType()) {
-llvm::Type *ResType = IsEffectivelyAAPCS_VFP ?
-  llvm::Type::getFloatTy(getVMContext()) :
-  llvm::Type::getInt32Ty(getVMContext());
-return ABIArgInfo::getDirect(ResType);
-  }
-
   if (!isAggregateTypeForABI(Ty)) {
 // Treat an enum type as its underlying type.
 if (const EnumType *EnumTy = Ty->getAs()) {
@@ -4881,15 +4872,6 @@ ABIArgInfo ARMABIInfo::classifyReturnTyp
 return ABIArgInfo::getIndirect(0);
   }
 
-  // __fp16 gets returned as if it were an int or float, but with the top 16
-  // bits unspecified.
-  if (RetTy->isHalfType()) {
-llvm::Type *ResType = IsEffectivelyAAPCS_VFP ?
-  llvm::Type::getFloatTy(getVMContext()) :
-  llvm::Type::getInt32Ty(getVMContext());
-return ABIArgInfo::getDirect(ResType);
-  }
-
   if (!isAggregateTypeForABI(RetTy)) {
 // Treat an enum type as its underlying type.
 if (const EnumType *EnumTy = RetTy->getAs())

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=246760&r1=246759&r2=246760&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Sep  3 06:46:24 2015
@@ -4293,19 +4293,9 @@ void Clang::ConstructJob(Compilation &C,
   CmdArgs.push_back("-mstack-probe-size=0");
   }
 
-  switch (getToolChain().getArch()) {
-  case llvm::Triple::aarch64:
-  case llvm::Triple::aarch64_be:
-  case llvm::Triple::arm:
-  case llvm::Triple::armeb:
-  case llvm::Triple::thumb:
-  case llvm::Triple::thumbeb:
+  if (getToolChain().getArch() == llvm::Triple::aarch64 ||
+  getToolChain().getArch() == llvm::Triple::aarch64_be)
 CmdArgs.push_back("-fallow-half-arguments-and-returns");
-break;
-
-  default:
-break;
-  }
 
   if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it,
options::OPT_mno_restrict_it)) {

Removed: cfe/trunk/test/CodeGen/arm-fp16-arguments.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm-fp16-arguments.c?rev=246759&view=auto
==
--- cfe/trunk/test/CodeGen/arm-fp16-arguments.c (original)
+++ cfe/trunk/test/CodeGen/arm-fp16-arguments.c (removed)
@@ -

RE: r246755 - [ARM] Allow passing/returning of __fp16 arguments

2015-09-03 Thread Oliver Stannard via cfe-commits
> On 3 September 2015 at 10:34, Oliver Stannard via cfe-commits
>  wrote:
> > Author: olista01
> > Date: Thu Sep  3 04:34:53 2015
> > New Revision: 246755
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=246755&view=rev
> > Log:
> > [ARM] Allow passing/returning of __fp16 arguments
> >
> > The ACLE (ARM C Language Extensions) 2.0 allows the __fp16 type to be
> > used as a functon argument or return type (ACLE 1.1 did not).
> 
> This looks like has something to do with FP16:
> 
> http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-
> a15/builds/5546/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Ahalf.cl
> 
> I'm also seeing on the NEON bot:
> 
> http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost-
> neon/builds/3291

I've reverted it as r246760 for now.

Oliver


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


Re: [PATCH] D12002: Initial WebAssembly support in clang

2015-09-03 Thread Dan Gohman via cfe-commits
sunfishcode added a subscriber: sunfishcode.


Comment at: lib/Basic/Targets.cpp:6943-6944
@@ +6942,4 @@
+
+  Diags.Report(diag::err_opt_not_valid_with_opt) << Feature
+ << "-target-feature";
+  return false;

echristo wrote:
> The backend should handle any weirdness here with missing features especially 
> as this will report an error based on -cc1 compilation and not the main 
> command line.
> 
> I.e. it's not necessary, that said if you feel wedded to it there's no 
> problem either.
I do feel more comfortable rejecting anything that I'm not specifically 
expecting in this area.


Comment at: lib/Basic/Targets.cpp:7643-7649
@@ +7642,9 @@
+  case llvm::Triple::wasm64:
+// Until specific variations are defined, don't permit any.
+if (!(Triple == llvm::Triple("wasm64-unknown-unknown")) ||
+(!Triple.getVendorName().empty() &&
+ Triple.getVendorName() != "unknown") ||
+(!Triple.getOSName().empty() && Triple.getOSName() != "unknown") ||
+(Triple.hasEnvironment() && Triple.getEnvironmentName() != "unknown"))
+  return nullptr;
+return new WebAssemblyOSTargetInfo(Triple);

echristo wrote:
> Ditto.
> 
> (I said this just below, but it seems to have gotten munged in the newer 
> version)
I actually did see your comment and updated the code accordingly. It now does a 
positive test, `Triple == llvm::Triple("wasm64-unknown-unknown")`, which is 
simpler than what it did before.

However, it's also doing additional tests, because the Triple class's 
operator== doesn't distinguish between an Unknown that was actually "unknown" 
or an unknown that was some other string. Until we figure out what "vendor", 
"OS", and "environment" variations of wasm make sense (if any), we want to 
avoid dealing with accidental alternate triples.


Repository:
  rL LLVM

http://reviews.llvm.org/D12002



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


Re: libtooling and ast matchers owners

2015-09-03 Thread Aaron Ballman via cfe-commits
Sounds great to me, thank you for updating this!

~Aaron

On Thu, Sep 3, 2015 at 4:44 AM, Manuel Klimek  wrote:
> After Aaron updated the clang-tools-extra owners, I looked at the clang
> owners and noticed that I'm not in there for libtooling and ast matchers.
> Doug suggested 3 years back that I should be in there, but apparently I
> forgot to update it. Anybody raising objections to me putting myself in for
> libtooling and ast matchers?
>
> Cheers,
> /Manuel
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12148: [ARM] Allow passing/returning of __fp16 arguments

2015-09-03 Thread Oliver Stannard via cfe-commits
olista01 updated this revision to Diff 33932.
olista01 added a comment.

Don't make this change for OpenCL, which handles the half type natively.


http://reviews.llvm.org/D12148

Files:
  lib/Basic/Targets.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Driver/Tools.cpp
  test/CodeGen/arm-fp16-arguments.c
  test/Preprocessor/arm-acle-6.5.c
  test/Preprocessor/arm-target-features.c

Index: test/Preprocessor/arm-target-features.c
===
--- test/Preprocessor/arm-target-features.c
+++ test/Preprocessor/arm-target-features.c
@@ -5,6 +5,8 @@
 // CHECK: __ARM_FEATURE_CRC32 1
 // CHECK: __ARM_FEATURE_DIRECTED_ROUNDING 1
 // CHECK: __ARM_FEATURE_NUMERIC_MAXMIN 1
+// CHECK: __ARM_FP16_ARGS 1
+// CHECK: __ARM_FP16_FORMAT_IEEE 1
 
 // RUN: %clang -target armv7a-none-linux-gnu -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-V7 %s
 // CHECK-V7: __ARMEL__ 1
Index: test/Preprocessor/arm-acle-6.5.c
===
--- test/Preprocessor/arm-acle-6.5.c
+++ test/Preprocessor/arm-acle-6.5.c
@@ -1,6 +1,6 @@
 // RUN: %clang -target arm-eabi -x c -E -dM %s -o - | FileCheck %s -check-prefix CHECK-DEFAULT
 
-// CHECK-DEFAULT-NOT: __ARM_FP
+// CHECK-DEFAULT-NOT: __ARM_FP 0x
 
 // RUN: %clang -target arm-eabi -mfpu=vfp -x c -E -dM %s -o - | FileCheck %s -check-prefix CHECK-SP-DP
 // RUN: %clang -target arm-eabi -mfpu=vfp3 -x c -E -dM %s -o - | FileCheck %s -check-prefix CHECK-SP-DP
Index: test/CodeGen/arm-fp16-arguments.c
===
--- /dev/null
+++ test/CodeGen/arm-fp16-arguments.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple armv7a--none-eabi -target-abi aapcs -mfloat-abi soft -fallow-half-arguments-and-returns -emit-llvm -o - -O1 %s | FileCheck %s --check-prefix=CHECK --check-prefix=SOFT
+// RUN: %clang_cc1 -triple armv7a--none-eabi -target-abi aapcs -mfloat-abi hard -fallow-half-arguments-and-returns -emit-llvm -o - -O1 %s | FileCheck %s --check-prefix=CHECK --check-prefix=HARD
+
+__fp16 g;
+
+void t1(__fp16 a) { g = a; }
+// SOFT: define void @t1(i32 [[PARAM:%.*]])
+// SOFT: [[TRUNC:%.*]] = trunc i32 [[PARAM]] to i16
+// HARD: define arm_aapcs_vfpcc void @t1(float [[PARAM:%.*]])
+// HARD: [[BITCAST:%.*]] = bitcast float [[PARAM]] to i32
+// HARD: [[TRUNC:%.*]] = trunc i32 [[BITCAST]] to i16
+// CHECK: store i16 [[TRUNC]], i16* bitcast (half* @g to i16*)
+
+__fp16 t2() { return g; }
+// SOFT: define i32 @t2()
+// HARD: define arm_aapcs_vfpcc float @t2()
+// CHECK: [[LOAD:%.*]] = load i16, i16* bitcast (half* @g to i16*)
+// CHECK: [[ZEXT:%.*]] = zext i16 [[LOAD]] to i32
+// SOFT: ret i32 [[ZEXT]]
+// HARD: [[BITCAST:%.*]] = bitcast i32 [[ZEXT]] to float
+// HARD: ret float [[BITCAST]]
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -4293,9 +4293,19 @@
   CmdArgs.push_back("-mstack-probe-size=0");
   }
 
-  if (getToolChain().getArch() == llvm::Triple::aarch64 ||
-  getToolChain().getArch() == llvm::Triple::aarch64_be)
+  switch (getToolChain().getArch()) {
+  case llvm::Triple::aarch64:
+  case llvm::Triple::aarch64_be:
+  case llvm::Triple::arm:
+  case llvm::Triple::armeb:
+  case llvm::Triple::thumb:
+  case llvm::Triple::thumbeb:
 CmdArgs.push_back("-fallow-half-arguments-and-returns");
+break;
+
+  default:
+break;
+  }
 
   if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it,
options::OPT_mno_restrict_it)) {
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -4714,6 +4714,15 @@
 return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
   }
 
+  // __fp16 gets passed as if it were an int or float, but with the top 16 bits
+  // unspecified.
+  if (Ty->isHalfType() && !getContext().getLangOpts().OpenCL) {
+llvm::Type *ResType = IsEffectivelyAAPCS_VFP ?
+  llvm::Type::getFloatTy(getVMContext()) :
+  llvm::Type::getInt32Ty(getVMContext());
+return ABIArgInfo::getDirect(ResType);
+  }
+
   if (!isAggregateTypeForABI(Ty)) {
 // Treat an enum type as its underlying type.
 if (const EnumType *EnumTy = Ty->getAs()) {
@@ -4872,6 +4881,15 @@
 return ABIArgInfo::getIndirect(0);
   }
 
+  // __fp16 gets returned as if it were an int or float, but with the top 16
+  // bits unspecified.
+  if (RetTy->isHalfType() && !getContext().getLangOpts().OpenCL) {
+llvm::Type *ResType = IsEffectivelyAAPCS_VFP ?
+  llvm::Type::getFloatTy(getVMContext()) :
+  llvm::Type::getInt32Ty(getVMContext());
+return ABIArgInfo::getDirect(ResType);
+  }
+
   if (!isAggregateTypeForABI(RetTy)) {
 // Treat an enum type as its underlying type.
 if (const EnumType *EnumTy = RetTy->getAs())
Index: lib/Basic/Targets.cpp
=

[PATCH] D12597: Two more fixes to loop convert.

2015-09-03 Thread Angel Garcia via cfe-commits
angelgarcia created this revision.
angelgarcia added a reviewer: klimek.
angelgarcia added subscribers: cfe-commits, alexfh.

Ensure that the alias has the same type than the loop variable. Now it works 
with lambda captures.

http://reviews.llvm.org/D12597

Files:
  clang-tidy/modernize/LoopConvertUtils.cpp
  clang-tidy/modernize/LoopConvertUtils.h
  test/clang-tidy/modernize-loop-convert-extra.cpp

Index: test/clang-tidy/modernize-loop-convert-extra.cpp
===
--- test/clang-tidy/modernize-loop-convert-extra.cpp
+++ test/clang-tidy/modernize-loop-convert-extra.cpp
@@ -159,8 +159,17 @@
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto alias : IntArr)
   // CHECK-FIXES-NEXT: for (unsigned j = 0; alias; ++j) {
+
+  struct IntRef { IntRef(const int& i); };
+  for (int i = 0; i < N; ++i) {
+IntRef Int(IntArr[i]);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : IntArr) {
+  // CHECK-FIXES-NEXT: IntRef Int(elem);
 }
 
+
 void refs_and_vals() {
   // The following tests check that the transform correctly preserves the
   // reference or value qualifiers of the aliased variable. That is, if the
@@ -713,3 +722,165 @@
 }
 
 } // namespace Templates
+
+namespace Lambdas {
+
+void capturesIndex() {
+  const int N = 10;
+  int Arr[N];
+  // FIXME: the next four loops could be convertible, if the capture list is
+  // also changed.
+
+  for (int I = 0; I < N; ++I)
+auto F1 = [Arr, I]() { int R1 = Arr[I] + 1; };
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES-NEXT: auto F1 = [Arr, elem]() { int R1 = elem + 1; };
+
+  for (int I = 0; I < N; ++I)
+auto F2 = [Arr, &I]() { int R2 = Arr[I] + 3; };
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES-NEXT: auto F2 = [Arr, &elem]() { int R2 = elem + 3; };
+
+  // FIXME: alias don't work if the index is captured.
+  // Alias declared inside lambda (by value).
+  for (int I = 0; I < N; ++I)
+auto F3 = [&Arr, I]() { int R3 = Arr[I]; };
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES-NEXT: auto F3 = [&Arr, elem]() { int R3 = elem; };
+  // FIXME: this does two copies instead of one. Capture elem by ref?
+
+
+  for (int I = 0; I < N; ++I)
+auto F4 = [&Arr, &I]() { int R4 = Arr[I]; };
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES-NEXT: auto F4 = [&Arr, &elem]() { int R4 = elem; };
+
+  // Alias declared inside lambda (by reference).
+  for (int I = 0; I < N; ++I)
+auto F5 = [&Arr, I]() { int &R5 = Arr[I]; };
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES-NEXT: auto F5 = [&Arr, elem]() { int &R5 = elem; };
+  // FIXME: this does one copy instead of none. Capture elem by ref?
+
+
+  for (int I = 0; I < N; ++I)
+auto F6 = [&Arr, &I]() { int &R6 = Arr[I]; };
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES-NEXT: auto F6 = [&Arr, &elem]() { int &R6 = elem; };
+
+  for (int I = 0; I < N; ++I) {
+auto F = [Arr, I](int k) {
+  printf("%d\n", Arr[I] + k);
+};
+F(Arr[I]);
+  }
+  // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES-NEXT: auto F = [Arr, elem](int k) {
+  // CHECK-FIXES-NEXT: printf("%d\n", elem + k);
+  // CHECK-FIXES-NEXT: };
+  // CHECK-FIXES-NEXT: F(elem);
+}
+
+void implicitCapture() {
+  const int N = 10;
+  int Arr[N];
+  // Index is used, not convertible.
+  for (int I = 0; I < N; ++I) {
+auto G1 = [&]() {
+  int R = Arr[I];
+  int J = I;
+};
+  }
+
+  for (int I = 0; I < N; ++I) {
+auto G2 = [=]() {
+  int R = Arr[I];
+  int J = I;
+};
+  }
+
+  // Convertible.
+  for (int I = 0; I < N; ++I) {
+auto G3 = [&]() {
+  int R3 = Arr[I];
+  int J3 = Arr[I] + R3;
+};
+  }
+  // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES-NEXT: auto G3 = [&]() {
+  // CHECK-FIXES-NEXT: int R3 = elem;
+  // CHECK-FIXES-NEXT: int J3 = elem + R3;
+
+  for (int I = 0; I < N; ++I) {
+auto G4 = [=]() {
+  int R4 = Arr[I] + 5;
+};
+  }
+  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES-NEXT: auto G4 = [=]() {
+  // CHECK-FIXES-NEXT: int R4 = elem + 5;
+
+  // Alias by value.
+  for (int I = 0; I < N; +

Re: [PATCH] D12597: Two more fixes to loop convert.

2015-09-03 Thread Angel Garcia via cfe-commits
angelgarcia updated this revision to Diff 33936.
angelgarcia added a comment.

Remove unused include.


http://reviews.llvm.org/D12597

Files:
  clang-tidy/modernize/LoopConvertUtils.cpp
  clang-tidy/modernize/LoopConvertUtils.h
  test/clang-tidy/modernize-loop-convert-extra.cpp

Index: test/clang-tidy/modernize-loop-convert-extra.cpp
===
--- test/clang-tidy/modernize-loop-convert-extra.cpp
+++ test/clang-tidy/modernize-loop-convert-extra.cpp
@@ -159,8 +159,17 @@
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto alias : IntArr)
   // CHECK-FIXES-NEXT: for (unsigned j = 0; alias; ++j) {
+
+  struct IntRef { IntRef(const int& i); };
+  for (int i = 0; i < N; ++i) {
+IntRef Int(IntArr[i]);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : IntArr) {
+  // CHECK-FIXES-NEXT: IntRef Int(elem);
 }
 
+
 void refs_and_vals() {
   // The following tests check that the transform correctly preserves the
   // reference or value qualifiers of the aliased variable. That is, if the
@@ -713,3 +722,165 @@
 }
 
 } // namespace Templates
+
+namespace Lambdas {
+
+void capturesIndex() {
+  const int N = 10;
+  int Arr[N];
+  // FIXME: the next four loops could be convertible, if the capture list is
+  // also changed.
+
+  for (int I = 0; I < N; ++I)
+auto F1 = [Arr, I]() { int R1 = Arr[I] + 1; };
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES-NEXT: auto F1 = [Arr, elem]() { int R1 = elem + 1; };
+
+  for (int I = 0; I < N; ++I)
+auto F2 = [Arr, &I]() { int R2 = Arr[I] + 3; };
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES-NEXT: auto F2 = [Arr, &elem]() { int R2 = elem + 3; };
+
+  // FIXME: alias don't work if the index is captured.
+  // Alias declared inside lambda (by value).
+  for (int I = 0; I < N; ++I)
+auto F3 = [&Arr, I]() { int R3 = Arr[I]; };
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES-NEXT: auto F3 = [&Arr, elem]() { int R3 = elem; };
+  // FIXME: this does two copies instead of one. Capture elem by ref?
+
+
+  for (int I = 0; I < N; ++I)
+auto F4 = [&Arr, &I]() { int R4 = Arr[I]; };
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES-NEXT: auto F4 = [&Arr, &elem]() { int R4 = elem; };
+
+  // Alias declared inside lambda (by reference).
+  for (int I = 0; I < N; ++I)
+auto F5 = [&Arr, I]() { int &R5 = Arr[I]; };
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES-NEXT: auto F5 = [&Arr, elem]() { int &R5 = elem; };
+  // FIXME: this does one copy instead of none. Capture elem by ref?
+
+
+  for (int I = 0; I < N; ++I)
+auto F6 = [&Arr, &I]() { int &R6 = Arr[I]; };
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES-NEXT: auto F6 = [&Arr, &elem]() { int &R6 = elem; };
+
+  for (int I = 0; I < N; ++I) {
+auto F = [Arr, I](int k) {
+  printf("%d\n", Arr[I] + k);
+};
+F(Arr[I]);
+  }
+  // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES-NEXT: auto F = [Arr, elem](int k) {
+  // CHECK-FIXES-NEXT: printf("%d\n", elem + k);
+  // CHECK-FIXES-NEXT: };
+  // CHECK-FIXES-NEXT: F(elem);
+}
+
+void implicitCapture() {
+  const int N = 10;
+  int Arr[N];
+  // Index is used, not convertible.
+  for (int I = 0; I < N; ++I) {
+auto G1 = [&]() {
+  int R = Arr[I];
+  int J = I;
+};
+  }
+
+  for (int I = 0; I < N; ++I) {
+auto G2 = [=]() {
+  int R = Arr[I];
+  int J = I;
+};
+  }
+
+  // Convertible.
+  for (int I = 0; I < N; ++I) {
+auto G3 = [&]() {
+  int R3 = Arr[I];
+  int J3 = Arr[I] + R3;
+};
+  }
+  // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES-NEXT: auto G3 = [&]() {
+  // CHECK-FIXES-NEXT: int R3 = elem;
+  // CHECK-FIXES-NEXT: int J3 = elem + R3;
+
+  for (int I = 0; I < N; ++I) {
+auto G4 = [=]() {
+  int R4 = Arr[I] + 5;
+};
+  }
+  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES-NEXT: auto G4 = [=]() {
+  // CHECK-FIXES-NEXT: int R4 = elem + 5;
+
+  // Alias by value.
+  for (int I = 0; I < N; ++I) {
+auto G5 = [&]() {
+  int R5 = Arr[I];
+  int J5 = 8 + R5;
+};
+  }
+  // CHECK-MESSAGES: :[[@LINE-6]

Re: [PATCH] D12597: Two more fixes to loop convert.

2015-09-03 Thread Manuel Klimek via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

lg


http://reviews.llvm.org/D12597



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


Re: [PATCH] D12148: [ARM] Allow passing/returning of __fp16 arguments

2015-09-03 Thread Renato Golin via cfe-commits
rengolin added a comment.

I don't like the idea of making it language-specific, but I don't have a better 
idea. I don't know if there are support flags in Clang's languages like we have 
for back-ends. Anyway, this should fix the current problem. Maybe adding a 
comment to that effect on the usage of !CL?

LGTM.


http://reviews.llvm.org/D12148



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


[clang-tools-extra] r246762 - Two more fixes to loop convert.

2015-09-03 Thread Angel Garcia Gomez via cfe-commits
Author: angelgarcia
Date: Thu Sep  3 07:28:11 2015
New Revision: 246762

URL: http://llvm.org/viewvc/llvm-project?rev=246762&view=rev
Log:
Two more fixes to loop convert.

Summary: Ensure that the alias has the same type than the loop variable. Now it 
works with lambda captures.

Reviewers: klimek

Subscribers: alexfh, cfe-commits

Differential Revision: http://reviews.llvm.org/D12597

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.h
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp?rev=246762&r1=246761&r2=246762&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp Thu Sep  
3 07:28:11 2015
@@ -334,7 +334,8 @@ static bool isDereferenceOfUop(const Una
 /// // use t, do not use i
 ///   }
 /// \endcode
-static bool isAliasDecl(const Decl *TheDecl, const VarDecl *IndexVar) {
+static bool isAliasDecl(ASTContext *Context, const Decl *TheDecl,
+const VarDecl *IndexVar) {
   const auto *VDecl = dyn_cast(TheDecl);
   if (!VDecl)
 return false;
@@ -346,6 +347,15 @@ static bool isAliasDecl(const Decl *TheD
   if (!Init)
 return false;
 
+  // Check that the declared type is the same as (or a reference to) the
+  // container type.
+  QualType DeclarationType = VDecl->getType();
+  if (DeclarationType->isReferenceType())
+DeclarationType = DeclarationType.getNonReferenceType();
+  QualType InitType = Init->getType();
+  if (!Context->hasSameUnqualifiedType(DeclarationType, InitType))
+return false;
+
   switch (Init->getStmtClass()) {
   case Stmt::ArraySubscriptExprClass: {
 const auto *E = cast(Init);
@@ -711,13 +721,49 @@ bool ForLoopIndexUseVisitor::VisitDeclRe
   return true;
 }
 
+/// \brief If the loop index is captured by a lambda, replace this capture
+/// by the range-for loop variable.
+///
+/// For example:
+/// \code
+///   for (int i = 0; i < N; ++i) {
+/// auto f = [v, i](int k) {
+///   printf("%d\n", v[i] + k);
+/// };
+/// f(v[i]);
+///   }
+/// \endcode
+///
+/// Will be replaced by:
+/// \code
+///   for (auto & elem : v) {
+/// auto f = [v, elem](int k) {
+///   printf("%d\n", elem + k);
+/// };
+/// f(elem);
+///   }
+/// \endcode
+bool ForLoopIndexUseVisitor::TraverseLambdaCapture(LambdaExpr *LE,
+   const LambdaCapture *C) {
+  if (C->capturesVariable()) {
+const VarDecl* VDecl = C->getCapturedVar();
+if (areSameVariable(IndexVar, cast(VDecl))) {
+  // FIXME: if the index is captured, it will count as an usage and the
+  // alias (if any) won't work, because it is only used in case of having
+  // exactly one usage.
+  Usages.push_back(Usage(nullptr, false, C->getLocation()));
+}
+  }
+  return VisitorBase::TraverseLambdaCapture(LE, C);
+}
+
 /// \brief If we find that another variable is created just to refer to the 
loop
 /// element, note it for reuse as the loop variable.
 ///
 /// See the comments for isAliasDecl.
 bool ForLoopIndexUseVisitor::VisitDeclStmt(DeclStmt *S) {
   if (!AliasDecl && S->isSingleDecl() &&
-  isAliasDecl(S->getSingleDecl(), IndexVar)) {
+  isAliasDecl(Context, S->getSingleDecl(), IndexVar)) {
 AliasDecl = S;
 if (CurrStmtParent) {
   if (isa(CurrStmtParent) || isa(CurrStmtParent) ||

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.h?rev=246762&r1=246761&r2=246762&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.h (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.h Thu Sep  3 
07:28:11 2015
@@ -309,6 +309,7 @@ private:
   bool TraverseArraySubscriptExpr(ArraySubscriptExpr *E);
   bool TraverseCXXMemberCallExpr(CXXMemberCallExpr *MemberCall);
   bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *OpCall);
+  bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C);
   bool TraverseMemberExpr(MemberExpr *Member);
   bool TraverseUnaryDeref(UnaryOperator *Uop);
   bool VisitDeclRefExpr(DeclRefExpr *E);

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp?rev=246762&r1=246761&r2=246762&view=diff
==
--- clang-tools-extra

Re: [PATCH] D12244: Implement ACLE 2.0 macros of chapters 6.4 and 6.5 for [ARM] and [Aarch64] targets

2015-09-03 Thread Alexandros Lamprineas via cfe-commits
labrinea added inline comments.


Comment at: lib/Basic/Targets.cpp:4790
@@ +4789,3 @@
+  Builder.defineMacro("__ARM_FEATURE_SAT", "1");
+  Builder.defineMacro("__ARM_FEATURE_QBIT", "1");
+}

rengolin wrote:
> Isn't there a combination where you'll emit this macro twice?
This could be addressed as:

```
bool hasDSP = false;
if (is5EOrAbove && is32Bit && (CPUProfile != "M" || CPUAttr  == "7EM")) {
  Builder.defineMacro("__ARM_FEATURE_DSP", "1");
  hasDSP = true;
}

bool hasSAT = false;
if ((ArchVersion == 6 && CPUProfile != "M") || ArchVersion > 6 ) {
  Builder.defineMacro("__ARM_FEATURE_SAT", "1");
  hasSAT = true;
}

if (hasDSP || hasSAT)
  Builder.defineMacro("__ARM_FEATURE_QBIT", "1");
```


http://reviews.llvm.org/D12244



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


r246764 - [ARM] Allow passing/returning of __fp16 arguments

2015-09-03 Thread Oliver Stannard via cfe-commits
Author: olista01
Date: Thu Sep  3 07:40:58 2015
New Revision: 246764

URL: http://llvm.org/viewvc/llvm-project?rev=246764&view=rev
Log:
[ARM] Allow passing/returning of __fp16 arguments

The ACLE (ARM C Language Extensions) 2.0 allows the __fp16 type to be
used as a functon argument or return type (ACLE 1.1 did not).

The current public release of the AAPCS (2.09) states that __fp16 values
should be converted to single-precision before being passed or returned,
but AAPCS 2.10 (to be released shortly) changes this, so that they are
passed in the least-significant 16 bits of either a GPR (for base AAPCS)
or a single-precision register (for AAPCS-VFP). This does not change how
arguments are passed if they get passed on the stack.

This patch brings clang up to compliance with the latest versions of
both of these specs.

We can now set the __ARM_FP16_ARGS ACLE predefine, and we have always
been able to set the __ARM_FP16_FORMAT_IEEE predefine (we do not support
the alternative format).


Added:
cfe/trunk/test/CodeGen/arm-fp16-arguments.c
Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Preprocessor/arm-acle-6.5.c
cfe/trunk/test/Preprocessor/arm-target-features.c

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=246764&r1=246763&r2=246764&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Sep  3 07:40:58 2015
@@ -4568,6 +4568,10 @@ public:
 // ACLE predefines.
 Builder.defineMacro("__ARM_ACLE", "200");
 
+// FP16 support (we currently only support IEEE format).
+Builder.defineMacro("__ARM_FP16_FORMAT_IEEE", "1");
+Builder.defineMacro("__ARM_FP16_ARGS", "1");
+
 // Subtarget options.
 
 // FIXME: It's more complicated than this and we don't really support

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=246764&r1=246763&r2=246764&view=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Thu Sep  3 07:40:58 2015
@@ -4714,6 +4714,16 @@ ABIArgInfo ARMABIInfo::classifyArgumentT
 return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
   }
 
+  // __fp16 gets passed as if it were an int or float, but with the top 16 bits
+  // unspecified. This is not done for OpenCL as it handles the half type
+  // natively, and does not need to interwork with AAPCS code.
+  if (Ty->isHalfType() && !getContext().getLangOpts().OpenCL) {
+llvm::Type *ResType = IsEffectivelyAAPCS_VFP ?
+  llvm::Type::getFloatTy(getVMContext()) :
+  llvm::Type::getInt32Ty(getVMContext());
+return ABIArgInfo::getDirect(ResType);
+  }
+
   if (!isAggregateTypeForABI(Ty)) {
 // Treat an enum type as its underlying type.
 if (const EnumType *EnumTy = Ty->getAs()) {
@@ -4872,6 +4882,16 @@ ABIArgInfo ARMABIInfo::classifyReturnTyp
 return ABIArgInfo::getIndirect(0);
   }
 
+  // __fp16 gets returned as if it were an int or float, but with the top 16
+  // bits unspecified. This is not done for OpenCL as it handles the half type
+  // natively, and does not need to interwork with AAPCS code.
+  if (RetTy->isHalfType() && !getContext().getLangOpts().OpenCL) {
+llvm::Type *ResType = IsEffectivelyAAPCS_VFP ?
+  llvm::Type::getFloatTy(getVMContext()) :
+  llvm::Type::getInt32Ty(getVMContext());
+return ABIArgInfo::getDirect(ResType);
+  }
+
   if (!isAggregateTypeForABI(RetTy)) {
 // Treat an enum type as its underlying type.
 if (const EnumType *EnumTy = RetTy->getAs())

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=246764&r1=246763&r2=246764&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Sep  3 07:40:58 2015
@@ -4293,9 +4293,19 @@ void Clang::ConstructJob(Compilation &C,
   CmdArgs.push_back("-mstack-probe-size=0");
   }
 
-  if (getToolChain().getArch() == llvm::Triple::aarch64 ||
-  getToolChain().getArch() == llvm::Triple::aarch64_be)
+  switch (getToolChain().getArch()) {
+  case llvm::Triple::aarch64:
+  case llvm::Triple::aarch64_be:
+  case llvm::Triple::arm:
+  case llvm::Triple::armeb:
+  case llvm::Triple::thumb:
+  case llvm::Triple::thumbeb:
 CmdArgs.push_back("-fallow-half-arguments-and-returns");
+break;
+
+  default:
+break;
+  }
 
   if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it,
options::OPT_mno_restrict_it)) {

Added: cfe/trunk/test/CodeGen/arm-fp16-arguments.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/C

Re: [PATCH] D12148: [ARM] Allow passing/returning of __fp16 arguments

2015-09-03 Thread Oliver Stannard via cfe-commits
olista01 added a comment.

Committed as r246764, with an additional comment explaining why we don't do 
this for OpenCL.


http://reviews.llvm.org/D12148



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


Re: [PATCH] D12244: Implement ACLE 2.0 macros of chapters 6.4 and 6.5 for [ARM] and [Aarch64] targets

2015-09-03 Thread Renato Golin via cfe-commits
rengolin added inline comments.


Comment at: lib/Basic/Targets.cpp:4790
@@ +4789,3 @@
+  Builder.defineMacro("__ARM_FEATURE_SAT", "1");
+  Builder.defineMacro("__ARM_FEATURE_QBIT", "1");
+}

labrinea wrote:
> rengolin wrote:
> > Isn't there a combination where you'll emit this macro twice?
> This could be addressed as:
> 
> ```
> bool hasDSP = false;
> if (is5EOrAbove && is32Bit && (CPUProfile != "M" || CPUAttr  == "7EM")) {
>   Builder.defineMacro("__ARM_FEATURE_DSP", "1");
>   hasDSP = true;
> }
> 
> bool hasSAT = false;
> if ((ArchVersion == 6 && CPUProfile != "M") || ArchVersion > 6 ) {
>   Builder.defineMacro("__ARM_FEATURE_SAT", "1");
>   hasSAT = true;
> }
> 
> if (hasDSP || hasSAT)
>   Builder.defineMacro("__ARM_FEATURE_QBIT", "1");
> ```
Yup, that looks good.


http://reviews.llvm.org/D12244



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


Re: [PATCH] D12244: Implement ACLE 2.0 macros of chapters 6.4 and 6.5 for [ARM] and [Aarch64] targets

2015-09-03 Thread Alexandros Lamprineas via cfe-commits
labrinea added a comment.

This means accepted?


http://reviews.llvm.org/D12244



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


Re: [PATCH] D12244: Implement ACLE 2.0 macros of chapters 6.4 and 6.5 for [ARM] and [Aarch64] targets

2015-09-03 Thread Renato Golin via cfe-commits
rengolin accepted this revision.
rengolin added a comment.
This revision is now accepted and ready to land.

With the changes you proposed, LGTM. Thanks!


http://reviews.llvm.org/D12244



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


r246765 - [mips] Added support for choosing between traps and breaks in the integrated assembler macros.

2015-09-03 Thread Daniel Sanders via cfe-commits
Author: dsanders
Date: Thu Sep  3 07:58:39 2015
New Revision: 246765

URL: http://llvm.org/viewvc/llvm-project?rev=246765&view=rev
Log:
[mips] Added support for choosing between traps and breaks in the integrated 
assembler macros.

Summary: The command line options for these are -Wa,--trap and -Wa,--break.

Patch by Scott Egerton.

Reviewers: vkalintiris, dsanders

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D11676

Added:
cfe/trunk/test/Driver/mips-ias-Wa.s
Modified:
cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=246765&r1=246764&r2=246765&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Sep  3 07:58:39 2015
@@ -2335,6 +2335,12 @@ static void CollectArgsForIntegratedAsse
   } else if (Value.startswith("-mcpu") || Value.startswith("-mfpu") ||
  Value.startswith("-mhwdiv") || Value.startswith("-march")) {
 // Do nothing, we'll validate it later.
+  } else if (Value == "--trap") {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("+use-tcc-in-div");
+  } else if (Value == "--break") {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("-use-tcc-in-div");
   } else {
 D.Diag(diag::err_drv_unsupported_option_argument)
 << A->getOption().getName() << Value;

Added: cfe/trunk/test/Driver/mips-ias-Wa.s
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/mips-ias-Wa.s?rev=246765&view=auto
==
--- cfe/trunk/test/Driver/mips-ias-Wa.s (added)
+++ cfe/trunk/test/Driver/mips-ias-Wa.s Thu Sep  3 07:58:39 2015
@@ -0,0 +1,24 @@
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=TRAP-DEFAULT %s
+// TRAP-DEFAULT: -cc1as
+// TRAP-DEFAULT-NOT: "-target-feature" "-use-tcc-in-div"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -Wa,--trap 
2>&1 | \
+// RUN:   FileCheck -check-prefix=TRAP-ON %s
+// TRAP-ON: -cc1as
+// TRAP-ON: "-target-feature" "+use-tcc-in-div"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -Wa,--break 
2>&1 | \
+// RUN:   FileCheck -check-prefix=TRAP-OFF %s
+// TRAP-OFF: -cc1as
+// TRAP-OFF: "-target-feature" "-use-tcc-in-div"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 
-Wa,--trap,--break 2>&1 | \
+// RUN:   FileCheck -check-prefix=TRAP-BOTH-TRAP-FIRST %s
+// TRAP-BOTH-TRAP-FIRST: -cc1as
+// TRAP-BOTH-TRAP-FIRST: "-target-feature" "+use-tcc-in-div" "-target-feature" 
"-use-tcc-in-div"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 
-Wa,--break,--trap 2>&1 | \
+// RUN:   FileCheck -check-prefix=TRAP-BOTH-BREAK-FIRST %s
+// TRAP-BOTH-BREAK-FIRST: -cc1as
+// TRAP-BOTH-BREAK-FIRST: "-target-feature" "-use-tcc-in-div" 
"-target-feature" "+use-tcc-in-div"


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


[PATCH] D12598: clang should emulate GCC's -fabi-version=

2015-09-03 Thread Stefan Teleman via cfe-commits
steleman created this revision.
steleman added a subscriber: cfe-commits.

This changeset provides an implementation of GCC's -fabi-version= flag.

-fabi-version is documented at GCC here:
https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html

GCC implements it here:
${top_srcdir}/gcc/c-family/c-cppbuiltin.c



http://reviews.llvm.org/D12598

Files:
  tools/clang/include/clang/Basic/LangOptions.def
  tools/clang/include/clang/Driver/Options.td
  tools/clang/lib/Driver/Tools.cpp
  tools/clang/lib/Frontend/CompilerInvocation.cpp
  tools/clang/lib/Frontend/InitPreprocessor.cpp

Index: tools/clang/lib/Driver/Tools.cpp
===
--- tools/clang/lib/Driver/Tools.cpp
+++ tools/clang/lib/Driver/Tools.cpp
@@ -2812,6 +2812,12 @@
 CmdArgs.push_back(A->getValue());
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_fabi_version_EQ)) {
+StringRef v = A->getValue();
+CmdArgs.push_back(Args.MakeArgString("-fabi-version=" + v));
+A->claim();
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_fpcc_struct_return,
options::OPT_freg_struct_return)) {
 if (getToolChain().getArch() != llvm::Triple::x86) {
Index: tools/clang/include/clang/Driver/Options.td
===
--- tools/clang/include/clang/Driver/Options.td
+++ tools/clang/include/clang/Driver/Options.td
@@ -574,6 +574,8 @@
 def ffp_contract : Joined<["-"], "ffp-contract=">, Group,
   Flags<[CC1Option]>, HelpText<"Form fused FP ops (e.g. FMAs): fast 
(everywhere)"
   " | on (according to FP_CONTRACT pragma, default) | off (never fuse)">;
+def fabi_version_EQ : Joined<["-"], "fabi-version=">, Group,
+  Flags<[CC1Option]>, HelpText<"Use specified GNU C++ ABI version">;
 
 def ffor_scope : Flag<["-"], "ffor-scope">, Group;
 def fno_for_scope : Flag<["-"], "fno-for-scope">, Group;
Index: tools/clang/lib/Frontend/CompilerInvocation.cpp
===
--- tools/clang/lib/Frontend/CompilerInvocation.cpp
+++ tools/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1539,6 +1539,7 @@
   Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls);
   Opts.PackStruct = getLastArgIntValue(Args, OPT_fpack_struct_EQ, 0, Diags);
   Opts.MaxTypeAlign = getLastArgIntValue(Args, OPT_fmax_type_align_EQ, 0, 
Diags);
+  Opts.GXXABIVersion = getLastArgIntValue(Args, OPT_fabi_version_EQ, 0, Diags);
   Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags);
   Opts.PIELevel = getLastArgIntValue(Args, OPT_pie_level, 0, Diags);
   Opts.Static = Args.hasArg(OPT_static_define);
Index: tools/clang/lib/Frontend/InitPreprocessor.cpp
===
--- tools/clang/lib/Frontend/InitPreprocessor.cpp
+++ tools/clang/lib/Frontend/InitPreprocessor.cpp
@@ -479,7 +479,31 @@
 Builder.defineMacro("__GNUC_MINOR__", "2");
 Builder.defineMacro("__GNUC_PATCHLEVEL__", "1");
 Builder.defineMacro("__GNUC__", "4");
+// GCC provides a number of C++ ABI Versions in:
+// ${top_srcdir}/gcc/c-family/c-cppbuiltin.c
+// Currently valid GXX ABI Versions are documented here:
+// https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html
+// clang only supports a subset.
+switch (LangOpts.GXXABIVersion) {
+default:
 Builder.defineMacro("__GXX_ABI_VERSION", "1002");
+  break;
+case 4:
+  Builder.defineMacro("__GXX_ABI_VERSION", "1004");
+  break;
+case 5:
+  Builder.defineMacro("__GXX_ABI_VERSION", "1005");
+  break;
+case 6:
+  Builder.defineMacro("__GXX_ABI_VERSION", "1006");
+  break;
+case 7:
+  Builder.defineMacro("__GXX_ABI_VERSION", "1007");
+  break;
+case 8:
+  Builder.defineMacro("__GXX_ABI_VERSION", "1008");
+  break;
+}
   }
 
   // Define macros for the C11 / C++11 memory orderings
Index: tools/clang/include/clang/Basic/LangOptions.def
===
--- tools/clang/include/clang/Basic/LangOptions.def
+++ tools/clang/include/clang/Basic/LangOptions.def
@@ -134,6 +134,8 @@
   "default struct packing maximum alignment")
 VALUE_LANGOPT(MaxTypeAlign  , 32, 0,
   "default maximum alignment for types")
+VALUE_LANGOPT(GXXABIVersion , 32, 0,
+  "Use specified GNU C++ Standard Library ABI version")
 VALUE_LANGOPT(PICLevel, 2, 0, "__PIC__ level")
 VALUE_LANGOPT(PIELevel, 2, 0, "__PIE__ level")
 LANGOPT(GNUInline , 1, 0, "GNU inline semantics")


Index: tools/clang/lib/Driver/Tools.cpp
===
--- tools/clang/lib/Driver/Tools.cpp
+++ tools/clang/lib/Driver/Tools.cpp
@@ -2812,6 +2812,12 @@
 CmdArgs.push_back(A->getValue());
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_fabi_version_EQ)) {
+StringRef v = A->getValue();
+CmdArgs.push_back(Args.MakeArgS

Re: [PATCH] D12598: clang should emulate GCC's -fabi-version=

2015-09-03 Thread Stefan Teleman via cfe-commits
steleman added a comment.

The diff is based on 3.6.2.


http://reviews.llvm.org/D12598



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


Re: [PATCH] D12087: always_inline codegen rewrite

2015-09-03 Thread Yaron Keren via cfe-commits
yaron.keren added a comment.

In CGCXX.cpp, may be fixable after this commit:

  // FIXME: An extern template instantiation will create functions with
  // linkage "AvailableExternally". In libc++, some classes also define
  // members with attribute "AlwaysInline" and expect no reference to
  // be generated. It is desirable to reenable this optimisation after
  // corresponding LLVM changes.


Repository:
  rL LLVM

http://reviews.llvm.org/D12087



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


Re: [PATCH] D10599: [OPENMP 4.0] Initial support for '#pragma omp declare simd' directive.

2015-09-03 Thread Alexey Bataev via cfe-commits
ABataev added a comment.

Ping


http://reviews.llvm.org/D10599



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


Re: [PATCH] D11182: [OPENMP 4.0] Initial support for 'omp declare reduction' construct.

2015-09-03 Thread Alexey Bataev via cfe-commits
ABataev added a comment.

Ping


http://reviews.llvm.org/D11182



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


Re: [PATCH] D12547: Add support for function attribute "disable_tail_calls"

2015-09-03 Thread Aaron Ballman via cfe-commits
aaron.ballman added inline comments.


Comment at: include/clang/Basic/Attr.td:894
@@ -893,1 +893,3 @@
 
+def DisableTailCalls : InheritableAttr {
+  let Spellings = [GNU<"disable_tail_calls">,

Pardon me if this is obvious, but -- are there times when you would want to 
disable tail calls but leave other optimizations in place? I'm trying to 
understand why these attributes are orthogonal.


Comment at: include/clang/Basic/Attr.td:896
@@ +895,3 @@
+  let Spellings = [GNU<"disable_tail_calls">,
+   CXX11<"clang", "disable_tail_calls">];
+  let Subjects = SubjectList<[Function, ObjCMethod]>;

Should this attribute be plural? Are there multiple tail calls within a single 
method that can be optimized away?


Comment at: include/clang/Basic/AttrDocs.td:1619
@@ +1618,3 @@
+  let Content = [{
+Use ``__attribute__((disable_tail_calls)))`` to instruct the backend not to do 
tail call optimization.
+  }];

I would avoid using the exact syntax here because this is a GNU and C++ 
attribute. Could just say:

The ``disable_tail_calls`` attribute instructs the backend to not perform tail 
call optimization.


Comment at: lib/Sema/SemaDeclAttr.cpp:4882
@@ +4881,3 @@
+  case AttributeList::AT_DisableTailCalls:
+handleSimpleAttribute(S, D, Attr);
+break;

Okay, that makes sense. I can contrive examples of noreturn where TCO could 
happen, it just took me a while to think of them. ;-)

What about other semantic checks, like warning the user about disabling TCO 
when TCO could never be enabled in the first place? Can you disable TCO for 
functions that are marked __attribute__((naked))? What about returns_twice?

Unfortunately, we have a lot of attributes for which we've yet to write 
documentation, so you may need to look through Attr.td.


http://reviews.llvm.org/D12547



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


Re: [PATCH] D12547: Add support for function attribute "disable_tail_calls"

2015-09-03 Thread Aaron Ballman via cfe-commits
Oops, apologies for making this harder than it needs to be. It seems
phab didn't provide context to these comments. Check out the phab
review link for more context, if you'd like it.

~Aaron

On Thu, Sep 3, 2015 at 9:48 AM, Aaron Ballman  wrote:
> aaron.ballman added inline comments.
>
> 
> Comment at: include/clang/Basic/Attr.td:894
> @@ -893,1 +893,3 @@
>
> +def DisableTailCalls : InheritableAttr {
> +  let Spellings = [GNU<"disable_tail_calls">,
> 
> Pardon me if this is obvious, but -- are there times when you would want to 
> disable tail calls but leave other optimizations in place? I'm trying to 
> understand why these attributes are orthogonal.
>
> 
> Comment at: include/clang/Basic/Attr.td:896
> @@ +895,3 @@
> +  let Spellings = [GNU<"disable_tail_calls">,
> +   CXX11<"clang", "disable_tail_calls">];
> +  let Subjects = SubjectList<[Function, ObjCMethod]>;
> 
> Should this attribute be plural? Are there multiple tail calls within a 
> single method that can be optimized away?
>
> 
> Comment at: include/clang/Basic/AttrDocs.td:1619
> @@ +1618,3 @@
> +  let Content = [{
> +Use ``__attribute__((disable_tail_calls)))`` to instruct the backend not to 
> do tail call optimization.
> +  }];
> 
> I would avoid using the exact syntax here because this is a GNU and C++ 
> attribute. Could just say:
>
> The ``disable_tail_calls`` attribute instructs the backend to not perform 
> tail call optimization.
>
> 
> Comment at: lib/Sema/SemaDeclAttr.cpp:4882
> @@ +4881,3 @@
> +  case AttributeList::AT_DisableTailCalls:
> +handleSimpleAttribute(S, D, Attr);
> +break;
> 
> Okay, that makes sense. I can contrive examples of noreturn where TCO could 
> happen, it just took me a while to think of them. ;-)
>
> What about other semantic checks, like warning the user about disabling TCO 
> when TCO could never be enabled in the first place? Can you disable TCO for 
> functions that are marked __attribute__((naked))? What about returns_twice?
>
> Unfortunately, we have a lot of attributes for which we've yet to write 
> documentation, so you may need to look through Attr.td.
>
>
> http://reviews.llvm.org/D12547
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r246768 - Implement ACLE 2.0 macros of chapters 6.4 and 6.5 for [ARM] and [Aarch64] targets.

2015-09-03 Thread Alexandros Lamprineas via cfe-commits
Author: alelab01
Date: Thu Sep  3 09:40:57 2015
New Revision: 246768

URL: http://llvm.org/viewvc/llvm-project?rev=246768&view=rev
Log:
Implement ACLE 2.0 macros of chapters 6.4 and 6.5 for [ARM] and [Aarch64] 
targets.
Differential Revision: http://reviews.llvm.org/D12244

Change-Id: Iffd4e822c15e18668fe8868278230ff232ef50aa

Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/test/Preprocessor/aarch64-target-features.c
cfe/trunk/test/Preprocessor/arm-acle-6.4.c
cfe/trunk/test/Preprocessor/arm-acle-6.5.c

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=246768&r1=246767&r2=246768&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Sep  3 09:40:57 2015
@@ -4081,6 +4081,16 @@ class ARMTargetInfo : public TargetInfo
 
   unsigned CRC : 1;
   unsigned Crypto : 1;
+  unsigned Unaligned : 1;
+
+  enum {
+LDREX_B = (1 << 0), /// byte (8-bit)
+LDREX_H = (1 << 1), /// half (16-bit)
+LDREX_W = (1 << 2), /// word (32-bit)
+LDREX_D = (1 << 3), /// double (64-bit)
+  };
+
+  uint32_t LDREX;
 
   // ACLE 6.5.1 Hardware floating point
   enum {
@@ -4299,7 +4309,7 @@ class ARMTargetInfo : public TargetInfo
 public:
   ARMTargetInfo(const llvm::Triple &Triple, bool IsBigEndian)
   : TargetInfo(Triple), CPU("arm1136j-s"), FPMath(FP_Default),
-IsAAPCS(true), HW_FP(0) {
+IsAAPCS(true), LDREX(0), HW_FP(0) {
 BigEndian = IsBigEndian;
 
 switch (getTriple().getOS()) {
@@ -4426,6 +4436,11 @@ public:
CPU == "sc300" || CPU == "cortex-r4" || CPU == "cortex-r4f") {
   Features["hwdiv"] = true;
 }
+
+if (ArchVersion < 6  || 
+   (ArchVersion == 6 && ArchProfile == llvm::ARM::PK_M))
+  Features["strict-align"] = true;
+
 return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
   }
 
@@ -4434,6 +4449,7 @@ public:
 FPU = 0;
 CRC = 0;
 Crypto = 0;
+Unaligned = 1;
 SoftFloat = SoftFloatABI = false;
 HWDiv = 0;
 
@@ -4470,10 +4486,33 @@ public:
 Crypto = 1;
   } else if (Feature == "+fp-only-sp") {
 HW_FP_remove |= HW_FP_DP | HW_FP_HP;
+  } else if (Feature == "+strict-align") {
+Unaligned = 0;
+  } else if (Feature == "+fp16") {
+HW_FP |= HW_FP_HP;
   }
 }
 HW_FP &= ~HW_FP_remove;
 
+switch (ArchVersion) {
+case 6:
+  if (ArchProfile == llvm::ARM::PK_M)
+LDREX = 0;
+  else if (ArchKind == llvm::ARM::AK_ARMV6K)
+LDREX = LDREX_D | LDREX_W | LDREX_H | LDREX_B ;
+  else
+LDREX = LDREX_W;
+  break;
+case 7:
+  if (ArchProfile == llvm::ARM::PK_M)
+LDREX = LDREX_W | LDREX_H | LDREX_B ;
+  else
+LDREX = LDREX_D | LDREX_W | LDREX_H | LDREX_B ;
+  break;
+case 8:
+  LDREX = LDREX_D | LDREX_W | LDREX_H | LDREX_B ;
+}
+
 if (!(FPU & NeonFPU) && FPMath == FP_Neon) {
   Diags.Report(diag::err_target_unsupported_fpmath) << "neon";
   return false;
@@ -4532,9 +4571,18 @@ public:
 // ACLE 6.4.1 ARM/Thumb instruction set architecture
 // __ARM_ARCH is defined as an integer value indicating the current ARM ISA
 Builder.defineMacro("__ARM_ARCH", llvm::utostr(ArchVersion));
+
 if (ArchVersion >= 8) {
-  Builder.defineMacro("__ARM_FEATURE_NUMERIC_MAXMIN");
-  Builder.defineMacro("__ARM_FEATURE_DIRECTED_ROUNDING");
+  // ACLE 6.5.7 Crypto Extension
+  if (Crypto)
+Builder.defineMacro("__ARM_FEATURE_CRYPTO", "1");
+  // ACLE 6.5.8 CRC32 Extension
+  if (CRC)
+Builder.defineMacro("__ARM_FEATURE_CRC32", "1");
+  // ACLE 6.5.10 Numeric Maximum and Minimum
+  Builder.defineMacro("__ARM_FEATURE_NUMERIC_MAXMIN", "1");
+  // ACLE 6.5.9 Directed Rounding
+  Builder.defineMacro("__ARM_FEATURE_DIRECTED_ROUNDING", "1");
 }
 
 // __ARM_ARCH_ISA_ARM is defined to 1 if the core supports the ARM ISA.  It
@@ -4561,6 +4609,20 @@ public:
 if (!CPUProfile.empty())
   Builder.defineMacro("__ARM_ARCH_PROFILE", "'" + CPUProfile + "'");
 
+// ACLE 6.4.3 Unaligned access supported in hardware
+if (Unaligned) 
+  Builder.defineMacro("__ARM_FEATURE_UNALIGNED", "1");
+ 
+// ACLE 6.4.4 LDREX/STREX
+if (LDREX)
+  Builder.defineMacro("__ARM_FEATURE_LDREX", "0x" + 
llvm::utohexstr(LDREX));
+
+// ACLE 6.4.5 CLZ
+if (ArchVersion == 5 || 
+   (ArchVersion == 6 && CPUProfile != "M") || 
+ArchVersion >  6) 
+  Builder.defineMacro("__ARM_FEATURE_CLZ", "1");
+
 // ACLE 6.5.1 Hardware Floating Point
 if (HW_FP)
   Builder.defineMacro("__ARM_FP", "0x" + llvm::utohexstr(HW_FP));
@@ -4572,6 +4634,10 @@ public:
 Builder.defineMacro("__ARM_FP16_FORMAT_IEEE", "1");
 Builder.defineMacro("__ARM_FP16_ARGS", "1");
 
+// ACLE 6.5.3 Fused multiply-accumulate (FMA)
+if

Re: [PATCH] D12471: Correct documentation for numSelectorArgs matcher

2015-09-03 Thread Manuel Klimek via cfe-commits
klimek added a reviewer: dfsuther.
klimek added a comment.

+Dean, as I really don't know Obj-C (sorry for the delay in reply, was on 
vacation)


http://reviews.llvm.org/D12471



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


[libcxx] r246772 - Make a helper routine __throw_future_error, and encapsulate the #ifdef _LIBCPP_NO_EXCEPTIONS there, instead of duplicating it throughout the code. No functionality change

2015-09-03 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Sep  3 10:11:32 2015
New Revision: 246772

URL: http://llvm.org/viewvc/llvm-project?rev=246772&view=rev
Log:
Make a helper routine __throw_future_error, and encapsulate the #ifdef 
_LIBCPP_NO_EXCEPTIONS there, instead of duplicating it throughout the code. No 
functionality change

Modified:
libcxx/trunk/include/future

Modified: libcxx/trunk/include/future
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/future?rev=246772&r1=246771&r2=246772&view=diff
==
--- libcxx/trunk/include/future (original)
+++ libcxx/trunk/include/future Thu Sep  3 10:11:32 2015
@@ -512,6 +512,17 @@ public:
 virtual ~future_error() _NOEXCEPT;
 };
 
+template 
+_LIBCPP_ALWAYS_INLINE
+void __throw_future_error()
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+throw future_error(make_error_code(_Ev));
+#else
+assert(!"future_error");
+#endif
+}
+
 class _LIBCPP_TYPE_VIS __assoc_sub_state
 : public __shared_count
 {
@@ -645,10 +656,8 @@ __assoc_state<_Rp>::set_value(_Arg& __ar
 #endif
 {
 unique_lock __lk(this->__mut_);
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (this->__has_value())
-throw 
future_error(make_error_code(future_errc::promise_already_satisfied));
-#endif
+__throw_future_error();
 ::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg));
 this->__state_ |= base::__constructed | base::ready;
 __cv_.notify_all();
@@ -664,10 +673,8 @@ __assoc_state<_Rp>::set_value_at_thread_
 #endif
 {
 unique_lock __lk(this->__mut_);
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (this->__has_value())
-throw 
future_error(make_error_code(future_errc::promise_already_satisfied));
-#endif
+__throw_future_error();
 ::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg));
 this->__state_ |= base::__constructed;
 __thread_local_data()->__make_ready_at_thread_exit(this);
@@ -725,10 +732,8 @@ void
 __assoc_state<_Rp&>::set_value(_Rp& __arg)
 {
 unique_lock __lk(this->__mut_);
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (this->__has_value())
-throw 
future_error(make_error_code(future_errc::promise_already_satisfied));
-#endif
+__throw_future_error();
 __value_ = _VSTD::addressof(__arg);
 this->__state_ |= base::__constructed | base::ready;
 __cv_.notify_all();
@@ -739,10 +744,8 @@ void
 __assoc_state<_Rp&>::set_value_at_thread_exit(_Rp& __arg)
 {
 unique_lock __lk(this->__mut_);
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (this->__has_value())
-throw 
future_error(make_error_code(future_errc::promise_already_satisfied));
-#endif
+__throw_future_error();
 __value_ = _VSTD::addressof(__arg);
 this->__state_ |= base::__constructed;
 __thread_local_data()->__make_ready_at_thread_exit(this);
@@ -1138,10 +1141,8 @@ template 
 future<_Rp>::future(__assoc_state<_Rp>* __state)
 : __state_(__state)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (__state_->__has_future_attached())
-throw 
future_error(make_error_code(future_errc::future_already_retrieved));
-#endif
+__throw_future_error();
 __state_->__add_shared();
 __state_->__set_future_attached();
 }
@@ -1242,10 +1243,8 @@ template 
 future<_Rp&>::future(__assoc_state<_Rp&>* __state)
 : __state_(__state)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (__state_->__has_future_attached())
-throw 
future_error(make_error_code(future_errc::future_already_retrieved));
-#endif
+__throw_future_error();
 __state_->__add_shared();
 __state_->__set_future_attached();
 }
@@ -1445,10 +1444,8 @@ template 
 future<_Rp>
 promise<_Rp>::get_future()
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (__state_ == nullptr)
-throw future_error(make_error_code(future_errc::no_state));
-#endif
+__throw_future_error();
 return future<_Rp>(__state_);
 }
 
@@ -1456,10 +1453,8 @@ template 
 void
 promise<_Rp>::set_value(const _Rp& __r)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (__state_ == nullptr)
-throw future_error(make_error_code(future_errc::no_state));
-#endif
+__throw_future_error();
 __state_->set_value(__r);
 }
 
@@ -1469,10 +1464,8 @@ template 
 void
 promise<_Rp>::set_value(_Rp&& __r)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (__state_ == nullptr)
-throw future_error(make_error_code(future_errc::no_state));
-#endif
+__throw_future_error();
 __state_->set_value(_VSTD::move(__r));
 }
 
@@ -1482,10 +1475,8 @@ template 
 void
 promise<_Rp>::set_exception(exception_ptr __p)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (__state_ == nullptr)
-throw future_error(make_error_code(future_errc::no_state));
-#endif
+__throw_future_error();
 __state_->set_exception(__p);
 }
 
@@ -1493,10 +1484,8 @@ template 
 void
 promise<_Rp>::set_value_at_thread_exit(const _Rp& __r)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (__state_ == nullptr)
-throw future_error(make_error_code(future_errc::no_state));
-#endif
+

Re: [PATCH] D12402: PR24595: clang-cl fails to compile vswriter.h header from Windows SDK 8.1 in 32 bit mode

2015-09-03 Thread Andrey Bokhanko via cfe-commits
andreybokhanko updated this revision to Diff 33945.
andreybokhanko added a comment.

Patch updated after fixing all (but one) of Reid's comments.


http://reviews.llvm.org/D12402

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/DeclSpec.h
  include/clang/Sema/Sema.h
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenCXX/microsoft-abi-structors.cpp
  test/SemaCXX/decl-microsoft-call-conv.cpp

Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2269,8 +2269,11 @@
 
   // Adjust the default free function calling convention to the default method
   // calling convention.
+  bool IsCtorOrDtor =
+  (Entity.getNameKind() == DeclarationName::CXXConstructorName) ||
+  (Entity.getNameKind() == DeclarationName::CXXDestructorName);
   if (T->isFunctionType())
-adjustMemberFunctionCC(T, /*IsStatic=*/false);
+adjustMemberFunctionCC(T, /*IsStatic=*/false, IsCtorOrDtor, Loc);
 
   return Context.getMemberPointerType(T, Class.getTypePtr());
 }
@@ -5842,24 +5845,51 @@
   return false;
 }
 
-void Sema::adjustMemberFunctionCC(QualType &T, bool IsStatic) {
+void Sema::adjustMemberFunctionCC(QualType &T, bool IsStatic, bool IsCtorOrDtor,
+  SourceLocation Loc) {
   FunctionTypeUnwrapper Unwrapped(*this, T);
   const FunctionType *FT = Unwrapped.get();
   bool IsVariadic = (isa(FT) &&
  cast(FT)->isVariadic());
-
-  // Only adjust types with the default convention.  For example, on Windows we
-  // should adjust a __cdecl type to __thiscall for instance methods, and a
-  // __thiscall type to __cdecl for static methods.
   CallingConv CurCC = FT->getCallConv();
-  CallingConv FromCC =
+  CallingConv DefaultCC =
   Context.getDefaultCallingConvention(IsVariadic, IsStatic);
-  CallingConv ToCC = Context.getDefaultCallingConvention(IsVariadic, !IsStatic);
-  if (CurCC != FromCC || FromCC == ToCC)
-return;
+  CallingConv ToCC;
 
-  if (hasExplicitCallingConv(T))
-return;
+  // MS compiler ignores explicit calling convention attributes on structors. We
+  // should do the same.
+  if (Context.getTargetInfo().getCXXABI().isMicrosoft() && IsCtorOrDtor) {
+// getDefaultCallingConvention provides incorrect answer for structors in 32
+// bit MS ABI environment. This probably should be fixed.
+if (Context.getTargetInfo().getTriple().isArch32Bit())
+  DefaultCC = CC_X86ThisCall;
+
+if (CurCC == DefaultCC)
+  return;
+
+// __declspec(dllexport) got transformed to CC_C and allowed.
+if (CurCC == CC_C)
+  return;
+
+ToCC = DefaultCC;
+
+// Issue a warning on ignored calling convention -- except of __stdcall.
+// Again, this is what MS compiler does.
+if (CurCC != CC_X86StdCall)
+  Diag(Loc, diag::warn_cconv_structors)
+  << FunctionType::getNameForCallConv(CurCC);
+  // Default adjustment.
+  } else {
+// Only adjust types with the default convention.  For example, on Windows
+// we should adjust a __cdecl type to __thiscall for instance methods, and a
+// __thiscall type to __cdecl for static methods.
+ToCC = Context.getDefaultCallingConvention(IsVariadic, !IsStatic);
+if (CurCC != DefaultCC || DefaultCC == ToCC)
+  return;
+
+if (hasExplicitCallingConv(T))
+  return;
+  }
 
   FT = Context.adjustFunctionType(FT, FT->getExtInfo().withCallingConv(ToCC));
   QualType Wrapped = Unwrapped.wrap(*this, FT);
Index: lib/Sema/DeclSpec.cpp
===
--- lib/Sema/DeclSpec.cpp
+++ lib/Sema/DeclSpec.cpp
@@ -351,6 +351,11 @@
   getName().OperatorFunctionId.Operator));
 }
 
+bool Declarator::isCtorOrDtor() {
+  return (getName().getKind() == UnqualifiedId::IK_ConstructorName) ||
+ (getName().getKind() == UnqualifiedId::IK_DestructorName);
+}
+
 bool DeclSpec::hasTagDefinition() const {
   if (!TypeSpecOwned)
 return false;
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -7219,7 +7219,8 @@
   << DeclSpec::getSpecifierName(TSCS);
 
   if (D.isFirstDeclarationOfMember())
-adjustMemberFunctionCC(R, D.isStaticMember());
+adjustMemberFunctionCC(R, D.isStaticMember(), D.isCtorOrDtor(),
+   D.getIdentifierLoc());
 
   bool isFriend = false;
   FunctionTemplateDecl *FunctionTemplate = nullptr;
Index: include/clang/Sema/DeclSpec.h
===
--- include/clang/Sema/DeclSpec.h
+++ include/clang/Sema/DeclSpec.h
@@ -2208,6 +2208,9 @@
   /// redeclaration time if the decl is static.
   bool isStaticMember();
 
+  /// Returns true if this declares a constructor or a destructor.
+  bool isCtorOrDtor();
+
   void setRedeclaration(bool Val) { Redeclaration = Val; }
   boo

Re: [PATCH] D12402: PR24595: clang-cl fails to compile vswriter.h header from Windows SDK 8.1 in 32 bit mode

2015-09-03 Thread Andrey Bokhanko via cfe-commits
andreybokhanko marked 4 inline comments as done.


Comment at: lib/Sema/SemaType.cpp:5873-5877
@@ +5872,7 @@
+  return;
+
+ToCC = DefaultCC;
+
+// Issue a warning on ignored calling convention -- except of __stdcall.
+// Again, this is what MS compiler does.
+if (CurCC != CC_X86StdCall)

I tried, but this leads to massive stability fails. I'm willing to investigate 
and fix them (if needed), but in a separate patch, OK?


http://reviews.llvm.org/D12402



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


Re: [PATCH] D12508: [libcxx] Make it drastically simpler to link libc++.

2015-09-03 Thread Jonathan Roelofs via cfe-commits
jroelofs added inline comments.


Comment at: utils/gen_link_script/gen_link_script.py:1
@@ +1,2 @@
+#!/usr/bin/env python
+import os

Do you foresee these linker scripts being significantly more complicated for 
other platforms? ISTM that it would be much simpler to have CMake generate 
these directly.


http://reviews.llvm.org/D12508



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


Re: [PATCH] D12489: [clang-format] Fixed missing space between Obj-C for/in and a typecast

2015-09-03 Thread Manuel Klimek via cfe-commits
klimek added a comment.

In the future, please add cfe-commits as subscriber on the initial post, 
otherwise the initial email will not go to the mailing list. Thx!


http://reviews.llvm.org/D12489



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


Re: [PATCH] D12489: [clang-format] Fixed missing space between Obj-C for/in and a typecast

2015-09-03 Thread Manuel Klimek via cfe-commits
klimek added a comment.

Oh, and you'll want to add tests :) unittests/Format/FormatTest.cpp


http://reviews.llvm.org/D12489



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


Re: [PATCH] D12402: PR24595: clang-cl fails to compile vswriter.h header from Windows SDK 8.1 in 32 bit mode

2015-09-03 Thread Reid Kleckner via cfe-commits
rnk added inline comments.


Comment at: lib/Sema/SemaType.cpp:5855-5856
@@ -5854,3 +5854,4 @@
   CallingConv CurCC = FT->getCallConv();
-  CallingConv FromCC =
+  CallingConv DefaultCC =
   Context.getDefaultCallingConvention(IsVariadic, IsStatic);
+  CallingConv ToCC;

DefaultCC is only meaningful when we're dealing with non-structor member 
functions. In the structor case, you're conflating it with ToCC. Let's sink the 
DefaultCC definition down into the 'else' block, since it's only meaningful 
there.


Comment at: lib/Sema/SemaType.cpp:5857
@@ -5856,5 +5856,3 @@
   Context.getDefaultCallingConvention(IsVariadic, IsStatic);
-  CallingConv ToCC = Context.getDefaultCallingConvention(IsVariadic, 
!IsStatic);
-  if (CurCC != FromCC || FromCC == ToCC)
-return;
+  CallingConv ToCC;
 

ToCC is always the same in both cases:
  CallingConv ToCC = Context.getDefaultCallingConvention(IsVariadic, !IsStatic);
Let's just keep that here, and return early if CurrCC == ToCC, since the common 
case is that we don't need to do anything.


Comment at: lib/Sema/SemaType.cpp:5864-5865
@@ +5863,4 @@
+// bit MS ABI environment. This probably should be fixed.
+if (Context.getTargetInfo().getTriple().isArch32Bit())
+  DefaultCC = CC_X86ThisCall;
+

This is reimplementing ASTContext::getDefaultCallingConv. Let's not duplicate 
that logic.


Comment at: lib/Sema/SemaType.cpp:5867-5868
@@ +5866,4 @@
+
+if (CurCC == DefaultCC)
+  return;
+

This can be covered by returning earlier if CurrCC == ToCC.


Comment at: lib/Sema/SemaType.cpp:5870-5872
@@ +5869,5 @@
+
+// __declspec(dllexport) got transformed to CC_C and allowed.
+if (CurCC == CC_C)
+  return;
+

This seems wrong, see this test case:
  struct A {
__cdecl A(int x);
int f;
  };
  A::A(int x) : f(x) {}
32-bit MSVC turns it into thiscall.

I think what you're really seeing is that variadic constructors need to stay 
cdecl. getDefaultCallingConvention already handles this case.


Comment at: lib/Sema/SemaType.cpp:5873-5877
@@ +5872,7 @@
+  return;
+
+ToCC = DefaultCC;
+
+// Issue a warning on ignored calling convention -- except of __stdcall.
+// Again, this is what MS compiler does.
+if (CurCC != CC_X86StdCall)

andreybokhanko wrote:
> I tried, but this leads to massive stability fails. I'm willing to 
> investigate and fix them (if needed), but in a separate patch, OK?
I'd really rather get the *structor calling convention logic right on the first 
try.


http://reviews.llvm.org/D12402



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


Re: [PATCH] D11279: Initial patch for PS4 toolchain

2015-09-03 Thread Jonathan Roelofs via cfe-commits
jroelofs added inline comments.


Comment at: lib/Frontend/InitHeaderSearch.cpp:340
@@ +339,3 @@
+BaseSDKPath = P.str();
+  }
+}

kromanova wrote:
> jroelofs wrote:
> > The lifetime of `P` ends here, yet a reference to it lives on because of 
> > the `= P.str()`. Using it later on line 344 is UB.
> Good catch. Thank you! We will fix it.
Oops, nevermind... I was wrong: BaseSDKPath is a std::string, not a `char*` so 
there's no lifetime issue here.


http://reviews.llvm.org/D11279



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


Re: [PATCH] fix parentheses location in a CXXConstructExpr

2015-09-03 Thread Manuel Klimek via cfe-commits
On Tue, Sep 1, 2015 at 12:31 AM Olivier Goffart  wrote:

> On Monday 31. August 2015 08:07:58 Manuel Klimek wrote:
> > On Sat, Aug 29, 2015 at 12:23 PM Olivier Goffart via cfe-commits <
> >
> > cfe-commits@lists.llvm.org> wrote:
> > > Hi,
> > >
> > > Please review the attached patch.
> > >
> > > In Sema::BuildCXXFunctionalCastExpr, if the class has a destructor, the
> > > Op.SrcExpr might be a CXXBindTemporaryExpr which we need to unwrap.
> > >
> > > In the testcase, the first new CHECK worked (because A does not have a
> > > destructor),  but the second CHECK failed (did not include the last
> > > parenthese) because D has a destructor.
> > >
> > > I used dyn_cast_or_null just to be safe, becasue i don't know if it is
> > > possible for the BindExpr->getSubExpr() to be null.
> >
> > Do you know why the added test for A says 'class foo::A' instead of
> > 'foo::A' as the other tests do in that file?
>
> I don't know.  It seems it has to do with the fully quallified name vs.
> normal
> name.
>
> For example, if you dumpt the AST of:
>
>  namespace foo { class A {} *a1 = new foo::A , *a2 = new A; }
>
> You get:
>
> [...]
> | |-VarDecl 0x1c9a7a0  col:29 a1 'class A *' cinit
> | | `-CXXNewExpr 0x1ce2648  'foo::A *'
> | |   `-CXXConstructExpr 0x1ce2618  'foo::A':'class foo::A' 'void
> (void) throw()'
> | `-VarDecl 0x1ce26d0  col:48 a2 'class A *' cinit
> |   `-CXXNewExpr 0x1ce2768  'class foo::A *'
> | `-CXXConstructExpr 0x1ce2738  'class foo::A' 'void (void)
> throw()'
>
>
> As you can see, when the type of CXXNewExpr is fully quialified, the
> 'class'
> keyword is omited, but for a2, it prints the 'class' keyword.
> The printed type of CXXConstructExpr is even more wierd when it is fully
> qualified.
>
>
> I guess that's because of ElaboratedTypePolicyRAII in TypePrinter.cpp
>
> But this is irrelevant for this patch and the problem it's trying to solve.
> The reason I used 'using namespace foo' in the test was just so the line
> with
> A and D have the same size.   I just copy pasted the thing without thinking
> about that.
>

Makes sense. In that case I think it looks good, adding Richard to
cross-check for the final approval.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12489: [clang-format] Fixed missing space between Obj-C for/in and a typecast

2015-09-03 Thread Kent Sutherland via cfe-commits
ksuther updated this revision to Diff 33947.
ksuther added a comment.

Added two tests: One of a for/in loop with a cast, and one without.


http://reviews.llvm.org/D12489

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7430,6 +7430,19 @@
"@import baz;");
 }
 
+TEST_F(FormatTest, ObjCForIn) {
+  verifyFormat("- (void)test {\n"
+   "  for (NSString *n in arrayOfStrings) {\n"
+   "foo(n);\n"
+   "  }\n"
+   "}");
+  verifyFormat("- (void)test {\n"
+   "  for (NSString *n in (__bridge NSArray *)arrayOfStrings) {\n"
+   "foo(n);\n"
+   "  }\n"
+   "}");
+}
+
 TEST_F(FormatTest, ObjCLiterals) {
   verifyFormat("@\"String\"");
   verifyFormat("@1");
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1900,7 +1900,8 @@
 return Line.Type == LT_ObjCDecl || Left.is(tok::semi) ||
(Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
 (Left.isOneOf(tok::kw_if, tok::pp_elif, tok::kw_for, tok::kw_while,
-  tok::kw_switch, tok::kw_case, TT_ForEachMacro) ||
+  tok::kw_switch, tok::kw_case, TT_ForEachMacro,
+  TT_ObjCForIn) ||
  (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch,
tok::kw_new, tok::kw_delete) &&
   (!Left.Previous || Left.Previous->isNot(tok::period) ||


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7430,6 +7430,19 @@
"@import baz;");
 }
 
+TEST_F(FormatTest, ObjCForIn) {
+  verifyFormat("- (void)test {\n"
+   "  for (NSString *n in arrayOfStrings) {\n"
+   "foo(n);\n"
+   "  }\n"
+   "}");
+  verifyFormat("- (void)test {\n"
+   "  for (NSString *n in (__bridge NSArray *)arrayOfStrings) {\n"
+   "foo(n);\n"
+   "  }\n"
+   "}");
+}
+
 TEST_F(FormatTest, ObjCLiterals) {
   verifyFormat("@\"String\"");
   verifyFormat("@1");
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1900,7 +1900,8 @@
 return Line.Type == LT_ObjCDecl || Left.is(tok::semi) ||
(Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
 (Left.isOneOf(tok::kw_if, tok::pp_elif, tok::kw_for, tok::kw_while,
-  tok::kw_switch, tok::kw_case, TT_ForEachMacro) ||
+  tok::kw_switch, tok::kw_case, TT_ForEachMacro,
+  TT_ObjCForIn) ||
  (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch,
tok::kw_new, tok::kw_delete) &&
   (!Left.Previous || Left.Previous->isNot(tok::period) ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12579: AST: simplify handling of the mangling

2015-09-03 Thread Reid Kleckner via cfe-commits
rnk added inline comments.


Comment at: lib/AST/Mangle.cpp:142
@@ +141,3 @@
+  // language).
+  if (MCXX || (CC == CM_Other && TI.getCXXABI() == TargetCXXABI::Microsoft))
+return mangleCXXName(D, Out);

TI.getCXXABI().isMicrosoft() is better than the == check.


Comment at: lib/AST/Mangle.cpp:156-161
@@ -155,8 +151,3 @@
 
-  if (!MCXX)
-Out << D->getIdentifier()->getName();
-  else if (const ObjCMethodDecl *OMD = dyn_cast(D))
-mangleObjCMethodName(OMD, Out);
-  else
-mangleCXXName(D, Out);
 

This looks like a functional change for Itanium. The old code was intentionally 
structured so that Itanium also had C calling convention mangling on Windows.


http://reviews.llvm.org/D12579



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


r246778 - [libclang] Return deduced type for auto type, not the one written in the source.

2015-09-03 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Thu Sep  3 11:11:10 2015
New Revision: 246778

URL: http://llvm.org/viewvc/llvm-project?rev=246778&view=rev
Log:
[libclang] Return deduced type for auto type, not the one written in the source.

It used to work, but was accidentally broken by r179769.
The issue with decayed types was fixed by r190796.
So this patch partially reverts r179769, and adds more tests.

This also fixes PR 18669.

Patch by Sergey Kalinichev.

Modified:
cfe/trunk/bindings/python/tests/cindex/test_type.py
cfe/trunk/test/Index/print-type.cpp
cfe/trunk/tools/libclang/CXType.cpp

Modified: cfe/trunk/bindings/python/tests/cindex/test_type.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_type.py?rev=246778&r1=246777&r2=246778&view=diff
==
--- cfe/trunk/bindings/python/tests/cindex/test_type.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_type.py Thu Sep  3 11:11:10 2015
@@ -134,7 +134,7 @@ def test_equal():
 
 def test_type_spelling():
 """Ensure Type.spelling works."""
-tu = get_tu('int c[5]; int i[]; int x; int v[x];')
+tu = get_tu('int c[5]; void f(int i[]); int x; int v[x];')
 c = get_cursor(tu, 'c')
 i = get_cursor(tu, 'i')
 x = get_cursor(tu, 'x')
@@ -253,7 +253,7 @@ void bar(int a, int b);
 
 def test_element_type():
 """Ensure Type.element_type works."""
-tu = get_tu('int c[5]; int i[]; int x; int v[x];')
+tu = get_tu('int c[5]; void f(int i[]); int x; int v[x];')
 c = get_cursor(tu, 'c')
 i = get_cursor(tu, 'i')
 v = get_cursor(tu, 'v')

Modified: cfe/trunk/test/Index/print-type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-type.cpp?rev=246778&r1=246777&r2=246778&view=diff
==
--- cfe/trunk/test/Index/print-type.cpp (original)
+++ cfe/trunk/test/Index/print-type.cpp Thu Sep  3 11:11:10 2015
@@ -48,7 +48,15 @@ struct Blob {
 };
 int Blob::*member_pointer;
 
-// RUN: c-index-test -test-print-type %s -std=c++11 | FileCheck %s
+
+
+auto autoI = 0;
+auto autoTbar = tbar(0);
+auto autoBlob = new Blob();
+auto autoFunction(){return int();}
+decltype(auto) autoInt = 5;
+
+// RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
 // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
 // CHECK: TemplateTypeParameter=T:3:19 (Definition) [type=T] 
[typekind=Unexposed] [canonicaltype=type-parameter-0-0] 
[canonicaltypekind=Unexposed] [isPOD=0]
@@ -119,3 +127,20 @@ int Blob::*member_pointer;
 // CHECK: StructDecl=Blob:45:8 (Definition) [type=Blob] [typekind=Record] 
[isPOD=1] [nbFields=2]
 // CHECK: FieldDecl=i:46:7 (Definition) [type=int] [typekind=Int] [isPOD=1]
 // CHECK: VarDecl=member_pointer:49:12 (Definition) [type=int Blob::*] 
[typekind=MemberPointer] [isPOD=1]
+// CHECK: VarDecl=autoI:53:6 (Definition) [type=int] [typekind=Unexposed] 
[canonicaltype=int] [canonicaltypekind=Int] [isPOD=1]
+// CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
+// CHECK: VarDecl=autoTbar:54:6 (Definition) [type=int] [typekind=Unexposed] 
[canonicaltype=int] [canonicaltypekind=Int] [isPOD=1]
+// CHECK: CallExpr=tbar:35:3 [type=int] [typekind=Unexposed] 
[canonicaltype=int] [canonicaltypekind=Int] [args= [int] [Int]] [isPOD=1]
+// CHECK: UnexposedExpr=tbar:35:3 [type=int (*)(int)] [typekind=Pointer] 
[canonicaltype=int (*)(int)] [canonicaltypekind=Pointer] [isPOD=1] 
[pointeetype=int (int)] [pointeekind=FunctionProto]
+// CHECK: DeclRefExpr=tbar:35:3 RefName=[54:17 - 54:21] RefName=[54:21 - 
54:26] [type=int (int)] [typekind=FunctionProto] [canonicaltype=int (int)] 
[canonicaltypekind=FunctionProto] [isPOD=0]
+// CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
+// CHECK: VarDecl=autoBlob:55:6 (Definition) [type=Blob *] 
[typekind=Unexposed] [canonicaltype=Blob *] [canonicaltypekind=Pointer] 
[isPOD=1]
+// CHECK: CXXNewExpr= [type=Blob *] [typekind=Pointer] [isPOD=1] 
[pointeetype=Blob] [pointeekind=Record]
+// CHECK: TypeRef=struct Blob:45:8 [type=Blob] [typekind=Record] [isPOD=1] 
[nbFields=2]
+// CHECK: CallExpr=Blob:45:8 [type=Blob] [typekind=Record] [isPOD=1] 
[nbFields=2]
+// CHECK: FunctionDecl=autoFunction:56:6 (Definition) [type=int ()] 
[typekind=FunctionProto] [canonicaltype=int ()] 
[canonicaltypekind=FunctionProto] [resulttype=int] [resulttypekind=Unexposed] 
[isPOD=0]
+// CHECK: CompoundStmt= [type=] [typekind=Invalid] [isPOD=0]
+// CHECK: ReturnStmt= [type=] [typekind=Invalid] [isPOD=0]
+// CHECK: UnexposedExpr= [type=int] [typekind=Int] [isPOD=1]
+// CHECK: VarDecl=autoInt:57:16 (Definition) [type=int] [typekind=Unexposed] 
[canonicaltype=int] [canonicaltypekind=Int] [isPOD=1]
+// CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]

Modified: cfe/trunk/tools/libclang/CXType.cpp
URL: 
ht

Re: [PATCH] D11976: [libclang] Return deduced type for auto type, not the one written in the source.

2015-09-03 Thread Manuel Klimek via cfe-commits
klimek closed this revision.
klimek added a comment.

Submitted as r246778.


http://reviews.llvm.org/D11976



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


[PATCH] D12600: [mips] Added support for using the command line options -Wa, -msoft-float and -Wa, -mhard-float.

2015-09-03 Thread Scott Egerton via cfe-commits
s.egerton created this revision.
s.egerton added reviewers: dsanders, vkalintiris.
s.egerton added a subscriber: cfe-commits.

http://reviews.llvm.org/D12600

Files:
  lib/Driver/Tools.cpp
  test/Driver/mips-ias-Wa.s

Index: test/Driver/mips-ias-Wa.s
===
--- test/Driver/mips-ias-Wa.s
+++ test/Driver/mips-ias-Wa.s
@@ -22,3 +22,28 @@
 // RUN:   FileCheck -check-prefix=TRAP-BOTH-BREAK-FIRST %s
 // TRAP-BOTH-BREAK-FIRST: -cc1as
 // TRAP-BOTH-BREAK-FIRST: "-target-feature" "-use-tcc-in-div" 
"-target-feature" "+use-tcc-in-div"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=MSOFT-FLOAT-DEFAULT %s
+// MSOFT-FLOAT-DEFAULT: -cc1as
+// MSOFT-FLOAT-DEFAULT-NOT: "-target-feature" "-soft-float"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 
-Wa,-msoft-float 2>&1 | \
+// RUN:   FileCheck -check-prefix=MSOFT-FLOAT-ON %s
+// MSOFT-FLOAT-ON: -cc1as
+// MSOFT-FLOAT-ON: "-target-feature" "+soft-float"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 
-Wa,-mhard-float 2>&1 | \
+// RUN:   FileCheck -check-prefix=MSOFT-FLOAT-OFF %s
+// MSOFT-FLOAT-OFF: -cc1as
+// MSOFT-FLOAT-OFF: "-target-feature" "-soft-float"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 
-Wa,-msoft-float,-mhard-float 2>&1 | \
+// RUN:   FileCheck -check-prefix=MSOFT-FLOAT-BOTH-MSOFT-FLOAT-FIRST %s
+// MSOFT-FLOAT-BOTH-MSOFT-FLOAT-FIRST: -cc1as
+// MSOFT-FLOAT-BOTH-MSOFT-FLOAT-FIRST: "-target-feature" "+soft-float" 
"-target-feature" "-soft-float"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 
-Wa,-mhard-float,-msoft-float 2>&1 | \
+// RUN:   FileCheck -check-prefix=MSOFT-FLOAT-BOTH-MHARD-FLOAT-FIRST %s
+// MSOFT-FLOAT-BOTH-MHARD-FLOAT-FIRST: -cc1as
+// MSOFT-FLOAT-BOTH-MHARD-FLOAT-FIRST: "-target-feature" "-soft-float" 
"-target-feature" "+soft-float"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -2341,6 +2341,12 @@
   } else if (Value == "--break") {
 CmdArgs.push_back("-target-feature");
 CmdArgs.push_back("-use-tcc-in-div");
+  } else if (Value.startswith("-msoft-float")) {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("+soft-float");
+  } else if (Value.startswith("-mhard-float")) {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("-soft-float");
   } else {
 D.Diag(diag::err_drv_unsupported_option_argument)
 << A->getOption().getName() << Value;


Index: test/Driver/mips-ias-Wa.s
===
--- test/Driver/mips-ias-Wa.s
+++ test/Driver/mips-ias-Wa.s
@@ -22,3 +22,28 @@
 // RUN:   FileCheck -check-prefix=TRAP-BOTH-BREAK-FIRST %s
 // TRAP-BOTH-BREAK-FIRST: -cc1as
 // TRAP-BOTH-BREAK-FIRST: "-target-feature" "-use-tcc-in-div" "-target-feature" "+use-tcc-in-div"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=MSOFT-FLOAT-DEFAULT %s
+// MSOFT-FLOAT-DEFAULT: -cc1as
+// MSOFT-FLOAT-DEFAULT-NOT: "-target-feature" "-soft-float"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -Wa,-msoft-float 2>&1 | \
+// RUN:   FileCheck -check-prefix=MSOFT-FLOAT-ON %s
+// MSOFT-FLOAT-ON: -cc1as
+// MSOFT-FLOAT-ON: "-target-feature" "+soft-float"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -Wa,-mhard-float 2>&1 | \
+// RUN:   FileCheck -check-prefix=MSOFT-FLOAT-OFF %s
+// MSOFT-FLOAT-OFF: -cc1as
+// MSOFT-FLOAT-OFF: "-target-feature" "-soft-float"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -Wa,-msoft-float,-mhard-float 2>&1 | \
+// RUN:   FileCheck -check-prefix=MSOFT-FLOAT-BOTH-MSOFT-FLOAT-FIRST %s
+// MSOFT-FLOAT-BOTH-MSOFT-FLOAT-FIRST: -cc1as
+// MSOFT-FLOAT-BOTH-MSOFT-FLOAT-FIRST: "-target-feature" "+soft-float" "-target-feature" "-soft-float"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -Wa,-mhard-float,-msoft-float 2>&1 | \
+// RUN:   FileCheck -check-prefix=MSOFT-FLOAT-BOTH-MHARD-FLOAT-FIRST %s
+// MSOFT-FLOAT-BOTH-MHARD-FLOAT-FIRST: -cc1as
+// MSOFT-FLOAT-BOTH-MHARD-FLOAT-FIRST: "-target-feature" "-soft-float" "-target-feature" "+soft-float"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -2341,6 +2341,12 @@
   } else if (Value == "--break") {
 CmdArgs.push_back("-target-feature");
 CmdArgs.push_back("-use-tcc-in-div");
+  } else if (Value.startswith("-msoft-float")) {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("+soft-float");
+  } else if (Value.startswith("-mhard-float")) {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("-soft-float");
   } else {
 D.D

Re: [PATCH] D11797: [LIbClang] Report the named type for ElaboratedType

2015-09-03 Thread Manuel Klimek via cfe-commits
klimek added a subscriber: klimek.
klimek added a comment.

Is this still ready for submission or do you want to change something (not 
clear after your last comment :)


http://reviews.llvm.org/D11797



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


Re: [PATCH] D12022: Refactored dtor sanitizing into EHScopeStack

2015-09-03 Thread Naomi Musgrave via cfe-commits
nmusgrave updated this revision to Diff 33956.
nmusgrave marked 4 inline comments as done.
nmusgrave added a comment.

- Testing sanitizing bit fields.


http://reviews.llvm.org/D12022

Files:
  lib/CodeGen/CGCXX.cpp
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CodeGenModule.h
  test/CodeGenCXX/sanitize-dtor-bit-field.cpp
  test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
  test/CodeGenCXX/sanitize-dtor-repress-aliasing.cpp

Index: test/CodeGenCXX/sanitize-dtor-repress-aliasing.cpp
===
--- /dev/null
+++ test/CodeGenCXX/sanitize-dtor-repress-aliasing.cpp
@@ -0,0 +1,30 @@
+// Test -fsanitize-memory-use-after-dtor
+// RUN: %clang_cc1 -fsanitize=memory -O1 -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fsanitize=memory -O2 -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+
+template 
+class Vector {
+public:
+  int size;
+  ~Vector() {}
+};
+
+// Virtual function table for the derived class only contains
+// its own destructors, with no aliasing to base class dtors.
+struct Base {
+  Vector v;
+  int x;
+  Base() { x = 5; }
+  virtual ~Base() {}
+};
+
+struct Derived : public Base {
+  int z;
+  Derived() { z = 10; }
+  ~Derived() {}
+};
+
+Derived d;
+
+// Definition of virtual function table
+// CHECK: @_ZTV7Derived = {{.*}}@_ZN7DerivedD1Ev{{.*}}@_ZN7DerivedD0Ev
Index: test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
===
--- /dev/null
+++ test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
@@ -0,0 +1,82 @@
+// RUN: %clang_cc1 -fsanitize=memory -O0 -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fsanitize=memory -O1 -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+
+template 
+class Vector {
+public:
+  int size;
+  ~Vector() {
+size += 1;
+  }
+};
+
+struct Base {
+  int b1;
+  double b2;
+  Base() {
+b1 = 5;
+b2 = 10.989;
+  }
+  virtual ~Base() {}
+};
+
+struct VirtualBase {
+  int vb1;
+  int vb2;
+  VirtualBase() {
+vb1 = 10;
+vb2 = 11;
+  }
+  virtual ~VirtualBase() {}
+};
+
+struct Derived : public Base, public virtual VirtualBase {
+  int d1;
+  Vector v;
+  int d2;
+  Derived() {
+d1 = 10;
+  }
+  ~Derived() {}
+};
+
+Derived d;
+
+// Destruction order:
+// Derived: int, Vector, Base, VirtualBase
+
+// CHECK-LABEL: define {{.*}}ZN7DerivedD1Ev
+// CHECK: call void {{.*}}ZN11VirtualBaseD2Ev
+// CHECK: ret void
+
+// CHECK-LABEL: define {{.*}}ZN7DerivedD0Ev
+// CHECK: ret void
+
+// CHECK-LABEL: define {{.*}}ZN11VirtualBaseD1Ev
+// CHECK: ret void
+
+// CHECK-LABEL: define {{.*}}ZN11VirtualBaseD0Ev
+// CHECK: ret void
+
+// poison 2 ints
+// CHECK-LABEL: define {{.*}}ZN11VirtualBaseD2Ev
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 8)
+// CHECK: ret void
+
+// poison int and double
+// CHECK-LABEL: define {{.*}}ZN4BaseD2Ev
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 16)
+// CHECK: ret void
+
+// poison int, ignore vector, poison int
+// CHECK-LABEL: define {{.*}}ZN7DerivedD2Ev
+// CHECK: call void {{.*}}ZN6VectorIiED1Ev
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 4)
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 4)
+// CHECK: call void {{.*}}ZN4BaseD2Ev
+// CHECK: ret void
+
+// poison int
+// CHECK-LABEL: define {{.*}}ZN6VectorIiED2Ev
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 4)
+// CHECK: ret void
Index: test/CodeGenCXX/sanitize-dtor-bit-field.cpp
===
--- /dev/null
+++ test/CodeGenCXX/sanitize-dtor-bit-field.cpp
@@ -0,0 +1,66 @@
+// Test -fsanitize-memory-use-after-dtor
+// RUN: %clang_cc1 -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+
+// 24 bytes total
+struct Packed {
+  // Packed into 4 bytes
+  unsigned int a : 1;
+  unsigned int b : 1;
+  //unsigned int c : 1;
+  // Force alignment to next 4 bytes
+  unsigned int   : 0;
+  unsigned int d : 1;
+  // Force alignment, 8 more bytes
+  double e = 5.0;
+  // 4 bytes
+  unsigned int f : 1;
+};
+Packed p;
+
+
+// 1 byte total
+struct Empty {
+  unsigned int : 0;
+};
+Empty e;
+
+
+// 4 byte total
+struct Simple {
+  unsigned int a : 1;
+};
+Simple s;
+
+
+// 8 bytes total
+struct Anon {
+  // 1 byte
+  unsigned int a : 1;
+  unsigned int b : 2;
+  // Force alignment to next byte
+  unsigned int   : 0;
+  unsigned int c : 1;
+};
+Anon a;
+
+struct Foo {
+  int f;
+};
+Foo f;
+
+// CHECK-LABEL: define {{.*}}PackedD2Ev
+//

Patch for PR23472

2015-09-03 Thread Yaron Keren via cfe-commits
http://llvm.org/pr23472

As suggested by Reid, OK to commit?
Index: tools/clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- tools/clang/lib/CodeGen/ItaniumCXXABI.cpp   (revision 246575)
+++ tools/clang/lib/CodeGen/ItaniumCXXABI.cpp   (working copy)
@@ -1826,7 +1826,8 @@
 // The ABI says: It is suggested that it be emitted in the same COMDAT 
group
 // as the associated data object
 llvm::Comdat *C = var->getComdat();
-if (!D.isLocalVarDecl() && C) {
+if (!D.isLocalVarDecl() && C &&
+CGM.getTarget().getTriple().isOSBinFormatELF()) {
   guard->setComdat(C);
   CGF.CurFn->setComdat(C);
 } else if (CGM.supportsCOMDAT() && guard->isWeakForLinker()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12022: Refactored dtor sanitizing into EHScopeStack

2015-09-03 Thread Naomi Musgrave via cfe-commits
nmusgrave updated this revision to Diff 33959.
nmusgrave added a comment.

- Refined testing for bit fields.


http://reviews.llvm.org/D12022

Files:
  lib/CodeGen/CGCXX.cpp
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CodeGenModule.h
  test/CodeGenCXX/sanitize-dtor-bit-field.cpp
  test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
  test/CodeGenCXX/sanitize-dtor-repress-aliasing.cpp

Index: test/CodeGenCXX/sanitize-dtor-repress-aliasing.cpp
===
--- /dev/null
+++ test/CodeGenCXX/sanitize-dtor-repress-aliasing.cpp
@@ -0,0 +1,30 @@
+// Test -fsanitize-memory-use-after-dtor
+// RUN: %clang_cc1 -fsanitize=memory -O1 -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fsanitize=memory -O2 -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+
+template 
+class Vector {
+public:
+  int size;
+  ~Vector() {}
+};
+
+// Virtual function table for the derived class only contains
+// its own destructors, with no aliasing to base class dtors.
+struct Base {
+  Vector v;
+  int x;
+  Base() { x = 5; }
+  virtual ~Base() {}
+};
+
+struct Derived : public Base {
+  int z;
+  Derived() { z = 10; }
+  ~Derived() {}
+};
+
+Derived d;
+
+// Definition of virtual function table
+// CHECK: @_ZTV7Derived = {{.*}}@_ZN7DerivedD1Ev{{.*}}@_ZN7DerivedD0Ev
Index: test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
===
--- /dev/null
+++ test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
@@ -0,0 +1,82 @@
+// RUN: %clang_cc1 -fsanitize=memory -O0 -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fsanitize=memory -O1 -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+
+template 
+class Vector {
+public:
+  int size;
+  ~Vector() {
+size += 1;
+  }
+};
+
+struct Base {
+  int b1;
+  double b2;
+  Base() {
+b1 = 5;
+b2 = 10.989;
+  }
+  virtual ~Base() {}
+};
+
+struct VirtualBase {
+  int vb1;
+  int vb2;
+  VirtualBase() {
+vb1 = 10;
+vb2 = 11;
+  }
+  virtual ~VirtualBase() {}
+};
+
+struct Derived : public Base, public virtual VirtualBase {
+  int d1;
+  Vector v;
+  int d2;
+  Derived() {
+d1 = 10;
+  }
+  ~Derived() {}
+};
+
+Derived d;
+
+// Destruction order:
+// Derived: int, Vector, Base, VirtualBase
+
+// CHECK-LABEL: define {{.*}}ZN7DerivedD1Ev
+// CHECK: call void {{.*}}ZN11VirtualBaseD2Ev
+// CHECK: ret void
+
+// CHECK-LABEL: define {{.*}}ZN7DerivedD0Ev
+// CHECK: ret void
+
+// CHECK-LABEL: define {{.*}}ZN11VirtualBaseD1Ev
+// CHECK: ret void
+
+// CHECK-LABEL: define {{.*}}ZN11VirtualBaseD0Ev
+// CHECK: ret void
+
+// poison 2 ints
+// CHECK-LABEL: define {{.*}}ZN11VirtualBaseD2Ev
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 8)
+// CHECK: ret void
+
+// poison int and double
+// CHECK-LABEL: define {{.*}}ZN4BaseD2Ev
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 16)
+// CHECK: ret void
+
+// poison int, ignore vector, poison int
+// CHECK-LABEL: define {{.*}}ZN7DerivedD2Ev
+// CHECK: call void {{.*}}ZN6VectorIiED1Ev
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 4)
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 4)
+// CHECK: call void {{.*}}ZN4BaseD2Ev
+// CHECK: ret void
+
+// poison int
+// CHECK-LABEL: define {{.*}}ZN6VectorIiED2Ev
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 4)
+// CHECK: ret void
Index: test/CodeGenCXX/sanitize-dtor-bit-field.cpp
===
--- /dev/null
+++ test/CodeGenCXX/sanitize-dtor-bit-field.cpp
@@ -0,0 +1,65 @@
+// Test -fsanitize-memory-use-after-dtor
+// RUN: %clang_cc1 -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+
+// 24 bytes total
+struct Packed {
+  // Packed into 4 bytes
+  unsigned int a : 1;
+  unsigned int b : 1;
+  //unsigned int c : 1;
+  // Force alignment to next 4 bytes
+  unsigned int   : 0;
+  unsigned int d : 1;
+  // Force alignment, 8 more bytes
+  double e = 5.0;
+  // 4 bytes
+  unsigned int f : 1;
+  ~Packed() {}
+};
+Packed p;
+
+
+// 1 byte total
+struct Empty {
+  unsigned int : 0;
+  ~Empty() {}
+};
+Empty e;
+
+
+// 4 byte total
+struct Simple {
+  unsigned int a : 1;
+  ~Simple() {}
+};
+Simple s;
+
+
+// 8 bytes total
+struct Anon {
+  // 1 byte
+  unsigned int a : 1;
+  unsigned int b : 2;
+  // Force alignment to next byte
+  unsigned int   : 0;
+  unsigned int c : 1;
+  ~Anon() {}
+};
+Anon a;
+
+// CHECK-LABEL: define {{.*}}PackedD2Ev
+// CHECK: call void @_

Re: Patch for PR23472

2015-09-03 Thread Rafael Espíndola via cfe-commits
I fully trust Reid review on this, so OK with me.

On 3 September 2015 at 14:04, Yaron Keren  wrote:
> http://llvm.org/pr23472
>
> As suggested by Reid, OK to commit?
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12580: Added StrictVTablePointers linking requirement

2015-09-03 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

I see that CGObjCMac.cpp names it like this:

"Objective-C Garbage Collection"


http://reviews.llvm.org/D12580



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


Re: [PATCH] D12594: [X86-64] Allow additional register names in inline assembler.

2015-09-03 Thread Eric Christopher via cfe-commits
echristo accepted this revision.
echristo added a comment.
This revision is now accepted and ready to land.

If you could interleave the test and the check I'd really appreciate it, e.g.:

  __asm__ ("mov r8w, 100;");

// CHECK: call void asm sideeffect "mov r8w, 100;"

Otherwise LGTM. Thanks!

-eric


http://reviews.llvm.org/D12594



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


r246795 - Add -target flag to Clang invocations in this test.

2015-09-03 Thread Alexey Samsonov via cfe-commits
Author: samsonov
Date: Thu Sep  3 14:11:42 2015
New Revision: 246795

URL: http://llvm.org/viewvc/llvm-project?rev=246795&view=rev
Log:
Add -target flag to Clang invocations in this test.

ASan may not be supported for the default target triple.

Modified:
cfe/trunk/test/Driver/fsanitize-blacklist.c

Modified: cfe/trunk/test/Driver/fsanitize-blacklist.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize-blacklist.c?rev=246795&r1=246794&r2=246795&view=diff
==
--- cfe/trunk/test/Driver/fsanitize-blacklist.c (original)
+++ cfe/trunk/test/Driver/fsanitize-blacklist.c Thu Sep  3 14:11:42 2015
@@ -12,40 +12,40 @@
 // RUN: echo "fun:bar" > %t.second
 // RUN: echo "badline" > %t.bad
 
-// RUN: %clang -fsanitize=address -fsanitize-blacklist=%t.good 
-fsanitize-blacklist=%t.second %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-BLACKLIST
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address 
-fsanitize-blacklist=%t.good -fsanitize-blacklist=%t.second %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-BLACKLIST
 // CHECK-BLACKLIST: -fsanitize-blacklist={{.*}}.good" 
"-fsanitize-blacklist={{.*}}.second
 
 // Now, check for -fdepfile-entry flags.
-// RUN: %clang -fsanitize=address -fsanitize-blacklist=%t.good 
-fsanitize-blacklist=%t.second %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-BLACKLIST2
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address 
-fsanitize-blacklist=%t.good -fsanitize-blacklist=%t.second %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-BLACKLIST2
 // CHECK-BLACKLIST2: -fdepfile-entry={{.*}}.good" 
"-fdepfile-entry={{.*}}.second
 
 // Check that the default blacklist is not added as an extra dependency.
-// RUN: %clang -fsanitize=address -resource-dir=%S/Inputs/resource_dir %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-DEFAULT-BLACKLIST 
--implicit-check-not=fdepfile-entry
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address 
-resource-dir=%S/Inputs/resource_dir %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-DEFAULT-BLACKLIST --implicit-check-not=fdepfile-entry
 // CHECK-DEFAULT-BLACKLIST: -fsanitize-blacklist={{.*}}asan_blacklist.txt
 
 // Ignore -fsanitize-blacklist flag if there is no -fsanitize flag.
-// RUN: %clang -fsanitize-blacklist=%t.good %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-NO-SANITIZE --check-prefix=DELIMITERS
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-blacklist=%t.good %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-SANITIZE --check-prefix=DELIMITERS
 // CHECK-NO-SANITIZE-NOT: -fsanitize-blacklist
 
 // Ignore -fsanitize-blacklist flag if there is no -fsanitize flag.
 // Now, check for the absense of -fdepfile-entry flags.
-// RUN: %clang -fsanitize-blacklist=%t.good %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-NO-SANITIZE2 --check-prefix=DELIMITERS
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-blacklist=%t.good %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-SANITIZE2 --check-prefix=DELIMITERS
 // CHECK-NO-SANITIZE2-NOT: -fdepfile-entry
 
 // Flag -fno-sanitize-blacklist wins if it is specified later.
-// RUN: %clang -fsanitize=address -fsanitize-blacklist=%t.good 
-fno-sanitize-blacklist %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-NO-BLACKLIST --check-prefix=DELIMITERS
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address 
-fsanitize-blacklist=%t.good -fno-sanitize-blacklist %s -### 2>&1 | FileCheck 
%s --check-prefix=CHECK-NO-BLACKLIST --check-prefix=DELIMITERS
 // CHECK-NO-BLACKLIST-NOT: -fsanitize-blacklist
 
 // Driver barks on unexisting blacklist files.
-// RUN: %clang -fno-sanitize-blacklist -fsanitize-blacklist=unexisting.txt %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-SUCH-FILE
+// RUN: %clang -target x86_64-linux-gnu -fno-sanitize-blacklist 
-fsanitize-blacklist=unexisting.txt %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-NO-SUCH-FILE
 // CHECK-NO-SUCH-FILE: error: no such file or directory: 'unexisting.txt'
 
 // Driver properly reports malformed blacklist files.
-// RUN: %clang -fsanitize=address -fsanitize-blacklist=%t.second 
-fsanitize-blacklist=%t.bad -fsanitize-blacklist=%t.good %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-BAD-BLACKLIST
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address 
-fsanitize-blacklist=%t.second -fsanitize-blacklist=%t.bad 
-fsanitize-blacklist=%t.good %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-BAD-BLACKLIST
 // CHECK-BAD-BLACKLIST: error: malformed sanitizer blacklist: 'error parsing 
file '{{.*}}.bad': malformed line 1: 'badline''
 
 // -fno-sanitize-blacklist disables all blacklists specified earlier.
-// RUN: %clang -fsanitize=address -fsanitize-blacklist=%t.good 
-fno-sanitize-blacklist -fsanitize-blacklist=%t.second %s -### 2>&1 | FileCheck 
%s --check-prefix=CHECK-ONLY-FIRST-DISABLED
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address 
-fsanitize-blacklist=%t.good -fno-sanitize-blacklist 
-fsanitize-blacklist=

Re: Patch for PR23472

2015-09-03 Thread Reid Kleckner via cfe-commits
LGTM, but I would expand on the comment a bit:
 // The ABI says: "It is suggested that it be emitted in the same
COMDAT group
 // as the associated data object." In practice, this doesn't work for
non-ELF object formats, so only do it for ELF.

On Thu, Sep 3, 2015 at 11:31 AM, Rafael Espíndola <
rafael.espind...@gmail.com> wrote:

> I fully trust Reid review on this, so OK with me.
>
> On 3 September 2015 at 14:04, Yaron Keren  wrote:
> > http://llvm.org/pr23472
> >
> > As suggested by Reid, OK to commit?
> >
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12580: Added StrictVTablePointers linking requirement

2015-09-03 Thread Piotr Padlewski via cfe-commits
Prazek updated this revision to Diff 33969.

http://reviews.llvm.org/D12580

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGenCXX/strict-vtable-pointers.cpp

Index: test/CodeGenCXX/strict-vtable-pointers.cpp
===
--- test/CodeGenCXX/strict-vtable-pointers.cpp
+++ test/CodeGenCXX/strict-vtable-pointers.cpp
@@ -2,6 +2,7 @@
 // RUN: FileCheck --check-prefix=CHECK-CTORS %s < %t.ll
 // RUN: FileCheck --check-prefix=CHECK-NEW %s < %t.ll
 // RUN: FileCheck --check-prefix=CHECK-DTORS %s < %t.ll
+// RUN: FileCheck --check-prefix=CHECK-LINK-REQ %s < %t.ll
 
 typedef __typeof__(sizeof(0)) size_t;
 void *operator new(size_t, void*) throw();
@@ -191,3 +192,11 @@
 // CHECK-DTORS-LABEL: define linkonce_odr void @_ZN14DynamicDerivedD2Ev
 // CHECK-DTORS-NOT: call i8* @llvm.invariant.group.barrier(
 // CHECK-DTORS-LABEL: }
+
+
+// CHECK-LINK-REQ: !llvm.module.flags = !{![[FIRST:.*]], ![[SEC:.*]]{{.*}}}
+
+// CHECK-LINK-REQ: ![[FIRST]] = !{i32 1, !"StrictVTablePointers", i32 1}
+// CHECK-LINK-REQ: ![[SEC]] = !{i32 3, !"StrictVTablePointersRequirement", 
![[META:.*]]}
+// CHECK-LINK-REQ: ![[META]] = !{!"StrictVTablePointers", i32 1}
+
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -394,6 +394,22 @@
 // Indicate that we want CodeView in the metadata.
 getModule().addModuleFlag(llvm::Module::Warning, "CodeView", 1);
   }
+  if (CodeGenOpts.OptimizationLevel > 0 && CodeGenOpts.StrictVTablePointers) {
+// We don't support LTO with 2 with different StrictVTablePointers
+// FIXME: we could support it by stripping all the information introduced
+// by StrictVTablePointers.
+
+getModule().addModuleFlag(llvm::Module::Error, "StrictVTablePointers",1);
+
+llvm::Metadata *Ops[2] = {
+  llvm::MDString::get(VMContext, "StrictVTablePointers"),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  llvm::Type::getInt32Ty(VMContext), 1))};
+
+getModule().addModuleFlag(llvm::Module::Require,
+  "StrictVTablePointersRequirement",
+  llvm::MDNode::get(VMContext, Ops));
+  }
   if (DebugInfo)
 // We support a single version in the linked module. The LLVM
 // parser will drop debug info with a different version number


Index: test/CodeGenCXX/strict-vtable-pointers.cpp
===
--- test/CodeGenCXX/strict-vtable-pointers.cpp
+++ test/CodeGenCXX/strict-vtable-pointers.cpp
@@ -2,6 +2,7 @@
 // RUN: FileCheck --check-prefix=CHECK-CTORS %s < %t.ll
 // RUN: FileCheck --check-prefix=CHECK-NEW %s < %t.ll
 // RUN: FileCheck --check-prefix=CHECK-DTORS %s < %t.ll
+// RUN: FileCheck --check-prefix=CHECK-LINK-REQ %s < %t.ll
 
 typedef __typeof__(sizeof(0)) size_t;
 void *operator new(size_t, void*) throw();
@@ -191,3 +192,11 @@
 // CHECK-DTORS-LABEL: define linkonce_odr void @_ZN14DynamicDerivedD2Ev
 // CHECK-DTORS-NOT: call i8* @llvm.invariant.group.barrier(
 // CHECK-DTORS-LABEL: }
+
+
+// CHECK-LINK-REQ: !llvm.module.flags = !{![[FIRST:.*]], ![[SEC:.*]]{{.*}}}
+
+// CHECK-LINK-REQ: ![[FIRST]] = !{i32 1, !"StrictVTablePointers", i32 1}
+// CHECK-LINK-REQ: ![[SEC]] = !{i32 3, !"StrictVTablePointersRequirement", ![[META:.*]]}
+// CHECK-LINK-REQ: ![[META]] = !{!"StrictVTablePointers", i32 1}
+
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -394,6 +394,22 @@
 // Indicate that we want CodeView in the metadata.
 getModule().addModuleFlag(llvm::Module::Warning, "CodeView", 1);
   }
+  if (CodeGenOpts.OptimizationLevel > 0 && CodeGenOpts.StrictVTablePointers) {
+// We don't support LTO with 2 with different StrictVTablePointers
+// FIXME: we could support it by stripping all the information introduced
+// by StrictVTablePointers.
+
+getModule().addModuleFlag(llvm::Module::Error, "StrictVTablePointers",1);
+
+llvm::Metadata *Ops[2] = {
+  llvm::MDString::get(VMContext, "StrictVTablePointers"),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  llvm::Type::getInt32Ty(VMContext), 1))};
+
+getModule().addModuleFlag(llvm::Module::Require,
+  "StrictVTablePointersRequirement",
+  llvm::MDNode::get(VMContext, Ops));
+  }
   if (DebugInfo)
 // We support a single version in the linked module. The LLVM
 // parser will drop debug info with a different version number
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] fix parentheses location in a CXXConstructExpr

2015-09-03 Thread Richard Smith via cfe-commits
On Thu, Sep 3, 2015 at 8:58 AM, Manuel Klimek  wrote:

> On Tue, Sep 1, 2015 at 12:31 AM Olivier Goffart  wrote:
>
>> On Monday 31. August 2015 08:07:58 Manuel Klimek wrote:
>> > On Sat, Aug 29, 2015 at 12:23 PM Olivier Goffart via cfe-commits <
>> >
>> > cfe-commits@lists.llvm.org> wrote:
>> > > Hi,
>> > >
>> > > Please review the attached patch.
>> > >
>> > > In Sema::BuildCXXFunctionalCastExpr, if the class has a destructor,
>> the
>> > > Op.SrcExpr might be a CXXBindTemporaryExpr which we need to unwrap.
>> > >
>> > > In the testcase, the first new CHECK worked (because A does not have a
>> > > destructor),  but the second CHECK failed (did not include the last
>> > > parenthese) because D has a destructor.
>> > >
>> > > I used dyn_cast_or_null just to be safe, becasue i don't know if it is
>> > > possible for the BindExpr->getSubExpr() to be null.
>> >
>> > Do you know why the added test for A says 'class foo::A' instead of
>> > 'foo::A' as the other tests do in that file?
>>
>> I don't know.  It seems it has to do with the fully quallified name vs.
>> normal
>> name.
>>
>> For example, if you dumpt the AST of:
>>
>>  namespace foo { class A {} *a1 = new foo::A , *a2 = new A; }
>>
>> You get:
>>
>> [...]
>> | |-VarDecl 0x1c9a7a0  col:29 a1 'class A *' cinit
>> | | `-CXXNewExpr 0x1ce2648  'foo::A *'
>> | |   `-CXXConstructExpr 0x1ce2618  'foo::A':'class foo::A' 'void
>> (void) throw()'
>> | `-VarDecl 0x1ce26d0  col:48 a2 'class A *' cinit
>> |   `-CXXNewExpr 0x1ce2768  'class foo::A *'
>> | `-CXXConstructExpr 0x1ce2738  'class foo::A' 'void (void)
>> throw()'
>>
>>
>> As you can see, when the type of CXXNewExpr is fully quialified, the
>> 'class'
>> keyword is omited, but for a2, it prints the 'class' keyword.
>> The printed type of CXXConstructExpr is even more wierd when it is fully
>> qualified.
>>
>>
>> I guess that's because of ElaboratedTypePolicyRAII in TypePrinter.cpp
>>
>> But this is irrelevant for this patch and the problem it's trying to
>> solve.
>> The reason I used 'using namespace foo' in the test was just so the line
>> with
>> A and D have the same size.   I just copy pasted the thing without
>> thinking
>> about that.
>>
>
> Makes sense. In that case I think it looks good, adding Richard to
> cross-check for the final approval.
>

+  auto ConstructExpr = dyn_cast(Op.SrcExpr.get());
+  if (auto BindExpr = dyn_cast(Op.SrcExpr.get()))
+ConstructExpr =
dyn_cast_or_null(BindExpr->getSubExpr());
+  if (ConstructExpr)

It's slightly better to write this as:

  auto *SubExpr = Op.SrcExpr.get();
  if (auto *BindExpr = dyn_cast(SubExpr))
SubExpr = BindExpr->getSubExpr();
  if (auto *ConstructExpr = dyn_cast(SubExpr))

Otherwise, LGTM.


[The root cause of the problem here is suboptimal design of this AST node.
It doesn't make sense for both CXXFunctionalCastExpr and CXXConstructExpr
to hold the locations of the same set of parens (and we can see from
StmtPrinter that CXXFunctionalCastExpr currently "owns" the parens). But
fixing that is a larger task, so let's just get this immediate bug fixed
for now.]
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12002: Initial WebAssembly support in clang

2015-09-03 Thread Eric Christopher via cfe-commits
echristo added inline comments.


Comment at: lib/Basic/Targets.cpp:7643-7649
@@ +7642,9 @@
+  case llvm::Triple::wasm64:
+// Until specific variations are defined, don't permit any.
+if (!(Triple == llvm::Triple("wasm64-unknown-unknown")) ||
+(!Triple.getVendorName().empty() &&
+ Triple.getVendorName() != "unknown") ||
+(!Triple.getOSName().empty() && Triple.getOSName() != "unknown") ||
+(Triple.hasEnvironment() && Triple.getEnvironmentName() != "unknown"))
+  return nullptr;
+return new WebAssemblyOSTargetInfo(Triple);

sunfishcode wrote:
> echristo wrote:
> > Ditto.
> > 
> > (I said this just below, but it seems to have gotten munged in the newer 
> > version)
> I actually did see your comment and updated the code accordingly. It now does 
> a positive test, `Triple == llvm::Triple("wasm64-unknown-unknown")`, which is 
> simpler than what it did before.
> 
> However, it's also doing additional tests, because the Triple class's 
> operator== doesn't distinguish between an Unknown that was actually "unknown" 
> or an unknown that was some other string. Until we figure out what "vendor", 
> "OS", and "environment" variations of wasm make sense (if any), we want to 
> avoid dealing with accidental alternate triples.
I think this is a lot of overkill here, no other target cares about this so why 
should the wasm target? If it's that important maybe fix Triple?


Repository:
  rL LLVM

http://reviews.llvm.org/D12002



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


Re: [PATCH] D12580: Added StrictVTablePointers linking requirement

2015-09-03 Thread Richard Smith via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

LGTM


http://reviews.llvm.org/D12580



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


Re: [PATCH] D12119: Analyzer: Fix a crasher in UbigraphViz

2015-09-03 Thread Ismail Pazarbasi via cfe-commits
ismailp added a comment.

Ping!


http://reviews.llvm.org/D12119



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


Re: Patch for PR23472

2015-09-03 Thread Yaron Keren via cfe-commits
r246803, thanks!


2015-09-03 23:16 GMT+03:00 Reid Kleckner :

> LGTM, but I would expand on the comment a bit:
>  // The ABI says: "It is suggested that it be emitted in the same
> COMDAT group
>  // as the associated data object." In practice, this doesn't work for
> non-ELF object formats, so only do it for ELF.
>

On Thu, Sep 3, 2015 at 11:31 AM, Rafael Espíndola <
rafael.espind...@gmail.com> wrote:

> I fully trust Reid review on this, so OK with me.
>
> On 3 September 2015 at 14:04, Yaron Keren  wrote:
> > http://llvm.org/pr23472
> >
> > As suggested by Reid, OK to commit?
> >
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r246804 - Add target flag to clang-cl invocation in this test.

2015-09-03 Thread Alexey Samsonov via cfe-commits
Author: samsonov
Date: Thu Sep  3 15:53:14 2015
New Revision: 246804

URL: http://llvm.org/viewvc/llvm-project?rev=246804&view=rev
Log:
Add target flag to clang-cl invocation in this test.

Modified:
cfe/trunk/test/Driver/fsanitize-coverage.c

Modified: cfe/trunk/test/Driver/fsanitize-coverage.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize-coverage.c?rev=246804&r1=246803&r2=246804&view=diff
==
--- cfe/trunk/test/Driver/fsanitize-coverage.c (original)
+++ cfe/trunk/test/Driver/fsanitize-coverage.c Thu Sep  3 15:53:14 2015
@@ -61,7 +61,7 @@
 // CHECK-EXTEND-LEGACY: -fsanitize-coverage-type=1
 // CHECK-EXTEND-LEGACY: -fsanitize-coverage-trace-cmp
 
-// RUN: %clang_cl -fsanitize=address -fsanitize-coverage=1 -c -### -- %s 2>&1 
| FileCheck %s -check-prefix=CLANG-CL-COVERAGE
+// RUN: %clang_cl --target=i386-pc-win32 -fsanitize=address 
-fsanitize-coverage=1 -c -### -- %s 2>&1 | FileCheck %s 
-check-prefix=CLANG-CL-COVERAGE
 // CLANG-CL-COVERAGE-NOT: error:
 // CLANG-CL-COVERAGE-NOT: warning:
 // CLANG-CL-COVERAGE-NOT: argument unused


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


r246806 - Thread safety analysis: the NO_THREAD_SAFETY_ANALYSIS attribute will now

2015-09-03 Thread DeLesley Hutchins via cfe-commits
Author: delesley
Date: Thu Sep  3 16:14:22 2015
New Revision: 246806

URL: http://llvm.org/viewvc/llvm-project?rev=246806&view=rev
Log:
Thread safety analysis: the NO_THREAD_SAFETY_ANALYSIS attribute will now
disable checking of arguments to the function, which is done by
-Wthread-safety-reference.

Modified:
cfe/trunk/lib/Analysis/ThreadSafety.cpp
cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp

Modified: cfe/trunk/lib/Analysis/ThreadSafety.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ThreadSafety.cpp?rev=246806&r1=246805&r2=246806&view=diff
==
--- cfe/trunk/lib/Analysis/ThreadSafety.cpp (original)
+++ cfe/trunk/lib/Analysis/ThreadSafety.cpp Thu Sep  3 16:14:22 2015
@@ -1926,34 +1926,42 @@ void BuildLockset::VisitCallExpr(CallExp
 }
   }
 
-
   if (ExamineArgs) {
 if (FunctionDecl *FD = Exp->getDirectCallee()) {
-  unsigned Fn = FD->getNumParams();
-  unsigned Cn = Exp->getNumArgs();
-  unsigned Skip = 0;
 
-  unsigned i = 0;
-  if (OperatorFun) {
-if (isa(FD)) {
-  // First arg in operator call is implicit self argument,
-  // and doesn't appear in the FunctionDecl.
-  Skip = 1;
-  Cn--;
-} else {
-  // Ignore the first argument of operators; it's been checked above.
-  i = 1;
+  // NO_THREAD_SAFETY_ANALYSIS does double duty here.  Normally it
+  // only turns off checking within the body of a function, but we also
+  // use it to turn off checking in arguments to the function.  This
+  // could result in some false negatives, but the alternative is to
+  // create yet another attribute.
+  //
+  if (!FD->hasAttr()) {
+unsigned Fn = FD->getNumParams();
+unsigned Cn = Exp->getNumArgs();
+unsigned Skip = 0;
+
+unsigned i = 0;
+if (OperatorFun) {
+  if (isa(FD)) {
+// First arg in operator call is implicit self argument,
+// and doesn't appear in the FunctionDecl.
+Skip = 1;
+Cn--;
+  } else {
+// Ignore the first argument of operators; it's been checked above.
+i = 1;
+  }
 }
-  }
-  // Ignore default arguments
-  unsigned n = (Fn < Cn) ? Fn : Cn;
+// Ignore default arguments
+unsigned n = (Fn < Cn) ? Fn : Cn;
 
-  for (; i < n; ++i) {
-ParmVarDecl* Pvd = FD->getParamDecl(i);
-Expr* Arg = Exp->getArg(i+Skip);
-QualType Qt = Pvd->getType();
-if (Qt->isReferenceType())
-  checkAccess(Arg, AK_Read, POK_PassByRef);
+for (; i < n; ++i) {
+  ParmVarDecl* Pvd = FD->getParamDecl(i);
+  Expr* Arg = Exp->getArg(i+Skip);
+  QualType Qt = Pvd->getType();
+  if (Qt->isReferenceType())
+checkAccess(Arg, AK_Read, POK_PassByRef);
+}
   }
 }
   }

Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp?rev=246806&r1=246805&r2=246806&view=diff
==
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Thu Sep  3 16:14:22 
2015
@@ -5091,3 +5091,58 @@ class Foo {
 
 }  // end namespace ScopedAdoptTest
 
+
+namespace TestReferenceNoThreadSafetyAnalysis {
+
+#define TS_UNCHECKED_READ(x) ts_unchecked_read(x)
+
+// Takes a reference to a guarded data member, and returns an unguarded
+// reference.
+template 
+inline const T& ts_unchecked_read(const T& v) NO_THREAD_SAFETY_ANALYSIS {
+  return v;
+}
+
+template 
+inline T& ts_unchecked_read(T& v) NO_THREAD_SAFETY_ANALYSIS {
+  return v;
+}
+
+
+class Foo {
+public:
+  Foo(): a(0) { }
+
+  int a;
+};
+
+
+class Bar {
+public:
+  Bar() : a(0) { }
+
+  Mutex mu;
+  int a   GUARDED_BY(mu);
+  Foo foo GUARDED_BY(mu);
+};
+
+
+void test() {
+  Bar bar;
+  const Bar cbar;
+
+  int a = TS_UNCHECKED_READ(bar.a);   // nowarn
+  TS_UNCHECKED_READ(bar.a) = 1;   // nowarn
+
+  int b = TS_UNCHECKED_READ(bar.foo).a;   // nowarn
+  TS_UNCHECKED_READ(bar.foo).a = 1;   // nowarn
+
+  int c = TS_UNCHECKED_READ(cbar.a);  // nowarn
+}
+
+#undef TS_UNCHECKED_READ
+
+}  // end namespace TestReferenceNoThreadSafetyAnalysis
+
+
+


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


Re: [PATCH] D12022: Refactored dtor sanitizing into EHScopeStack

2015-09-03 Thread Richard Smith via cfe-commits
rsmith added inline comments.


Comment at: lib/CodeGen/CGCXX.cpp:140-147
@@ -131,1 +139,10 @@
 
+  // If sanitizing memory to check for use-after-dtor, do not emit as
+  //  an alias, unless this class owns no members with trivial destructors.
+  const CXXMethodDecl *MD =
+  cast(AliasDecl.getDecl())->getCanonicalDecl();
+  if (isa(MD) &&
+  getCodeGenOpts().SanitizeMemoryUseAfterDtor &&
+  HasFieldWithTrivialDestructor(*this, MD->getParent()))
+return true;
+

Having checked a bit more, I think this test should go in 
`TryEmitBaseDestructorAsAlias`: it's OK to emit the complete object destructor 
for a class as an alias for the base subobject constructor for the same class 
even if this sanitizer is enabled, but it's not OK to emit the destructor for 
the class as an alias for a base class's destructor (which is what 
`TryEmitBaseDestructorAsAlias` is checking).

The check then becomes a lot simpler: with the sanitizer enabled, for each 
field we will do exactly one of (a) invoke a destructor (which will poison the 
memory) or (b) poison the memory ourselves. So if the sanitizer is enabled, we 
can emit an alias only if the derived class has no fields.


Comment at: lib/CodeGen/CGClass.cpp:1559-1560
@@ +1558,4 @@
+  // RecordDecl::field_iterator Field;
+  for (const auto F : Dtor->getParent()->fields()) {
+FieldDecl const *Field = F;
+// Poison field if it is trivial

Separately declaring `F` and `Field` seems unnecessary; how about:

  for (const FieldDecl *Field : Dtor->getParent()->fields()) {


Comment at: lib/CodeGen/CGClass.cpp:1592-1593
@@ +1591,4 @@
+  Context.getASTRecordLayout(Dtor->getParent());
+  llvm::ConstantInt *OffsetSizePtr;
+  llvm::Value *OffsetPtr;
+  CharUnits::QuantityType PoisonSize;

Initialize these as you declare them, rather than separately:

  llvm::ConstantInt *OffsetSizePtr = llvm::ConstantInt::get(
// ...
  llvm::Value *OffsetPtr = // ...


Comment at: test/CodeGenCXX/sanitize-dtor-bit-field.cpp:1
@@ +1,2 @@
+// Test -fsanitize-memory-use-after-dtor
+// RUN: %clang_cc1 -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor 
-disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | 
FileCheck %s

It'd also be good to test for the case where a bit-field is adjacent to 
non-sanitized fields:

  struct A { char c; ~A(); };
  struct B {
A x;
int n : 1;
A y;
  };


http://reviews.llvm.org/D12022



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


Re: [PATCH] fix parentheses location in a CXXConstructExpr

2015-09-03 Thread Olivier Goffart via cfe-commits
On Thursday 3. September 2015 13:41:12 Richard Smith wrote:
> On Thu, Sep 3, 2015 at 8:58 AM, Manuel Klimek  wrote:
> > On Tue, Sep 1, 2015 at 12:31 AM Olivier Goffart  wrote:
> >> On Monday 31. August 2015 08:07:58 Manuel Klimek wrote:
> >> > On Sat, Aug 29, 2015 at 12:23 PM Olivier Goffart via cfe-commits <
> >> > 
> >> > cfe-commits@lists.llvm.org> wrote:
> >> > > Hi,
> >> > > 
> >> > > Please review the attached patch.
> >> > > 
> >> > > In Sema::BuildCXXFunctionalCastExpr, if the class has a destructor,
> >> 
> >> the
> >> 
> >> > > Op.SrcExpr might be a CXXBindTemporaryExpr which we need to unwrap.
> >> > > 
> >> > > In the testcase, the first new CHECK worked (because A does not have
> >> > > a
> >> > > destructor),  but the second CHECK failed (did not include the last
> >> > > parenthese) because D has a destructor.
> >> > > 
> >> > > I used dyn_cast_or_null just to be safe, becasue i don't know if it
> >> > > is
> >> > > possible for the BindExpr->getSubExpr() to be null.
> >> > 
> >> > Do you know why the added test for A says 'class foo::A' instead of
> >> > 'foo::A' as the other tests do in that file?
> >> 
> >> I don't know.  It seems it has to do with the fully quallified name vs.
> >> normal
> >> name.
> >> 
> >> For example, if you dumpt the AST of:
> >>  namespace foo { class A {} *a1 = new foo::A , *a2 = new A; }
> >> 
> >> You get:
> >> 
> >> [...]
> >> 
> >> | |-VarDecl 0x1c9a7a0  col:29 a1 'class A *' cinit
> >> | |
> >> | | `-CXXNewExpr 0x1ce2648  'foo::A *'
> >> | | 
> >> | |   `-CXXConstructExpr 0x1ce2618  'foo::A':'class foo::A' 'void
> >> 
> >> (void) throw()'
> >> 
> >> | `-VarDecl 0x1ce26d0  col:48 a2 'class A *' cinit
> >> | 
> >> |   `-CXXNewExpr 0x1ce2768  'class foo::A *'
> >> |   
> >> | `-CXXConstructExpr 0x1ce2738  'class foo::A' 'void (void)
> >> 
> >> throw()'
> >> 
> >> 
> >> As you can see, when the type of CXXNewExpr is fully quialified, the
> >> 'class'
> >> keyword is omited, but for a2, it prints the 'class' keyword.
> >> The printed type of CXXConstructExpr is even more wierd when it is fully
> >> qualified.
> >> 
> >> 
> >> I guess that's because of ElaboratedTypePolicyRAII in TypePrinter.cpp
> >> 
> >> But this is irrelevant for this patch and the problem it's trying to
> >> solve.
> >> The reason I used 'using namespace foo' in the test was just so the line
> >> with
> >> A and D have the same size.   I just copy pasted the thing without
> >> thinking
> >> about that.
> > 
> > Makes sense. In that case I think it looks good, adding Richard to
> > cross-check for the final approval.
> 
> +  auto ConstructExpr = dyn_cast(Op.SrcExpr.get());
> +  if (auto BindExpr = dyn_cast(Op.SrcExpr.get()))
> +ConstructExpr =
> dyn_cast_or_null(BindExpr->getSubExpr());
> +  if (ConstructExpr)
> 
> It's slightly better to write this as:
> 
>   auto *SubExpr = Op.SrcExpr.get();
>   if (auto *BindExpr = dyn_cast(SubExpr))
> SubExpr = BindExpr->getSubExpr();
>   if (auto *ConstructExpr = dyn_cast(SubExpr))
> 
> Otherwise, LGTM.


Thanks.

So no dyn_cast_or_null?   CXXBindTemporaryExpr::getSubExpr never returns null 
here?

> [The root cause of the problem here is suboptimal design of this AST node.
> It doesn't make sense for both CXXFunctionalCastExpr and CXXConstructExpr
> to hold the locations of the same set of parens (and we can see from
> StmtPrinter that CXXFunctionalCastExpr currently "owns" the parens). But
> fixing that is a larger task, so let's just get this immediate bug fixed
> for now.]

[This is however quite convnient for me to get the location of the parentheses 
of a CXXConstructorExpr. There are may cases where CXXConstructorExpr is not 
in a CXXFunctionalCastExpr]

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


Re: [PATCH] D12119: Analyzer: Fix a crasher in UbigraphViz

2015-09-03 Thread Anna Zaks via cfe-commits
zaks.anna added a comment.

I do not understand why there should be a cycle here in the Exploded Graph. 
Most likely this assertion uncovers a bug in cfg-temporary-doors, which is a 
disabled by default feature (it has not been completed yet). You can think of 
"ProgramState" as the state of the program, so it would have information about 
the values of both, 'a' and 'b' at the same time. You are right, maybe while we 
are evaluating the destructor, the distinction between 'a' and 'b' is lost, but 
that's a bug in how the temporary destructors are handled.

I do not think the assertion should be removed.


http://reviews.llvm.org/D12119



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


Re: [PATCH] D12022: Refactored dtor sanitizing into EHScopeStack

2015-09-03 Thread Naomi Musgrave via cfe-commits
nmusgrave updated this revision to Diff 33978.
nmusgrave marked 4 inline comments as done.
nmusgrave added a comment.

- Simplified fields and checks for aliasing.


http://reviews.llvm.org/D12022

Files:
  lib/CodeGen/CGCXX.cpp
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CodeGenModule.h
  test/CodeGenCXX/sanitize-dtor-bit-field.cpp
  test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
  test/CodeGenCXX/sanitize-dtor-repress-aliasing.cpp

Index: test/CodeGenCXX/sanitize-dtor-repress-aliasing.cpp
===
--- /dev/null
+++ test/CodeGenCXX/sanitize-dtor-repress-aliasing.cpp
@@ -0,0 +1,30 @@
+// Test -fsanitize-memory-use-after-dtor
+// RUN: %clang_cc1 -fsanitize=memory -O1 -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fsanitize=memory -O2 -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+
+template 
+class Vector {
+public:
+  int size;
+  ~Vector() {}
+};
+
+// Virtual function table for the derived class only contains
+// its own destructors, with no aliasing to base class dtors.
+struct Base {
+  Vector v;
+  int x;
+  Base() { x = 5; }
+  virtual ~Base() {}
+};
+
+struct Derived : public Base {
+  int z;
+  Derived() { z = 10; }
+  ~Derived() {}
+};
+
+Derived d;
+
+// Definition of virtual function table
+// CHECK: @_ZTV7Derived = {{.*}}@_ZN7DerivedD1Ev{{.*}}@_ZN7DerivedD0Ev
Index: test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
===
--- /dev/null
+++ test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
@@ -0,0 +1,82 @@
+// RUN: %clang_cc1 -fsanitize=memory -O0 -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fsanitize=memory -O1 -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+
+template 
+class Vector {
+public:
+  int size;
+  ~Vector() {
+size += 1;
+  }
+};
+
+struct Base {
+  int b1;
+  double b2;
+  Base() {
+b1 = 5;
+b2 = 10.989;
+  }
+  virtual ~Base() {}
+};
+
+struct VirtualBase {
+  int vb1;
+  int vb2;
+  VirtualBase() {
+vb1 = 10;
+vb2 = 11;
+  }
+  virtual ~VirtualBase() {}
+};
+
+struct Derived : public Base, public virtual VirtualBase {
+  int d1;
+  Vector v;
+  int d2;
+  Derived() {
+d1 = 10;
+  }
+  ~Derived() {}
+};
+
+Derived d;
+
+// Destruction order:
+// Derived: int, Vector, Base, VirtualBase
+
+// CHECK-LABEL: define {{.*}}ZN7DerivedD1Ev
+// CHECK: call void {{.*}}ZN11VirtualBaseD2Ev
+// CHECK: ret void
+
+// CHECK-LABEL: define {{.*}}ZN7DerivedD0Ev
+// CHECK: ret void
+
+// CHECK-LABEL: define {{.*}}ZN11VirtualBaseD1Ev
+// CHECK: ret void
+
+// CHECK-LABEL: define {{.*}}ZN11VirtualBaseD0Ev
+// CHECK: ret void
+
+// poison 2 ints
+// CHECK-LABEL: define {{.*}}ZN11VirtualBaseD2Ev
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 8)
+// CHECK: ret void
+
+// poison int and double
+// CHECK-LABEL: define {{.*}}ZN4BaseD2Ev
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 16)
+// CHECK: ret void
+
+// poison int, ignore vector, poison int
+// CHECK-LABEL: define {{.*}}ZN7DerivedD2Ev
+// CHECK: call void {{.*}}ZN6VectorIiED1Ev
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 4)
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 4)
+// CHECK: call void {{.*}}ZN4BaseD2Ev
+// CHECK: ret void
+
+// poison int
+// CHECK-LABEL: define {{.*}}ZN6VectorIiED2Ev
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 4)
+// CHECK: ret void
Index: test/CodeGenCXX/sanitize-dtor-bit-field.cpp
===
--- /dev/null
+++ test/CodeGenCXX/sanitize-dtor-bit-field.cpp
@@ -0,0 +1,84 @@
+// Test -fsanitize-memory-use-after-dtor
+// RUN: %clang_cc1 -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+
+// 24 bytes total
+struct Packed {
+  // Packed into 4 bytes
+  unsigned int a : 1;
+  unsigned int b : 1;
+  //unsigned int c : 1;
+  // Force alignment to next 4 bytes
+  unsigned int   : 0;
+  unsigned int d : 1;
+  // Force alignment, 8 more bytes
+  double e = 5.0;
+  // 4 bytes
+  unsigned int f : 1;
+  ~Packed() {}
+};
+Packed p;
+
+
+// 1 byte total
+struct Empty {
+  unsigned int : 0;
+  ~Empty() {}
+};
+Empty e;
+
+
+// 4 byte total
+struct Simple {
+  unsigned int a : 1;
+  ~Simple() {}
+};
+Simple s;
+
+
+// 8 bytes total
+struct Anon {
+  // 1 byte
+  unsigned int a : 1;
+  unsigned int b : 2;
+  // Force alignment to next byte
+  unsigned int   : 0;
+  unsigned int c : 1;
+  ~Anon() {}
+};
+Anon an;
+
+
+struc

Re: [PATCH] fix parentheses location in a CXXConstructExpr

2015-09-03 Thread Richard Smith via cfe-commits
On Thu, Sep 3, 2015 at 2:26 PM, Olivier Goffart  wrote:

> On Thursday 3. September 2015 13:41:12 Richard Smith wrote:
> > On Thu, Sep 3, 2015 at 8:58 AM, Manuel Klimek  wrote:
> > > On Tue, Sep 1, 2015 at 12:31 AM Olivier Goffart 
> wrote:
> > >> On Monday 31. August 2015 08:07:58 Manuel Klimek wrote:
> > >> > On Sat, Aug 29, 2015 at 12:23 PM Olivier Goffart via cfe-commits <
> > >> >
> > >> > cfe-commits@lists.llvm.org> wrote:
> > >> > > Hi,
> > >> > >
> > >> > > Please review the attached patch.
> > >> > >
> > >> > > In Sema::BuildCXXFunctionalCastExpr, if the class has a
> destructor,
> > >>
> > >> the
> > >>
> > >> > > Op.SrcExpr might be a CXXBindTemporaryExpr which we need to
> unwrap.
> > >> > >
> > >> > > In the testcase, the first new CHECK worked (because A does not
> have
> > >> > > a
> > >> > > destructor),  but the second CHECK failed (did not include the
> last
> > >> > > parenthese) because D has a destructor.
> > >> > >
> > >> > > I used dyn_cast_or_null just to be safe, becasue i don't know if
> it
> > >> > > is
> > >> > > possible for the BindExpr->getSubExpr() to be null.
> > >> >
> > >> > Do you know why the added test for A says 'class foo::A' instead of
> > >> > 'foo::A' as the other tests do in that file?
> > >>
> > >> I don't know.  It seems it has to do with the fully quallified name
> vs.
> > >> normal
> > >> name.
> > >>
> > >> For example, if you dumpt the AST of:
> > >>  namespace foo { class A {} *a1 = new foo::A , *a2 = new A; }
> > >>
> > >> You get:
> > >>
> > >> [...]
> > >>
> > >> | |-VarDecl 0x1c9a7a0  col:29 a1 'class A *' cinit
> > >> | |
> > >> | | `-CXXNewExpr 0x1ce2648  'foo::A *'
> > >> | |
> > >> | |   `-CXXConstructExpr 0x1ce2618  'foo::A':'class foo::A'
> 'void
> > >>
> > >> (void) throw()'
> > >>
> > >> | `-VarDecl 0x1ce26d0  col:48 a2 'class A *' cinit
> > >> |
> > >> |   `-CXXNewExpr 0x1ce2768  'class foo::A *'
> > >> |
> > >> | `-CXXConstructExpr 0x1ce2738  'class foo::A' 'void
> (void)
> > >>
> > >> throw()'
> > >>
> > >>
> > >> As you can see, when the type of CXXNewExpr is fully quialified, the
> > >> 'class'
> > >> keyword is omited, but for a2, it prints the 'class' keyword.
> > >> The printed type of CXXConstructExpr is even more wierd when it is
> fully
> > >> qualified.
> > >>
> > >>
> > >> I guess that's because of ElaboratedTypePolicyRAII in TypePrinter.cpp
> > >>
> > >> But this is irrelevant for this patch and the problem it's trying to
> > >> solve.
> > >> The reason I used 'using namespace foo' in the test was just so the
> line
> > >> with
> > >> A and D have the same size.   I just copy pasted the thing without
> > >> thinking
> > >> about that.
> > >
> > > Makes sense. In that case I think it looks good, adding Richard to
> > > cross-check for the final approval.
> >
> > +  auto ConstructExpr = dyn_cast(Op.SrcExpr.get());
> > +  if (auto BindExpr = dyn_cast(Op.SrcExpr.get()))
> > +ConstructExpr =
> > dyn_cast_or_null(BindExpr->getSubExpr());
> > +  if (ConstructExpr)
> >
> > It's slightly better to write this as:
> >
> >   auto *SubExpr = Op.SrcExpr.get();
> >   if (auto *BindExpr = dyn_cast(SubExpr))
> > SubExpr = BindExpr->getSubExpr();
> >   if (auto *ConstructExpr = dyn_cast(SubExpr))
> >
> > Otherwise, LGTM.
>
>
> Thanks.
>
> So no dyn_cast_or_null?   CXXBindTemporaryExpr::getSubExpr never returns
> null
> here?
>
> > [The root cause of the problem here is suboptimal design of this AST
> node.
> > It doesn't make sense for both CXXFunctionalCastExpr and CXXConstructExpr
> > to hold the locations of the same set of parens (and we can see from
> > StmtPrinter that CXXFunctionalCastExpr currently "owns" the parens). But
> > fixing that is a larger task, so let's just get this immediate bug fixed
> > for now.]
>
> [This is however quite convnient for me to get the location of the
> parentheses
> of a CXXConstructorExpr. There are may cases where CXXConstructorExpr is
> not
> in a CXXFunctionalCastExpr]


There are also many cases where it doesn't involve parens =)

The problem is that for a declaration of the form:

  T x(y);

... the parens are owned by the VarDecl, because we don't have a separate
AST representation for "direct initialization of scalar type" to hold the
parens. Consistency with that implies CXXConstructExprs do not own their
own parens, and it doesn't make sense to store those paren locations on the
CXXConstructExpr node as a result.

Conversely, for a declaration of the form:

  T x{y};

... the braces are owned by the initialization expression, not by the
VarDecl, either as an InitListExpr or by the CXXConstructExpr representing
the list initialization.

The most natural approach to resolve this tension would be to add a new AST
node for non-class direct initialization, and to add subclasses of
CXXConstructExpr for different syntaxes (and remove the redundant and
conflicting CXXTemporaryObjectExpr node). But this is a fairly large
restructuring, and I've not found time to do it yet.

(If you're interested i

Re: [PATCH] D12022: Refactored dtor sanitizing into EHScopeStack

2015-09-03 Thread Richard Smith via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

LGTM with a couple of tweaks.



Comment at: lib/CodeGen/CGCXX.cpp:45-46
@@ +44,4 @@
+  //  an alias, unless this class owns no members.
+  unsigned totalFields =
+  std::distance(D->getParent()->field_begin(), 
D->getParent()->field_end());
+  if (getCodeGenOpts().SanitizeMemoryUseAfterDtor && totalFields > 0)

You can just use `!D->getParent()->field_empty()`


Comment at: lib/CodeGen/CGClass.cpp:1289
@@ -1288,7 +1288,3 @@
 
-static bool
-FieldHasTrivialDestructorBody(ASTContext &Context, const FieldDecl *Field);
-
-static bool
-HasTrivialDestructorBody(ASTContext &Context,
+bool CodeGenModule::HasTrivialDestructorBody(ASTContext &Context,
  const CXXRecordDecl *BaseClassDecl,

I think you no longer need to make these functions members.


http://reviews.llvm.org/D12022



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


Re: [PATCH] D12022: Refactored dtor sanitizing into EHScopeStack

2015-09-03 Thread Naomi Musgrave via cfe-commits
nmusgrave updated this revision to Diff 33982.
nmusgrave marked 2 inline comments as done.
nmusgrave added a comment.

- Clean method headers, style.


http://reviews.llvm.org/D12022

Files:
  lib/CodeGen/CGCXX.cpp
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CodeGenModule.h
  test/CodeGenCXX/sanitize-dtor-bit-field.cpp
  test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
  test/CodeGenCXX/sanitize-dtor-repress-aliasing.cpp

Index: test/CodeGenCXX/sanitize-dtor-repress-aliasing.cpp
===
--- /dev/null
+++ test/CodeGenCXX/sanitize-dtor-repress-aliasing.cpp
@@ -0,0 +1,30 @@
+// Test -fsanitize-memory-use-after-dtor
+// RUN: %clang_cc1 -fsanitize=memory -O1 -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fsanitize=memory -O2 -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+
+template 
+class Vector {
+public:
+  int size;
+  ~Vector() {}
+};
+
+// Virtual function table for the derived class only contains
+// its own destructors, with no aliasing to base class dtors.
+struct Base {
+  Vector v;
+  int x;
+  Base() { x = 5; }
+  virtual ~Base() {}
+};
+
+struct Derived : public Base {
+  int z;
+  Derived() { z = 10; }
+  ~Derived() {}
+};
+
+Derived d;
+
+// Definition of virtual function table
+// CHECK: @_ZTV7Derived = {{.*}}@_ZN7DerivedD1Ev{{.*}}@_ZN7DerivedD0Ev
Index: test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
===
--- /dev/null
+++ test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
@@ -0,0 +1,82 @@
+// RUN: %clang_cc1 -fsanitize=memory -O0 -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fsanitize=memory -O1 -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+
+template 
+class Vector {
+public:
+  int size;
+  ~Vector() {
+size += 1;
+  }
+};
+
+struct Base {
+  int b1;
+  double b2;
+  Base() {
+b1 = 5;
+b2 = 10.989;
+  }
+  virtual ~Base() {}
+};
+
+struct VirtualBase {
+  int vb1;
+  int vb2;
+  VirtualBase() {
+vb1 = 10;
+vb2 = 11;
+  }
+  virtual ~VirtualBase() {}
+};
+
+struct Derived : public Base, public virtual VirtualBase {
+  int d1;
+  Vector v;
+  int d2;
+  Derived() {
+d1 = 10;
+  }
+  ~Derived() {}
+};
+
+Derived d;
+
+// Destruction order:
+// Derived: int, Vector, Base, VirtualBase
+
+// CHECK-LABEL: define {{.*}}ZN7DerivedD1Ev
+// CHECK: call void {{.*}}ZN11VirtualBaseD2Ev
+// CHECK: ret void
+
+// CHECK-LABEL: define {{.*}}ZN7DerivedD0Ev
+// CHECK: ret void
+
+// CHECK-LABEL: define {{.*}}ZN11VirtualBaseD1Ev
+// CHECK: ret void
+
+// CHECK-LABEL: define {{.*}}ZN11VirtualBaseD0Ev
+// CHECK: ret void
+
+// poison 2 ints
+// CHECK-LABEL: define {{.*}}ZN11VirtualBaseD2Ev
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 8)
+// CHECK: ret void
+
+// poison int and double
+// CHECK-LABEL: define {{.*}}ZN4BaseD2Ev
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 16)
+// CHECK: ret void
+
+// poison int, ignore vector, poison int
+// CHECK-LABEL: define {{.*}}ZN7DerivedD2Ev
+// CHECK: call void {{.*}}ZN6VectorIiED1Ev
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 4)
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 4)
+// CHECK: call void {{.*}}ZN4BaseD2Ev
+// CHECK: ret void
+
+// poison int
+// CHECK-LABEL: define {{.*}}ZN6VectorIiED2Ev
+// CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 4)
+// CHECK: ret void
Index: test/CodeGenCXX/sanitize-dtor-bit-field.cpp
===
--- /dev/null
+++ test/CodeGenCXX/sanitize-dtor-bit-field.cpp
@@ -0,0 +1,84 @@
+// Test -fsanitize-memory-use-after-dtor
+// RUN: %clang_cc1 -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+
+// 24 bytes total
+struct Packed {
+  // Packed into 4 bytes
+  unsigned int a : 1;
+  unsigned int b : 1;
+  //unsigned int c : 1;
+  // Force alignment to next 4 bytes
+  unsigned int   : 0;
+  unsigned int d : 1;
+  // Force alignment, 8 more bytes
+  double e = 5.0;
+  // 4 bytes
+  unsigned int f : 1;
+  ~Packed() {}
+};
+Packed p;
+
+
+// 1 byte total
+struct Empty {
+  unsigned int : 0;
+  ~Empty() {}
+};
+Empty e;
+
+
+// 4 byte total
+struct Simple {
+  unsigned int a : 1;
+  ~Simple() {}
+};
+Simple s;
+
+
+// 8 bytes total
+struct Anon {
+  // 1 byte
+  unsigned int a : 1;
+  unsigned int b : 2;
+  // Force alignment to next byte
+  unsigned int   : 0;
+  unsigned int c : 1;
+  ~Anon() {}
+};
+Anon an;
+
+
+struct CharStruct {

Re: [PATCH] D12002: Initial WebAssembly support in clang

2015-09-03 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL246814: [WebAssembly] Initial WebAssembly support in clang 
(authored by djg).

Changed prior to commit:
  http://reviews.llvm.org/D12002?vs=33637&id=33985#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D12002

Files:
  cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
  cfe/trunk/include/clang/Basic/TargetBuiltins.h
  cfe/trunk/include/clang/Basic/TargetCXXABI.h
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/include/clang/module.modulemap
  cfe/trunk/lib/AST/ASTContext.cpp
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
  cfe/trunk/lib/CodeGen/TargetInfo.cpp
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/lib/Driver/ToolChain.cpp
  cfe/trunk/lib/Driver/ToolChains.cpp
  cfe/trunk/lib/Driver/ToolChains.h
  cfe/trunk/lib/Driver/Tools.cpp
  cfe/trunk/test/CodeGen/align-wasm.c
  cfe/trunk/test/CodeGen/builtins-wasm.c
  cfe/trunk/test/CodeGen/target-data.c
  cfe/trunk/test/CodeGen/wasm-arguments.c
  cfe/trunk/test/CodeGen/wasm-regparm.c
  cfe/trunk/test/CodeGenCXX/constructor-destructor-return-this.cpp
  cfe/trunk/test/CodeGenCXX/member-alignment.cpp
  cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp
  cfe/trunk/test/CodeGenCXX/static-init-wasm.cpp
  cfe/trunk/test/CodeGenCXX/wasm-args-returns.cpp
  cfe/trunk/test/Driver/thread-model.c
  cfe/trunk/test/Driver/wasm32-unknown-unknown.cpp
  cfe/trunk/test/Driver/wasm64-unknown-unknown.cpp
  cfe/trunk/test/Preprocessor/init.c
  cfe/trunk/test/Preprocessor/wasm-target-features.c

Index: cfe/trunk/include/clang/Basic/TargetBuiltins.h
===
--- cfe/trunk/include/clang/Basic/TargetBuiltins.h
+++ cfe/trunk/include/clang/Basic/TargetBuiltins.h
@@ -185,6 +185,17 @@
 LastTSBuiltin
 };
   }
+
+  /// \brief WebAssembly builtins
+  namespace WebAssembly {
+enum {
+  LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1,
+#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
+#include "clang/Basic/BuiltinsWebAssembly.def"
+  LastTSBuiltin
+};
+  }
+
 } // end namespace clang.
 
 #endif
Index: cfe/trunk/include/clang/Basic/TargetCXXABI.h
===
--- cfe/trunk/include/clang/Basic/TargetCXXABI.h
+++ cfe/trunk/include/clang/Basic/TargetCXXABI.h
@@ -85,6 +85,21 @@
 ///   - representation of member function pointers adjusted as in ARM.
 GenericMIPS,
 
+/// The WebAssembly ABI is a modified version of the Itanium ABI.
+///
+/// The changes from the Itanium ABI are:
+///   - representation of member function pointers is adjusted, as in ARM;
+///   - member functions are not specially aligned;
+///   - constructors and destructors return 'this', as in ARM;
+///   - guard variables are 32-bit on wasm32, as in ARM;
+///   - unused bits of guard variables are reserved, as in ARM;
+///   - inline functions are never key functions, as in ARM;
+///   - C++11 POD rules are used for tail padding, as in iOS64.
+///
+/// TODO: At present the WebAssembly ABI is not considered stable, so none
+/// of these details is necessarily final yet.
+WebAssembly,
+
 /// The Microsoft ABI is the ABI used by Microsoft Visual Studio (and
 /// compatible compilers).
 ///
@@ -121,6 +136,7 @@
 case iOS:
 case iOS64:
 case GenericMIPS:
+case WebAssembly:
   return true;
 
 case Microsoft:
@@ -138,14 +154,44 @@
 case iOS:
 case iOS64:
 case GenericMIPS:
+case WebAssembly:
   return false;
 
 case Microsoft:
   return true;
 }
 llvm_unreachable("bad ABI kind");
   }
 
+  /// \brief Are member functions differently aligned?
+  ///
+  /// Many Itanium-style C++ ABIs require member functions to be aligned, so
+  /// that a pointer to such a function is guaranteed to have a zero in the
+  /// least significant bit, so that pointers to member functions can use that
+  /// bit to distinguish between virtual and non-virtual functions. However,
+  /// some Itanium-style C++ ABIs differentiate between virtual and non-virtual
+  /// functions via other means, and consequently don't require that member
+  /// functions be aligned.
+  bool areMemberFunctionsAligned() const {
+switch (getKind()) {
+case WebAssembly:
+  // WebAssembly doesn't require any special alignment for member functions.
+  return false;
+case GenericARM:
+case GenericAArch64:
+case GenericMIPS:
+  // TODO: ARM-style pointers to member functions put the discriminator in
+  //   the this adjustment, so they don't require functions to have any
+  //   special alignment and could therefore also return false.
+case GenericItanium:
+case iOS:
+case iOS64:
+case Microsoft:
+   

r246814 - [WebAssembly] Initial WebAssembly support in clang

2015-09-03 Thread Dan Gohman via cfe-commits
Author: djg
Date: Thu Sep  3 17:51:53 2015
New Revision: 246814

URL: http://llvm.org/viewvc/llvm-project?rev=246814&view=rev
Log:
[WebAssembly] Initial WebAssembly support in clang

This implements basic support for compiling (though not yet assembling
or linking) for a WebAssembly target. Note that ABI details are not yet
finalized, and may change.

Differential Revision: http://reviews.llvm.org/D12002

Added:
cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
cfe/trunk/test/CodeGen/align-wasm.c
  - copied, changed from r244997, cfe/trunk/test/CodeGen/align-x68_64.c
cfe/trunk/test/CodeGen/builtins-wasm.c
cfe/trunk/test/CodeGen/wasm-arguments.c
cfe/trunk/test/CodeGen/wasm-regparm.c
cfe/trunk/test/CodeGenCXX/static-init-wasm.cpp
cfe/trunk/test/CodeGenCXX/wasm-args-returns.cpp
cfe/trunk/test/Driver/wasm32-unknown-unknown.cpp
cfe/trunk/test/Driver/wasm64-unknown-unknown.cpp
cfe/trunk/test/Preprocessor/wasm-target-features.c
Modified:
cfe/trunk/include/clang/Basic/TargetBuiltins.h
cfe/trunk/include/clang/Basic/TargetCXXABI.h
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/module.modulemap
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/lib/Driver/ToolChains.h
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/CodeGen/target-data.c
cfe/trunk/test/CodeGenCXX/constructor-destructor-return-this.cpp
cfe/trunk/test/CodeGenCXX/member-alignment.cpp
cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp
cfe/trunk/test/Driver/thread-model.c
cfe/trunk/test/Preprocessor/init.c

Added: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def?rev=246814&view=auto
==
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def (added)
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def Thu Sep  3 17:51:53 
2015
@@ -0,0 +1,21 @@
+// BuiltinsWebAssembly.def - WebAssembly builtin function database -*- C++ 
-*-//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+///
+/// \file
+/// \brief This file defines the WebAssembly-specific builtin function 
database.
+/// Users of this file must define the BUILTIN macro to make use of this
+/// information.
+///
+//===--===//
+
+// The format of this database matches clang/Basic/Builtins.def.
+
+BUILTIN(__builtin_wasm_page_size, "z", "nc")
+
+#undef BUILTIN

Modified: cfe/trunk/include/clang/Basic/TargetBuiltins.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetBuiltins.h?rev=246814&r1=246813&r2=246814&view=diff
==
--- cfe/trunk/include/clang/Basic/TargetBuiltins.h (original)
+++ cfe/trunk/include/clang/Basic/TargetBuiltins.h Thu Sep  3 17:51:53 2015
@@ -185,6 +185,17 @@ namespace clang {
 LastTSBuiltin
 };
   }
+
+  /// \brief WebAssembly builtins
+  namespace WebAssembly {
+enum {
+  LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1,
+#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
+#include "clang/Basic/BuiltinsWebAssembly.def"
+  LastTSBuiltin
+};
+  }
+
 } // end namespace clang.
 
 #endif

Modified: cfe/trunk/include/clang/Basic/TargetCXXABI.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetCXXABI.h?rev=246814&r1=246813&r2=246814&view=diff
==
--- cfe/trunk/include/clang/Basic/TargetCXXABI.h (original)
+++ cfe/trunk/include/clang/Basic/TargetCXXABI.h Thu Sep  3 17:51:53 2015
@@ -85,6 +85,21 @@ public:
 ///   - representation of member function pointers adjusted as in ARM.
 GenericMIPS,
 
+/// The WebAssembly ABI is a modified version of the Itanium ABI.
+///
+/// The changes from the Itanium ABI are:
+///   - representation of member function pointers is adjusted, as in ARM;
+///   - member functions are not specially aligned;
+///   - constructors and destructors return 'this', as in ARM;
+///   - guard variables are 32-bit on wasm32, as in ARM;
+///   - unused bits of guard variables are reserved, as in ARM;
+///   - inline functions are never key functions, as in ARM;
+///   - C++11 POD rules 

r246815 - Refactored dtor sanitizing into EHScopeStack

2015-09-03 Thread Naomi Musgrave via cfe-commits
Author: nmusgrave
Date: Thu Sep  3 18:02:30 2015
New Revision: 246815

URL: http://llvm.org/viewvc/llvm-project?rev=246815&view=rev
Log:
Refactored dtor sanitizing into EHScopeStack

Summary:
Dtor sanitization handled amidst other dtor cleanups,
between cleaning bases and fields. Sanitizer call pushed onto
stack of cleanup operations.

Reviewers: eugenis, kcc

Differential Revision: http://reviews.llvm.org/D12022

Refactoring dtor sanitizing emission order.

- Support multiple inheritance by poisoning after
 member destructors are invoked, and before base
 class destructors are invoked.
- Poison for virtual destructor and virtual bases.
- Repress dtor aliasing when sanitizing in dtor.
- CFE test for dtor aliasing, and repression of aliasing in dtor
 code generation.
- Poison members on field-by-field basis, with collective poisoning
 of trivial members when possible.
- Check msan flags and existence of fields, before dtor sanitizing,
 and when determining if aliasing is allowed.
- Testing sanitizing bit fields.

Added:
cfe/trunk/test/CodeGenCXX/sanitize-dtor-bit-field.cpp
cfe/trunk/test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
cfe/trunk/test/CodeGenCXX/sanitize-dtor-repress-aliasing.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=246815&r1=246814&r2=246815&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Thu Sep  3 18:02:30 2015
@@ -39,6 +39,12 @@ bool CodeGenModule::TryEmitBaseDestructo
   if (getCodeGenOpts().OptimizationLevel == 0)
 return true;
 
+  // If sanitizing memory to check for use-after-dtor, do not emit as
+  //  an alias, unless this class owns no members.
+  if (getCodeGenOpts().SanitizeMemoryUseAfterDtor &&
+  !D->getParent()->field_empty())
+return true;
+
   // If the destructor doesn't have a trivial body, we have to emit it
   // separately.
   if (!D->hasTrivialBody())

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=246815&r1=246814&r2=246815&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Thu Sep  3 18:02:30 2015
@@ -1334,7 +1334,7 @@ HasTrivialDestructorBody(ASTContext &Con
 
 static bool
 FieldHasTrivialDestructorBody(ASTContext &Context,
-  const FieldDecl *Field)
+  const FieldDecl *Field)
 {
   QualType FieldBaseElementType = Context.getBaseElementType(Field->getType());
 
@@ -1353,7 +1353,7 @@ FieldHasTrivialDestructorBody(ASTContext
 
 /// CanSkipVTablePointerInitialization - Check whether we need to initialize
 /// any vtable pointers before calling this destructor.
-static bool CanSkipVTablePointerInitialization(ASTContext &Context,
+static bool CanSkipVTablePointerInitialization(CodeGenFunction &CGF,
const CXXDestructorDecl *Dtor) {
   if (!Dtor->hasTrivialBody())
 return false;
@@ -1361,58 +1361,12 @@ static bool CanSkipVTablePointerInitiali
   // Check the fields.
   const CXXRecordDecl *ClassDecl = Dtor->getParent();
   for (const auto *Field : ClassDecl->fields())
-if (!FieldHasTrivialDestructorBody(Context, Field))
+if (!FieldHasTrivialDestructorBody(CGF.getContext(), Field))
   return false;
 
   return true;
 }
 
-// Generates function call for handling object poisoning, passing in
-// references to 'this' and its size as arguments.
-// Disables tail call elimination, to prevent the current stack frame from
-// disappearing from the stack trace.
-static void EmitDtorSanitizerCallback(CodeGenFunction &CGF,
-  const CXXDestructorDecl *Dtor) {
-  const ASTRecordLayout &Layout =
-  CGF.getContext().getASTRecordLayout(Dtor->getParent());
-
-  // Nothing to poison
-  if(Layout.getFieldCount() == 0)
-return;
-
-  // Construct pointer to region to begin poisoning, and calculate poison
-  // size, so that only members declared in this class are poisoned.
-  llvm::Value *OffsetPtr;
-  CharUnits::QuantityType PoisonSize;
-  ASTContext &Context = CGF.getContext();
-
-  llvm::ConstantInt *OffsetSizePtr = llvm::ConstantInt::get(
-  CGF.SizeTy, Context.toCharUnitsFromBits(Layout.getFieldOffset(0)).
-  getQuantity());
-
-  OffsetPtr = CGF.Builder.CreateGEP(CGF.Builder.CreateBitCast(
-  CGF.LoadCXXThis(), CGF.Int8PtrTy), OffsetSizePtr);
-
-  PoisonSize = Layout.getSize().getQuantity() -
-  Context.toCharUnitsFromBits(Layout.getFieldOffset(0)).getQuantity();
-
-  llvm::Value *Args[] = {
-CGF.Builder.CreateBitCast(OffsetPtr, CGF.VoidPtrT

[PATCH] D12614: [OpenMP] Offloading descriptor registration and device codegen.

2015-09-03 Thread Samuel Antao via cfe-commits
sfantao created this revision.
sfantao added reviewers: ABataev, rjmccall, hfinkel, tra.
sfantao added a subscriber: cfe-commits.

In order to offloading work properly two things need to be in place:
- a descriptor with all the offloading information (device entry functions, and 
global variable) has to be created by the host and registered in the OpenMP 
offloading runtime library.
- all the device functions need to be emitted for the device and a convention 
has to be in place so that the runtime library can easily map the host ID of an 
entry point with the actual function in the device.

This patch adds support for these two things. However, only entry functions are 
being registered given that 'declare target' directive is not yet implemented.

About offloading descriptor:

The details of the descriptor are explained with more detail in 
http://goo.gl/L1rnKJ. Basically the descriptor will have fields that specify 
the number of devices, the pointers to where the device images begin and end 
(that will be defined by the linker), and also pointers to a the begin and end 
of table whose entries contain information about a specific entry point. Each 
entry has the type:
```
struct __tgt_offload_entry{
 void *addr;
 char *name;
 int64_t size;
};
```  
and will be implemented in a pre determined (ELF) section 
`.omp_offloading.entries` with 1-byte alignment, so that when all the objects 
are linked, the table is in that section with no padding in between entries 
(will be like a C array). The code generation ensures that all 
`__tgt_offload_entry` entries are emitted in the same order for both host and 
device so that the runtime can have the corresponding entries in both host and 
device in same index of the table, and efficiently implement the mapping.

The resulting descriptor is registered/unregistered with the runtime library 
using the calls `__tgt_register_lib` and `__tgt_unregister_lib`. The 
registration is implemented in a high priority global initializer so that the 
registration happens always before any initializer (that can potentially 
include target regions) is run.

The driver flag -omptargets= was created to specify a comma separated list of 
devices the user wants to support so that the new functionality can be 
exercised. Each device is specified with its triple.


About target codegen:

The target codegen is pretty much straightforward as it reuses completely the 
logic of the host version for the same target region. The tricky part is to 
identify the meaningful target regions in the device side. Unlike other 
programming models, like CUDA, there are no already outlined functions with 
attributes that mark what should be emitted or not. So, the information on what 
to emit is passed in the form of metadata in host bc file. This requires a new 
option to pass the host bc to the device frontend. Then everything is similar 
to what happens in CUDA: the global declarations emission is intercepted to 
check to see if it is an "interesting" declaration. The difference is that 
instead of checking an attribute, the metadata information in checked. Right 
now, there is only a form of metadata to pass information about the device 
entry points (target regions). A class `OffloadEntriesInfoManagerTy` was 
created to manage all the information and queries related with the metadata. 
The metadata looks like this:
```
!omp_offload.info = !{!0, !1, !2, !3, !4, !5, !6}

!0 = !{i32 0, i32 52, i32 77426347, !"_ZN2S12r1Ei", i32 479, i32 13, i32 4}
!1 = !{i32 0, i32 52, i32 77426347, !"_ZL7fstatici", i32 461, i32 11, i32 5}
!2 = !{i32 0, i32 52, i32 77426347, !"_Z9ftemplateIiET_i", i32 444, i32 11, i32 
6}
!3 = !{i32 0, i32 52, i32 77426347, !"_Z3fooi", i32 99, i32 11, i32 0}
!4 = !{i32 0, i32 52, i32 77426347, !"_Z3fooi", i32 272, i32 11, i32 3}
!5 = !{i32 0, i32 52, i32 77426347, !"_Z3fooi", i32 127, i32 11, i32 1}
!6 = !{i32 0, i32 52, i32 77426347, !"_Z3fooi", i32 159, i32 11, i32 2}
```
The fields in each metadata entry are (in sequence):
1) an ID of the type of metadata - right now only zero is used meaning "OpenMP 
target region".
2) a unique ID of the device where the input source file that contain the 
target region lives. 
3) a unique ID of the file where the input source file that contain the target 
region lives. 
4) a mangled name of the function that encloses the target region.
5) and 6) line and column number where the target region was found.

2) and 3) are required to distinguish files that have the same function name.
4) is required to distinguish different instances of the same declaration 
(usually templated ones)
5) and 6) are required to distinguish the particular target region in body of 
the function (it is possible that a given target region is not an entry point - 
if clause can evaluate always to zero - and therefore we need to identify the 
"interesting" target regions. )

This patch depends on http://reviews.llvm.org/D11361.
This patch replaces http://reviews.llvm.org/D12306.

r246818 - [Static Analyzer] Remove sinks from nullability checks.

2015-09-03 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Thu Sep  3 18:16:21 2015
New Revision: 246818

URL: http://llvm.org/viewvc/llvm-project?rev=246818&view=rev
Log:
[Static Analyzer] Remove sinks from nullability checks.

Differential Revision: http://reviews.llvm.org/D12445 


Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
cfe/trunk/test/Analysis/nullability.mm

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp?rev=246818&r1=246817&r2=246818&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp Thu Sep  3 
18:16:21 2015
@@ -161,6 +161,16 @@ private:
 const MemRegion *Region;
   };
 
+  /// When any of the nonnull arguments of the analyzed function is null, do 
not
+  /// report anything and turn off the check.
+  ///
+  /// When \p SuppressPath is set to true, no more bugs will be reported on 
this
+  /// path by this checker.
+  void reportBugIfPreconditionHolds(ErrorKind Error, ExplodedNode *N,
+const MemRegion *Region, CheckerContext &C,
+const Stmt *ValueExpr = nullptr,
+bool SuppressPath = false) const;
+
   void reportBug(ErrorKind Error, ExplodedNode *N, const MemRegion *Region,
  BugReporter &BR, const Stmt *ValueExpr = nullptr) const {
 if (!BT)
@@ -220,6 +230,13 @@ bool operator==(NullabilityState Lhs, Nu
 REGISTER_MAP_WITH_PROGRAMSTATE(NullabilityMap, const MemRegion *,
NullabilityState)
 
+// If the nullability precondition of a function is violated, we should not
+// report nullability related issues on that path. For this reason once a
+// precondition is not met on a path, this checker will be esentially turned 
off
+// for the rest of the analysis. We do not want to generate a sink node 
however,
+// so this checker would not lead to reduced coverage.
+REGISTER_TRAIT_WITH_PROGRAMSTATE(PreconditionViolated, bool)
+
 enum class NullConstraint { IsNull, IsNotNull, Unknown };
 
 static NullConstraint getNullConstraint(DefinedOrUnknownSVal Val,
@@ -302,6 +319,82 @@ static Nullability getNullabilityAnnotat
   return Nullability::Unspecified;
 }
 
+template 
+static bool
+checkParamsForPreconditionViolation(const ParamVarDeclRange &Params,
+ProgramStateRef State,
+const LocationContext *LocCtxt) {
+  for (const auto *ParamDecl : Params) {
+if (ParamDecl->isParameterPack())
+  break;
+
+if (getNullabilityAnnotation(ParamDecl->getType()) != Nullability::Nonnull)
+  continue;
+
+auto RegVal = State->getLValue(ParamDecl, LocCtxt)
+  .template getAs();
+if (!RegVal)
+  continue;
+
+auto ParamValue = State->getSVal(RegVal->getRegion())
+  .template getAs();
+if (!ParamValue)
+  continue;
+
+if (getNullConstraint(*ParamValue, State) == NullConstraint::IsNull) {
+  return true;
+}
+  }
+  return false;
+}
+
+static bool checkPreconditionViolation(ProgramStateRef State, ExplodedNode *N,
+   CheckerContext &C) {
+  if (State->get())
+return true;
+
+  const LocationContext *LocCtxt = C.getLocationContext();
+  const Decl *D = LocCtxt->getDecl();
+  if (!D)
+return false;
+
+  if (const auto *BlockD = dyn_cast(D)) {
+if (checkParamsForPreconditionViolation(BlockD->parameters(), State,
+LocCtxt)) {
+  if (!N->isSink())
+C.addTransition(State->set(true), N);
+  return true;
+}
+return false;
+  }
+
+  if (const auto *FuncDecl = dyn_cast(D)) {
+if (checkParamsForPreconditionViolation(FuncDecl->parameters(), State,
+LocCtxt)) {
+  if (!N->isSink())
+C.addTransition(State->set(true), N);
+  return true;
+}
+return false;
+  }
+  return false;
+}
+
+void NullabilityChecker::reportBugIfPreconditionHolds(
+ErrorKind Error, ExplodedNode *N, const MemRegion *Region,
+CheckerContext &C, const Stmt *ValueExpr, bool SuppressPath) const {
+  ProgramStateRef OriginalState = N->getState();
+
+  if (checkPreconditionViolation(OriginalState, N, C))
+return;
+  if (SuppressPath) {
+OriginalState = OriginalState->set(true);
+N = C.addTransition(OriginalState, N);
+  }
+
+  reportBug(Error, N, Region, C.getBugReporter(), ValueExpr);
+}
+
 /// Cleaning up the program state.
 void NullabilityChecker::checkDeadSymbols(SymbolReaper &SR,
   CheckerContext &C) const {
@@ -314,12 +407,22 @@ void NullabilityChecker::checkDeadSymbol
   State = State->remove(I->first);
 

Re: [PATCH] D12445: [Static Analyzer] Remove sinks from nullability checks.

2015-09-03 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL246818: [Static Analyzer] Remove sinks from nullability 
checks. (authored by xazax).

Changed prior to commit:
  http://reviews.llvm.org/D12445?vs=33728&id=33987#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D12445

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
  cfe/trunk/test/Analysis/nullability.mm

Index: cfe/trunk/test/Analysis/nullability.mm
===
--- cfe/trunk/test/Analysis/nullability.mm
+++ cfe/trunk/test/Analysis/nullability.mm
@@ -179,3 +179,65 @@
   takesNullable(p);
   takesNonnull(p);
 }
+
+void onlyReportFirstPreconditionViolationOnPath() {
+  Dummy *p = returnsNullable();
+  takesNonnull(p); // expected-warning {{}}
+  takesNonnull(p); // No warning.
+  // The first warning was not a sink. The analysis expected to continue.
+  int i = 0;
+  i = 5 / i; // expected-warning {{Division by zero}}
+  (void)i;
+}
+
+Dummy *_Nonnull doNotWarnWhenPreconditionIsViolatedInTopFunc(
+Dummy *_Nonnull p) {
+  if (!p) {
+Dummy *ret =
+0; // avoid compiler warning (which is not generated by the analyzer)
+if (getRandom())
+  return ret; // no warning
+else
+  return p; // no warning
+  } else {
+return p;
+  }
+}
+
+Dummy *_Nonnull doNotWarnWhenPreconditionIsViolated(Dummy *_Nonnull p) {
+  if (!p) {
+Dummy *ret =
+0; // avoid compiler warning (which is not generated by the analyzer)
+if (getRandom())
+  return ret; // no warning
+else
+  return p; // no warning
+  } else {
+return p;
+  }
+}
+
+void testPreconditionViolationInInlinedFunction(Dummy *p) {
+  doNotWarnWhenPreconditionIsViolated(p);
+}
+
+void inlinedNullable(Dummy *_Nullable p) {
+  if (p) return;
+}
+void inlinedNonnull(Dummy *_Nonnull p) {
+  if (p) return;
+}
+void inlinedUnspecified(Dummy *p) {
+  if (p) return;
+}
+
+Dummy *_Nonnull testDefensiveInlineChecks(Dummy * p) {
+  switch (getRandom()) {
+  case 1: inlinedNullable(p); break;
+  case 2: inlinedNonnull(p); break;
+  case 3: inlinedUnspecified(p); break;
+  }
+  if (getRandom())
+takesNonnull(p);
+  return p;
+}
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -161,6 +161,16 @@
 const MemRegion *Region;
   };
 
+  /// When any of the nonnull arguments of the analyzed function is null, do not
+  /// report anything and turn off the check.
+  ///
+  /// When \p SuppressPath is set to true, no more bugs will be reported on this
+  /// path by this checker.
+  void reportBugIfPreconditionHolds(ErrorKind Error, ExplodedNode *N,
+const MemRegion *Region, CheckerContext &C,
+const Stmt *ValueExpr = nullptr,
+bool SuppressPath = false) const;
+
   void reportBug(ErrorKind Error, ExplodedNode *N, const MemRegion *Region,
  BugReporter &BR, const Stmt *ValueExpr = nullptr) const {
 if (!BT)
@@ -220,6 +230,13 @@
 REGISTER_MAP_WITH_PROGRAMSTATE(NullabilityMap, const MemRegion *,
NullabilityState)
 
+// If the nullability precondition of a function is violated, we should not
+// report nullability related issues on that path. For this reason once a
+// precondition is not met on a path, this checker will be esentially turned off
+// for the rest of the analysis. We do not want to generate a sink node however,
+// so this checker would not lead to reduced coverage.
+REGISTER_TRAIT_WITH_PROGRAMSTATE(PreconditionViolated, bool)
+
 enum class NullConstraint { IsNull, IsNotNull, Unknown };
 
 static NullConstraint getNullConstraint(DefinedOrUnknownSVal Val,
@@ -302,6 +319,82 @@
   return Nullability::Unspecified;
 }
 
+template 
+static bool
+checkParamsForPreconditionViolation(const ParamVarDeclRange &Params,
+ProgramStateRef State,
+const LocationContext *LocCtxt) {
+  for (const auto *ParamDecl : Params) {
+if (ParamDecl->isParameterPack())
+  break;
+
+if (getNullabilityAnnotation(ParamDecl->getType()) != Nullability::Nonnull)
+  continue;
+
+auto RegVal = State->getLValue(ParamDecl, LocCtxt)
+  .template getAs();
+if (!RegVal)
+  continue;
+
+auto ParamValue = State->getSVal(RegVal->getRegion())
+  .template getAs();
+if (!ParamValue)
+  continue;
+
+if (getNullConstraint(*ParamValue, State) == NullConstraint::IsNull) {
+  return true;
+}
+  }
+  return false;
+}
+
+static bool checkPreconditionViolation(ProgramStateRef State, ExplodedNode *N,
+   CheckerContext &C

Re: [PATCH] D12306: [OpenMP] Implement the creation and registration of the offloading descriptor.

2015-09-03 Thread Samuel Antao via cfe-commits
sfantao abandoned this revision.
sfantao added a comment.

I am closing this revision as I added the functionality for the device codegen 
on top of this patch in http://reviews.llvm.org/D12614 because the two are 
tightly coupled.

Thanks,
Samuel


http://reviews.llvm.org/D12306



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


Re: [PATCH] D12002: Initial WebAssembly support in clang

2015-09-03 Thread Dan Gohman via cfe-commits
sunfishcode added inline comments.


Comment at: lib/Basic/Targets.cpp:7643-7649
@@ +7642,9 @@
+  case llvm::Triple::wasm64:
+// Until specific variations are defined, don't permit any.
+if (!(Triple == llvm::Triple("wasm64-unknown-unknown")) ||
+(!Triple.getVendorName().empty() &&
+ Triple.getVendorName() != "unknown") ||
+(!Triple.getOSName().empty() && Triple.getOSName() != "unknown") ||
+(Triple.hasEnvironment() && Triple.getEnvironmentName() != "unknown"))
+  return nullptr;
+return new WebAssemblyOSTargetInfo(Triple);

echristo wrote:
> sunfishcode wrote:
> > echristo wrote:
> > > Ditto.
> > > 
> > > (I said this just below, but it seems to have gotten munged in the newer 
> > > version)
> > I actually did see your comment and updated the code accordingly. It now 
> > does a positive test, `Triple == llvm::Triple("wasm64-unknown-unknown")`, 
> > which is simpler than what it did before.
> > 
> > However, it's also doing additional tests, because the Triple class's 
> > operator== doesn't distinguish between an Unknown that was actually 
> > "unknown" or an unknown that was some other string. Until we figure out 
> > what "vendor", "OS", and "environment" variations of wasm make sense (if 
> > any), we want to avoid dealing with accidental alternate triples.
> I think this is a lot of overkill here, no other target cares about this so 
> why should the wasm target? If it's that important maybe fix Triple?
This Triple issue is not important enough to hold up the rest of the patch for, 
so I just removed it. Thanks for the review!


Repository:
  rL LLVM

http://reviews.llvm.org/D12002



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


[PATCH] D12616: Failing test highlighting no poisoning if dtor undeclared.

2015-09-03 Thread Naomi Musgrave via cfe-commits
nmusgrave created this revision.
nmusgrave added reviewers: eugenis, kcc.
nmusgrave added a subscriber: cfe-commits.

If class or struct has not declared a destructor,
no destsructor is emitted, and members are not poisoned
after destruction. This case highlights bug in current
implementation of use-after-dtor poisoning.

http://reviews.llvm.org/D12616

Files:
  test/CodeGenCXX/sanitize-dtor-generated.cpp

Index: test/CodeGenCXX/sanitize-dtor-generated.cpp
===
--- /dev/null
+++ test/CodeGenCXX/sanitize-dtor-generated.cpp
@@ -0,0 +1,32 @@
+// Test -fsanitize-memory-use-after-dtor
+// RUN: %clang_cc1 -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor 
-disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor 
-disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | 
FileCheck %s
+
+// TODO Success pending on resolution of issue 596
+// XFAIL: *
+
+template  class Vector {
+ public:
+  int size;
+  ~Vector() {}
+};
+
+struct NonTrivial {
+  int a;
+  Vector v;
+};
+NonTrivial nt;
+
+struct Trivial {
+  int a;
+  int b;
+};
+Trivial t;
+
+// CHECK-LABEL: define {{.*}}NonTrivialD2Ev
+// CHECK: call void @__sanitizer_dtor_callback
+// CHECK: ret void
+
+// CHECK-LABEL: define {{.*}}TrivialD2Ev
+// CHECK: call void @__sanitizer_dtor_callback
+// CHECK: ret void


Index: test/CodeGenCXX/sanitize-dtor-generated.cpp
===
--- /dev/null
+++ test/CodeGenCXX/sanitize-dtor-generated.cpp
@@ -0,0 +1,32 @@
+// Test -fsanitize-memory-use-after-dtor
+// RUN: %clang_cc1 -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+
+// TODO Success pending on resolution of issue 596
+// XFAIL: *
+
+template  class Vector {
+ public:
+  int size;
+  ~Vector() {}
+};
+
+struct NonTrivial {
+  int a;
+  Vector v;
+};
+NonTrivial nt;
+
+struct Trivial {
+  int a;
+  int b;
+};
+Trivial t;
+
+// CHECK-LABEL: define {{.*}}NonTrivialD2Ev
+// CHECK: call void @__sanitizer_dtor_callback
+// CHECK: ret void
+
+// CHECK-LABEL: define {{.*}}TrivialD2Ev
+// CHECK: call void @__sanitizer_dtor_callback
+// CHECK: ret void
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12616: Failing test highlighting no poisoning if dtor undeclared.

2015-09-03 Thread Evgeniy Stepanov via cfe-commits
eugenis added inline comments.


Comment at: test/CodeGenCXX/sanitize-dtor-generated.cpp:5
@@ +4,3 @@
+
+// TODO Success pending on resolution of issue 596
+// XFAIL: *

Add the link to the issue.


Comment at: test/CodeGenCXX/sanitize-dtor-generated.cpp:18
@@ +17,3 @@
+};
+NonTrivial nt;
+

Why include NonTrivial in this test at all?
With just Trivial, all the checks could be replaced with just one
// CHECK: call void @__sanitizer_dtor_callback


http://reviews.llvm.org/D12616



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


r246826 - Untabify.

2015-09-03 Thread Eric Christopher via cfe-commits
Author: echristo
Date: Thu Sep  3 19:15:47 2015
New Revision: 246826

URL: http://llvm.org/viewvc/llvm-project?rev=246826&view=rev
Log:
Untabify.

Modified:
cfe/trunk/include/clang/Sema/Sema.h

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=246826&r1=246825&r2=246826&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Sep  3 19:15:47 2015
@@ -8815,7 +8815,7 @@ private:
   bool CheckObjCString(Expr *Arg);
 
   ExprResult CheckBuiltinFunctionCall(FunctionDecl *FDecl,
- unsigned BuiltinID, CallExpr *TheCall);
+  unsigned BuiltinID, CallExpr *TheCall);
 
   bool CheckARMBuiltinExclusiveCall(unsigned BuiltinID, CallExpr *TheCall,
 unsigned MaxWidth);


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


[PATCH] D12619: [Static Analyzer] Minor cleanups for the nullability checker.

2015-09-03 Thread Gábor Horváth via cfe-commits
xazax.hun created this revision.
xazax.hun added reviewers: dcoughlin, zaks.anna.
xazax.hun added a subscriber: cfe-commits.

This patch contains minor cleanups and style fixes for the nullability checker. 
NFC.

http://reviews.llvm.org/D12619

Files:
  lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp

Index: lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -58,12 +58,12 @@
 /// the nullability of the receiver or the nullability of the return type of the
 /// method, depending on which is more nullable. Contradicted is considered to
 /// be the most nullable, to avoid false positive results.
-static Nullability getMostNullable(Nullability Lhs, Nullability Rhs) {
+Nullability getMostNullable(Nullability Lhs, Nullability Rhs) {
   return static_cast(
   std::min(static_cast(Lhs), static_cast(Rhs)));
 }
 
-static const char *getNullabilityString(Nullability Nullab) {
+const char *getNullabilityString(Nullability Nullab) {
   switch (Nullab) {
   case Nullability::Contradicted:
 return "contradicted";
@@ -74,7 +74,7 @@
   case Nullability::Nonnull:
 return "nonnull";
   }
-  assert(false);
+  llvm_unreachable("Unexpected enumeration.");
   return "";
 }
 
@@ -89,19 +89,19 @@
   NullablePassedToNonnull
 };
 
-const char *ErrorMessages[] = {"Null pointer is assigned to a pointer which "
-   "has _Nonnull type",
-   "Null pointer is passed to a parameter which is "
-   "marked as _Nonnull",
-   "Null pointer is returned from a function that "
-   "has _Nonnull return type",
-   "Nullable pointer is assigned to a pointer "
-   "which has _Nonnull type",
-   "Nullable pointer is returned from a function "
-   "that has _Nonnull return type",
-   "Nullable pointer is dereferenced",
-   "Nullable pointer is passed to a parameter "
-   "which is marked as _Nonnull"};
+const char *const ErrorMessages[] = {"Null pointer is assigned to a pointer "
+ "which has _Nonnull type",
+ "Null pointer is passed to a parameter "
+ "which is marked as _Nonnull",
+ "Null pointer is returned from a function "
+ "that has _Nonnull return type",
+ "Nullable pointer is assigned to a "
+ "pointer which has _Nonnull type",
+ "Nullable pointer is returned from a "
+ "function that has _Nonnull return type",
+ "Nullable pointer is dereferenced",
+ "Nullable pointer is passed to a "
+ "parameter which is marked as _Nonnull"};
 
 class NullabilityChecker
 : public Checker,
@@ -176,7 +176,6 @@
 if (!BT)
   BT.reset(new BugType(this, "Nullability", "Memory error"));
 const char *Msg = ErrorMessages[static_cast(Error)];
-assert(Msg);
 std::unique_ptr R(new BugReport(*BT, Msg, N));
 if (Region) {
   R->markInteresting(Region);
@@ -262,7 +261,7 @@
   if (CheckSuperRegion) {
 if (auto FieldReg = Region->getAs())
   return dyn_cast(FieldReg->getSuperRegion());
-else if (auto ElementReg = Region->getAs())
+if (auto ElementReg = Region->getAs())
   return dyn_cast(ElementReg->getSuperRegion());
   }
 
@@ -272,12 +271,12 @@
 PathDiagnosticPiece *NullabilityChecker::NullabilityBugVisitor::VisitNode(
 const ExplodedNode *N, const ExplodedNode *PrevN, BugReporterContext &BRC,
 BugReport &BR) {
-  ProgramStateRef state = N->getState();
-  ProgramStateRef statePrev = PrevN->getState();
+  ProgramStateRef State = N->getState();
+  ProgramStateRef StatePrev = PrevN->getState();
 
-  const NullabilityState *TrackedNullab = state->get(Region);
+  const NullabilityState *TrackedNullab = State->get(Region);
   const NullabilityState *TrackedNullabPrev =
-  statePrev->get(Region);
+  StatePrev->get(Region);
   if (!TrackedNullab)
 return nullptr;
 
@@ -645,34 +644,31 @@
 
 static Nullability getReceiverNullability(const ObjCMethodCall &M,
   ProgramStateRef State) {
-  Nullability RetNullability = Nullability::Unspecified;
   if (M.isReceiverSelfOrSuper()) {
 // For super and super class receivers we assume that the receiver is
 // nonnull.
-RetNullability = Nullability::Nonnull;
-  } else {
-

Re: [PATCH] D12087: always_inline codegen rewrite

2015-09-03 Thread Evgeniy Stepanov via cfe-commits
eugenis updated this revision to Diff 33997.

Repository:
  rL LLVM

http://reviews.llvm.org/D12087

Files:
  lib/CodeGen/CGCXX.cpp
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGen/always-inline.c
  test/CodeGen/always_inline-unused.c
  test/CodeGen/always_inline-wrappers.c
  test/CodeGen/always_inline.c
  test/CodeGen/function-attributes.c
  test/CodeGen/pr9614.c
  test/CodeGenCXX/alwaysinline.cpp
  test/Frontend/optimization-remark-line-directive.c
  test/Frontend/optimization-remark.c
  test/Modules/cxx-irgen.cpp

Index: test/Modules/cxx-irgen.cpp
===
--- test/Modules/cxx-irgen.cpp
+++ test/Modules/cxx-irgen.cpp
@@ -26,14 +26,14 @@
   };
 }
 
-// CHECK-DAG: define available_externally hidden {{.*}}{{signext i32|i32}} @_ZN1SIiE1gEv({{.*}} #[[ALWAYS_INLINE:.*]] align
+// CHECK-DAG: define internal i32 @_ZN1SIiE1gEv.alwaysinline() #[[ALWAYS_INLINE:.*]] align
 int a = S::g();
 
 int b = h();
 
 // CHECK-DAG: define linkonce_odr {{.*}}{{signext i32|i32}} @_Z3minIiET_S0_S0_(i32
 int c = min(1, 2);
-// CHECK: define available_externally {{.*}}{{signext i32|i32}} @_ZN1SIiE1fEv({{.*}} #[[ALWAYS_INLINE]] align
+// CHECK-DAG: define internal {{.*}}{{signext i32|i32}} @_ZN1SIiE1fEv.alwaysinline() #[[ALWAYS_INLINE]] align
 
 namespace ImplicitSpecialMembers {
   // CHECK-LABEL: define {{.*}} @_ZN22ImplicitSpecialMembers1BC2ERKS0_(
Index: test/Frontend/optimization-remark.c
===
--- test/Frontend/optimization-remark.c
+++ test/Frontend/optimization-remark.c
@@ -32,6 +32,8 @@
 // CHECK-NOT: !llvm.dbg.cu = !{
 
 int foo(int x, int y) __attribute__((always_inline));
+// expected-remark@+2 {{foo.alwaysinline should always be inlined}}
+// expected-remark@+1 {{foo.alwaysinline inlined into foo}}
 int foo(int x, int y) { return x + y; }
 
 float foz(int x, int y) __attribute__((noinline));
@@ -45,7 +47,7 @@
 // expected-remark@+5 {{foz will not be inlined into bar}}
 // expected-remark@+4 {{foz should never be inlined}}
 // expected-remark@+3 {{foz will not be inlined into bar}}
-// expected-remark@+2 {{foo should always be inlined}}
-// expected-remark@+1 {{foo inlined into bar}}
+// expected-remark@+2 {{foo.alwaysinline should always be inlined}}
+// expected-remark@+1 {{foo.alwaysinline inlined into bar}}
   return foo(j, j - 2) * foz(j - 2, j);
 }
Index: test/Frontend/optimization-remark-line-directive.c
===
--- test/Frontend/optimization-remark-line-directive.c
+++ test/Frontend/optimization-remark-line-directive.c
@@ -5,8 +5,9 @@
 // RUN: %clang_cc1 %s -Rpass=inline -gline-tables-only -dwarf-column-info -emit-llvm-only -verify
 
 int foo(int x, int y) __attribute__((always_inline));
+// expected-remark@+1 {{foo.alwaysinline inlined into foo}}
 int foo(int x, int y) { return x + y; }
 
-// expected-remark@+2 {{foo inlined into bar}} expected-note@+2 {{could not determine the original source location for /bad/path/to/original.c:1230:25}}
+// expected-remark@+2 {{foo.alwaysinline inlined into bar}} expected-note@+2 {{could not determine the original source location for /bad/path/to/original.c:1230:25}}
 #line 1230 "/bad/path/to/original.c"
 int bar(int j) { return foo(j, j - 2); }
Index: test/CodeGenCXX/alwaysinline.cpp
===
--- /dev/null
+++ test/CodeGenCXX/alwaysinline.cpp
@@ -0,0 +1,68 @@
+// Test different kinds of alwaysinline *structor definitions.
+
+// RUN: %clang_cc1 -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-CALL
+
+// RUN: %clang_cc1 -mconstructor-aliases -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -mconstructor-aliases -disable-llvm-optzns -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-CALL
+
+struct A1 {
+  __attribute__((__always_inline__)) A1() {}
+  __attribute__((__always_inline__)) ~A1() {}
+};
+
+void g1() {
+  A1 a1;
+}
+
+struct A2 {
+  inline __attribute__((__always_inline__)) A2() {}
+  inline __attribute__((__always_inline__)) ~A2() {}
+};
+
+void g2() {
+  A2 a2;
+}
+
+struct A3 {
+  inline __attribute__((gnu_inline, __always_inline__)) A3() {}
+  inline __attribute__((gnu_inline, __always_inline__)) ~A3() {}
+};
+
+void g3() {
+  A3 a3;
+}
+
+// CHECK-DAG: define internal void @_ZN2A1C1Ev.alwaysinline(%struct.A1* %this) unnamed_addr #[[AI:[01-9]+]]
+// CHECK-DAG: define internal void @_ZN2A1C2Ev.alwaysinline(%struct.A1* %this) unnamed_addr #[[AI]]
+// CHECK-DAG: define internal void @_ZN2A1D1Ev.alwaysinline(%struct.A1* %this) unnamed_addr #[[AI]]
+// CHECK-DAG: define internal void @_ZN2A1D2Ev.alwaysinline(%struct.A1* %this) unnamed_addr #[[A

Re: [PATCH] D12087: always_inline codegen rewrite

2015-09-03 Thread Evgeniy Stepanov via cfe-commits
eugenis added a comment.

In http://reviews.llvm.org/D12087#239243, @yaron.keren wrote:

> In CGCXX.cpp, may be fixable after this commit:
>
>   // FIXME: An extern template instantiation will create functions with
>   // linkage "AvailableExternally". In libc++, some classes also define
>   // members with attribute "AlwaysInline" and expect no reference to
>   // be generated. It is desirable to reenable this optimisation after
>   // corresponding LLVM changes.


I've removed the checks for alwaysinline and available_externally. Tests + 
bootstrap do not show any new failures.


Repository:
  rL LLVM

http://reviews.llvm.org/D12087



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


r246830 - Fix a potential APInt memory leak when using __attribute__((flag_enum)), and

2015-09-03 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Sep  3 20:03:03 2015
New Revision: 246830

URL: http://llvm.org/viewvc/llvm-project?rev=246830&view=rev
Log:
Fix a potential APInt memory leak when using __attribute__((flag_enum)), and
simplify the implementation a bit.

Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=246830&r1=246829&r2=246830&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Thu Sep  3 20:03:03 2015
@@ -747,18 +747,6 @@ def FlagEnum : InheritableAttr {
   let Subjects = SubjectList<[Enum]>;
   let Documentation = [FlagEnumDocs];
   let LangOpts = [COnly];
-  let AdditionalMembers = [{
-private:
-llvm::APInt FlagBits;
-public:
-llvm::APInt &getFlagBits() {
-  return FlagBits;
-}
-
-const llvm::APInt &getFlagBits() const {
-  return FlagBits;
-}
-}];
 }
 
 def Flatten : InheritableAttr {

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=246830&r1=246829&r2=246830&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Sep  3 20:03:03 2015
@@ -903,6 +903,10 @@ public:
   /// for C++ records.
   llvm::FoldingSet SpecialMemberCache;
 
+  /// \brief A cache of the flags available in enumerations with the flag_bits
+  /// attribute.
+  mutable llvm::DenseMap FlagBitsCache;
+
   /// \brief The kind of translation unit we are processing.
   ///
   /// When we're processing a complete translation unit, Sema will perform

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=246830&r1=246829&r2=246830&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Sep  3 20:03:03 2015
@@ -14017,14 +14017,21 @@ static void CheckForDuplicateEnumValues(
 bool
 Sema::IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val,
 bool AllowMask) const {
-  FlagEnumAttr *FEAttr = ED->getAttr();
-  assert(FEAttr && "looking for value in non-flag enum");
+  assert(ED->hasAttr() && "looking for value in non-flag enum");
 
-  llvm::APInt FlagMask = ~FEAttr->getFlagBits();
-  unsigned Width = FlagMask.getBitWidth();
+  auto R = FlagBitsCache.insert(std::make_pair(ED, llvm::APInt()));
+  llvm::APInt &FlagBits = R.first->second;
 
-  // We will try a zero-extended value for the regular check first.
-  llvm::APInt ExtVal = Val.zextOrSelf(Width);
+  if (R.second) {
+for (auto *E : ED->enumerators()) {
+  const auto &Val = E->getInitVal();
+  // Only single-bit enumerators introduce new flag values.
+  if (Val.isPowerOf2())
+FlagBits = FlagBits.zextOrSelf(Val.getBitWidth()) | Val;
+}
+  }
+
+  llvm::APInt FlagMask = ~FlagBits.zextOrTrunc(Val.getBitWidth());
 
   // A value is in a flag enum if either its bits are a subset of the enum's
   // flag bits (the first condition) or we are allowing masks and the same is
@@ -14034,26 +14041,10 @@ Sema::IsValueInFlagEnum(const EnumDecl *
   // While it's true that any value could be used as a mask, the assumption is
   // that a mask will have all of the insignificant bits set. Anything else is
   // likely a logic error.
-  if (!(FlagMask & ExtVal))
+  if (!(FlagMask & Val) ||
+  (AllowMask && !(FlagMask & ~Val)))
 return true;
 
-  if (AllowMask) {
-// Try a one-extended value instead. This can happen if the enum is wider
-// than the constant used, in C with extensions to allow for wider enums.
-// The mask will still have the correct behaviour, so we give the user the
-// benefit of the doubt.
-//
-// FIXME: This heuristic can cause weird results if the enum was extended
-// to a larger type and is signed, because then bit-masks of smaller types
-// that get extended will fall out of range (e.g. ~0x1u). We currently 
don't
-// detect that case and will get a false positive for it. In most cases,
-// though, it can be fixed by making it a signed type (e.g. ~0x1), so it 
may
-// be fine just to accept this as a warning.
-ExtVal |= llvm::APInt::getHighBitsSet(Width, Width - Val.getBitWidth());
-if (!(FlagMask & ~ExtVal))
-  return true;
-  }
-
   return false;
 }
 
@@ -14208,13 +14199,8 @@ void Sema::ActOnEnumBody(SourceLocation
 }
   }
 
-  FlagEnumAttr *FEAttr = Enum->getAttr();
-  if (FEAttr)
-FEAttr->getFlagBits() = llvm::APInt(BestWidth, 0);
-
   // Loop over all of the enumerator constant

Re: [PATCH] D12619: [Static Analyzer] Minor cleanups for the nullability checker.

2015-09-03 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added a subscriber: Eugene.Zelenko.
Eugene.Zelenko added a comment.

Why static was removed from getMostNullable() and getNullabilityString()? If 
these functions are not intended to be used outside this source file, it's good 
idea to limit their scope. Same should be done for ErrorMessages,


http://reviews.llvm.org/D12619



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


  1   2   >