r248929 - clang-format: Add clangRewrite dependency to fix cmake build.

2015-09-30 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Sep 30 14:28:47 2015
New Revision: 248929

URL: http://llvm.org/viewvc/llvm-project?rev=248929=rev
Log:
clang-format: Add clangRewrite dependency to fix cmake build.

Modified:
cfe/trunk/tools/clang-format/CMakeLists.txt

Modified: cfe/trunk/tools/clang-format/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/CMakeLists.txt?rev=248929=248928=248929=diff
==
--- cfe/trunk/tools/clang-format/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-format/CMakeLists.txt Wed Sep 30 14:28:47 2015
@@ -7,6 +7,7 @@ add_clang_executable(clang-format
 set(CLANG_FORMAT_LIB_DEPS
   clangBasic
   clangFormat
+  clangRewrite
   clangToolingCore
   )
 


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


Re: r248904 - clang-format: Use Rewriter again to write the output files.

2015-09-30 Thread Daniel Jasper via cfe-commits
cmake build hopefully fixed in r248929. How is the patch you have attached
related?

On Wed, Sep 30, 2015 at 9:24 PM, Daniel Jasper  wrote:

> This breaks your *build*? How?
>
> On Wed, Sep 30, 2015 at 9:19 PM, Jan Vesely 
> wrote:
>
>> Hi,
>> I think this change breaks cmake build. Please consider the attached fix
>> (I can't push atm).
>>
>> thank you,
>> Jan
>>
>> On Wed, Sep 30, 2015 at 8:59 AM, Daniel Jasper via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: djasper
>>> Date: Wed Sep 30 08:59:29 2015
>>> New Revision: 248904
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=248904=rev
>>> Log:
>>> clang-format: Use Rewriter again to write the output files.
>>>
>>> This has two advantages:
>>> 1. Atomic writes.
>>> 2. Proper handling of line endings (hopefully solving llvm.org/PR24999
>>>
>>> Modified:
>>> cfe/trunk/tools/clang-format/ClangFormat.cpp
>>>
>>> Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=248904=248903=248904=diff
>>>
>>> ==
>>> --- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)
>>> +++ cfe/trunk/tools/clang-format/ClangFormat.cpp Wed Sep 30 08:59:29 2015
>>> @@ -19,6 +19,7 @@
>>>  #include "clang/Basic/SourceManager.h"
>>>  #include "clang/Basic/Version.h"
>>>  #include "clang/Format/Format.h"
>>> +#include "clang/Rewrite/Core/Rewriter.h"
>>>  #include "llvm/ADT/StringMap.h"
>>>  #include "llvm/Support/CommandLine.h"
>>>  #include "llvm/Support/Debug.h"
>>> @@ -77,7 +78,7 @@ AssumeFileName("assume-filename",
>>> cl::desc("When reading from stdin, clang-format assumes
>>> this\n"
>>>  "filename to look for a style config file
>>> (with\n"
>>>  "-style=file) and to determine the language."),
>>> -   cl::cat(ClangFormatCategory));
>>> +   cl::init(""), cl::cat(ClangFormatCategory));
>>>
>>>  static cl::opt Inplace("i",
>>>   cl::desc("Inplace edit s, if
>>> specified."),
>>> @@ -109,8 +110,7 @@ namespace format {
>>>
>>>  static FileID createInMemoryFile(StringRef FileName, MemoryBuffer
>>> *Source,
>>>   SourceManager , FileManager
>>> ) {
>>> -  const FileEntry *Entry = Files.getVirtualFile(FileName == "-" ?
>>> "" :
>>> -FileName,
>>> +  const FileEntry *Entry = Files.getVirtualFile(FileName,
>>>
>>>  Source->getBufferSize(), 0);
>>>Sources.overrideFileContents(Entry, Source, true);
>>>return Sources.createFileID(Entry, SourceLocation(), SrcMgr::C_User);
>>> @@ -132,7 +132,7 @@ static bool fillRanges(MemoryBuffer *Cod
>>>IntrusiveRefCntPtr(new DiagnosticIDs),
>>>new DiagnosticOptions);
>>>SourceManager Sources(Diagnostics, Files);
>>> -  FileID ID = createInMemoryFile("-", Code, Sources, Files);
>>> +  FileID ID = createInMemoryFile("", Code, Sources, Files);
>>>if (!LineRanges.empty()) {
>>>  if (!Offsets.empty() || !Lengths.empty()) {
>>>llvm::errs() << "error: cannot use -lines with -offset/-length\n";
>>> @@ -255,8 +255,8 @@ static bool format(StringRef FileName) {
>>>
>>>bool IncompleteFormat = false;
>>>Replaces = tooling::mergeReplacements(
>>> -  Replaces,
>>> -  reformat(FormatStyle, ChangedCode, Ranges, FileName,
>>> ));
>>> +  Replaces, reformat(FormatStyle, ChangedCode, Ranges,
>>> AssumedFileName,
>>> + ));
>>>if (OutputXML) {
>>>  llvm::outs() << "\n>>  "xml:space='preserve' incomplete_format='"
>>> @@ -269,27 +269,26 @@ static bool format(StringRef FileName) {
>>>  outputReplacementsXML(Replaces);
>>>  llvm::outs() << "\n";
>>>} else {
>>> -std::string FormattedCode =
>>> -applyAllReplacements(Code->getBuffer(), Replaces);
>>> +FileManager Files((FileSystemOptions()));
>>> +DiagnosticsEngine Diagnostics(
>>> +IntrusiveRefCntPtr(new DiagnosticIDs),
>>> +new DiagnosticOptions);
>>> +SourceManager Sources(Diagnostics, Files);
>>> +FileID ID = createInMemoryFile(AssumedFileName, Code.get(),
>>> Sources, Files);
>>> +Rewriter Rewrite(Sources, LangOptions());
>>> +tooling::applyAllReplacements(Replaces, Rewrite);
>>>  if (Inplace) {
>>>if (FileName == "-")
>>>  llvm::errs() << "error: cannot use -i when reading from
>>> stdin.\n";
>>> -  else {
>>> -std::error_code EC;
>>> -raw_fd_ostream FileOut(FileName, EC, llvm::sys::fs::F_Text);
>>> -if (EC) {
>>> -  llvm::errs() << EC.message() << "\n";
>>> -  return true;
>>> -}
>>> -FileOut << FormattedCode;
>>> -  }
>>> +  else if (Rewrite.overwriteChangedFiles())
>>> +return true;
>>>  } else {
>>>

Re: r248904 - clang-format: Use Rewriter again to write the output files.

2015-09-30 Thread Jan Vesely via cfe-commits
Hi,
I think this change breaks cmake build. Please consider the attached fix (I
can't push atm).

thank you,
Jan

On Wed, Sep 30, 2015 at 8:59 AM, Daniel Jasper via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: djasper
> Date: Wed Sep 30 08:59:29 2015
> New Revision: 248904
>
> URL: http://llvm.org/viewvc/llvm-project?rev=248904=rev
> Log:
> clang-format: Use Rewriter again to write the output files.
>
> This has two advantages:
> 1. Atomic writes.
> 2. Proper handling of line endings (hopefully solving llvm.org/PR24999
>
> Modified:
> cfe/trunk/tools/clang-format/ClangFormat.cpp
>
> Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=248904=248903=248904=diff
>
> ==
> --- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)
> +++ cfe/trunk/tools/clang-format/ClangFormat.cpp Wed Sep 30 08:59:29 2015
> @@ -19,6 +19,7 @@
>  #include "clang/Basic/SourceManager.h"
>  #include "clang/Basic/Version.h"
>  #include "clang/Format/Format.h"
> +#include "clang/Rewrite/Core/Rewriter.h"
>  #include "llvm/ADT/StringMap.h"
>  #include "llvm/Support/CommandLine.h"
>  #include "llvm/Support/Debug.h"
> @@ -77,7 +78,7 @@ AssumeFileName("assume-filename",
> cl::desc("When reading from stdin, clang-format assumes
> this\n"
>  "filename to look for a style config file (with\n"
>  "-style=file) and to determine the language."),
> -   cl::cat(ClangFormatCategory));
> +   cl::init(""), cl::cat(ClangFormatCategory));
>
>  static cl::opt Inplace("i",
>   cl::desc("Inplace edit s, if
> specified."),
> @@ -109,8 +110,7 @@ namespace format {
>
>  static FileID createInMemoryFile(StringRef FileName, MemoryBuffer *Source,
>   SourceManager , FileManager
> ) {
> -  const FileEntry *Entry = Files.getVirtualFile(FileName == "-" ?
> "" :
> -FileName,
> +  const FileEntry *Entry = Files.getVirtualFile(FileName,
>  Source->getBufferSize(),
> 0);
>Sources.overrideFileContents(Entry, Source, true);
>return Sources.createFileID(Entry, SourceLocation(), SrcMgr::C_User);
> @@ -132,7 +132,7 @@ static bool fillRanges(MemoryBuffer *Cod
>IntrusiveRefCntPtr(new DiagnosticIDs),
>new DiagnosticOptions);
>SourceManager Sources(Diagnostics, Files);
> -  FileID ID = createInMemoryFile("-", Code, Sources, Files);
> +  FileID ID = createInMemoryFile("", Code, Sources, Files);
>if (!LineRanges.empty()) {
>  if (!Offsets.empty() || !Lengths.empty()) {
>llvm::errs() << "error: cannot use -lines with -offset/-length\n";
> @@ -255,8 +255,8 @@ static bool format(StringRef FileName) {
>
>bool IncompleteFormat = false;
>Replaces = tooling::mergeReplacements(
> -  Replaces,
> -  reformat(FormatStyle, ChangedCode, Ranges, FileName,
> ));
> +  Replaces, reformat(FormatStyle, ChangedCode, Ranges,
> AssumedFileName,
> + ));
>if (OutputXML) {
>  llvm::outs() << "\n  "xml:space='preserve' incomplete_format='"
> @@ -269,27 +269,26 @@ static bool format(StringRef FileName) {
>  outputReplacementsXML(Replaces);
>  llvm::outs() << "\n";
>} else {
> -std::string FormattedCode =
> -applyAllReplacements(Code->getBuffer(), Replaces);
> +FileManager Files((FileSystemOptions()));
> +DiagnosticsEngine Diagnostics(
> +IntrusiveRefCntPtr(new DiagnosticIDs),
> +new DiagnosticOptions);
> +SourceManager Sources(Diagnostics, Files);
> +FileID ID = createInMemoryFile(AssumedFileName, Code.get(), Sources,
> Files);
> +Rewriter Rewrite(Sources, LangOptions());
> +tooling::applyAllReplacements(Replaces, Rewrite);
>  if (Inplace) {
>if (FileName == "-")
>  llvm::errs() << "error: cannot use -i when reading from stdin.\n";
> -  else {
> -std::error_code EC;
> -raw_fd_ostream FileOut(FileName, EC, llvm::sys::fs::F_Text);
> -if (EC) {
> -  llvm::errs() << EC.message() << "\n";
> -  return true;
> -}
> -FileOut << FormattedCode;
> -  }
> +  else if (Rewrite.overwriteChangedFiles())
> +return true;
>  } else {
>if (Cursor.getNumOccurrences() != 0)
>  outs() << "{ \"Cursor\": "
> << tooling::shiftedCodePosition(Replaces, Cursor)
> << ", \"IncompleteFormat\": "
> << (IncompleteFormat ? "true" : "false") << " }\n";
> -  outs() << FormattedCode;
> +  Rewrite.getEditBuffer(ID).write(outs());
>  }
>}
>return false;
> @@ -350,3 +349,4 @@ int main(int argc, const char **argv) {
>}
>return Error ? 1 : 0;
>  }
> 

Re: [PATCH] D13279: Decorating virtual functions load with invariant.load

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

http://reviews.llvm.org/D13279

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/virtual-function-calls.cpp

Index: test/CodeGenCXX/virtual-function-calls.cpp
===
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - 
-fstrict-vtable-pointers | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} align 8, !invariant.load 
![[EMPTY_NODE:[0-9]]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1609,7 +1609,16 @@
   uint64_t VTableIndex = 
CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
   llvm::Value *VFuncPtr =
   CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-  return CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+  auto *Inst = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+  // It's safe to add "invariant.load" without -fstrict-vtable-pointers, but it
+  // would not help in devirtualization.
+  if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+  CGM.getCodeGenOpts().StrictVTablePointers)
+Inst->setMetadata(llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+  return Inst;
 }
 
 llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(


Index: test/CodeGenCXX/virtual-function-calls.cpp
===
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - -fstrict-vtable-pointers | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} align 8, !invariant.load ![[EMPTY_NODE:[0-9]]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1609,7 +1609,16 @@
   uint64_t VTableIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
   llvm::Value *VFuncPtr =
   CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-  return CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+  auto *Inst = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+  // It's safe to add "invariant.load" without -fstrict-vtable-pointers, but it
+  // would not help in devirtualization.
+  if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+  CGM.getCodeGenOpts().StrictVTablePointers)
+Inst->setMetadata(llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+  return Inst;
 }
 
 llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D11908: Clang support for -fthinlto.

2015-09-30 Thread Teresa Johnson via cfe-commits
On Wed, Sep 30, 2015 at 10:19 AM, Duncan P. N. Exon Smith
 wrote:
>
>> On 2015-Sep-23, at 10:28, Teresa Johnson  wrote:
>>
>> tejohnson updated this revision to Diff 35527.
>> tejohnson added a comment.
>>
>> Updated the patch for the new LLVM/gold patch 
>> (http://reviews.llvm.org/D13107).
>>
>> Two changes:
>>
>> - I put back the original change to pass a new plugin option to gold. Since 
>> the function index design/name has been generalized to not be 
>> ThinLTO-specific, it makes sense to have the ThinLTO-related gold behavior 
>> for modules with those sections to be dependent on an option.
>> - Added 2 tests.
>>
>>
>> http://reviews.llvm.org/D11908
>>
>> Files:
>>  include/clang/Driver/Options.td
>>  include/clang/Frontend/CodeGenOptions.def
>>  lib/CodeGen/BackendUtil.cpp
>>  lib/Driver/Driver.cpp
>>  lib/Driver/Tools.cpp
>>  lib/Frontend/CompilerInvocation.cpp
>>  test/Driver/thinlto.c
>>  test/Misc/thinlto.c
>>
>> 
>
>> Index: test/Misc/thinlto.c
>> ===
>> --- /dev/null
>> +++ test/Misc/thinlto.c
>> @@ -0,0 +1,22 @@
>> +// RUN: %clang_cc1 -fthinlto -emit-llvm-bc < %s | llvm-bcanalyzer -dump | 
>> FileCheck %s
>> +// CHECK: > +// CHECK-NEXT: > +// CHECK-NEXT: > +// CHECK-NEXT: > +
>> +// RUN: %clang -fthinlto %s -o %t -fuse-ld=gold
>
> Why isn't this using -cc1?

I can try it again, but I believe -fuse-ld is not a -cc1 option.

>
>> +// RUN: llvm-bcanalyzer -dump %t.thinlto.bc | FileCheck %s 
>> --check-prefix=COMBINED
>> +// COMBINED: > +// COMBINED-NEXT: > +// COMBINED-NEXT: > +// COMBINED-NEXT: > +// COMBINED-NEXT: > +// COMBINED-NEXT: > +// COMBINED-NEXT: > +
>> +__attribute__((noinline)) void foo() {
>> +}
>> +
>> +int main() {
>> +  foo();
>> +}
>> Index: test/Driver/thinlto.c
>> ===
>> --- /dev/null
>> +++ test/Driver/thinlto.c
>> @@ -0,0 +1,11 @@
>> +// -fthinlto causes a switch to llvm-bc object files.
>> +// RUN: %clang -ccc-print-phases -c %s -fthinlto 2> %t.log
>> +// RUN: grep '2: compiler, {1}, ir' %t.log
>> +// RUN: grep '3: backend, {2}, lto-bc' %t.log
>> +
>> +// RUN: %clang -ccc-print-phases %s -fthinlto 2> %t.log
>> +// RUN: grep '0: input, ".*thinlto.c", c' %t.log
>> +// RUN: grep '1: preprocessor, {0}, cpp-output' %t.log
>> +// RUN: grep '2: compiler, {1}, ir' %t.log
>> +// RUN: grep '3: backend, {2}, lto-bc' %t.log
>> +// RUN: grep '4: linker, {3}, image' %t.log
>
> Usually we prefer FileCheck tests over grep (typically the grep tests
> are just old and haven't been converted yet).  Is there a particular
> reason you're using grep, or were you just copying an example?

This was cloned from test/Driver/lto.c. Let me see if I can rework
this with FileCheck.

>
>> Index: lib/Frontend/CompilerInvocation.cpp
>> ===
>> --- lib/Frontend/CompilerInvocation.cpp
>> +++ lib/Frontend/CompilerInvocation.cpp
>> @@ -518,6 +518,7 @@
>>Opts.MergeFunctions = Args.hasArg(OPT_fmerge_functions);
>>
>>Opts.PrepareForLTO = Args.hasArg(OPT_flto);
>> +  Opts.EmitThinLTOIndex = Args.hasArg(OPT_fthinlto);
>>
>>Opts.MSVolatile = Args.hasArg(OPT_fms_volatile);
>>
>> Index: lib/Driver/Tools.cpp
>> ===
>> --- lib/Driver/Tools.cpp
>> +++ lib/Driver/Tools.cpp
>> @@ -1664,6 +1664,9 @@
>>std::string CPU = getCPUName(Args, ToolChain.getTriple());
>>if (!CPU.empty())
>>  CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=mcpu=") + CPU));
>> +
>> +  if (Args.hasArg(options::OPT_fthinlto))
>> +CmdArgs.push_back("-plugin-opt=thinlto");
>>  }
>>
>>  /// This is a helper function for validating the optional refinement step
>> @@ -2818,6 +2821,8 @@
>>// preprocessing, precompiling or assembling.
>>Args.ClaimAllArgs(options::OPT_flto);
>>Args.ClaimAllArgs(options::OPT_fno_lto);
>> +  Args.ClaimAllArgs(options::OPT_fthinlto);
>> +  Args.ClaimAllArgs(options::OPT_fno_thinlto);
>>  }
>>
>>  static void appendUserToPath(SmallVectorImpl ) {
>> @@ -3236,6 +3241,8 @@
>> "Invalid action for clang tool.");
>>
>>  if (JA.getType() == types::TY_LTO_IR || JA.getType() == 
>> types::TY_LTO_BC) {
>> +  // Enables PrepareForLTO, which we want for -fthinlto as well.
>> +  // ThinLTO also uses the TY_LTO_* types.
>>CmdArgs.push_back("-flto");
>>  }
>>  if (JA.getType() == types::TY_Nothing) {
>> @@ -3268,6 +3275,10 @@
>>  // the use-list order, since serialization to bitcode is part of the 
>> flow.
>>  if (JA.getType() == types::TY_LLVM_BC)
>>CmdArgs.push_back("-emit-llvm-uselists");
>> +
>> +if (Args.hasArg(options::OPT_fthinlto)) {
>> +  CmdArgs.push_back("-fthinlto");
>> +}
>>}
>>
>>// We normally speed up the clang process a bit by skipping destructors at
>> Index: lib/Driver/Driver.cpp
>> 

r248925 - [Sema] Avoid crashing during this-> insertion recovery

2015-09-30 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Wed Sep 30 12:30:48 2015
New Revision: 248925

URL: http://llvm.org/viewvc/llvm-project?rev=248925=rev
Log:
[Sema] Avoid crashing during this-> insertion recovery

We get into this bad state when someone defines a new member function
for a class but forgets to add the declaration to the class body.
Calling the new member function from a member function template of the
class will crash during instantiation.

Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaTemplate/recovery-crash.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=248925=248924=248925=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Sep 30 12:30:48 2015
@@ -1824,7 +1824,6 @@ Sema::DiagnoseEmptyLookup(Scope *S, CXXS
 bool isInstance = CurMethod &&
   CurMethod->isInstance() &&
   DC == CurMethod->getParent() && !isDefaultArgument;
-  
 
 // Give a code modification hint to insert 'this->'.
 // TODO: fixit for inserting 'Base::' in the other cases.
@@ -1838,15 +1837,23 @@ Sema::DiagnoseEmptyLookup(Scope *S, CXXS
   CallsUndergoingInstantiation.back()->getCallee());
 
   CXXMethodDecl *DepMethod;
-  if (CurMethod->isDependentContext())
+  if (CurMethod->isDependentContext()) {
 DepMethod = CurMethod;
-  else if (CurMethod->getTemplatedKind() ==
-  FunctionDecl::TK_FunctionTemplateSpecialization)
-DepMethod = cast(CurMethod->getPrimaryTemplate()->
-getInstantiatedFromMemberTemplate()->getTemplatedDecl());
-  else
+  } else if (FunctionTemplateDecl *FTD =
+ CurMethod->getPrimaryTemplate()) {
+// We have a member function template. It may be contained in a
+// class template. If so, get the original pattern for the member
+// function template. Otherwise, 'this' isn't dependent and we can
+// use CurMethod as is.
+if (FunctionTemplateDecl *MemberFTD =
+FTD->getInstantiatedFromMemberTemplate())
+  DepMethod = cast(MemberFTD->getTemplatedDecl());
+else
+  DepMethod = CurMethod;
+  } else {
 DepMethod = cast(
 CurMethod->getInstantiatedFromMemberFunction());
+  }
   assert(DepMethod && "No template pattern found");
 
   QualType DepThisType = DepMethod->getThisType(Context);
@@ -1856,7 +1863,7 @@ Sema::DiagnoseEmptyLookup(Scope *S, CXXS
   TemplateArgumentListInfo TList;
   if (ULE->hasExplicitTemplateArgs())
 ULE->copyTemplateArgumentsInto(TList);
-  
+
   CXXScopeSpec SS;
   SS.Adopt(ULE->getQualifierLoc());
   CXXDependentScopeMemberExpr *DepExpr =

Modified: cfe/trunk/test/SemaTemplate/recovery-crash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/recovery-crash.cpp?rev=248925=248924=248925=diff
==
--- cfe/trunk/test/SemaTemplate/recovery-crash.cpp (original)
+++ cfe/trunk/test/SemaTemplate/recovery-crash.cpp Wed Sep 30 12:30:48 2015
@@ -35,3 +35,25 @@ namespace PR16225 {
 g(0);  // expected-note {{in instantiation of function template 
specialization}}
   }
 }
+
+namespace test1 {
+  template  class ArraySlice {};
+  class Foo;
+  class NonTemplateClass {
+void MemberFunction(ArraySlice, int);
+template  void MemberFuncTemplate(ArraySlice, int);
+  };
+  void NonTemplateClass::MemberFunction(ArraySlice resource_data,
+int now) {
+// expected-note@+1 {{in instantiation of function template specialization 
'test1::NonTemplateClass::MemberFuncTemplate'}}
+MemberFuncTemplate(resource_data, now);
+  }
+  template 
+  void NonTemplateClass::MemberFuncTemplate(ArraySlice resource_data, int) {
+// expected-error@+1 {{use of undeclared identifier 'UndeclaredMethod'}}
+UndeclaredMethod(resource_data);
+  }
+  // expected-error@+2 {{out-of-line definition of 'UndeclaredMethod' does not 
match any declaration}}
+  // expected-note@+1 {{must qualify identifier to find this declaration in 
dependent base class}}
+  void NonTemplateClass::UndeclaredMethod() {}
+}


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


Re: [PATCH] D13279: Decorating virtual functions load with invariant.load

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

http://reviews.llvm.org/D13279

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/virtual-function-calls.cpp

Index: test/CodeGenCXX/virtual-function-calls.cpp
===
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - 
-fstrict-vtable-pointers -O1 | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} align 8, !invariant.load 
![[EMPTY_NODE:[0-9]]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1609,7 +1609,16 @@
   uint64_t VTableIndex = 
CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
   llvm::Value *VFuncPtr =
   CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-  return CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+  auto *Inst = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+  // It's safe to add "invariant.load" without -fstrict-vtable-pointers, but it
+  // would not help in devirtualization.
+  if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+  CGM.getCodeGenOpts().StrictVTablePointers)
+Inst->setMetadata(llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+  return Inst;
 }
 
 llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(


Index: test/CodeGenCXX/virtual-function-calls.cpp
===
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - -fstrict-vtable-pointers -O1 | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} align 8, !invariant.load ![[EMPTY_NODE:[0-9]]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1609,7 +1609,16 @@
   uint64_t VTableIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
   llvm::Value *VFuncPtr =
   CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-  return CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+  auto *Inst = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+  // It's safe to add "invariant.load" without -fstrict-vtable-pointers, but it
+  // would not help in devirtualization.
+  if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+  CGM.getCodeGenOpts().StrictVTablePointers)
+Inst->setMetadata(llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+  return Inst;
 }
 
 llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12251: Analyzer: Calculate field offset correctly

2015-09-30 Thread Devin Coughlin via cfe-commits
dcoughlin added inline comments.


Comment at: test/Analysis/array-struct-region.cpp:128
@@ +127,3 @@
+#if __cplusplus
+  clang_analyzer_eval((void *)>secondField != (void *)); // 
expected-warning{{TRUE}}
+#endif

ismailp wrote:
> I might be missing something, and would be very happy if you could explain 
> why it is necessary to add `PFOConstant`.
> 
> At line 122, for example, where `` is always non-null. Likewise, I'd 
> expect line 128 to be non-null, because `new` in this translation unit either 
> throws -- in which case, we shouldn't be executing this line -- or succeeds 
> -- in which case, `PFONew` is non-null.
Sorry I wasn't clear. The branch of the case that you modified here only 
executes when the base is an int with a known value, such as '0xa' (see the 
code comment with the FIXME you removed.) This means that your test with 
`PFONew` doesn't exercise your new code at all. The `PFONull` case does 
exercise this case branch (because NULL is the 0 concreteInt) but it does not 
exercise your newly added logic for calculating field offsets (because for 
`NULL`, `Base.isZeroConstant()` is true). This means there were no tests 
exercising that logic (try removing the logic and adding `assert(false)` -- 
your old tests would still pass).

Separately, as I mentioned before, I think it is important to leave a FIXME 
here documenting that the `NULL` case still doesn't work properly. That is, 
even with your changes, the analyzer still incorrectly says that `&(((struct 
foo *) NULL)->f == 0`. (Fixing this would be quite an undertaking.)  It would 
probably also be good to add comments to the tests saying the behavior they 
expect for `PFONull` is incorrect so that if we ever fix this issue we will 
know it is safe to update the tests:

```
  clang_analyzer_eval((void *)>secondField != (void 
*)>thirdField); // expected-warning{{FALSE}}
  clang_analyzer_eval((void *)>secondField == (void *)0); // 
expected-warning{{TRUE}}

```
(If we handled `NULL` properly, the first would be TRUE and second would be 
FALSE.)

Note that your updated version doesn't calculate field offsets for ObjC ivars 
with concreteInt bases, so the analyzer also still won't properly say `&((Root 
*)0x10)->uniqueID != (Root *)0x10)`. Please add it to the FIXME comment, as 
well.


http://reviews.llvm.org/D12251



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


r248928 - Don't correct non-class using declarations to class members.

2015-09-30 Thread Kaelyn Takata via cfe-commits
Author: rikka
Date: Wed Sep 30 13:23:35 2015
New Revision: 248928

URL: http://llvm.org/viewvc/llvm-project?rev=248928=rev
Log:
Don't correct non-class using declarations to class members.

Such declarations would be invalid anyway, and trying to make the
correction will lead to a crash. Fixes PR 24781.

Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/typo-correction.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=248928=248927=248928=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Sep 30 13:23:35 2015
@@ -8031,6 +8031,10 @@ public:
 
 // FIXME: Check that the base class member is accessible?
   }
+} else {
+  auto *FoundRecord = dyn_cast(ND);
+  if (FoundRecord && FoundRecord->isInjectedClassName())
+return false;
 }
 
 if (isa(ND))

Modified: cfe/trunk/test/SemaCXX/typo-correction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction.cpp?rev=248928=248927=248928=diff
==
--- cfe/trunk/test/SemaCXX/typo-correction.cpp (original)
+++ cfe/trunk/test/SemaCXX/typo-correction.cpp Wed Sep 30 13:23:35 2015
@@ -640,3 +640,19 @@ int has_include(int); // expected-note {
 // expected-error@+1 {{__has_include must be used within a preprocessing 
directive}}
 int foo = __has_include(42); // expected-error {{use of undeclared identifier 
'__has_include'; did you mean 'has_include'?}}
 }
+
+namespace PR24781_using_crash {
+namespace A {
+namespace B {
+class Foofoo {};  // expected-note {{'A::B::Foofoo' declared here}}
+}
+}
+
+namespace C {
+namespace D {
+class Bar : public A::B::Foofoo {};
+}
+}
+
+using C::D::Foofoo;  // expected-error {{no member named 'Foofoo' in namespace 
'PR24781_using_crash::C::D'; did you mean 'A::B::Foofoo'?}}
+}


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


Re: [PATCH] D11908: Clang support for -fthinlto.

2015-09-30 Thread Duncan P. N. Exon Smith via cfe-commits

> On 2015-Sep-23, at 10:28, Teresa Johnson  wrote:
> 
> tejohnson updated this revision to Diff 35527.
> tejohnson added a comment.
> 
> Updated the patch for the new LLVM/gold patch 
> (http://reviews.llvm.org/D13107).
> 
> Two changes:
> 
> - I put back the original change to pass a new plugin option to gold. Since 
> the function index design/name has been generalized to not be 
> ThinLTO-specific, it makes sense to have the ThinLTO-related gold behavior 
> for modules with those sections to be dependent on an option.
> - Added 2 tests.
> 
> 
> http://reviews.llvm.org/D11908
> 
> Files:
>  include/clang/Driver/Options.td
>  include/clang/Frontend/CodeGenOptions.def
>  lib/CodeGen/BackendUtil.cpp
>  lib/Driver/Driver.cpp
>  lib/Driver/Tools.cpp
>  lib/Frontend/CompilerInvocation.cpp
>  test/Driver/thinlto.c
>  test/Misc/thinlto.c
> 
> 

> Index: test/Misc/thinlto.c
> ===
> --- /dev/null
> +++ test/Misc/thinlto.c
> @@ -0,0 +1,22 @@
> +// RUN: %clang_cc1 -fthinlto -emit-llvm-bc < %s | llvm-bcanalyzer -dump | 
> FileCheck %s
> +// CHECK:  +// CHECK-NEXT:  +// CHECK-NEXT:  +// CHECK-NEXT:  +
> +// RUN: %clang -fthinlto %s -o %t -fuse-ld=gold

Why isn't this using -cc1?

> +// RUN: llvm-bcanalyzer -dump %t.thinlto.bc | FileCheck %s 
> --check-prefix=COMBINED
> +// COMBINED:  +// COMBINED-NEXT:  +// COMBINED-NEXT:  +// COMBINED-NEXT:  +// COMBINED-NEXT:  +// COMBINED-NEXT:  +// COMBINED-NEXT:  +
> +__attribute__((noinline)) void foo() {
> +}
> +
> +int main() {
> +  foo();
> +}
> Index: test/Driver/thinlto.c
> ===
> --- /dev/null
> +++ test/Driver/thinlto.c
> @@ -0,0 +1,11 @@
> +// -fthinlto causes a switch to llvm-bc object files.
> +// RUN: %clang -ccc-print-phases -c %s -fthinlto 2> %t.log
> +// RUN: grep '2: compiler, {1}, ir' %t.log
> +// RUN: grep '3: backend, {2}, lto-bc' %t.log
> +
> +// RUN: %clang -ccc-print-phases %s -fthinlto 2> %t.log
> +// RUN: grep '0: input, ".*thinlto.c", c' %t.log
> +// RUN: grep '1: preprocessor, {0}, cpp-output' %t.log
> +// RUN: grep '2: compiler, {1}, ir' %t.log
> +// RUN: grep '3: backend, {2}, lto-bc' %t.log
> +// RUN: grep '4: linker, {3}, image' %t.log

Usually we prefer FileCheck tests over grep (typically the grep tests
are just old and haven't been converted yet).  Is there a particular
reason you're using grep, or were you just copying an example?

> Index: lib/Frontend/CompilerInvocation.cpp
> ===
> --- lib/Frontend/CompilerInvocation.cpp
> +++ lib/Frontend/CompilerInvocation.cpp
> @@ -518,6 +518,7 @@
>Opts.MergeFunctions = Args.hasArg(OPT_fmerge_functions);
>  
>Opts.PrepareForLTO = Args.hasArg(OPT_flto);
> +  Opts.EmitThinLTOIndex = Args.hasArg(OPT_fthinlto);
>  
>Opts.MSVolatile = Args.hasArg(OPT_fms_volatile);
>  
> Index: lib/Driver/Tools.cpp
> ===
> --- lib/Driver/Tools.cpp
> +++ lib/Driver/Tools.cpp
> @@ -1664,6 +1664,9 @@
>std::string CPU = getCPUName(Args, ToolChain.getTriple());
>if (!CPU.empty())
>  CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=mcpu=") + CPU));
> +
> +  if (Args.hasArg(options::OPT_fthinlto))
> +CmdArgs.push_back("-plugin-opt=thinlto");
>  }
>  
>  /// This is a helper function for validating the optional refinement step
> @@ -2818,6 +2821,8 @@
>// preprocessing, precompiling or assembling.
>Args.ClaimAllArgs(options::OPT_flto);
>Args.ClaimAllArgs(options::OPT_fno_lto);
> +  Args.ClaimAllArgs(options::OPT_fthinlto);
> +  Args.ClaimAllArgs(options::OPT_fno_thinlto);
>  }
>  
>  static void appendUserToPath(SmallVectorImpl ) {
> @@ -3236,6 +3241,8 @@
> "Invalid action for clang tool.");
>  
>  if (JA.getType() == types::TY_LTO_IR || JA.getType() == 
> types::TY_LTO_BC) {
> +  // Enables PrepareForLTO, which we want for -fthinlto as well.
> +  // ThinLTO also uses the TY_LTO_* types.
>CmdArgs.push_back("-flto");
>  }
>  if (JA.getType() == types::TY_Nothing) {
> @@ -3268,6 +3275,10 @@
>  // the use-list order, since serialization to bitcode is part of the 
> flow.
>  if (JA.getType() == types::TY_LLVM_BC)
>CmdArgs.push_back("-emit-llvm-uselists");
> +
> +if (Args.hasArg(options::OPT_fthinlto)) {
> +  CmdArgs.push_back("-fthinlto");
> +}
>}
>  
>// We normally speed up the clang process a bit by skipping destructors at
> Index: lib/Driver/Driver.cpp
> ===
> --- lib/Driver/Driver.cpp
> +++ lib/Driver/Driver.cpp
> @@ -1576,7 +1576,8 @@
>  }
>  
>  bool Driver::IsUsingLTO(const ArgList ) const {
> -  return Args.hasFlag(options::OPT_flto, options::OPT_fno_lto, false);
> +  return Args.hasFlag(options::OPT_flto, options::OPT_fno_lto, false) ||
> +  

Re: [PATCH] D11908: Clang support for -fthinlto.

2015-09-30 Thread Duncan P. N. Exon Smith via cfe-commits

> On 2015-Sep-30, at 10:40, Teresa Johnson  wrote:
> 
> On Wed, Sep 30, 2015 at 10:19 AM, Duncan P. N. Exon Smith
>  wrote:
>> 
>>> On 2015-Sep-23, at 10:28, Teresa Johnson  wrote:
>>> 
>>> tejohnson updated this revision to Diff 35527.
>>> tejohnson added a comment.
>>> 
>>> Updated the patch for the new LLVM/gold patch 
>>> (http://reviews.llvm.org/D13107).
>>> 
>>> Two changes:
>>> 
>>> - I put back the original change to pass a new plugin option to gold. Since 
>>> the function index design/name has been generalized to not be 
>>> ThinLTO-specific, it makes sense to have the ThinLTO-related gold behavior 
>>> for modules with those sections to be dependent on an option.
>>> - Added 2 tests.
>>> 
>>> 
>>> http://reviews.llvm.org/D11908
>>> 
>>> Files:
>>> include/clang/Driver/Options.td
>>> include/clang/Frontend/CodeGenOptions.def
>>> lib/CodeGen/BackendUtil.cpp
>>> lib/Driver/Driver.cpp
>>> lib/Driver/Tools.cpp
>>> lib/Frontend/CompilerInvocation.cpp
>>> test/Driver/thinlto.c
>>> test/Misc/thinlto.c
>>> 
>>> 
>> 
>>> Index: test/Misc/thinlto.c
>>> ===
>>> --- /dev/null
>>> +++ test/Misc/thinlto.c
>>> @@ -0,0 +1,22 @@
>>> +// RUN: %clang_cc1 -fthinlto -emit-llvm-bc < %s | llvm-bcanalyzer -dump | 
>>> FileCheck %s
>>> +// CHECK: >> +// CHECK-NEXT: >> +// CHECK-NEXT: >> +// CHECK-NEXT: >> +
>>> +// RUN: %clang -fthinlto %s -o %t -fuse-ld=gold
>> 
>> Why isn't this using -cc1?
> 
> I can try it again, but I believe -fuse-ld is not a -cc1 option.

Oh, right, of course.  -cc1 doesn't invoke the linker, the driver does.

In that case, it seems to me like you should:
1. have a driver test that uses -### to check that you're getting the
expected linker command-line (in test/Driver), and
2. somewhere (probably in test/tools/gold in LLVM?) confirm that gold
does the right thing with the thinlto plugin.



>>> +// RUN: llvm-bcanalyzer -dump %t.thinlto.bc | FileCheck %s 
>>> --check-prefix=COMBINED
>>> +// COMBINED: >> +// COMBINED-NEXT: >> +// COMBINED-NEXT: >> +// COMBINED-NEXT: >> +// COMBINED-NEXT: >> +// COMBINED-NEXT: >> +// COMBINED-NEXT: >> +
>>> +__attribute__((noinline)) void foo() {
>>> +}
>>> +
>>> +int main() {
>>> +  foo();
>>> +}
>>> Index: test/Driver/thinlto.c
>>> ===
>>> --- /dev/null
>>> +++ test/Driver/thinlto.c
>>> @@ -0,0 +1,11 @@
>>> +// -fthinlto causes a switch to llvm-bc object files.
>>> +// RUN: %clang -ccc-print-phases -c %s -fthinlto 2> %t.log
>>> +// RUN: grep '2: compiler, {1}, ir' %t.log
>>> +// RUN: grep '3: backend, {2}, lto-bc' %t.log
>>> +
>>> +// RUN: %clang -ccc-print-phases %s -fthinlto 2> %t.log
>>> +// RUN: grep '0: input, ".*thinlto.c", c' %t.log
>>> +// RUN: grep '1: preprocessor, {0}, cpp-output' %t.log
>>> +// RUN: grep '2: compiler, {1}, ir' %t.log
>>> +// RUN: grep '3: backend, {2}, lto-bc' %t.log
>>> +// RUN: grep '4: linker, {3}, image' %t.log
>> 
>> Usually we prefer FileCheck tests over grep (typically the grep tests
>> are just old and haven't been converted yet).  Is there a particular
>> reason you're using grep, or were you just copying an example?
> 
> This was cloned from test/Driver/lto.c. Let me see if I can rework
> this with FileCheck.
> 
>> 
>>> Index: lib/Frontend/CompilerInvocation.cpp
>>> ===
>>> --- lib/Frontend/CompilerInvocation.cpp
>>> +++ lib/Frontend/CompilerInvocation.cpp
>>> @@ -518,6 +518,7 @@
>>>   Opts.MergeFunctions = Args.hasArg(OPT_fmerge_functions);
>>> 
>>>   Opts.PrepareForLTO = Args.hasArg(OPT_flto);
>>> +  Opts.EmitThinLTOIndex = Args.hasArg(OPT_fthinlto);
>>> 
>>>   Opts.MSVolatile = Args.hasArg(OPT_fms_volatile);
>>> 
>>> Index: lib/Driver/Tools.cpp
>>> ===
>>> --- lib/Driver/Tools.cpp
>>> +++ lib/Driver/Tools.cpp
>>> @@ -1664,6 +1664,9 @@
>>>   std::string CPU = getCPUName(Args, ToolChain.getTriple());
>>>   if (!CPU.empty())
>>> CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=mcpu=") + CPU));
>>> +
>>> +  if (Args.hasArg(options::OPT_fthinlto))
>>> +CmdArgs.push_back("-plugin-opt=thinlto");
>>> }
>>> 
>>> /// This is a helper function for validating the optional refinement step
>>> @@ -2818,6 +2821,8 @@
>>>   // preprocessing, precompiling or assembling.
>>>   Args.ClaimAllArgs(options::OPT_flto);
>>>   Args.ClaimAllArgs(options::OPT_fno_lto);
>>> +  Args.ClaimAllArgs(options::OPT_fthinlto);
>>> +  Args.ClaimAllArgs(options::OPT_fno_thinlto);
>>> }
>>> 
>>> static void appendUserToPath(SmallVectorImpl ) {
>>> @@ -3236,6 +3241,8 @@
>>>"Invalid action for clang tool.");
>>> 
>>> if (JA.getType() == types::TY_LTO_IR || JA.getType() == 
>>> types::TY_LTO_BC) {
>>> +  // Enables PrepareForLTO, which we want for -fthinlto as well.
>>> +  // ThinLTO also uses the TY_LTO_* 

Re: r248904 - clang-format: Use Rewriter again to write the output files.

2015-09-30 Thread Daniel Jasper via cfe-commits
This breaks your *build*? How?

On Wed, Sep 30, 2015 at 9:19 PM, Jan Vesely  wrote:

> Hi,
> I think this change breaks cmake build. Please consider the attached fix
> (I can't push atm).
>
> thank you,
> Jan
>
> On Wed, Sep 30, 2015 at 8:59 AM, Daniel Jasper via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: djasper
>> Date: Wed Sep 30 08:59:29 2015
>> New Revision: 248904
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=248904=rev
>> Log:
>> clang-format: Use Rewriter again to write the output files.
>>
>> This has two advantages:
>> 1. Atomic writes.
>> 2. Proper handling of line endings (hopefully solving llvm.org/PR24999
>>
>> Modified:
>> cfe/trunk/tools/clang-format/ClangFormat.cpp
>>
>> Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=248904=248903=248904=diff
>>
>> ==
>> --- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)
>> +++ cfe/trunk/tools/clang-format/ClangFormat.cpp Wed Sep 30 08:59:29 2015
>> @@ -19,6 +19,7 @@
>>  #include "clang/Basic/SourceManager.h"
>>  #include "clang/Basic/Version.h"
>>  #include "clang/Format/Format.h"
>> +#include "clang/Rewrite/Core/Rewriter.h"
>>  #include "llvm/ADT/StringMap.h"
>>  #include "llvm/Support/CommandLine.h"
>>  #include "llvm/Support/Debug.h"
>> @@ -77,7 +78,7 @@ AssumeFileName("assume-filename",
>> cl::desc("When reading from stdin, clang-format assumes
>> this\n"
>>  "filename to look for a style config file
>> (with\n"
>>  "-style=file) and to determine the language."),
>> -   cl::cat(ClangFormatCategory));
>> +   cl::init(""), cl::cat(ClangFormatCategory));
>>
>>  static cl::opt Inplace("i",
>>   cl::desc("Inplace edit s, if
>> specified."),
>> @@ -109,8 +110,7 @@ namespace format {
>>
>>  static FileID createInMemoryFile(StringRef FileName, MemoryBuffer
>> *Source,
>>   SourceManager , FileManager
>> ) {
>> -  const FileEntry *Entry = Files.getVirtualFile(FileName == "-" ?
>> "" :
>> -FileName,
>> +  const FileEntry *Entry = Files.getVirtualFile(FileName,
>>  Source->getBufferSize(),
>> 0);
>>Sources.overrideFileContents(Entry, Source, true);
>>return Sources.createFileID(Entry, SourceLocation(), SrcMgr::C_User);
>> @@ -132,7 +132,7 @@ static bool fillRanges(MemoryBuffer *Cod
>>IntrusiveRefCntPtr(new DiagnosticIDs),
>>new DiagnosticOptions);
>>SourceManager Sources(Diagnostics, Files);
>> -  FileID ID = createInMemoryFile("-", Code, Sources, Files);
>> +  FileID ID = createInMemoryFile("", Code, Sources, Files);
>>if (!LineRanges.empty()) {
>>  if (!Offsets.empty() || !Lengths.empty()) {
>>llvm::errs() << "error: cannot use -lines with -offset/-length\n";
>> @@ -255,8 +255,8 @@ static bool format(StringRef FileName) {
>>
>>bool IncompleteFormat = false;
>>Replaces = tooling::mergeReplacements(
>> -  Replaces,
>> -  reformat(FormatStyle, ChangedCode, Ranges, FileName,
>> ));
>> +  Replaces, reformat(FormatStyle, ChangedCode, Ranges,
>> AssumedFileName,
>> + ));
>>if (OutputXML) {
>>  llvm::outs() << "\n>  "xml:space='preserve' incomplete_format='"
>> @@ -269,27 +269,26 @@ static bool format(StringRef FileName) {
>>  outputReplacementsXML(Replaces);
>>  llvm::outs() << "\n";
>>} else {
>> -std::string FormattedCode =
>> -applyAllReplacements(Code->getBuffer(), Replaces);
>> +FileManager Files((FileSystemOptions()));
>> +DiagnosticsEngine Diagnostics(
>> +IntrusiveRefCntPtr(new DiagnosticIDs),
>> +new DiagnosticOptions);
>> +SourceManager Sources(Diagnostics, Files);
>> +FileID ID = createInMemoryFile(AssumedFileName, Code.get(), Sources,
>> Files);
>> +Rewriter Rewrite(Sources, LangOptions());
>> +tooling::applyAllReplacements(Replaces, Rewrite);
>>  if (Inplace) {
>>if (FileName == "-")
>>  llvm::errs() << "error: cannot use -i when reading from
>> stdin.\n";
>> -  else {
>> -std::error_code EC;
>> -raw_fd_ostream FileOut(FileName, EC, llvm::sys::fs::F_Text);
>> -if (EC) {
>> -  llvm::errs() << EC.message() << "\n";
>> -  return true;
>> -}
>> -FileOut << FormattedCode;
>> -  }
>> +  else if (Rewrite.overwriteChangedFiles())
>> +return true;
>>  } else {
>>if (Cursor.getNumOccurrences() != 0)
>>  outs() << "{ \"Cursor\": "
>> << tooling::shiftedCodePosition(Replaces, Cursor)
>> << ", \"IncompleteFormat\": "
>> << (IncompleteFormat ? 

[PATCH] D13280: Adding reserved operator logical xor for OpenCL

2015-09-30 Thread Neil Hickey via cfe-commits
neil.hickey created this revision.
neil.hickey added a reviewer: cfe-commits.

This patch adds the reserved operator ^^ when compiling for OpenCL, which 
results in a more meaningful error message.

http://reviews.llvm.org/D13280

Files:
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/TokenKinds.def
  lib/Basic/OperatorPrecedence.cpp
  lib/Lex/Lexer.cpp
  lib/Parse/ParseExpr.cpp
  test/SemaOpenCL/unsupported.cl

Index: test/SemaOpenCL/unsupported.cl
===
--- test/SemaOpenCL/unsupported.cl
+++ test/SemaOpenCL/unsupported.cl
@@ -7,3 +7,7 @@
 void no_vla(int n) {
   int a[n]; // expected-error {{variable length arrays are not supported in 
OpenCL}}
 }
+
+void no_logxor(int n) {
+  int logxor = n ^^ n; // expected-error {{^^ is a reserved operator in 
OpenCL}}
+}
Index: lib/Parse/ParseExpr.cpp
===
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -261,6 +261,9 @@
 Token OpToken = Tok;
 ConsumeToken();
 
+if (OpToken.is(tok::caretcaret)) {
+  return ExprError(Diag(Tok, diag::err_opencl_logical_exclusive_or));
+}
 // Bail out when encountering a comma followed by a token which can't
 // possibly be the start of an expression. For instance:
 //   int f() { return 1, }
Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -3473,6 +3473,9 @@
 if (Char == '=') {
   CurPtr = ConsumeChar(CurPtr, SizeTmp, Result);
   Kind = tok::caretequal;
+} else if (LangOpts.OpenCL && Char == '^') {
+  CurPtr = ConsumeChar(CurPtr, SizeTmp, Result);
+  Kind = tok::caretcaret;
 } else {
   Kind = tok::caret;
 }
Index: lib/Basic/OperatorPrecedence.cpp
===
--- lib/Basic/OperatorPrecedence.cpp
+++ lib/Basic/OperatorPrecedence.cpp
@@ -53,6 +53,7 @@
   case tok::pipeequal:return prec::Assignment;
   case tok::question: return prec::Conditional;
   case tok::pipepipe: return prec::LogicalOr;
+  case tok::caretcaret:
   case tok::ampamp:   return prec::LogicalAnd;
   case tok::pipe: return prec::InclusiveOr;
   case tok::caret:return prec::ExclusiveOr;
Index: include/clang/Basic/TokenKinds.def
===
--- include/clang/Basic/TokenKinds.def
+++ include/clang/Basic/TokenKinds.def
@@ -219,6 +219,9 @@
 PUNCTUATOR(lesslessless,  "<<<")
 PUNCTUATOR(greatergreatergreater, ">>>")
 
+// CL support
+PUNCTUATOR(caretcaret,"^^")
+
 // C99 6.4.1: Keywords.  These turn into kw_* tokens.
 // Flags allowed:
 //   KEYALL   - This is a keyword in all variants of C and C++, or it
Index: include/clang/Basic/DiagnosticParseKinds.td
===
--- include/clang/Basic/DiagnosticParseKinds.td
+++ include/clang/Basic/DiagnosticParseKinds.td
@@ -964,6 +964,8 @@
 // OpenCL Section 6.8.g
 def err_opencl_unknown_type_specifier : Error<
   "OpenCL does not support the '%0' %select{type qualifier|storage class 
specifier}1">;
+def err_opencl_logical_exclusive_or : Error<
+  "^^ is a reserved operator in OpenCL">;
 
 // OpenCL EXTENSION pragma (OpenCL 1.1 [9.1])
 def warn_pragma_expected_colon : Warning<


Index: test/SemaOpenCL/unsupported.cl
===
--- test/SemaOpenCL/unsupported.cl
+++ test/SemaOpenCL/unsupported.cl
@@ -7,3 +7,7 @@
 void no_vla(int n) {
   int a[n]; // expected-error {{variable length arrays are not supported in OpenCL}}
 }
+
+void no_logxor(int n) {
+  int logxor = n ^^ n; // expected-error {{^^ is a reserved operator in OpenCL}}
+}
Index: lib/Parse/ParseExpr.cpp
===
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -261,6 +261,9 @@
 Token OpToken = Tok;
 ConsumeToken();
 
+if (OpToken.is(tok::caretcaret)) {
+  return ExprError(Diag(Tok, diag::err_opencl_logical_exclusive_or));
+}
 // Bail out when encountering a comma followed by a token which can't
 // possibly be the start of an expression. For instance:
 //   int f() { return 1, }
Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -3473,6 +3473,9 @@
 if (Char == '=') {
   CurPtr = ConsumeChar(CurPtr, SizeTmp, Result);
   Kind = tok::caretequal;
+} else if (LangOpts.OpenCL && Char == '^') {
+  CurPtr = ConsumeChar(CurPtr, SizeTmp, Result);
+  Kind = tok::caretcaret;
 } else {
   Kind = tok::caret;
 }
Index: lib/Basic/OperatorPrecedence.cpp
===
--- 

[PATCH] D13279: Decorating virtual functions load with invariant.load

2015-09-30 Thread Piotr Padlewski via cfe-commits
Prazek created this revision.
Prazek added reviewers: rsmith, majnemer, nlewycky, rjmccall.
Prazek added a subscriber: cfe-commits.

http://reviews.llvm.org/D13279

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/virtual-function-calls.cpp

Index: test/CodeGenCXX/virtual-function-calls.cpp
===
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - 
-fstrict-vtable-pointers | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} align 8, !invariant.load 
![[EMPTY_NODE:[0-9]]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1609,7 +1609,15 @@
   uint64_t VTableIndex = 
CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
   llvm::Value *VFuncPtr =
   CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-  return CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+  auto *Inst = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+  // It's safe to add "invariant.load" without -fstrict-vtable-pointers, but it
+  // would not help in devirtualization.
+  if (CGM.getCodeGenOpts().StrictVTablePointers)
+Inst->setMetadata(llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+  return Inst;
 }
 
 llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(


Index: test/CodeGenCXX/virtual-function-calls.cpp
===
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - -fstrict-vtable-pointers | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} align 8, !invariant.load ![[EMPTY_NODE:[0-9]]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1609,7 +1609,15 @@
   uint64_t VTableIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
   llvm::Value *VFuncPtr =
   CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-  return CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+  auto *Inst = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+  // It's safe to add "invariant.load" without -fstrict-vtable-pointers, but it
+  // would not help in devirtualization.
+  if (CGM.getCodeGenOpts().StrictVTablePointers)
+Inst->setMetadata(llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+  return Inst;
 }
 
 llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r248904 - clang-format: Use Rewriter again to write the output files.

2015-09-30 Thread Daniel Jasper via cfe-commits
Ah, very sorry, I was looking at the wrong patch. So I did make the same
change :-)

On Wed, Sep 30, 2015 at 9:30 PM, Daniel Jasper  wrote:

> cmake build hopefully fixed in r248929. How is the patch you have attached
> related?
>
> On Wed, Sep 30, 2015 at 9:24 PM, Daniel Jasper  wrote:
>
>> This breaks your *build*? How?
>>
>> On Wed, Sep 30, 2015 at 9:19 PM, Jan Vesely 
>> wrote:
>>
>>> Hi,
>>> I think this change breaks cmake build. Please consider the attached fix
>>> (I can't push atm).
>>>
>>> thank you,
>>> Jan
>>>
>>> On Wed, Sep 30, 2015 at 8:59 AM, Daniel Jasper via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
 Author: djasper
 Date: Wed Sep 30 08:59:29 2015
 New Revision: 248904

 URL: http://llvm.org/viewvc/llvm-project?rev=248904=rev
 Log:
 clang-format: Use Rewriter again to write the output files.

 This has two advantages:
 1. Atomic writes.
 2. Proper handling of line endings (hopefully solving llvm.org/PR24999

 Modified:
 cfe/trunk/tools/clang-format/ClangFormat.cpp

 Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp
 URL:
 http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=248904=248903=248904=diff

 ==
 --- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)
 +++ cfe/trunk/tools/clang-format/ClangFormat.cpp Wed Sep 30 08:59:29
 2015
 @@ -19,6 +19,7 @@
  #include "clang/Basic/SourceManager.h"
  #include "clang/Basic/Version.h"
  #include "clang/Format/Format.h"
 +#include "clang/Rewrite/Core/Rewriter.h"
  #include "llvm/ADT/StringMap.h"
  #include "llvm/Support/CommandLine.h"
  #include "llvm/Support/Debug.h"
 @@ -77,7 +78,7 @@ AssumeFileName("assume-filename",
 cl::desc("When reading from stdin, clang-format assumes
 this\n"
  "filename to look for a style config file
 (with\n"
  "-style=file) and to determine the language."),
 -   cl::cat(ClangFormatCategory));
 +   cl::init(""), cl::cat(ClangFormatCategory));

  static cl::opt Inplace("i",
   cl::desc("Inplace edit s, if
 specified."),
 @@ -109,8 +110,7 @@ namespace format {

  static FileID createInMemoryFile(StringRef FileName, MemoryBuffer
 *Source,
   SourceManager , FileManager
 ) {
 -  const FileEntry *Entry = Files.getVirtualFile(FileName == "-" ?
 "" :
 -FileName,
 +  const FileEntry *Entry = Files.getVirtualFile(FileName,

  Source->getBufferSize(), 0);
Sources.overrideFileContents(Entry, Source, true);
return Sources.createFileID(Entry, SourceLocation(), SrcMgr::C_User);
 @@ -132,7 +132,7 @@ static bool fillRanges(MemoryBuffer *Cod
IntrusiveRefCntPtr(new DiagnosticIDs),
new DiagnosticOptions);
SourceManager Sources(Diagnostics, Files);
 -  FileID ID = createInMemoryFile("-", Code, Sources, Files);
 +  FileID ID = createInMemoryFile("", Code, Sources, Files);
if (!LineRanges.empty()) {
  if (!Offsets.empty() || !Lengths.empty()) {
llvm::errs() << "error: cannot use -lines with
 -offset/-length\n";
 @@ -255,8 +255,8 @@ static bool format(StringRef FileName) {

bool IncompleteFormat = false;
Replaces = tooling::mergeReplacements(
 -  Replaces,
 -  reformat(FormatStyle, ChangedCode, Ranges, FileName,
 ));
 +  Replaces, reformat(FormatStyle, ChangedCode, Ranges,
 AssumedFileName,
 + ));
if (OutputXML) {
  llvm::outs() << "\n>>>  "xml:space='preserve' incomplete_format='"
 @@ -269,27 +269,26 @@ static bool format(StringRef FileName) {
  outputReplacementsXML(Replaces);
  llvm::outs() << "\n";
} else {
 -std::string FormattedCode =
 -applyAllReplacements(Code->getBuffer(), Replaces);
 +FileManager Files((FileSystemOptions()));
 +DiagnosticsEngine Diagnostics(
 +IntrusiveRefCntPtr(new DiagnosticIDs),
 +new DiagnosticOptions);
 +SourceManager Sources(Diagnostics, Files);
 +FileID ID = createInMemoryFile(AssumedFileName, Code.get(),
 Sources, Files);
 +Rewriter Rewrite(Sources, LangOptions());
 +tooling::applyAllReplacements(Replaces, Rewrite);
  if (Inplace) {
if (FileName == "-")
  llvm::errs() << "error: cannot use -i when reading from
 stdin.\n";
 -  else {
 -std::error_code EC;
 -raw_fd_ostream FileOut(FileName, EC, 

r248935 - Revert "[DarwinDriver] Use -lto_library to specify the path for libLTO.dylib"

2015-09-30 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Wed Sep 30 15:11:02 2015
New Revision: 248935

URL: http://llvm.org/viewvc/llvm-project?rev=248935=rev
Log:
Revert "[DarwinDriver] Use -lto_library to specify the path for libLTO.dylib"

Revert r248932. Bots complaining about new warnings where they shouldn't.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/darwin-ld.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=248935=248934=248935=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Wed Sep 30 15:11:02 
2015
@@ -117,7 +117,6 @@ def err_drv_optimization_remark_pattern
 def err_drv_no_neon_modifier : Error<"[no]neon is not accepted as modifier, 
please use [no]simd instead">;
 
 def warn_O4_is_O3 : Warning<"-O4 is equivalent to -O3">, InGroup;
-def warn_lto_libpath : Warning<"libLTO.dylib relative to clang installed dir 
not found; using 'ld' default search path instead">;
 def warn_drv_optimization_value : Warning<"optimization level '%0' is not 
supported; using '%1%2' instead">,
   InGroup;
 def warn_ignored_gcc_optimization : Warning<"optimization flag '%0' is not 
supported">,

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=248935=248934=248935=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Sep 30 15:11:02 2015
@@ -6551,34 +6551,15 @@ void darwin::Linker::AddLinkArgs(Compila
options::OPT_fno_application_extension, false))
 CmdArgs.push_back("-application_extension");
 
-  if (D.IsUsingLTO(Args)) {
-// If we are using LTO, then automatically create a temporary file path for
-// the linker to use, so that it's lifetime will extend past a possible
-// dsymutil step.
-if (Version[0] >= 116 && NeedsTempPath(Inputs)) {
-  const char *TmpPath = C.getArgs().MakeArgString(
-  D.GetTemporaryPath("cc", 
types::getTypeTempSuffix(types::TY_Object)));
-  C.addTempFile(TmpPath);
-  CmdArgs.push_back("-object_path_lto");
-  CmdArgs.push_back(TmpPath);
-}
-
-// Use -lto_library option to specify the libLTO.dylib path. Try to find
-// it in clang installed libraries. If not found, the option is not used
-// and 'ld' will use its default mechanism to search for libLTO.dylib.
-if (Version[0] >= 133) {
-  // Search for libLTO in /../lib/libLTO.dylib
-  StringRef P = llvm::sys::path::parent_path(D.getInstalledDir());
-  SmallString<128> LibLTOPath(P);
-  llvm::sys::path::append(LibLTOPath, "lib");
-  llvm::sys::path::append(LibLTOPath, "libLTO.dylib");
-  if (llvm::sys::fs::exists(LibLTOPath)) {
-CmdArgs.push_back("-lto_library");
-CmdArgs.push_back(C.getArgs().MakeArgString(LibLTOPath));
-  } else {
-D.Diag(diag::warn_lto_libpath);
-  }
-}
+  // If we are using LTO, then automatically create a temporary file path for
+  // the linker to use, so that it's lifetime will extend past a possible
+  // dsymutil step.
+  if (Version[0] >= 116 && D.IsUsingLTO(Args) && NeedsTempPath(Inputs)) {
+const char *TmpPath = C.getArgs().MakeArgString(
+D.GetTemporaryPath("cc", types::getTypeTempSuffix(types::TY_Object)));
+C.addTempFile(TmpPath);
+CmdArgs.push_back("-object_path_lto");
+CmdArgs.push_back(TmpPath);
   }
 
   // Derived from the "link" spec.

Modified: cfe/trunk/test/Driver/darwin-ld.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-ld.c?rev=248935=248934=248935=diff
==
--- cfe/trunk/test/Driver/darwin-ld.c (original)
+++ cfe/trunk/test/Driver/darwin-ld.c Wed Sep 30 15:11:02 2015
@@ -110,21 +110,6 @@
 // LINK_OBJECT_LTO_PATH: {{ld(.exe)?"}}
 // LINK_OBJECT_LTO_PATH: "-object_path_lto"
 
-// RUN: %clang -target x86_64-apple-darwin10 -### %s \
-// RUN:   -mlinker-version=133 -flto 2> %t.log
-// RUN: cat %t.log
-// RUN: FileCheck -check-prefix=LINK_LTOLIB_PATH %s < %t.log
-//
-// LINK_LTOLIB_PATH: {{ld(.exe)?"}}
-// LINK_LTOLIB_PATH: "-lto_library"
-
-// RUN: %clang -target x86_64-apple-darwin10 -### %s \
-// RUN:   -ccc-install-dir %S/dummytestdir -mlinker-version=133 -flto 2> %t.log
-// RUN: cat %t.log
-// RUN: FileCheck -check-prefix=LINK_LTOLIB_PATH_WRN %s < %t.log
-//
-// LINK_LTOLIB_PATH_WRN: warning: libLTO.dylib relative to clang installed dir 
not found; using 'ld' default search path instead
-
 // RUN: %clang -target x86_64-apple-darwin10 -### %t.o \
 // RUN:   -force_load a -force_load b 2> %t.log
 // RUN: cat %t.log



r248932 - [DarwinDriver] Use -lto_library to specify the path for libLTO.dylib

2015-09-30 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Wed Sep 30 14:55:07 2015
New Revision: 248932

URL: http://llvm.org/viewvc/llvm-project?rev=248932=rev
Log:
[DarwinDriver] Use -lto_library to specify the path for libLTO.dylib

Usually, when using LTO with a clang installation newer than the
system's one, there's a libLTO.dylib version mismatch and LTO fails. One
solution to this is to make ld point to the right libLTO.dylib by
changing DYLD_LIBRARY_PATH.

However, ld64 supports specifying the complete path to the desired
libLTO.dylib through the -lto_library option. This commit adds support
for the clang driver to use this option whenever it's capable of finding
a libLTO.dylib in clang's installed library directory. This way, we
don't need to rely on DYLD_LIBRARY_PATH nor get caught by version
mismatches.

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

rdar://problem/7363476

Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/darwin-ld.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=248932=248931=248932=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Wed Sep 30 14:55:07 
2015
@@ -117,6 +117,7 @@ def err_drv_optimization_remark_pattern
 def err_drv_no_neon_modifier : Error<"[no]neon is not accepted as modifier, 
please use [no]simd instead">;
 
 def warn_O4_is_O3 : Warning<"-O4 is equivalent to -O3">, InGroup;
+def warn_lto_libpath : Warning<"libLTO.dylib relative to clang installed dir 
not found; using 'ld' default search path instead">;
 def warn_drv_optimization_value : Warning<"optimization level '%0' is not 
supported; using '%1%2' instead">,
   InGroup;
 def warn_ignored_gcc_optimization : Warning<"optimization flag '%0' is not 
supported">,

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=248932=248931=248932=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Sep 30 14:55:07 2015
@@ -6551,15 +6551,34 @@ void darwin::Linker::AddLinkArgs(Compila
options::OPT_fno_application_extension, false))
 CmdArgs.push_back("-application_extension");
 
-  // If we are using LTO, then automatically create a temporary file path for
-  // the linker to use, so that it's lifetime will extend past a possible
-  // dsymutil step.
-  if (Version[0] >= 116 && D.IsUsingLTO(Args) && NeedsTempPath(Inputs)) {
-const char *TmpPath = C.getArgs().MakeArgString(
-D.GetTemporaryPath("cc", types::getTypeTempSuffix(types::TY_Object)));
-C.addTempFile(TmpPath);
-CmdArgs.push_back("-object_path_lto");
-CmdArgs.push_back(TmpPath);
+  if (D.IsUsingLTO(Args)) {
+// If we are using LTO, then automatically create a temporary file path for
+// the linker to use, so that it's lifetime will extend past a possible
+// dsymutil step.
+if (Version[0] >= 116 && NeedsTempPath(Inputs)) {
+  const char *TmpPath = C.getArgs().MakeArgString(
+  D.GetTemporaryPath("cc", 
types::getTypeTempSuffix(types::TY_Object)));
+  C.addTempFile(TmpPath);
+  CmdArgs.push_back("-object_path_lto");
+  CmdArgs.push_back(TmpPath);
+}
+
+// Use -lto_library option to specify the libLTO.dylib path. Try to find
+// it in clang installed libraries. If not found, the option is not used
+// and 'ld' will use its default mechanism to search for libLTO.dylib.
+if (Version[0] >= 133) {
+  // Search for libLTO in /../lib/libLTO.dylib
+  StringRef P = llvm::sys::path::parent_path(D.getInstalledDir());
+  SmallString<128> LibLTOPath(P);
+  llvm::sys::path::append(LibLTOPath, "lib");
+  llvm::sys::path::append(LibLTOPath, "libLTO.dylib");
+  if (llvm::sys::fs::exists(LibLTOPath)) {
+CmdArgs.push_back("-lto_library");
+CmdArgs.push_back(C.getArgs().MakeArgString(LibLTOPath));
+  } else {
+D.Diag(diag::warn_lto_libpath);
+  }
+}
   }
 
   // Derived from the "link" spec.

Modified: cfe/trunk/test/Driver/darwin-ld.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-ld.c?rev=248932=248931=248932=diff
==
--- cfe/trunk/test/Driver/darwin-ld.c (original)
+++ cfe/trunk/test/Driver/darwin-ld.c Wed Sep 30 14:55:07 2015
@@ -110,6 +110,21 @@
 // LINK_OBJECT_LTO_PATH: {{ld(.exe)?"}}
 // LINK_OBJECT_LTO_PATH: "-object_path_lto"
 
+// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// RUN:   -mlinker-version=133 -flto 2> %t.log
+// RUN: cat %t.log
+// RUN: FileCheck -check-prefix=LINK_LTOLIB_PATH %s < %t.log

LLVM buildnaster will be restarted tonight

2015-09-30 Thread Galina Kistanova via cfe-commits
Hello everyone,

LLVM buildmaster will be restarted after 6 PM Pacific time today.

Thanks

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


Re: [PATCH] D12761: MPI-Checker patch for Clang Static Analyzer

2015-09-30 Thread Anna Zaks via cfe-commits
zaks.anna added inline comments.


Comment at: tools/clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPITypes.h:67
@@ +66,3 @@
+  // Every time a request is 'set' a new 'RequestId' gets created.
+  // Therefore, the 'UserKind' does not need to be profiled.
+  const int RequestId{RequestIdCount++};

Alexander_Droste wrote:
> zaks.anna wrote:
> > Still it looks like you have several pieces of information in the state 
> > that are redundant.. Looks like you've added more now.
> > 
> > For example, why do we need RequestId? Each report will only talk about a 
> > single request, is this not the case?
> > 
> > Do you absolutely need to store LastUser and VariableName?
> > 
> > Note that storing in the state is very expensive; on the other hand, we can 
> > afford to perform costly analysis on post-processing of an error report. 
> > This is why all other checkers store minimal information in the state, 
> > usually just a single enum and determine all the other information during 
> > the walk over the error path in BugReporterVisitor. The visitor will visit 
> > all nodes that you visited while reporting this bug, so it should have 
> > access to all the information you need.
> > 
> I need the RequestID to distinct function calls of the same type 
> and location using the request multiple times along the path.
> Like in a loop:
> ```
> for int i ...
>nonblocking(.., request) // double nonblocking
> ```
> 
> > Do you absolutely need to store LastUser and VariableName?
> Absolutely not. :D I will remove the string member.
> The variable name retrieval can be delayed to the point where the report is 
> created.
> 
> I can also remove the enum, as the state of the request can be derived from 
> the LastUser.
> The reason why I added the enum member, is that I was concerned about that 
> the CallEventRef
> can be invalid to reference again if the call is inlined from an 
> implementation defined in a header. 
> As this seems not to be the case, I can remove the redundancy.
> 
> > This is why all other checkers store minimal information in the state, 
> > usually just a single enum and determine all the other information during 
> > the walk over the error path in BugReporterVisitor.
> 
> Ah, I get it. Until now that seemed a bit overly complicated to me.
I suspect the only thing you need in Request is the enum; everything else can 
be determined while visiting the path. 

This should be in ento namespace not in the clang namespace.


http://reviews.llvm.org/D12761



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


Re: [PATCH] D12979: Avoid inlining in exception handling context

2015-09-30 Thread Jun Bum Lim via cfe-commits
junbuml abandoned this revision.
junbuml added a comment.

Move this clang  change  in  http://reviews.llvm.org/D13304


http://reviews.llvm.org/D12979



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


Re: r248932 - [DarwinDriver] Use -lto_library to specify the path for libLTO.dylib

2015-09-30 Thread Rafael Espíndola via cfe-commits
Nice!

On 30 September 2015 at 15:55, Bruno Cardoso Lopes via cfe-commits
 wrote:
> Author: bruno
> Date: Wed Sep 30 14:55:07 2015
> New Revision: 248932
>
> URL: http://llvm.org/viewvc/llvm-project?rev=248932=rev
> Log:
> [DarwinDriver] Use -lto_library to specify the path for libLTO.dylib
>
> Usually, when using LTO with a clang installation newer than the
> system's one, there's a libLTO.dylib version mismatch and LTO fails. One
> solution to this is to make ld point to the right libLTO.dylib by
> changing DYLD_LIBRARY_PATH.
>
> However, ld64 supports specifying the complete path to the desired
> libLTO.dylib through the -lto_library option. This commit adds support
> for the clang driver to use this option whenever it's capable of finding
> a libLTO.dylib in clang's installed library directory. This way, we
> don't need to rely on DYLD_LIBRARY_PATH nor get caught by version
> mismatches.
>
> Differential Revision: http://reviews.llvm.org/D13117
>
> rdar://problem/7363476
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
> cfe/trunk/lib/Driver/Tools.cpp
> cfe/trunk/test/Driver/darwin-ld.c
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=248932=248931=248932=diff
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Wed Sep 30 
> 14:55:07 2015
> @@ -117,6 +117,7 @@ def err_drv_optimization_remark_pattern
>  def err_drv_no_neon_modifier : Error<"[no]neon is not accepted as modifier, 
> please use [no]simd instead">;
>
>  def warn_O4_is_O3 : Warning<"-O4 is equivalent to -O3">, InGroup;
> +def warn_lto_libpath : Warning<"libLTO.dylib relative to clang installed dir 
> not found; using 'ld' default search path instead">;
>  def warn_drv_optimization_value : Warning<"optimization level '%0' is not 
> supported; using '%1%2' instead">,
>InGroup;
>  def warn_ignored_gcc_optimization : Warning<"optimization flag '%0' is not 
> supported">,
>
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=248932=248931=248932=diff
> ==
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Wed Sep 30 14:55:07 2015
> @@ -6551,15 +6551,34 @@ void darwin::Linker::AddLinkArgs(Compila
> options::OPT_fno_application_extension, false))
>  CmdArgs.push_back("-application_extension");
>
> -  // If we are using LTO, then automatically create a temporary file path for
> -  // the linker to use, so that it's lifetime will extend past a possible
> -  // dsymutil step.
> -  if (Version[0] >= 116 && D.IsUsingLTO(Args) && NeedsTempPath(Inputs)) {
> -const char *TmpPath = C.getArgs().MakeArgString(
> -D.GetTemporaryPath("cc", 
> types::getTypeTempSuffix(types::TY_Object)));
> -C.addTempFile(TmpPath);
> -CmdArgs.push_back("-object_path_lto");
> -CmdArgs.push_back(TmpPath);
> +  if (D.IsUsingLTO(Args)) {
> +// If we are using LTO, then automatically create a temporary file path 
> for
> +// the linker to use, so that it's lifetime will extend past a possible
> +// dsymutil step.
> +if (Version[0] >= 116 && NeedsTempPath(Inputs)) {
> +  const char *TmpPath = C.getArgs().MakeArgString(
> +  D.GetTemporaryPath("cc", 
> types::getTypeTempSuffix(types::TY_Object)));
> +  C.addTempFile(TmpPath);
> +  CmdArgs.push_back("-object_path_lto");
> +  CmdArgs.push_back(TmpPath);
> +}
> +
> +// Use -lto_library option to specify the libLTO.dylib path. Try to find
> +// it in clang installed libraries. If not found, the option is not used
> +// and 'ld' will use its default mechanism to search for libLTO.dylib.
> +if (Version[0] >= 133) {
> +  // Search for libLTO in /../lib/libLTO.dylib
> +  StringRef P = llvm::sys::path::parent_path(D.getInstalledDir());
> +  SmallString<128> LibLTOPath(P);
> +  llvm::sys::path::append(LibLTOPath, "lib");
> +  llvm::sys::path::append(LibLTOPath, "libLTO.dylib");
> +  if (llvm::sys::fs::exists(LibLTOPath)) {
> +CmdArgs.push_back("-lto_library");
> +CmdArgs.push_back(C.getArgs().MakeArgString(LibLTOPath));
> +  } else {
> +D.Diag(diag::warn_lto_libpath);
> +  }
> +}
>}
>
>// Derived from the "link" spec.
>
> Modified: cfe/trunk/test/Driver/darwin-ld.c
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-ld.c?rev=248932=248931=248932=diff
> ==
> --- cfe/trunk/test/Driver/darwin-ld.c (original)
> +++ cfe/trunk/test/Driver/darwin-ld.c Wed 

r248949 - Don't inherit availability information when implementing a protocol requirement.

2015-09-30 Thread Douglas Gregor via cfe-commits
Author: dgregor
Date: Wed Sep 30 16:27:42 2015
New Revision: 248949

URL: http://llvm.org/viewvc/llvm-project?rev=248949=rev
Log:
Don't inherit availability information when implementing a protocol requirement.

When an Objective-C method implements a protocol requirement, do not
inherit any availability information from the protocol
requirement. Rather, check that the implementation is not less
available than the protocol requirement, as we do when overriding a
method that has availability. Fixes rdar://problem/22734745.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/ARCMT/checking.m
cfe/trunk/test/SemaObjC/attr-availability.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=248949=248948=248949=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 30 16:27:42 
2015
@@ -2410,15 +2410,19 @@ def warn_availability_version_ordering :
 def warn_mismatched_availability: Warning<
   "availability does not match previous declaration">, InGroup;
 def warn_mismatched_availability_override : Warning<
-  "overriding method %select{introduced after|"
-  "deprecated before|obsoleted before}0 overridden method on %1 (%2 vs. %3)">, 
-  InGroup;
+  "%select{|overriding }4method %select{introduced after|"
+  "deprecated before|obsoleted before}0 "
+  "%select{the protocol method it implements|overridden method}4 "
+  "on %1 (%2 vs. %3)">, InGroup;
 def warn_mismatched_availability_override_unavail : Warning<
-  "overriding method cannot be unavailable on %0 when its overridden method is 
"
+  "%select{|overriding }1method cannot be unavailable on %0 when "
+  "%select{the protocol method it implements|its overridden method}1 is "
   "available">,
   InGroup;
 def note_overridden_method : Note<
   "overridden method is here">;
+def note_protocol_method : Note<
+  "protocol method is here">;
 
 // Thread Safety Attributes
 def warn_invalid_capability_name : Warning<

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=248949=248948=248949=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Sep 30 16:27:42 2015
@@ -2062,6 +2062,22 @@ public:
 TypeSourceInfo *TInfo);
   bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New);
 
+  /// \brief Describes the kind of merge to perform for availability
+  /// attributes (including "deprecated", "unavailable", and "availability").
+  enum AvailabilityMergeKind {
+/// \brief Don't merge availability attributes at all.
+AMK_None,
+/// \brief Merge availability attributes for a redeclaration, which 
requires
+/// an exact match.
+AMK_Redeclaration,
+/// \brief Merge availability attributes for an override, which requires
+/// an exact match or a weakening of constraints.
+AMK_Override,
+/// \brief Merge availability attributes for an implementation of
+/// a protocol requirement.
+AMK_ProtocolImplementation,
+  };
+
   /// Attribute merging methods. Return true if a new attribute was added.
   AvailabilityAttr *mergeAvailabilityAttr(NamedDecl *D, SourceRange Range,
   IdentifierInfo *Platform,
@@ -2070,7 +2086,7 @@ public:
   VersionTuple Obsoleted,
   bool IsUnavailable,
   StringRef Message,
-  bool Override,
+  AvailabilityMergeKind AMK,
   unsigned AttrSpellingListIndex);
   TypeVisibilityAttr *mergeTypeVisibilityAttr(Decl *D, SourceRange Range,
TypeVisibilityAttr::VisibilityType Vis,
@@ -2099,19 +2115,6 @@ public:
   OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, SourceRange Range,
   unsigned AttrSpellingListIndex);
 
-  /// \brief Describes the kind of merge to perform for availability
-  /// attributes (including "deprecated", "unavailable", and "availability").
-  enum AvailabilityMergeKind {
-/// \brief Don't merge availability attributes at all.
-AMK_None,
-/// \brief Merge availability attributes for a redeclaration, which 
requires
-/// an exact match.
-AMK_Redeclaration,
-/// \brief Merge availability attributes for an override, which requires
-/// an exact match or a weakening 

[PATCH] D13304: Avoid inlining in throw statement

2015-09-30 Thread Jun Bum Lim via cfe-commits
junbuml created this revision.
junbuml added reviewers: hfinkel, mcrosier, reames, ashutosh.nema, majnemer.
junbuml added subscribers: gberry, cfe-commits.

It might be reasonably to avoid inlining CallSites invoked in
exception handling context so that we can reduce code size blow-up in
EH regions as well as indirectly increase inline opportunites for unwinding
functions containing exception handling code.

In this change, the NoInline attribute is added in CallSites
invoked specifically by the throw statement.

http://reviews.llvm.org/D13304

Files:
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGException.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGenCXX/throw-expressions.cpp

Index: test/CodeGenCXX/throw-expressions.cpp
===
--- test/CodeGenCXX/throw-expressions.cpp
+++ test/CodeGenCXX/throw-expressions.cpp
@@ -112,3 +112,14 @@
   // CHECK: ret i32* @val
   return cond ? val : ((throw "foo"));
 }
+
+// CHECK-LABEL: _Z5test9v
+// CHECK: invoke void @_ZN2EHC1Ev(%class.EH* %0) [[ATTR_NUM:#[0-9]+]]
+// CHECK: attributes [[ATTR_NUM]] = { cold noinline }
+class EH {
+public :
+  EH();
+};
+void test9() {
+  throw EH();
+}
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -283,6 +283,11 @@
   /// finally block or filter expression.
   bool IsOutlinedSEHHelper;
 
+  // True if the current insertion point is in cold regions (e.g., exception
+  // handling regions). As of now, this flag is ture only when handling throw
+  // statement.
+  bool IsColdRegion;
+
   const CodeGen::CGBlockInfo *BlockInfo;
   llvm::Value *BlockPointer;
 
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -44,7 +44,7 @@
   CapturedStmtInfo(nullptr),
   SanOpts(CGM.getLangOpts().Sanitize), IsSanitizerScope(false),
   CurFuncIsThunk(false), AutoreleaseResult(false), SawAsmBlock(false),
-  IsOutlinedSEHHelper(false),
+  IsOutlinedSEHHelper(false), IsColdRegion(false),
   BlockInfo(nullptr), BlockPointer(nullptr),
   LambdaThisCaptureField(nullptr), NormalCleanupDest(nullptr),
   NextCleanupDestIndex(1), FirstBlockInfo(nullptr), EHResumeBlock(nullptr),
Index: lib/CodeGen/CGException.cpp
===
--- lib/CodeGen/CGException.cpp
+++ lib/CodeGen/CGException.cpp
@@ -400,6 +400,11 @@
 
 void CodeGenFunction::EmitCXXThrowExpr(const CXXThrowExpr *E,
bool KeepInsertionPoint) {
+  // While handling the throw statement, inform that the insertion point is in
+  // cold regions so that we could perform cold region specific IR generation.
+  // For example, the NoInline attribute could be added in CallSites in throw
+  // statements.
+  IsColdRegion = true;
   if (const Expr *SubExpr = E->getSubExpr()) {
 QualType ThrowType = SubExpr->getType();
 if (ThrowType->isObjCObjectPointerType()) {
@@ -417,6 +422,9 @@
   // to leave ourselves at a valid insertion point.
   if (KeepInsertionPoint)
 EmitBlock(createBasicBlock("throw.cont"));
+
+  IsColdRegion = false;
+  // FIXME: Similarly, we could set IsColdRegion for catch blocks in ExitCXXTryStmt().
 }
 
 void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -3464,6 +3464,27 @@
 Attrs.addAttribute(getLLVMContext(), llvm::AttributeSet::FunctionIndex,
llvm::Attribute::NoInline);
 
+  // As of now, IsColdRegion is true only while handling throw statements.
+  // It might be reasonable to avoid inlining CallSites invoked in exception
+  // handling context so that we can reduce code size blow-up in EH regions
+  // as well as indirectly increase inline opportunities for unwinding
+  // functions containing exception handling code.
+  if (IsColdRegion) {
+// FIXME: We add both NoInline and Cold because the inline cold-threshold
+// is not tuned yet (r200898). As of now, considering that CallSites in
+// exception handling regions are very cold is not unreasonable even without
+// profiling, and avoiding inlining in exception handling region may not have
+// significant impacts on performance unless a program execution logic
+// really depends on exception handling flows. However, when the inline
+// cold-threshold is tuned, we may need to remove NoInline here so that we
+// can allow a trivial constructor to be inlined.
+Attrs =
+Attrs.addAttribute(getLLVMContext(), llvm::AttributeSet::FunctionIndex,
+   llvm::Attribute::NoInline);
+Attrs =
+

Re: [PATCH] D11908: Clang support for -fthinlto.

2015-09-30 Thread Duncan P. N. Exon Smith via cfe-commits
+echristo, +espindola, +pcc

> On 2015-Sep-30, at 12:39, Teresa Johnson  wrote:
> 
> On Wed, Sep 30, 2015 at 11:11 AM, Duncan P. N. Exon Smith
>  wrote:
>> 
>>> On 2015-Sep-30, at 10:40, Teresa Johnson  wrote:
>>> 
>>> On Wed, Sep 30, 2015 at 10:19 AM, Duncan P. N. Exon Smith
>>>  wrote:
 
> On 2015-Sep-23, at 10:28, Teresa Johnson  wrote:
> 
> Index: include/clang/Driver/Options.td
> ===
> --- include/clang/Driver/Options.td
> +++ include/clang/Driver/Options.td
> @@ -686,6 +686,9 @@
> def flto_EQ : Joined<["-"], "flto=">, 
> Group;
> def flto : Flag<["-"], "flto">, Flags<[CC1Option]>, Group;
> def fno_lto : Flag<["-"], "fno-lto">, Group;
> +def fthinlto : Flag<["-"], "fthinlto">, Flags<[CC1Option]>, 
> Group;
 
 I wonder whether this is the right way to add new variants of LTO.
 I.e., maybe this should be "-flto=thin"?  Do you happen to know how this
 would conflict with GCC options?  (I see we ignore "-flto="...)
>>> 
>>> I looked at GCC docs and sources. It does have a -flto= variant. From
>>> https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html:
>>> -
>>> If you specify the optional n, the optimization and code generation
>>> done at link time is executed in parallel using n parallel jobs by
>>> utilizing an installed make program. The environment variable MAKE may
>>> be used to override the program used. The default value for n is 1.
>>> 
>>> You can also specify -flto=jobserver to use GNU make's job server mode
>>> to determine the number of parallel jobs. This is useful when the
>>> Makefile calling GCC is already executing in parallel. You must
>>> prepend a ‘+’ to the command recipe in the parent Makefile for this to
>>> work. This option likely only works if MAKE is GNU make.
>>> 
>>> 
>>> I would anticipate that we may want to support something like this for
>>> ThinLTO eventually to specify the number of parallel jobs for the
>>> ThinLTO backend processes. So it might be confusing to overload
>>> -flto=.
>> 
>> Hmm.  You're right that the GCC usage seems pretty different.
>> 
>> I guess you're envisioning -fthinlto=jobserver?
> 
> Or -fthinlto=n.
> 
>> I wonder if we could
>> do this as -flto=thin,jobserver or something similar?
> 
> I am ok with -flto=thin and then later extending to -flto=thin,n etc.
> 
> This simplifies the interaction with -fno-lto.
> 
> I think a -flto=thin followed by -flto should probably revert to
> normal LTO, WDYT?
> 
> Another thing to consider is to add -flto=full or something like that
> which is currently an alias for -flto. So we would have:
> 
> -flto= where type could be "full" or "thin"
> -flto means -flto=full
> -fno-lto disables all types of flto
> and last option of the above 3 wins.

This SGTM.  "monolithic" might be more descriptive than "full", or
maybe someone has a better name.

Eric/Rafael/Peter: any thoughts about driver options?

>> 
>> It's pretty hard to remove driver options, so I think it's important to
>> get the interface right.  I anticipate that we'll add more LTO variants
>> in the future, so we should take care that this scales reasonably.
>> 
>> (This may be a good discussion for cfe-dev, not sure.)
>> 
 E.g., as a user I'd expect -fno-lto to turn off whatever LTO was turned
 on.  And I might expect -flto to override -fthinlto, or vice versa.
>>> 
>>> Good point, I think the last one should win. Looks like right now
>>> -fthinlto is effectively always winning. I will fix that.
>>> 
>>> Not sure about -fno-lto behavior if we leave -fthinlto as a separate
>>> option. Let me know what you think based on the GCC usage of -flto=.
>> 
>> Right, if they're totally separate, then either behaviour for -fno-lto
>> is confusing.

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


Re: [PATCH] D12761: MPI-Checker patch for Clang Static Analyzer

2015-09-30 Thread Alexander Droste via cfe-commits
Alexander_Droste added a comment.

> We gave a talk about building checkers a while back; even though it does not 
> talk about the bug reporter visitors, it might be worth watching if you 
> haven't already seen it.


I have watched it some months ago but I'm sure it is a good idea to revisit the 
talk. Thanks for the idea!



Comment at: 
tools/clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPICheckerPathSensitive.cpp:68
@@ +67,3 @@
+  const CallEventRef<> CERef = PreCallEvent.cloneWithState(State);
+  const ExplodedNode *const ExplNode = Ctx.addTransition();
+  llvm::SmallVector ReqRegions;

zaks.anna wrote:
> There is no reason to add an empty transition to the graph. Maybe you want to 
> get the predecessor instead?
Yes, that's better!


Comment at: tools/clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPITypes.h:67
@@ +66,3 @@
+  // Every time a request is 'set' a new 'RequestId' gets created.
+  // Therefore, the 'UserKind' does not need to be profiled.
+  const int RequestId{RequestIdCount++};

zaks.anna wrote:
> Still it looks like you have several pieces of information in the state that 
> are redundant.. Looks like you've added more now.
> 
> For example, why do we need RequestId? Each report will only talk about a 
> single request, is this not the case?
> 
> Do you absolutely need to store LastUser and VariableName?
> 
> Note that storing in the state is very expensive; on the other hand, we can 
> afford to perform costly analysis on post-processing of an error report. This 
> is why all other checkers store minimal information in the state, usually 
> just a single enum and determine all the other information during the walk 
> over the error path in BugReporterVisitor. The visitor will visit all nodes 
> that you visited while reporting this bug, so it should have access to all 
> the information you need.
> 
I need the RequestID to distinct function calls of the same type 
and location using the request multiple times along the path.
Like in a loop:
```
for int i ...
   nonblocking(.., request) // double nonblocking
```

> Do you absolutely need to store LastUser and VariableName?
Absolutely not. :D I will remove the string member.
The variable name retrieval can be delayed to the point where the report is 
created.

I can also remove the enum, as the state of the request can be derived from the 
LastUser.
The reason why I added the enum member, is that I was concerned about that the 
CallEventRef
can be invalid to reference again if the call is inlined from an implementation 
defined in a header. 
As this seems not to be the case, I can remove the redundancy.

> This is why all other checkers store minimal information in the state, 
> usually just a single enum and determine all the other information during the 
> walk over the error path in BugReporterVisitor.

Ah, I get it. Until now that seemed a bit overly complicated to me.


http://reviews.llvm.org/D12761



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


r248891 - [OpenCL 2.0] Fix wrong atomic type detection in the diagnostics of allowed types

2015-09-30 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Wed Sep 30 06:48:15 2015
New Revision: 248891

URL: http://llvm.org/viewvc/llvm-project?rev=248891=rev
Log:
[OpenCL 2.0] Fix wrong atomic type detection in the diagnostics of allowed types

Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/Parser/opencl-atomics-cl20.cl

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=248891=248890=248891=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Sep 30 06:48:15 2015
@@ -1390,11 +1390,13 @@ static QualType ConvertDeclSpecToType(Ty
 if (Result.isNull()) {
   declarator.setInvalidType(true);
 } else if (S.getLangOpts().OpenCL) {
-  if (const AtomicType *AT = Result->getAs()) {
-const BuiltinType *BT = AT->getValueType()->getAs();
-bool NoExtTypes = BT && (BT->getKind() == BuiltinType::Int ||
- BT->getKind() == BuiltinType::UInt ||
- BT->getKind() == BuiltinType::Float);
+  if (Result->getAs()) {
+StringRef TypeName = Result.getBaseTypeIdentifier()->getName();
+bool NoExtTypes =
+llvm::StringSwitch(TypeName)
+.Cases("atomic_int", "atomic_uint", "atomic_float",
+   "atomic_flag", true)
+.Default(false);
 if (!S.getOpenCLOptions().cl_khr_int64_base_atomics && !NoExtTypes) {
   S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension)
   << Result << "cl_khr_int64_base_atomics";
@@ -1406,8 +1408,8 @@ static QualType ConvertDeclSpecToType(Ty
   << Result << "cl_khr_int64_extended_atomics";
   declarator.setInvalidType(true);
 }
-if (!S.getOpenCLOptions().cl_khr_fp64 && BT &&
-BT->getKind() == BuiltinType::Double) {
+if (!S.getOpenCLOptions().cl_khr_fp64 &&
+!TypeName.compare("atomic_double")) {
   S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension)
   << Result << "cl_khr_fp64";
   declarator.setInvalidType(true);

Modified: cfe/trunk/test/Parser/opencl-atomics-cl20.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/opencl-atomics-cl20.cl?rev=248891=248890=248891=diff
==
--- cfe/trunk/test/Parser/opencl-atomics-cl20.cl (original)
+++ cfe/trunk/test/Parser/opencl-atomics-cl20.cl Wed Sep 30 06:48:15 2015
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 %s -triple x86_64-unknown-unknown -verify -pedantic 
-fsyntax-only
-// RUN: %clang_cc1 %s -triple x86_64-unknown-unknown -verify  -fsyntax-only 
-cl-std=CL2.0 -DCL20
-// RUN: %clang_cc1 %s -triple x86_64-unknown-unknown -verify  -fsyntax-only 
-cl-std=CL2.0 -DCL20 -DEXT
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -verify  -fsyntax-only -cl-std=CL2.0 -DCL20
+// RUN: %clang_cc1 %s -verify  -fsyntax-only -cl-std=CL2.0 -DCL20 -DEXT
 
 #ifdef EXT
 #pragma OPENCL EXTENSION cl_khr_int64_base_atomics:enable


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


r248880 - [OPENMP 4.1] Sema analysis for array sections in 'reduction' clause.

2015-09-30 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Sep 30 04:22:36 2015
New Revision: 248880

URL: http://llvm.org/viewvc/llvm-project?rev=248880=rev
Log:
[OPENMP 4.1] Sema analysis for array sections in 'reduction' clause.
OpenMP 4.1 allows to use array sections|subscript expressions in 'reduction' 
clauses. Added sema analysis, updated tests.

Modified:
cfe/trunk/include/clang/AST/ExprOpenMP.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/for_reduction_messages.cpp
cfe/trunk/test/OpenMP/for_simd_reduction_messages.cpp
cfe/trunk/test/OpenMP/parallel_ast_print.cpp
cfe/trunk/test/OpenMP/parallel_for_reduction_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_reduction_messages.cpp
cfe/trunk/test/OpenMP/parallel_reduction_messages.cpp
cfe/trunk/test/OpenMP/parallel_sections_reduction_messages.cpp
cfe/trunk/test/OpenMP/sections_reduction_messages.cpp
cfe/trunk/test/OpenMP/simd_reduction_messages.cpp
cfe/trunk/test/OpenMP/teams_reduction_messages.cpp

Modified: cfe/trunk/include/clang/AST/ExprOpenMP.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprOpenMP.h?rev=248880=248879=248880=diff
==
--- cfe/trunk/include/clang/AST/ExprOpenMP.h (original)
+++ cfe/trunk/include/clang/AST/ExprOpenMP.h Wed Sep 30 04:22:36 2015
@@ -84,6 +84,9 @@ public:
   /// \brief Set base of the array section.
   void setBase(Expr *E) { SubExprs[BASE] = E; }
 
+  /// \brief Return original type of the base expression for array section.
+  static QualType getBaseOriginalType(Expr *Base);
+
   /// \brief Get lower bound of array section.
   Expr *getLowerBound() { return cast_or_null(SubExprs[LOWER_BOUND]); }
   const Expr *getLowerBound() const {

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=248880=248879=248880=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 30 04:22:36 
2015
@@ -7508,7 +7508,7 @@ def err_omp_firstprivate_incomplete_type
 def err_omp_lastprivate_incomplete_type : Error<
   "a lastprivate variable with incomplete type %0">;
 def err_omp_reduction_incomplete_type : Error<
-  "a reduction variable with incomplete type %0">;
+  "a reduction list item with incomplete type %0">;
 def err_omp_unexpected_clause_value : Error<
   "expected %0 in OpenMP clause '%1'">;
 def err_omp_expected_var_name : Error<
@@ -7565,6 +7565,8 @@ def err_omp_required_access : Error<
   "%0 variable must be %1">;
 def err_omp_const_variable : Error<
   "const-qualified variable cannot be %0">;
+def err_omp_const_reduction_list_item : Error<
+  "const-qualified list item cannot be reduction">;
 def err_omp_linear_incomplete_type : Error<
   "a linear variable with incomplete type %0">;
 def err_omp_linear_expected_int_or_ptr : Error<
@@ -7616,7 +7618,7 @@ def warn_omp_loop_64_bit_var : Warning<
 def err_omp_unknown_reduction_identifier : Error<
   "incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', 
'^', '&&', '||', 'min' or 'max'">;
 def err_omp_reduction_type_array : Error<
-  "a reduction variable with array type %0">;
+  "a reduction list item with array type %0">;
 def err_omp_reduction_ref_type_arg : Error<
   "argument of OpenMP clause 'reduction' must reference the same object in all 
threads">;
 def err_omp_clause_not_arithmetic_type_arg : Error<
@@ -7630,7 +7632,7 @@ def note_omp_referenced : Note<
 def err_omp_reduction_in_task : Error<
   "reduction variables may not be accessed in an explicit task">;
 def err_omp_reduction_id_not_compatible : Error<
-  "variable of type %0 is not valid for specified reduction operation: unable 
to provide default initialization value">;
+  "list item of type %0 is not valid for specified reduction operation: unable 
to provide default initialization value">;
 def err_omp_prohibited_region : Error<
   "region cannot be%select{| closely}0 nested inside '%1' region"
   "%select{|; perhaps you forget to enclose 'omp %3' directive into a parallel 
region?|"
@@ -7738,6 +7740,8 @@ def err_omp_ordered_directive_with_param
   "'ordered' directive %select{without any clauses|with 'threads' clause}0 
cannot be closely nested inside ordered region with specified parameter">;
 def note_omp_ordered_param : Note<
   "'ordered' clause with specified parameter">;
+def err_omp_expected_array_sect_reduction_lb_not_zero : Error<
+  "lower bound expected to be evaluated to zero">;
 } // end of OpenMP category
 
 let CategoryName = "Related Result Type Issue" in {

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 

Re: [PATCH] D13127: [ARM] Upgrade codegen for vld[234] and vst[234] to to communicate a 0 address space

2015-09-30 Thread silviu.bara...@arm.com via cfe-commits
sbaranga accepted this revision.
sbaranga added a comment.
This revision is now accepted and ready to land.

LGTM


http://reviews.llvm.org/D13127



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


[Patch][OpenCL] Custom atomic Builtin check ignores address space of a non-atomic pointer

2015-09-30 Thread Anastasia Stulova via cfe-commits
Hi all,

 

Address spaces are not handled in custom semantic checks of atomic Builtins.

 

If there are two pointers passed to the Builtin, it doesn't allow the second

(non-atomic) one to be qualified with an address space. 

 

This patch removed this restriction by recording the address space of the

passed pointers while checking its type correctness.

 

Currently, the following code:

 

_Atomic int __attribute__((address_space(1))) *A;

int __attribute__((address_space(2))) *B;

...

... = __c11_atomic_compare_exchange_strong(A, B, 1, memory_order_seq_cst,
memory_order_seq_cst);

 

fails to compile with an error: 

 

"passing '__attribute__((address_space(2))) int *' to parameter of type 'int
*' changes address space of pointer".

 

Please, review the attached fix for it!

 

Cheers,

Anastasia



atom-builtin-addrspace.patch
Description: Binary data
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13127: [ARM] Upgrade codegen for vld[234] and vst[234] to to communicate a 0 address space

2015-09-30 Thread Jeroen Ketema via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL24: [ARM][NEON] Use address space in 
vld([1234]|[234]lane) and vst([1234]|… (authored by jketema).

Changed prior to commit:
  http://reviews.llvm.org/D13127?vs=35871=36082#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D13127

Files:
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/test/CodeGen/arm-neon-misc.c
  cfe/trunk/test/CodeGen/arm-vector-align.c
  cfe/trunk/test/CodeGen/vld_dup.c

Index: cfe/trunk/test/CodeGen/vld_dup.c
===
--- cfe/trunk/test/CodeGen/vld_dup.c
+++ cfe/trunk/test/CodeGen/vld_dup.c
@@ -14,7 +14,7 @@
 int64_t v7[4];
 
 v1 = vld3_dup_s32(v0);
-// CHECK: [[T168:%.*]] = call { <2 x i32>, <2 x i32>, <2 x i32> } @llvm.arm.neon.vld3lane.v2i32(i8* {{.*}}, <2 x i32> undef, <2 x i32> undef, <2 x i32> undef, i32 {{[0-9]+}}, i32 {{[0-9]+}})
+// CHECK: [[T168:%.*]] = call { <2 x i32>, <2 x i32>, <2 x i32> } @llvm.arm.neon.vld3lane.v2i32.p0i8(i8* {{.*}}, <2 x i32> undef, <2 x i32> undef, <2 x i32> undef, i32 {{[0-9]+}}, i32 {{[0-9]+}})
 // CHECK-NEXT: [[T169:%.*]] = extractvalue { <2 x i32>, <2 x i32>, <2 x i32> } [[T168]], 0
 // CHECK-NEXT: [[T170:%.*]] = shufflevector <2 x i32> [[T169]], <2 x i32> [[T169]], <2 x i32> zeroinitializer
 // CHECK-NEXT: [[T171:%.*]] = insertvalue { <2 x i32>, <2 x i32>, <2 x i32> } [[T168]], <2 x i32> [[T170]], 0
@@ -26,7 +26,7 @@
 // CHECK-NEXT: [[T177:%.*]] = insertvalue { <2 x i32>, <2 x i32>, <2 x i32> } [[T174]], <2 x i32> [[T176]], 2
 
 v3 = vld4_dup_s32(v2);
-// CHECK: [[T178:%.*]] = call { <2 x i32>, <2 x i32>, <2 x i32>, <2 x i32> } @llvm.arm.neon.vld4lane.v2i32(i8* {{.*}}, <2 x i32> undef, <2 x i32> undef, <2 x i32> undef, <2 x i32> undef, i32 {{[0-9]+}}, i32 {{[0-9]+}})
+// CHECK: [[T178:%.*]] = call { <2 x i32>, <2 x i32>, <2 x i32>, <2 x i32> } @llvm.arm.neon.vld4lane.v2i32.p0i8(i8* {{.*}}, <2 x i32> undef, <2 x i32> undef, <2 x i32> undef, <2 x i32> undef, i32 {{[0-9]+}}, i32 {{[0-9]+}})
 // CHECK-NEXT: [[T179:%.*]] = extractvalue { <2 x i32>, <2 x i32>, <2 x i32>, <2 x i32> } [[T178]], 0
 // CHECK-NEXT: [[T180:%.*]] = shufflevector <2 x i32> [[T179]], <2 x i32> [[T179]], <2 x i32> zeroinitializer
 // CHECK-NEXT: [[T181:%.*]] = insertvalue { <2 x i32>, <2 x i32>, <2 x i32>, <2 x i32> } [[T178]], <2 x i32> [[T180]], 0
@@ -41,10 +41,10 @@
 // CHECK-NEXT: [[T190:%.*]] = insertvalue { <2 x i32>, <2 x i32>, <2 x i32>, <2 x i32> } [[T187]], <2 x i32> [[T189]], 3
 
 v4 = vld3_dup_s64(v6);
-// CHECK: {{%.*}} = call { <1 x i64>, <1 x i64>, <1 x i64> } @llvm.arm.neon.vld3.v1i64(i8* {{.*}}, i32 {{[0-9]+}})
+// CHECK: {{%.*}} = call { <1 x i64>, <1 x i64>, <1 x i64> } @llvm.arm.neon.vld3.v1i64.p0i8(i8* {{.*}}, i32 {{[0-9]+}})
 
 v5 = vld4_dup_s64(v7);
-// CHECK: {{%.*}} = call { <1 x i64>, <1 x i64>, <1 x i64>, <1 x i64> } @llvm.arm.neon.vld4.v1i64(i8* {{.*}}, i32 {{[0-9]+}})
+// CHECK: {{%.*}} = call { <1 x i64>, <1 x i64>, <1 x i64>, <1 x i64> } @llvm.arm.neon.vld4.v1i64.p0i8(i8* {{.*}}, i32 {{[0-9]+}})
 
 return 0;
 }
Index: cfe/trunk/test/CodeGen/arm-vector-align.c
===
--- cfe/trunk/test/CodeGen/arm-vector-align.c
+++ cfe/trunk/test/CodeGen/arm-vector-align.c
@@ -14,9 +14,9 @@
 typedef float AlignedAddr __attribute__ ((aligned (16)));
 void t1(AlignedAddr *addr1, AlignedAddr *addr2) {
 // CHECK: @t1
-// CHECK: call <4 x float> @llvm.arm.neon.vld1.v4f32(i8* %{{.*}}, i32 16)
+// CHECK: call <4 x float> @llvm.arm.neon.vld1.v4f32.p0i8(i8* %{{.*}}, i32 16)
   float32x4_t a = vld1q_f32(addr1);
-// CHECK: call void @llvm.arm.neon.vst1.v4f32(i8* %{{.*}}, <4 x float> %{{.*}}, i32 16)
+// CHECK: call void @llvm.arm.neon.vst1.p0i8.v4f32(i8* %{{.*}}, <4 x float> %{{.*}}, i32 16)
   vst1q_f32(addr2, a);
 }
 
Index: cfe/trunk/test/CodeGen/arm-neon-misc.c
===
--- cfe/trunk/test/CodeGen/arm-neon-misc.c
+++ cfe/trunk/test/CodeGen/arm-neon-misc.c
@@ -14,20 +14,20 @@
 void t1(uint64_t *src, uint8_t *dst) {
 // CHECK: @t1
   uint64x2_t q = vld1q_u64(src);
-// CHECK: call <2 x i64> @llvm.arm.neon.vld1.v2i64
+// CHECK: call <2 x i64> @llvm.arm.neon.vld1.v2i64.p0i8
   vst1q_lane_u64(dst, q, 1);
 // CHECK: bitcast <16 x i8> %{{.*}} to <2 x i64>
 // CHECK: shufflevector <2 x i64>
-// CHECK: call void @llvm.arm.neon.vst1.v1i64
+// CHECK: call void @llvm.arm.neon.vst1.p0i8.v1i64
 }
 
 void t2(uint64_t *src1, uint8_t *src2, uint64x2_t *dst) {
 // CHECK: @t2
 uint64x2_t q = vld1q_u64(src1);
-// CHECK: call <2 x i64> @llvm.arm.neon.vld1.v2i64
+// CHECK: call <2 x i64> @llvm.arm.neon.vld1.v2i64.p0i8
 q = vld1q_lane_u64(src2, q, 0);
 // CHECK: shufflevector <2 x i64>
-// CHECK: call <1 x i64> @llvm.arm.neon.vld1.v1i64
+// CHECK: call <1 x i64> @llvm.arm.neon.vld1.v1i64.p0i8
 // CHECK: shufflevector <1 x i64>
 *dst = q;
 // CHECK: store <2 x i64>
Index: 

r248888 - [ARM][NEON] Use address space in vld([1234]|[234]lane) and vst([1234]|[234]lane) instructions

2015-09-30 Thread Jeroen Ketema via cfe-commits
Author: jketema
Date: Wed Sep 30 05:56:56 2015
New Revision: 24

URL: http://llvm.org/viewvc/llvm-project?rev=24=rev
Log:
[ARM][NEON] Use address space in vld([1234]|[234]lane) and 
vst([1234]|[234]lane) instructions

This is the clang commit associated with llvm r248887.

This commit changes the interface of the vld[1234], vld[234]lane, and vst[1234],
vst[234]lane ARM neon intrinsics and associates an address space with the
pointer that these intrinsics take. This changes, e.g.,

<2 x i32> @llvm.arm.neon.vld1.v2i32(i8*, i32)

to

<2 x i32> @llvm.arm.neon.vld1.v2i32.p0i8(i8*, i32)

This change ensures that address spaces are fully taken into account in the ARM
target during lowering of interleaved loads and stores.

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


Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/arm-neon-misc.c
cfe/trunk/test/CodeGen/arm-vector-align.c
cfe/trunk/test/CodeGen/vld_dup.c

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=24=248887=24=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Sep 30 05:56:56 2015
@@ -2895,16 +2895,19 @@ Value *CodeGenFunction::EmitCommonNeonBu
 return Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0]});
   }
   case NEON::BI__builtin_neon_vld1_v:
-  case NEON::BI__builtin_neon_vld1q_v:
+  case NEON::BI__builtin_neon_vld1q_v: {
+llvm::Type *Tys[] = {Ty, Int8PtrTy};
 Ops.push_back(getAlignmentValue32(PtrOp0));
-return EmitNeonCall(CGM.getIntrinsic(LLVMIntrinsic, Ty), Ops, "vld1");
+return EmitNeonCall(CGM.getIntrinsic(LLVMIntrinsic, Tys), Ops, "vld1");
+  }
   case NEON::BI__builtin_neon_vld2_v:
   case NEON::BI__builtin_neon_vld2q_v:
   case NEON::BI__builtin_neon_vld3_v:
   case NEON::BI__builtin_neon_vld3q_v:
   case NEON::BI__builtin_neon_vld4_v:
   case NEON::BI__builtin_neon_vld4q_v: {
-Function *F = CGM.getIntrinsic(LLVMIntrinsic, Ty);
+llvm::Type *Tys[] = {Ty, Int8PtrTy};
+Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys);
 Value *Align = getAlignmentValue32(PtrOp1);
 Ops[1] = Builder.CreateCall(F, {Ops[1], Align}, NameHint);
 Ty = llvm::PointerType::getUnqual(Ops[1]->getType());
@@ -2927,7 +2930,8 @@ Value *CodeGenFunction::EmitCommonNeonBu
   case NEON::BI__builtin_neon_vld3q_lane_v:
   case NEON::BI__builtin_neon_vld4_lane_v:
   case NEON::BI__builtin_neon_vld4q_lane_v: {
-Function *F = CGM.getIntrinsic(LLVMIntrinsic, Ty);
+llvm::Type *Tys[] = {Ty, Int8PtrTy};
+Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys);
 for (unsigned I = 2; I < Ops.size() - 1; ++I)
   Ops[I] = Builder.CreateBitCast(Ops[I], Ty);
 Ops.push_back(getAlignmentValue32(PtrOp1));
@@ -3046,9 +3050,11 @@ Value *CodeGenFunction::EmitCommonNeonBu
   case NEON::BI__builtin_neon_vst3_lane_v:
   case NEON::BI__builtin_neon_vst3q_lane_v:
   case NEON::BI__builtin_neon_vst4_lane_v:
-  case NEON::BI__builtin_neon_vst4q_lane_v:
+  case NEON::BI__builtin_neon_vst4q_lane_v: {
+llvm::Type *Tys[] = {Int8PtrTy, Ty};
 Ops.push_back(getAlignmentValue32(PtrOp0));
-return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "");
+return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "");
+  }
   case NEON::BI__builtin_neon_vsubhn_v: {
 llvm::VectorType *SrcTy =
 llvm::VectorType::getExtendedElementVectorType(VTy);
@@ -3776,7 +3782,8 @@ Value *CodeGenFunction::EmitARMBuiltinEx
   Ops[1] = Builder.CreateShuffleVector(Ops[1], Ops[1], SV);
   // Load the value as a one-element vector.
   Ty = llvm::VectorType::get(VTy->getElementType(), 1);
-  Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vld1, Ty);
+  llvm::Type *Tys[] = {Ty, Int8PtrTy};
+  Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vld1, Tys);
   Value *Align = getAlignmentValue32(PtrOp0);
   Value *Ld = Builder.CreateCall(F, {Ops[0], Align});
   // Combine them.
@@ -3808,7 +3815,8 @@ Value *CodeGenFunction::EmitARMBuiltinEx
 break;
   default: llvm_unreachable("unknown vld_dup intrinsic?");
   }
-  Function *F = CGM.getIntrinsic(Int, Ty);
+  llvm::Type *Tys[] = {Ty, Int8PtrTy};
+  Function *F = CGM.getIntrinsic(Int, Tys);
   llvm::Value *Align = getAlignmentValue32(PtrOp1);
   Ops[1] = Builder.CreateCall(F, {Ops[1], Align}, "vld_dup");
   Ty = llvm::PointerType::getUnqual(Ops[1]->getType());
@@ -3827,7 +3835,8 @@ Value *CodeGenFunction::EmitARMBuiltinEx
   break;
 default: llvm_unreachable("unknown vld_dup intrinsic?");
 }
-Function *F = CGM.getIntrinsic(Int, Ty);
+llvm::Type *Tys[] = {Ty, Int8PtrTy};
+Function *F = CGM.getIntrinsic(Int, Tys);
 llvm::StructType *STy = cast(F->getReturnType());
 
 SmallVector Args;
@@ -3902,8 +3911,9 @@ Value 

[PATCH] D13285: Fix for bug 24196: clang fails on assertion on complex doubles multiplication when EH is enabled

2015-09-30 Thread Denis Zobnin via cfe-commits
d.zobnin.bugzilla created this revision.
d.zobnin.bugzilla added reviewers: rsmith, rjmccall.
d.zobnin.bugzilla added a subscriber: cfe-commits.

This patch fixes an assertion failure, caused by EmitCall function producing 
llvm::InvokeInst* when llvm::CallInst* is needed (when multiplication of 
complex arguments is being emitted).

http://reviews.llvm.org/D13285

Files:
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGExprComplex.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGenCXX/complex_mul_call.cpp

Index: lib/CodeGen/CGExprComplex.cpp
===
--- lib/CodeGen/CGExprComplex.cpp
+++ lib/CodeGen/CGExprComplex.cpp
@@ -592,7 +592,7 @@
   llvm::Instruction *Call;
 
   RValue Res = CGF.EmitCall(FuncInfo, Func, ReturnValueSlot(), Args,
-nullptr, );
+nullptr, , /*forceCallInstCreation =*/ true);
   cast(Call)->setCallingConv(CGF.CGM.getBuiltinCC());
   cast(Call)->setDoesNotThrow();
 
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -3102,9 +3102,17 @@
  ReturnValueSlot ReturnValue,
  const CallArgList ,
  const Decl *TargetDecl,
- llvm::Instruction **callOrInvoke) {
+ llvm::Instruction **callOrInvoke,
+ bool forceCallInstCreation) {
   // FIXME: We no longer need the types from CallArgs; lift up and simplify.
 
+  // It may be nessesary to create a CallInst* even if TargetDecl is not given
+  // (e. g. when emitting a complex operation call). Without TargetDecl there 
is
+  // no way to check the NoUnwind attribute required for CallInst creation. Use
+  // specific flag then, but take care of possible logical violations.
+  assert(!(TargetDecl && forceCallInstCreation) &&
+ "Should not force creation of CallInst if TargetDecl is present!");
+
   // Handle struct-return functions by passing a pointer to the
   // location that we would like to return into.
   QualType RetTy = CallInfo.getReturnType();
@@ -3442,7 +3450,7 @@
 InvokeDest = getInvokeDest();
 
   llvm::CallSite CS;
-  if (!InvokeDest) {
+  if (!InvokeDest || forceCallInstCreation) {
 CS = Builder.CreateCall(Callee, IRCallArgs);
   } else {
 llvm::BasicBlock *Cont = createBasicBlock("invoke.cont");
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -2651,7 +2651,8 @@
   ReturnValueSlot ReturnValue,
   const CallArgList ,
   const Decl *TargetDecl = nullptr,
-  llvm::Instruction **callOrInvoke = nullptr);
+  llvm::Instruction **callOrInvoke = nullptr,
+  bool forceCallInstCreation = false);
 
   RValue EmitCall(QualType FnType, llvm::Value *Callee, const CallExpr *E,
   ReturnValueSlot ReturnValue,
Index: test/CodeGenCXX/complex_mul_call.cpp
===
--- test/CodeGenCXX/complex_mul_call.cpp
+++ test/CodeGenCXX/complex_mul_call.cpp
@@ -0,0 +1,24 @@
+// Check that multiplication of complex arguments is performed properly without
+// assersion fails when exceptions are enabled.
+//
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexceptions 
-fcxx-exceptions -emit-llvm %s -o - | FileCheck %s
+
+struct A {
+  int x;
+  A() { x = 10; }
+  ~A() { x = 20; }
+};
+
+int main() {
+  {
+A a;
+double __complex__ d;
+float __complex__ f;
+// CHECK-LABEL: main
+// CHECK-DAG: call {{.*}} @__muldc3
+double __complex__ d1 = d * d;
+// CHECK-DAG: call {{.*}} @__mulsc3
+float __complex__ f1 = f * f;
+  }
+  return 0;
+}


Index: lib/CodeGen/CGExprComplex.cpp
===
--- lib/CodeGen/CGExprComplex.cpp
+++ lib/CodeGen/CGExprComplex.cpp
@@ -592,7 +592,7 @@
   llvm::Instruction *Call;
 
   RValue Res = CGF.EmitCall(FuncInfo, Func, ReturnValueSlot(), Args,
-nullptr, );
+nullptr, , /*forceCallInstCreation =*/ true);
   cast(Call)->setCallingConv(CGF.CGM.getBuiltinCC());
   cast(Call)->setDoesNotThrow();
 
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -3102,9 +3102,17 @@
  ReturnValueSlot ReturnValue,
  const CallArgList ,
  const Decl *TargetDecl,
- llvm::Instruction **callOrInvoke) {
+ llvm::Instruction **callOrInvoke,
+

r248902 - [OpenCL] Add missing OpenCL LangOpts in address space compatibility checks

2015-09-30 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Wed Sep 30 08:49:55 2015
New Revision: 248902

URL: http://llvm.org/viewvc/llvm-project?rev=248902=rev
Log:
[OpenCL] Add missing OpenCL LangOpts in address space compatibility checks

and test checking broken (due to CL specific diagnostics) C functionality

Mtest/Sema/address_spaces.c
Mlib/Sema/SemaExpr.cpp

Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/address_spaces.c

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=248902=248901=248902=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Sep 30 08:49:55 2015
@@ -7754,7 +7754,7 @@ static bool checkArithmeticBinOpPointerO
   if (isRHSPointer) RHSPointeeTy = RHSExpr->getType()->getPointeeType();
 
   // if both are pointers check if operation is valid wrt address spaces
-  if (isLHSPointer && isRHSPointer) {
+  if (S.getLangOpts().OpenCL && isLHSPointer && isRHSPointer) {
 const PointerType *lhsPtr = LHSExpr->getType()->getAs();
 const PointerType *rhsPtr = RHSExpr->getType()->getAs();
 if (!lhsPtr->isAddressSpaceOverlapping(*rhsPtr)) {
@@ -8783,12 +8783,14 @@ QualType Sema::CheckCompareOperands(Expr
   diagnoseDistinctPointerComparison(*this, Loc, LHS, RHS, 
/*isError*/false);
 }
 if (LCanPointeeTy != RCanPointeeTy) {
-  const PointerType *lhsPtr = LHSType->getAs();
-  if (!lhsPtr->isAddressSpaceOverlapping(*RHSType->getAs())) {
-Diag(Loc,
- diag::err_typecheck_op_on_nonoverlapping_address_space_pointers)
-<< LHSType << RHSType << 0 /* comparison */
-<< LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
+  if (getLangOpts().OpenCL) {
+const PointerType *LHSPtr = LHSType->getAs();
+if 
(!LHSPtr->isAddressSpaceOverlapping(*RHSType->getAs())) {
+  Diag(Loc,
+   diag::err_typecheck_op_on_nonoverlapping_address_space_pointers)
+  << LHSType << RHSType << 0 /* comparison */
+  << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
+}
   }
   unsigned AddrSpaceL = LCanPointeeTy.getAddressSpace();
   unsigned AddrSpaceR = RCanPointeeTy.getAddressSpace();

Modified: cfe/trunk/test/Sema/address_spaces.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/address_spaces.c?rev=248902=248901=248902=diff
==
--- cfe/trunk/test/Sema/address_spaces.c (original)
+++ cfe/trunk/test/Sema/address_spaces.c Wed Sep 30 08:49:55 2015
@@ -67,3 +67,8 @@ void access_as_field()
 
 typedef int PR4997 __attribute__((address_space(Foobar))); // expected-error 
{{use of undeclared identifier 'Foobar'}}
 __attribute__((address_space("12"))) int *i; // expected-error 
{{'address_space' attribute requires an integer constant}}
+
+// Clang extension doesn't forbid operations on pointers to different address 
spaces.
+char* cmp(_AS1 char *x,  _AS2 char *y) {
+  return x < y ? x : y; // expected-warning {{pointer type mismatch 
('__attribute__((address_space(1))) char *' and 
'__attribute__((address_space(2))) char *')}}
+}
\ No newline at end of file


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


[PATCH] D13289: [libc++] Provide additional templates for valarray transcendentals that satisfy the standard synopsis

2015-09-30 Thread Petr Pavlu via cfe-commits
petpav01 created this revision.
petpav01 added a subscriber: cfe-commits.

Libc++ provides valarray transcendentals with replacement types. These 
functions are implemented either as `template` or `template`, where `_Expr` can be `__val_expr` or `valarray`.

The patch provides additional function templates for valarray transcendentals 
that as a parameter use `_Tp` which is a type of elements in the valarray. This 
is required by the standard and is needed if the user tries to explicitly 
instantiate the transcendental functions using `_Tp`, for example, 
`std::abs(int_valarray)`.

New templates do not take an additional `_Expr` parameter and so the functions 
accept only `valarray` as their parameter. This means that if the user 
explicitly instantiates these function templates and passes `__val_expr` to 
them, it first needs to be converted to `valarray` and the benefit of the 
expression template optimization is not present. No performance is lost in the 
currently possible case where template parameters are deduced because using 
`__val_expr` as an argument will lead to instantiation of the already present 
templates.

http://reviews.llvm.org/D13289

Files:
  include/valarray
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/abs_valarray.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/acos_valarray.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/asin_valarray.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/atan2_valarray_valarray.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/atan2_valarray_value.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/atan2_value_valarray.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/atan_valarray.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/cos_valarray.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/cosh_valarray.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/exp_valarray.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/log10_valarray.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/log_valarray.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/pow_valarray_valarray.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/pow_valarray_value.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/pow_value_valarray.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/sin_valarray.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/sinh_valarray.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/sqrt_valarray.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/tan_valarray.pass.cpp
  
test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/tanh_valarray.pass.cpp

Index: test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/tanh_valarray.pass.cpp
===
--- test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/tanh_valarray.pass.cpp
+++ test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/tanh_valarray.pass.cpp
@@ -33,19 +33,26 @@
 
 int main()
 {
+typedef double T;
+T a1[] = {-.9, -.5, 0., .5, .75};
+T a3[] = {-7.1629787019902447e-01,
+  -4.6211715726000974e-01,
+   0.e+00,
+   4.6211715726000974e-01,
+   6.3514895238728730e-01};
+const unsigned N = sizeof(a1)/sizeof(a1[0]);
 {
-typedef double T;
-T a1[] = {-.9, -.5, 0., .5, .75};
-T a3[] = {-7.1629787019902447e-01,
-  -4.6211715726000974e-01,
-   0.e+00,
-   4.6211715726000974e-01,
-   6.3514895238728730e-01};
-const unsigned N = sizeof(a1)/sizeof(a1[0]);
 std::valarray v1(a1, N);
 std::valarray v3 = tanh(v1);
 assert(v3.size() == v1.size());
 for (int i = 0; i < v3.size(); ++i)
 assert(is_about(v3[i], a3[i], 10));
 }
+{
+std::valarray v1(a1, N);
+std::valarray v3 = std::tanh(v1);
+assert(v3.size() == v1.size());
+for (int i = 0; i < v3.size(); ++i)
+assert(is_about(v3[i], a3[i], 10));
+}
 }
Index: test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/tan_valarray.pass.cpp
===
--- test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/tan_valarray.pass.cpp
+++ test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/tan_valarray.pass.cpp
@@ -33,19 +33,26 @@
 
 int main()
 {
+typedef double T;
+T a1[] = {-.9, 

Re: [PATCH] D13249: Divide TraverseInitListExpr to a different function for each form.

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

Add some comments.


http://reviews.llvm.org/D13249

Files:
  include/clang/AST/RecursiveASTVisitor.h

Index: include/clang/AST/RecursiveASTVisitor.h
===
--- include/clang/AST/RecursiveASTVisitor.h
+++ include/clang/AST/RecursiveASTVisitor.h
@@ -255,6 +255,13 @@
   /// \returns false if the visitation was terminated early, true otherwise.
   bool TraverseLambdaBody(LambdaExpr *LE);
 
+  /// \brief Recursively visit the syntactic and semantic forms of a
+  /// initialization list.
+  ///
+  /// \returns false if the visitation was terminated early, true otherwise.
+  bool TraverseSyntacticInitListExpr(InitListExpr *S);
+  bool TraverseSemanticInitListExpr(InitListExpr *S);
+
   //  Methods on Attrs 
 
   // \brief Visit an attribute.
@@ -2056,21 +2063,21 @@
   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
 })
 
-// InitListExpr is a tricky one, because we want to do all our work on
-// the syntactic form of the listexpr, but this method takes the
-// semantic form by default.  We can't use the macro helper because it
-// calls WalkUp*() on the semantic form, before our code can convert
-// to the syntactic form.
 template 
-bool RecursiveASTVisitor::TraverseInitListExpr(InitListExpr *S) {
+bool RecursiveASTVisitor::TraverseSyntacticInitListExpr(InitListExpr 
*S) {
   InitListExpr *Syn = S->isSemanticForm() ? S->getSyntacticForm() : S;
   if (Syn) {
 TRY_TO(WalkUpFromInitListExpr(Syn));
 // All we need are the default actions.  FIXME: use a helper function.
 for (Stmt *SubStmt : Syn->children()) {
   TRY_TO(TraverseStmt(SubStmt));
 }
   }
+  return true;
+}
+
+template 
+bool RecursiveASTVisitor::TraverseSemanticInitListExpr(InitListExpr 
*S) {
   InitListExpr *Sem = S->isSemanticForm() ? S : S->getSemanticForm();
   if (Sem) {
 TRY_TO(WalkUpFromInitListExpr(Sem));
@@ -2081,6 +2088,25 @@
   return true;
 }
 
+// InitListExpr is a tricky one, because we want to do all our work on
+// the syntactic form of the listexpr, but this method takes the
+// semantic form by default.  We can't use the macro helper because it
+// calls WalkUp*() on the semantic form, before our code can convert
+// to the syntactic form.
+//
+// This method is called once for each pair of syntactic and semantic
+// InitListExpr, and it traverses the subtrees defined by the two forms. This
+// may cause some of the children to be visited twice, if they appear both in
+// the syntactic and the semantic form.
+//
+// There is no guarantee about which form \p S takes when this method is 
called.
+template 
+bool RecursiveASTVisitor::TraverseInitListExpr(InitListExpr *S) {
+  TRY_TO(TraverseSyntacticInitListExpr(S));
+  TRY_TO(TraverseSemanticInitListExpr(S));
+  return true;
+}
+
 // GenericSelectionExpr is a special case because the types and expressions
 // are interleaved.  We also need to watch out for null types (default
 // generic associations).


Index: include/clang/AST/RecursiveASTVisitor.h
===
--- include/clang/AST/RecursiveASTVisitor.h
+++ include/clang/AST/RecursiveASTVisitor.h
@@ -255,6 +255,13 @@
   /// \returns false if the visitation was terminated early, true otherwise.
   bool TraverseLambdaBody(LambdaExpr *LE);
 
+  /// \brief Recursively visit the syntactic and semantic forms of a
+  /// initialization list.
+  ///
+  /// \returns false if the visitation was terminated early, true otherwise.
+  bool TraverseSyntacticInitListExpr(InitListExpr *S);
+  bool TraverseSemanticInitListExpr(InitListExpr *S);
+
   //  Methods on Attrs 
 
   // \brief Visit an attribute.
@@ -2056,21 +2063,21 @@
   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
 })
 
-// InitListExpr is a tricky one, because we want to do all our work on
-// the syntactic form of the listexpr, but this method takes the
-// semantic form by default.  We can't use the macro helper because it
-// calls WalkUp*() on the semantic form, before our code can convert
-// to the syntactic form.
 template 
-bool RecursiveASTVisitor::TraverseInitListExpr(InitListExpr *S) {
+bool RecursiveASTVisitor::TraverseSyntacticInitListExpr(InitListExpr *S) {
   InitListExpr *Syn = S->isSemanticForm() ? S->getSyntacticForm() : S;
   if (Syn) {
 TRY_TO(WalkUpFromInitListExpr(Syn));
 // All we need are the default actions.  FIXME: use a helper function.
 for (Stmt *SubStmt : Syn->children()) {
   TRY_TO(TraverseStmt(SubStmt));
 }
   }
+  return true;
+}
+
+template 
+bool RecursiveASTVisitor::TraverseSemanticInitListExpr(InitListExpr *S) {
   InitListExpr *Sem = S->isSemanticForm() ? S : S->getSemanticForm();
   if (Sem) {
 TRY_TO(WalkUpFromInitListExpr(Sem));
@@ -2081,6 +2088,25 @@
   return true;
 }
 
+// InitListExpr is a tricky one, because we want to do all our work on
+// the 

[clang-tools-extra] r248895 - [clang-tidy] Fix an assertion in the readability-braces-around-statements check.

2015-09-30 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Wed Sep 30 07:48:42 2015
New Revision: 248895

URL: http://llvm.org/viewvc/llvm-project?rev=248895=rev
Log:
[clang-tidy] Fix an assertion in the readability-braces-around-statements check.

Modified:

clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp

clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp?rev=248895=248894=248895=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp 
Wed Sep 30 07:48:42 2015
@@ -232,8 +232,18 @@ bool BracesAroundStatementsCheck::checkS
 
   // InitialLoc points at the last token before opening brace to be inserted.
   assert(InitialLoc.isValid());
+  // Convert InitialLoc to file location, if it's on the same macro expansion
+  // level as the start of the statement. We also need file locations for
+  // Lexer::getLocForEndOfToken working properly.
+  InitialLoc = Lexer::makeFileCharRange(
+   CharSourceRange::getCharRange(InitialLoc, S->getLocStart()),
+   SM, Context->getLangOpts())
+   .getBegin();
+  if (InitialLoc.isInvalid())
+return false;
   SourceLocation StartLoc =
   Lexer::getLocForEndOfToken(InitialLoc, 0, SM, Context->getLangOpts());
+
   // StartLoc points at the location of the opening brace to be inserted.
   SourceLocation EndLoc;
   std::string ClosingInsertion;

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements.cpp?rev=248895=248894=248895=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements.cpp
 Wed Sep 30 07:48:42 2015
@@ -183,4 +183,12 @@ int test_macros(bool b) {
   // CHECK-FIXES: } else {
   // CHECK-FIXES-NEXT:   M(return 2);
   // CHECK-FIXES-NEXT: }
+  M(
+for (;;)
+  ;
+  );
+  // CHECK-MESSAGES: :[[@LINE-3]]:13: warning: statement should be inside 
braces
+  // CHECK-FIXES: {{^}}for (;;) {{{$}}
+  // CHECK-FIXES-NEXT: {{^  ;$}}
+  // CHECK-FIXES-NEXT: {{^}$}}
 }


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


r248896 - [OpenCL 2.0] This change adds extra diagnostics to atomic types

2015-09-30 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Wed Sep 30 08:18:52 2015
New Revision: 248896

URL: http://llvm.org/viewvc/llvm-project?rev=248896=rev
Log:
[OpenCL 2.0] This change adds extra diagnostics to atomic types

Applied restrictions from OpenCL v2.0 s6.13.11.8
that mainly disallow operations on atomic types (except for taking their 
address - &).

The patch is taken from SPIR2.0 provisional branch, contributed by Guy Benyei!


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Parser/opencl-atomics-cl20.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=248896=248895=248896=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 30 08:18:52 
2015
@@ -7480,6 +7480,9 @@ def err_opencl_return_value_with_address
   "return value cannot be qualified with address space">;
 def err_opencl_constant_no_init : Error<
   "variable in constant address space must be initialized">;
+def err_atomic_init_constant : Error<
+  "atomic variable can only be assigned to a compile time constant"
+  " in the declaration statement in the program scope">;
 def err_opencl_implicit_vector_conversion : Error<
   "implicit conversions between vector types (%0 and %1) are not permitted">;
 } // end of sema category

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=248896=248895=248896=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Sep 30 08:18:52 2015
@@ -10276,6 +10276,20 @@ ExprResult Sema::CreateBuiltinBinOp(Sour
   return ExprError();
   }
 
+  if (getLangOpts().OpenCL) {
+// OpenCLC v2.0 s6.13.11.1 allows atomic variables to be initialized by
+// the ATOMIC_VAR_INIT macro.
+if (LHSExpr->getType()->isAtomicType() ||
+RHSExpr->getType()->isAtomicType()) {
+  SourceRange SR(LHSExpr->getLocStart(), RHSExpr->getLocEnd());
+  if (BO_Assign == Opc)
+Diag(OpLoc, diag::err_atomic_init_constant) << SR;
+  else
+ResultTy = InvalidOperands(OpLoc, LHS, RHS);
+  return ExprError();
+}
+  }
+
   switch (Opc) {
   case BO_Assign:
 ResultTy = CheckAssignmentOperands(LHS.get(), RHS, OpLoc, QualType());
@@ -10748,6 +10762,14 @@ ExprResult Sema::CreateBuiltinUnaryOp(So
   ExprValueKind VK = VK_RValue;
   ExprObjectKind OK = OK_Ordinary;
   QualType resultType;
+  if (getLangOpts().OpenCL) {
+// The only legal unary operation for atomics is '&'.
+if (Opc != UO_AddrOf && InputExpr->getType()->isAtomicType()) {
+  return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr)
+   << InputExpr->getType()
+   << Input.get()->getSourceRange());
+}
+  }
   switch (Opc) {
   case UO_PreInc:
   case UO_PreDec:

Modified: cfe/trunk/test/Parser/opencl-atomics-cl20.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/opencl-atomics-cl20.cl?rev=248896=248895=248896=diff
==
--- cfe/trunk/test/Parser/opencl-atomics-cl20.cl (original)
+++ cfe/trunk/test/Parser/opencl-atomics-cl20.cl Wed Sep 30 08:18:52 2015
@@ -54,3 +54,16 @@ void atomic_types_test() {
 // expected-error-re@-31 {{use of type 'atomic_ptrdiff_t' (aka 
'_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be enabled}}
 // expected-error-re@-32 {{use of type 'atomic_ptrdiff_t' (aka 
'_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be 
enabled}}
 #endif
+
+#ifdef CL20
+void foo(atomic_int * ptr) {}
+void atomic_ops_test() {
+  atomic_int i;
+  foo();
+// OpenCL v2.0 s6.13.11.8, arithemtic operations are not permitted on atomic 
types.
+  i++; // expected-error {{invalid argument type 'atomic_int' (aka 
'_Atomic(int)') to unary expression}}
+  i = 1; // expected-error {{atomic variable can only be assigned to a compile 
time constant in the declaration statement in the program scope}}
+  i += 1; // expected-error {{invalid operands to binary expression 
('atomic_int' (aka '_Atomic(int)') and 'int')}}
+  i = i + i; // expected-error {{invalid operands to binary expression 
('atomic_int' (aka '_Atomic(int)') and 'atomic_int')}}
+}
+#endif


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


[clang-tools-extra] r248899 - [clang-tidy] Added missing check lines, made the checking stricter.

2015-09-30 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Wed Sep 30 08:32:42 2015
New Revision: 248899

URL: http://llvm.org/viewvc/llvm-project?rev=248899=rev
Log:
[clang-tidy] Added missing check lines, made the checking stricter.

Modified:
clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp

Modified: clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp?rev=248899=248898=248899=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp Wed Sep 30 08:32:42 
2015
@@ -1,14 +1,11 @@
-// RUN: clang-tidy -checks='-*,modernize-use-override' %s.nonexistent.cpp -- | 
FileCheck -check-prefix=CHECK1 %s
-// RUN: clang-tidy -checks='-*,clang-diagnostic-*,google-explicit-constructor' 
%s -- -fan-unknown-option | FileCheck -check-prefix=CHECK2 %s
-// RUN: clang-tidy 
-checks='-*,google-explicit-constructor,clang-diagnostic-literal-conversion' %s 
-- -fan-unknown-option | FileCheck -check-prefix=CHECK3 %s
-// RUN: clang-tidy 
-checks='-*,modernize-use-override,clang-diagnostic-macro-redefined' %s -- 
-DMACRO_FROM_COMMAND_LINE | FileCheck -check-prefix=CHECK4 %s
-
-// CHECK1-NOT: warning
-// CHECK2-NOT: warning
-// CHECK3-NOT: warning
+// RUN: clang-tidy -checks='-*,modernize-use-override' %s.nonexistent.cpp -- | 
FileCheck -check-prefix=CHECK1 -implicit-check-not='{{warning:|error:}}' %s
+// RUN: clang-tidy -checks='-*,clang-diagnostic-*,google-explicit-constructor' 
%s -- -fan-unknown-option | FileCheck -check-prefix=CHECK2 
-implicit-check-not='{{warning:|error:}}' %s
+// RUN: clang-tidy 
-checks='-*,google-explicit-constructor,clang-diagnostic-literal-conversion' %s 
-- -fan-unknown-option | FileCheck -check-prefix=CHECK3 
-implicit-check-not='{{warning:|error:}}' %s
+// RUN: clang-tidy 
-checks='-*,modernize-use-override,clang-diagnostic-macro-redefined' %s -- 
-DMACRO_FROM_COMMAND_LINE | FileCheck -check-prefix=CHECK4 
-implicit-check-not='{{warning:|error:}}' %s
 
 // CHECK1: error: error reading '{{.*}}.nonexistent.cpp' 
[clang-diagnostic-error]
 // CHECK2: error: unknown argument: '-fan-unknown-option' 
[clang-diagnostic-error]
+// CHECK3: error: unknown argument: '-fan-unknown-option' 
[clang-diagnostic-error]
 
 // CHECK2: :[[@LINE+2]]:9: warning: implicit conversion from 'double' to 'int' 
changes value from 1.5 to 1 [clang-diagnostic-literal-conversion]
 // CHECK3: :[[@LINE+1]]:9: warning: implicit conversion from 'double' to 'int' 
changes value
@@ -18,8 +15,5 @@ int a = 1.5;
 // CHECK3: :[[@LINE+1]]:11: warning: single-argument constructors must be 
explicit [google-explicit-constructor]
 class A { A(int) {} };
 
-// CHECK2-NOT: warning:
-// CHECK3-NOT: warning:
-
 #define MACRO_FROM_COMMAND_LINE
 // CHECK4: :[[@LINE-1]]:9: warning: 'MACRO_FROM_COMMAND_LINE' macro redefined


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


r248950 - Don't inherit the "unavailable" attribute from an overridden superclass method.

2015-09-30 Thread Douglas Gregor via cfe-commits
Author: dgregor
Date: Wed Sep 30 16:34:33 2015
New Revision: 248950

URL: http://llvm.org/viewvc/llvm-project?rev=248950=rev
Log:
Don't inherit the "unavailable" attribute from an overridden superclass method.

Fixes rdar://problem/22922259.

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaObjC/attr-availability.m

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=248950=248949=248950=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Sep 30 16:34:33 2015
@@ -2220,12 +2220,10 @@ static bool mergeDeclAttribute(Sema ,
 // AlignedAttrs are handled separately, because we need to handle all
 // such attributes on a declaration at the same time.
 NewAttr = nullptr;
-  else if (isa(Attr)  &&
+  else if ((isa(Attr) || isa(Attr)) &&
(AMK == Sema::AMK_Override ||
 AMK == Sema::AMK_ProtocolImplementation))
 NewAttr = nullptr;
-  else if (isa(Attr) && AMK == 
Sema::AMK_ProtocolImplementation)
-NewAttr = nullptr;
   else if (Attr->duplicatesAllowed() || !DeclHasAttr(D, Attr))
 NewAttr = cast(Attr->clone(S.Context));
 

Modified: cfe/trunk/test/SemaObjC/attr-availability.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/attr-availability.m?rev=248950=248949=248950=diff
==
--- cfe/trunk/test/SemaObjC/attr-availability.m (original)
+++ cfe/trunk/test/SemaObjC/attr-availability.m Wed Sep 30 16:34:33 2015
@@ -278,3 +278,19 @@ __attribute__((objc_root_class))
 -(void)methodB __attribute__((unavailable)) {
 }
 @end
+
+__attribute__((objc_root_class))
+@interface InheritUnavailableSuper
+-(void)method __attribute__((unavailable)); // expected-note{{'method' has 
been explicitly marked unavailable here}}
+@end
+
+@interface InheritUnavailableSub : InheritUnavailableSuper
+-(void)method;
+@end
+
+@implementation InheritUnavailableSub
+-(void)method {
+  InheritUnavailableSuper *obj = self;
+  [obj method]; // expected-error{{'method' is unavailable}}
+}
+@end


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


r248951 - [CUDA] fix codegen for __nvvm_atom_cas_*

2015-09-30 Thread Jingyue Wu via cfe-commits
Author: jingyue
Date: Wed Sep 30 16:49:32 2015
New Revision: 248951

URL: http://llvm.org/viewvc/llvm-project?rev=248951=rev
Log:
[CUDA] fix codegen for __nvvm_atom_cas_*

Summary: __nvvm_atom_cas_* returns the old value instead of whether the swap 
succeeds.

Reviewers: eliben, tra

Subscribers: jholewinski, llvm-commits

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

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/builtins-nvptx.c

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=248951=248950=248951=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Sep 30 16:49:32 2015
@@ -7021,7 +7021,9 @@ Value *CodeGenFunction::EmitNVPTXBuiltin
   case NVPTX::BI__nvvm_atom_cas_gen_i:
   case NVPTX::BI__nvvm_atom_cas_gen_l:
   case NVPTX::BI__nvvm_atom_cas_gen_ll:
-return MakeAtomicCmpXchgValue(*this, E, true);
+// __nvvm_atom_cas_gen_* should return the old value rather than the
+// success flag.
+return MakeAtomicCmpXchgValue(*this, E, /*ReturnBool=*/false);
 
   case NVPTX::BI__nvvm_atom_add_gen_f: {
 Value *Ptr = EmitScalarExpr(E->getArg(0));

Modified: cfe/trunk/test/CodeGen/builtins-nvptx.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-nvptx.c?rev=248951=248950=248951=diff
==
--- cfe/trunk/test/CodeGen/builtins-nvptx.c (original)
+++ cfe/trunk/test/CodeGen/builtins-nvptx.c Wed Sep 30 16:49:32 2015
@@ -260,10 +260,13 @@ __device__ void nvvm_atom(float *fp, flo
   __nvvm_atom_min_gen_ull((unsigned long long *), ll);
 
   // CHECK: cmpxchg
+  // CHECK-NEXT: extractvalue { i32, i1 } {{%[0-9]+}}, 0
   __nvvm_atom_cas_gen_i(ip, 0, i);
   // CHECK: cmpxchg
+  // CHECK-NEXT: extractvalue { {{i32|i64}}, i1 } {{%[0-9]+}}, 0
   __nvvm_atom_cas_gen_l(, 0, l);
   // CHECK: cmpxchg
+  // CHECK-NEXT: extractvalue { i64, i1 } {{%[0-9]+}}, 0
   __nvvm_atom_cas_gen_ll(, 0, ll);
 
   // CHECK: call float @llvm.nvvm.atomic.load.add.f32.p0f32


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


Re: [PATCH] D13313: [clang-tidy] new check misc-no-reinterpret-cast

2015-09-30 Thread Vedant Kumar via cfe-commits
vsk added a subscriber: vsk.
vsk added a comment.

The patch lgtm. Has there been a discussion on cfe-dev about adopting these 
guidelines?

I count well over 500 uses of reinterpret_cast in llvm+clang, so we might not 
all be on the same page on this.


http://reviews.llvm.org/D13313



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


[PATCH] D13317: clang_Cursor_getMangling shouldn't mangle if the declaration isn't mangled

2015-09-30 Thread Michael Wu via cfe-commits
michaelwu created this revision.
michaelwu added a subscriber: cfe-commits.

Right now clang_Cursor_getMangling will attempt to mangle any declaration, even 
if the declaration isn't mangled (extern "C"). This results in a partially 
mangled name which isn't useful for much. This patch makes 
clang_Cursor_getMangling return an empty string if the declaration isn't 
mangled.

http://reviews.llvm.org/D13317

Files:
  test/Index/print-mangled-name.cpp
  tools/libclang/CIndex.cpp

Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -3891,6 +3891,10 @@
   ASTContext  = ND->getASTContext();
   std::unique_ptr MC(Ctx.createMangleContext());
 
+  // Don't mangle if we don't need to.
+  if (!MC->shouldMangleCXXName(ND))
+return cxstring::createEmpty();
+
   std::string FrontendBuf;
   llvm::raw_string_ostream FrontendBufOS(FrontendBuf);
   MC->mangleName(ND, FrontendBufOS);
Index: test/Index/print-mangled-name.cpp
===
--- test/Index/print-mangled-name.cpp
+++ test/Index/print-mangled-name.cpp
@@ -29,3 +29,8 @@
 // ITANIUM: mangled=_Z3foo1SRS_
 // MACHO: mangled=__Z3foo1SRS_
 // MICROSOFT: mangled=?foo@@YAHUS
+
+extern "C" int foo(int);
+// ITANIUM: mangled=
+// MACHO: mangled=
+// MICROSOFT: mangled=


Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -3891,6 +3891,10 @@
   ASTContext  = ND->getASTContext();
   std::unique_ptr MC(Ctx.createMangleContext());
 
+  // Don't mangle if we don't need to.
+  if (!MC->shouldMangleCXXName(ND))
+return cxstring::createEmpty();
+
   std::string FrontendBuf;
   llvm::raw_string_ostream FrontendBufOS(FrontendBuf);
   MC->mangleName(ND, FrontendBufOS);
Index: test/Index/print-mangled-name.cpp
===
--- test/Index/print-mangled-name.cpp
+++ test/Index/print-mangled-name.cpp
@@ -29,3 +29,8 @@
 // ITANIUM: mangled=_Z3foo1SRS_
 // MACHO: mangled=__Z3foo1SRS_
 // MICROSOFT: mangled=?foo@@YAHUS
+
+extern "C" int foo(int);
+// ITANIUM: mangled=
+// MACHO: mangled=
+// MICROSOFT: mangled=
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13319: Eliminate __llvm_profile_register calls

2015-09-30 Thread David Li via cfe-commits
davidxl added a comment.

With this patch, 11M bytes (text section) can be shaved off clang build with 
instrumentation.


http://reviews.llvm.org/D13319



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


[PATCH] D13318: Add a utility function to add target information to a command line

2015-09-30 Thread Luke Zarko via cfe-commits
zarko created this revision.
zarko added reviewers: rnk, echristo, klimek.
zarko added a subscriber: cfe-commits.
Herald added subscribers: srhines, danalbert, tberghammer, klimek.

This diff adds `addTargetAndModeForProgramName`, a utility function that will 
add appropriate `-target foo` and `--driver-mode=g++` tokens to a command line 
for driver invocations of the form `a/b/foo-g++`. It is intended to support 
tooling: for example, should a compilation database record some invocation of 
`foo-g++` without these implicit flags, a Clang tool may use this function to 
add them back.

Note that a compilation database won't necessarily store these invocations 
without their corresponding implicit flags. Some may use 
`addTargetAndModeForProgramName` when the database is first written out so that 
later readers don't need to repeat the operation.

http://reviews.llvm.org/D13318

Files:
  include/clang/Tooling/Tooling.h
  lib/Tooling/Tooling.cpp
  unittests/Tooling/ToolingTest.cpp

Index: unittests/Tooling/ToolingTest.cpp
===
--- unittests/Tooling/ToolingTest.cpp
+++ unittests/Tooling/ToolingTest.cpp
@@ -18,6 +18,8 @@
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Config/llvm-config.h"
+#include "llvm/Support/TargetSelect.h"
+#include "llvm/Support/TargetRegistry.h"
 #include "gtest/gtest.h"
 #include 
 #include 
@@ -291,6 +293,84 @@
   EXPECT_FALSE(Found);
 }
 
+namespace {
+/// Find a target name such that looking for it in TargetRegistry by that name
+/// returns the same target. We expect that there is at least one target
+/// configured with this property.
+std::string getAnyTarget() {
+  llvm::InitializeAllTargets();
+  for (const auto  : llvm::TargetRegistry::targets()) {
+std::string Error;
+if (llvm::TargetRegistry::lookupTarget(Target.getName(), Error) ==
+) {
+  return Target.getName();
+}
+  }
+  return "";
+}
+}
+
+TEST(addTargetAndModeForProgramName, AddsTargetAndMode) {
+  std::string Target = getAnyTarget();
+  ASSERT_FALSE(Target.empty());
+
+  std::vector Args = {"clang", "-foo"};
+  addTargetAndModeForProgramName(Args, "");
+  EXPECT_EQ((std::vector{"clang", "-foo"}), Args);
+  addTargetAndModeForProgramName(Args, Target + "-g++");
+  EXPECT_EQ((std::vector{"clang", "-target", Target,
+  "--driver-mode=g++", "-foo"}),
+Args);
+}
+
+TEST(addTargetAndModeForProgramName, PathIgnored) {
+  std::string Target = getAnyTarget();
+  ASSERT_FALSE(Target.empty());
+
+  SmallString<32> ToolPath;
+  llvm::sys::path::append(ToolPath, "foo", "bar", Target + "-g++");
+
+  std::vector Args = {"clang", "-foo"};
+  addTargetAndModeForProgramName(Args, ToolPath);
+  EXPECT_EQ((std::vector{"clang", "-target", Target,
+  "--driver-mode=g++", "-foo"}),
+Args);
+}
+
+TEST(addTargetAndModeForProgramName, IgnoresExistingTarget) {
+  std::string Target = getAnyTarget();
+  ASSERT_FALSE(Target.empty());
+
+  std::vector Args = {"clang", "-foo", "-target", "something"};
+  addTargetAndModeForProgramName(Args, Target + "-g++");
+  EXPECT_EQ((std::vector{"clang", "--driver-mode=g++", "-foo",
+  "-target", "something"}),
+Args);
+
+  std::vector ArgsAlt = {"clang", "-foo", "-target=something"};
+  addTargetAndModeForProgramName(ArgsAlt, Target + "-g++");
+  EXPECT_EQ((std::vector{"clang", "--driver-mode=g++", "-foo",
+  "-target=something"}),
+ArgsAlt);
+}
+
+TEST(addTargetAndModeForProgramName, IgnoresExistingMode) {
+  std::string Target = getAnyTarget();
+  ASSERT_FALSE(Target.empty());
+
+  std::vector Args = {"clang", "-foo", "--driver-mode=abc"};
+  addTargetAndModeForProgramName(Args, Target + "-g++");
+  EXPECT_EQ((std::vector{"clang", "-target", Target, "-foo",
+  "--driver-mode=abc"}),
+Args);
+
+  std::vector ArgsAlt = {"clang", "-foo", "--driver-mode", "abc"};
+  addTargetAndModeForProgramName(ArgsAlt, Target + "-g++");
+  EXPECT_EQ((std::vector{"clang", "-target", Target, "-foo",
+  "--driver-mode", "abc"}),
+ArgsAlt);
+}
+
 #ifndef LLVM_ON_WIN32
 TEST(ClangToolTest, BuildASTs) {
   FixedCompilationDatabase Compilations("/", std::vector());
Index: lib/Tooling/Tooling.cpp
===
--- lib/Tooling/Tooling.cpp
+++ lib/Tooling/Tooling.cpp
@@ -17,6 +17,7 @@
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
@@ -162,6 +163,31 @@
   return AbsolutePath.str();
 }
 
+void addTargetAndModeForProgramName(std::vector ,
+  

Re: [PATCH] D12839: Extend MoveConstructorInitCheck to also flag constructor arguments passed by value and can be moved assigned to fields.

2015-09-30 Thread Felix Berger via cfe-commits
flx updated this revision to Diff 36151.
flx marked an inline comment as done.
flx added a comment.

Thanks for catching the last issues, Alex. I rebuilt and ran all tests using 
llvm-lit -v . for clang-tidy and they pass.


http://reviews.llvm.org/D12839

Files:
  clang-tidy/misc/MoveConstructorInitCheck.cpp
  clang-tidy/misc/MoveConstructorInitCheck.h
  clang-tidy/modernize/PassByValueCheck.cpp
  clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
  clang-tidy/utils/CMakeLists.txt
  clang-tidy/utils/IncludeSorter.cpp
  clang-tidy/utils/IncludeSorter.h
  clang-tidy/utils/Matchers.h
  clang-tidy/utils/TypeTraits.cpp
  clang-tidy/utils/TypeTraits.h
  docs/clang-tidy/checks/misc-move-constructor-init.rst
  test/clang-tidy/misc-move-constructor-init.cpp

Index: test/clang-tidy/misc-move-constructor-init.cpp
===
--- test/clang-tidy/misc-move-constructor-init.cpp
+++ test/clang-tidy/misc-move-constructor-init.cpp
@@ -1,78 +1,145 @@
-// RUN: %python %S/check_clang_tidy.py %s misc-move-constructor-init %t
-
-template  struct remove_reference  {typedef T type;};
-template  struct remove_reference  {typedef T type;};
-template  struct remove_reference {typedef T type;};
-
-template 
-typename remove_reference::type&& move(T&& arg) {
-  return static_cast::type&&>(arg);
-}
-
-struct C {
-  C() = default;
-  C(const C&) = default;
-};
-
-struct B {
-  B() {}
-  B(const B&) {}
-  B(B &&) {}
-};
-
-struct D : B {
-  D() : B() {}
-  D(const D ) : B(RHS) {}
-  // CHECK-MESSAGES: :[[@LINE+3]]:16: warning: move constructor initializes base class by calling a copy constructor [misc-move-constructor-init]
-  // CHECK-MESSAGES: 19:3: note: copy constructor being called
-  // CHECK-MESSAGES: 20:3: note: candidate move constructor here
-  D(D &) : B(RHS) {}
-};
-
-struct E : B {
-  E() : B() {}
-  E(const E ) : B(RHS) {}
-  E(E &) : B(move(RHS)) {} // ok
-};
-
-struct F {
-  C M;
-
-  F(F &&) : M(C()) {} // ok
-};
-
-struct G {
-  G() = default;
-  G(const G&) = default;
-  G(G&&) = delete;
-};
-
-struct H : G {
-  H() = default;
-  H(const H&) = default;
-  H(H &) : G(RHS) {} // ok
-};
-
-struct I {
-  I(const I &) = default; // suppresses move constructor creation
-};
-
-struct J : I {
-  J(J &) : I(RHS) {} // ok
-};
-
-struct K {}; // Has implicit copy and move constructors, is trivially copyable
-struct L : K {
-  L(L &) : K(RHS) {} // ok
-};
-
-struct M {
-  B Mem;
-  // CHECK-MESSAGES: :[[@LINE+1]]:16: warning: move constructor initializes class member by calling a copy constructor [misc-move-constructor-init]
-  M(M &) : Mem(RHS.Mem) {}
-};
-
-struct N {
-  B Mem;
-  N(N &) : Mem(move(RHS.Mem)) {}
-};
+// RUN: %python %S/check_clang_tidy.py %s misc-move-constructor-init %t -- -std=c++11 -isystem %S/Inputs/Headers
+
+#include 
+
+// CHECK-FIXES: #include 
+
+template  struct remove_reference  {typedef T type;};
+template  struct remove_reference  {typedef T type;};
+template  struct remove_reference {typedef T type;};
+
+template 
+typename remove_reference::type&& move(T&& arg) {
+  return static_cast::type&&>(arg);
+}
+
+struct C {
+  C() = default;
+  C(const C&) = default;
+};
+
+struct B {
+  B() {}
+  B(const B&) {}
+  B(B &&) {}
+};
+
+struct D : B {
+  D() : B() {}
+  D(const D ) : B(RHS) {}
+  // CHECK-MESSAGES: :[[@LINE+3]]:16: warning: move constructor initializes base class by calling a copy constructor [misc-move-constructor-init]
+  // CHECK-MESSAGES: 23:3: note: copy constructor being called
+  // CHECK-MESSAGES: 24:3: note: candidate move constructor here
+  D(D &) : B(RHS) {}
+};
+
+struct E : B {
+  E() : B() {}
+  E(const E ) : B(RHS) {}
+  E(E &) : B(move(RHS)) {} // ok
+};
+
+struct F {
+  C M;
+
+  F(F &&) : M(C()) {} // ok
+};
+
+struct G {
+  G() = default;
+  G(const G&) = default;
+  G(G&&) = delete;
+};
+
+struct H : G {
+  H() = default;
+  H(const H&) = default;
+  H(H &) : G(RHS) {} // ok
+};
+
+struct I {
+  I(const I &) = default; // suppresses move constructor creation
+};
+
+struct J : I {
+  J(J &) : I(RHS) {} // ok
+};
+
+struct K {}; // Has implicit copy and move constructors, is trivially copyable
+struct L : K {
+  L(L &) : K(RHS) {} // ok
+};
+
+struct M {
+  B Mem;
+  // CHECK-MESSAGES: :[[@LINE+1]]:16: warning: move constructor initializes class member by calling a copy constructor [misc-move-constructor-init]
+  M(M &) : Mem(RHS.Mem) {}
+};
+
+struct N {
+  B Mem;
+  N(N &) : Mem(move(RHS.Mem)) {}
+};
+
+struct Movable {
+  Movable(Movable &&) = default;
+  Movable(const Movable &) = default;
+  Movable =(const Movable &) = default;
+  ~Movable() {}
+};
+
+struct TriviallyCopyable {
+  TriviallyCopyable() = default;
+  TriviallyCopyable(TriviallyCopyable &&) = default;
+  TriviallyCopyable(const TriviallyCopyable &) = default;
+};
+
+struct Positive {
+  Positive(Movable M) : M_(M) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:28: warning: value argument can be moved to avoid copy 

[PATCH] D13319: Eliminate __llvm_profile_register calls

2015-09-30 Thread David Li via cfe-commits
davidxl created this revision.
davidxl added reviewers: bogner, rsmith.
davidxl added subscribers: cfe-commits, llvm-commits.
Herald added subscribers: srhines, danalbert, tberghammer.

With PGO, the instrumented binary needs to dump __llvm_prf_data, 
__llvm_prf_cnts, and __llvm_prf_names data sections. The runtime needs to 
figure out the start and end addresses of the sections. The way it is 
implemented for Linux is emit function calls during start up time to register 
the __llvm_profile_data variables created for the functions, and runtime 
library tracks the start and end.  On Darwin, special section symbol is used so 
this is avoided.

This is not only inefficient, but also wastes lots of space in text.

This patch proposes using linker script to solve the problem.  The changes in 
clang FE is basically refactoring. The core changes are in 
projects/compiler_rt/profile and llvm.

http://reviews.llvm.org/D13319

Files:
  include/clang/Driver/ToolChain.h
  lib/Driver/SanitizerArgs.cpp
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains.cpp
  lib/Driver/ToolChains.h
  lib/Driver/Tools.cpp
  lib/Transforms/Instrumentation/InstrProfiling.cpp
  lib/profile/CMakeLists.txt
  lib/profile/InstrProfilingPlatformOther.c
  lib/profile/prf_data.x
  test/Instrumentation/InstrProfiling/platform.ll

Index: lib/profile/prf_data.x
===
--- /dev/null
+++ lib/profile/prf_data.x
@@ -0,0 +1,8 @@
+SECTIONS {
+  __llvm_prf_data_start = ADDR(__llvm_prf_data);
+  __llvm_prf_data_end = ADDR(__llvm_prf_data) + SIZEOF(__llvm_prf_data);
+  __llvm_prf_cnts_start = ADDR(__llvm_prf_cnts);
+  __llvm_prf_cnts_end = ADDR(__llvm_prf_cnts) + SIZEOF(__llvm_prf_cnts);
+  __llvm_prf_names_start = ADDR(__llvm_prf_names);
+  __llvm_prf_names_end = ADDR(__llvm_prf_names) + SIZEOF(__llvm_prf_names);
+};
Index: lib/profile/InstrProfilingPlatformOther.c
===
--- lib/profile/InstrProfilingPlatformOther.c
+++ lib/profile/InstrProfilingPlatformOther.c
@@ -12,63 +12,35 @@
 #if !defined(__APPLE__)
 #include 
 
-static const __llvm_profile_data *DataFirst = NULL;
-static const __llvm_profile_data *DataLast = NULL;
-static const char *NamesFirst = NULL;
-static const char *NamesLast = NULL;
-static uint64_t *CountersFirst = NULL;
-static uint64_t *CountersLast = NULL;
-
-/*!
- * \brief Register an instrumented function.
- *
- * Calls to this are emitted by clang with -fprofile-instr-generate.  Such
- * calls are only required (and only emitted) on targets where we haven't
- * implemented linker magic to find the bounds of the sections.
- */
-__attribute__((visibility("hidden")))
-void __llvm_profile_register_function(void *Data_) {
-  /* TODO: Only emit this function if we can't use linker magic. */
-  const __llvm_profile_data *Data = (__llvm_profile_data*)Data_;
-  if (!DataFirst) {
-DataFirst = Data;
-DataLast = Data + 1;
-NamesFirst = Data->Name;
-NamesLast = Data->Name + Data->NameSize;
-CountersFirst = Data->Counters;
-CountersLast = Data->Counters + Data->NumCounters;
-return;
-  }
-
-#define UPDATE_FIRST(First, New) \
-  First = New < First ? New : First
-  UPDATE_FIRST(DataFirst, Data);
-  UPDATE_FIRST(NamesFirst, Data->Name);
-  UPDATE_FIRST(CountersFirst, Data->Counters);
-#undef UPDATE_FIRST
-
-#define UPDATE_LAST(Last, New) \
-  Last = New > Last ? New : Last
-  UPDATE_LAST(DataLast, Data + 1);
-  UPDATE_LAST(NamesLast, Data->Name + Data->NameSize);
-  UPDATE_LAST(CountersLast, Data->Counters + Data->NumCounters);
-#undef UPDATE_LAST
-}
+extern __llvm_profile_data __llvm_prf_data_start;
+extern __llvm_profile_data __llvm_prf_data_end;
+extern uint64_t __llvm_prf_cnts_start;
+extern uint64_t __llvm_prf_cnts_end;
+extern char __llvm_prf_names_start;
+extern char __llvm_prf_names_end;
 
 __attribute__((visibility("hidden")))
 const __llvm_profile_data *__llvm_profile_begin_data(void) {
-  return DataFirst;
+  return &__llvm_prf_data_start;
 }
 __attribute__((visibility("hidden")))
 const __llvm_profile_data *__llvm_profile_end_data(void) {
-  return DataLast;
+  return &__llvm_prf_data_end;
+}
+__attribute__((visibility("hidden"))) const char *__llvm_profile_begin_names(
+void) {
+  return &__llvm_prf_names_start;
+}
+__attribute__((visibility("hidden"))) const char *__llvm_profile_end_names(
+void) {
+  return &__llvm_prf_names_end;
+}
+__attribute__((visibility("hidden"))) uint64_t *__llvm_profile_begin_counters(
+void) {
+  return &__llvm_prf_cnts_start;
+}
+__attribute__((visibility("hidden"))) uint64_t *__llvm_profile_end_counters(
+void) {
+  return &__llvm_prf_cnts_end;
 }
-__attribute__((visibility("hidden")))
-const char *__llvm_profile_begin_names(void) { return NamesFirst; }
-__attribute__((visibility("hidden")))
-const char *__llvm_profile_end_names(void) { return NamesLast; }
-__attribute__((visibility("hidden")))
-uint64_t *__llvm_profile_begin_counters(void) { 

Re: [PATCH] D13157: Teach -Wtautological-overlap-compare about enums

2015-09-30 Thread Richard Trieu via cfe-commits
rtrieu accepted this revision.
rtrieu added a comment.

Fix the comments, then it should be ready to commit.



Comment at: lib/Analysis/CFG.cpp:49
@@ +48,3 @@
+tryNormalizeBinaryOperator(const BinaryOperator *B) {
+  auto TryTransformToIntOrEnumConstant = [](const Expr *E) -> const Expr * {
+E = E->IgnoreParens();

Why is this a lambda instead of a helper function?


Comment at: lib/Analysis/CFG.cpp:88
@@ +87,3 @@
+/// or DeclRefExprs (that have decls of type EnumConstantDecl)
+static bool areExprTypesCompatible(const Expr *A, const Expr *B) {
+  // User intent isn't clear if they're mixing int literals with enum

Use E1 and E2 instead of A and B to match the naming of decls below.


Comment at: lib/Analysis/CFG.cpp:98
@@ +97,3 @@
+
+  // Currently we're only given EnumConstantDecls or IntegerLiterals
+  auto *C1 = cast(cast(A)->getDecl());

Change the comment to note that IntegerLiterals are handled above and only 
EnumConstantDecls are expected beyond this point.


Comment at: lib/Analysis/CFG.cpp:99-104
@@ +98,8 @@
+  // Currently we're only given EnumConstantDecls or IntegerLiterals
+  auto *C1 = cast(cast(A)->getDecl());
+  auto *C2 = cast(cast(B)->getDecl());
+
+  const TagDecl *E1 = TagDecl::castFromDeclContext(C1->getDeclContext());
+  const TagDecl *E2 = TagDecl::castFromDeclContext(C2->getDeclContext());
+  return E1 == E2;
+}

There's a few extra casts in here, plus some blind conversions between types.  
Add your assumptions for the types in asserts.  Also, DeclContext should use 
cast<> to get to Decl types.  I recommend the following:

```
  assert(isa(E1) && isa(E2));
  auto *Decl1 = cast(E1)->getDecl();
  auto *Decl2 = cast(E2)->getDecl();

  assert(isa(Decl1) && isa(Decl2));
  const DeclContext *DC1 = Decl1->getDeclContext();
  const DeclContext *DC2 = Decl2->getDeclContext();

  assert(isa(DC1) && isa(DC2));
  return DC1 == DC2;

```


http://reviews.llvm.org/D13157



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


[PATCH] D13313: [clang-tidy] new check misc-no-reinterpret-cast

2015-09-30 Thread Matthias Gehre via cfe-commits
mgehre created this revision.
mgehre added a subscriber: cfe-commits.

This check flags all uses of reinterpret_cast in C++ code.

Use of these casts can violate type safety and cause the program to
access a variable that is actually of type X to be accessed as if it
were of an unrelated type Z.

This rule is part of the "Type safety" profile of the C++ Core
Guidelines, see
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-type1-dont-use-reinterpret_cast.

http://reviews.llvm.org/D13313

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/NoReinterpretCastCheck.cpp
  clang-tidy/misc/NoReinterpretCastCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-no-reinterpret-cast.rst
  test/clang-tidy/misc-no-reinterpret-cast.cpp

Index: test/clang-tidy/misc-no-reinterpret-cast.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-no-reinterpret-cast.cpp
@@ -0,0 +1,6 @@
+// RUN: %python %S/check_clang_tidy.py %s misc-no-reinterpret-cast %t
+
+int i = 0;
+void* j;
+void f() { j = reinterpret_cast(i); }
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use reinterpret_cast (C++ Core Guidelines, rule Type.1) [misc-no-reinterpret-cast]
\ No newline at end of file
Index: docs/clang-tidy/checks/misc-no-reinterpret-cast.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-no-reinterpret-cast.rst
@@ -0,0 +1,9 @@
+misc-no-reinterpret-cast
+
+
+This check flags all uses of reinterpret_cast in C++ code.
+
+Use of these casts can violate type safety and cause the program to access a variable that is actually of type X to be accessed as if it were of an unrelated type Z.
+
+This rule is part of the "Type safety" profile of the C++ Core Guidelines, see
+https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-type1-dont-use-reinterpret_cast.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -31,6 +31,7 @@
misc-macro-repeated-side-effects
misc-move-constructor-init
misc-new-delete-overloads
+   misc-no-reinterpret-cast
misc-noexcept-move-constructor
misc-non-copyable-objects
misc-sizeof-container
Index: clang-tidy/misc/NoReinterpretCastCheck.h
===
--- /dev/null
+++ clang-tidy/misc/NoReinterpretCastCheck.h
@@ -0,0 +1,33 @@
+//===--- NoReinterpretCastCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NO_REINTERPRETCAST_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NO_REINTERPRETCAST_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+
+/// Flags all occurrences of reinterpret_cast 
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/misc-no-reinterpret-cast.html
+class NoReinterpretCastCheck : public ClangTidyCheck {
+public:
+  NoReinterpretCastCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+};
+
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NO_REINTERPRETCAST_H
Index: clang-tidy/misc/NoReinterpretCastCheck.cpp
===
--- /dev/null
+++ clang-tidy/misc/NoReinterpretCastCheck.cpp
@@ -0,0 +1,34 @@
+//===--- NoReinterpretCastCheck.cpp - clang-tidy--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "NoReinterpretCastCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+
+void NoReinterpretCastCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus)
+return;
+  
+  Finder->addMatcher(cxxReinterpretCastExpr().bind("cast"), this);
+}
+
+void NoReinterpretCastCheck::check(const MatchFinder::MatchResult ) {
+  const auto *MatchedCast =
+  Result.Nodes.getNodeAs("cast");
+  diag(MatchedCast->getOperatorLoc(),
+   "do not use reinterpret_cast (C++ Core Guidelines, rule Type.1)");
+}
+
+} 

Re: [PATCH] D12774: createUniqueFile() is documented to create the file in the temporary directory unless it's supplied an absolute path.Make sure the output filepath supplied to createUniqueFile() in

2015-09-30 Thread Vedant Kumar via cfe-commits
vsk added a comment.

LGTM, thanks.


http://reviews.llvm.org/D12774



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


r248953 - [Sema] Don't crash when friending an unqualified templated constructor

2015-09-30 Thread David Majnemer via cfe-commits
Author: majnemer
Date: Wed Sep 30 17:07:43 2015
New Revision: 248953

URL: http://llvm.org/viewvc/llvm-project?rev=248953=rev
Log:
[Sema] Don't crash when friending an unqualified templated constructor

Unqualified templated constructors cannot be friended and our lack of a
diagnostic led to violated invariants.  Instead, raise a diagnostic when
processing the friend declaration.

This fixes PR20251.

Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CXX/class/class.friend/p1.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=248953=248952=248953=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Sep 30 17:07:43 2015
@@ -12689,15 +12689,31 @@ NamedDecl *Sema::ActOnFriendFunctionDecl
 DC = CurContext;
 assert(isa(DC) && "friend declaration not in class?");
   }
-  
+
   if (!DC->isRecord()) {
+int DiagArg = -1;
+switch (D.getName().getKind()) {
+case UnqualifiedId::IK_ConstructorTemplateId:
+case UnqualifiedId::IK_ConstructorName:
+  DiagArg = 0;
+  break;
+case UnqualifiedId::IK_DestructorName:
+  DiagArg = 1;
+  break;
+case UnqualifiedId::IK_ConversionFunctionId:
+  DiagArg = 2;
+  break;
+case UnqualifiedId::IK_Identifier:
+case UnqualifiedId::IK_ImplicitSelfParam:
+case UnqualifiedId::IK_LiteralOperatorId:
+case UnqualifiedId::IK_OperatorFunctionId:
+case UnqualifiedId::IK_TemplateId:
+  break;
+  llvm_unreachable("Didn't expect this kind of unqualified-id!");
+}
 // This implies that it has to be an operator or function.
-if (D.getName().getKind() == UnqualifiedId::IK_ConstructorName ||
-D.getName().getKind() == UnqualifiedId::IK_DestructorName ||
-D.getName().getKind() == UnqualifiedId::IK_ConversionFunctionId) {
-  Diag(Loc, diag::err_introducing_special_friend) <<
-(D.getName().getKind() == UnqualifiedId::IK_ConstructorName ? 0 :
- D.getName().getKind() == UnqualifiedId::IK_DestructorName ? 1 : 2);
+if (DiagArg >= 0) {
+  Diag(Loc, diag::err_introducing_special_friend) << DiagArg;
   return nullptr;
 }
   }

Modified: cfe/trunk/test/CXX/class/class.friend/p1.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class/class.friend/p1.cpp?rev=248953=248952=248953=diff
==
--- cfe/trunk/test/CXX/class/class.friend/p1.cpp (original)
+++ cfe/trunk/test/CXX/class/class.friend/p1.cpp Wed Sep 30 17:07:43 2015
@@ -79,3 +79,9 @@ class PreDeclared;
 int myoperation(float f) {
   return (int) f;
 }
+
+template 
+class B {
+  template 
+  friend B() {} // expected-error {{must use a qualified name when 
declaring a constructor as a friend}}
+};


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


Re: [PATCH] D13319: Eliminate __llvm_profile_register calls

2015-09-30 Thread Richard Smith via cfe-commits
rsmith added a comment.

Clang changes LGTM.


http://reviews.llvm.org/D13319



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


Re: [PATCH] D13317: clang_Cursor_getMangling shouldn't mangle if the declaration isn't mangled

2015-09-30 Thread Richard Smith via cfe-commits
rsmith added a subscriber: rsmith.


Comment at: tools/libclang/CIndex.cpp:3895
@@ +3894,3 @@
+  // Don't mangle if we don't need to.
+  if (!MC->shouldMangleCXXName(ND))
+return cxstring::createEmpty();

You should use `shouldMangleDeclName` here instead; this will do the wrong 
thing if there's an asm label on the declaration (where presumably we do want 
to list a "mangling").


Comment at: tools/libclang/CIndex.cpp:3896
@@ +3895,3 @@
+  if (!MC->shouldMangleCXXName(ND))
+return cxstring::createEmpty();
+

In this case, we should presumably use the decl's identifier as the "mangled 
name" rather than just giving up; there could still be backend mangling that 
applies here, and we should be producing the final symbol name here. In fact, 
`MangleContext::mangleName` should probably be changed to produce the 
identifier name in this case, rather than handling it here.


http://reviews.llvm.org/D13317



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


r248975 - Fix printing of parameterized Objective-C interfaces.

2015-09-30 Thread Bob Wilson via cfe-commits
Author: bwilson
Date: Wed Sep 30 19:53:13 2015
New Revision: 248975

URL: http://llvm.org/viewvc/llvm-project?rev=248975=rev
Log:
Fix printing of parameterized Objective-C interfaces.

This change was accidentally omitted from Doug's change in r241541.

Modified:
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/test/Index/comment-objc-parameterized-classes.m

Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=248975=248974=248975=diff
==
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Wed Sep 30 19:53:13 2015
@@ -1088,7 +1088,7 @@ void DeclPrinter::VisitObjCInterfaceDecl
   }
   
   if (SID)
-Out << " : " << OID->getSuperClass()->getName();
+Out << " : " << QualType(OID->getSuperClassType(), 0).getAsString(Policy);
 
   // Protocols?
   const ObjCList  = OID->getReferencedProtocols();

Modified: cfe/trunk/test/Index/comment-objc-parameterized-classes.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/comment-objc-parameterized-classes.m?rev=248975=248974=248975=diff
==
--- cfe/trunk/test/Index/comment-objc-parameterized-classes.m (original)
+++ cfe/trunk/test/Index/comment-objc-parameterized-classes.m Wed Sep 30 
19:53:13 2015
@@ -17,3 +17,8 @@
 /// A
 @interface A<__covariant T : id, U : NSObject *> : NSObject
 @end
+
+// CHECK: @interface AA : A id, NSObject *
+/// AA
+@interface AA : A
+@end


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


r248977 - createUniqueFile() is documented to create the file in the temporary directory unless it's supplied an absolute path.

2015-09-30 Thread Cameron Esfahani via cfe-commits
Author: dirty
Date: Wed Sep 30 20:24:59 2015
New Revision: 248977

URL: http://llvm.org/viewvc/llvm-project?rev=248977=rev
Log:
createUniqueFile() is documented to create the file in the temporary directory 
unless it's supplied an absolute path.

Make sure the output filepath supplied to createUniqueFile() in 
HTMLDiagnostics::ReportDiag() is absolute.

Summary: Make sure the output filepath supplied to createUniqueFile() in 
HTMLDiagnostics::ReportDiag() is absolute.

Reviewers: rsmith, akyrtzi

Subscribers: cfe-commits

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

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

Modified: cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp?rev=248977=248976=248977=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp Wed Sep 30 20:24:59 
2015
@@ -281,7 +281,12 @@ void HTMLDiagnostics::ReportDiag(const P
 
   if (!AnalyzerOpts.shouldWriteStableReportFilename()) {
   llvm::sys::path::append(Model, Directory, "report-%%.html");
-
+  if (std::error_code EC =
+  llvm::sys::fs::make_absolute(Model)) {
+  llvm::errs() << "warning: could not make '" << Model
+   << "' absolute: " << EC.message() << '\n';
+return;
+  }
   if (std::error_code EC =
   llvm::sys::fs::createUniqueFile(Model, FD, ResultPath)) {
   llvm::errs() << "warning: could not create file in '" << Directory


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


Re: [PATCH] D11207: Enable recognition of __declspec for PS4

2015-09-30 Thread Warren Ristow via cfe-commits
wristow abandoned this revision.
wristow added a comment.

This has been superseded by http://reviews.llvm.org/D13322.


http://reviews.llvm.org/D11207



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


Re: [PATCH] D13324: Fix the SSE4 byte sign extension in a cleaner way, and more thoroughly test that our intrinsics behave the same under -fsigned-char and -funsigned-char.

2015-09-30 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/D13324



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


[PATCH] D13322: Add -f[no-]declspec to control recognition of __declspec as a keyword

2015-09-30 Thread Warren Ristow via cfe-commits
wristow created this revision.
wristow added reviewers: aaron.ballman, ygao, alexr, silvas, compnerd, 
cfe-commits.

In versions of clang prior to r238238, __declspec was recognized as a
keyword in all modes.  It was then changed to only be enabled when
Microsoft or Borland extensions were enabled (and for CUDA, as a
temporary measure).  There is a desire to support __declspec in
Playstation code, and possibly other environments.  This commit adds a
command-line switch to allow explicit enabling/disabling of the
recognition of __declspec as a keyword.  Recognition is enabled by
default in Microsoft, Borland, CUDA and PS4 environments, and disabled
in all other environments.

This proposed change supersedes D11207.  In D11207, it was proposed that a new 
language-dialect be added to Clang, to support extensions used in the 
Playstation environment.  The primary motivation of that language-dialect was 
the recognition of __declspec as a keyword.  After consideration, it was 
suggested that adding a switch to independently control the recognition of 
__declspec was an alternative to consider.  See:

http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20150713/133310.html

As a result of that, this proposed change adds a switch to control the 
recognition of __declspec.

Can someone review, and if OK then commit this patch for me, please?

-Warren Ristow
SN Systems - Sony Computer Entertainment Group

http://reviews.llvm.org/D13322

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Basic/TokenKinds.def
  include/clang/Driver/Options.td
  include/clang/Parse/Parser.h
  lib/Basic/IdentifierTable.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseDecl.cpp
  test/Lexer/keywords_test.c
  test/Lexer/keywords_test.cpp

Index: test/Lexer/keywords_test.cpp
===
--- test/Lexer/keywords_test.cpp
+++ test/Lexer/keywords_test.cpp
@@ -1,6 +1,15 @@
 // RUN: %clang_cc1 -std=c++03 -fsyntax-only %s
 // RUN: %clang_cc1 -std=c++11 -DCXX11 -fsyntax-only %s
 // RUN: %clang_cc1 -std=c++14 -fconcepts-ts -DCXX11 -DCONCEPTS -fsyntax-only %s
+// RUN: %clang_cc1 -std=c++03 -fdeclspec -DDECLSPEC -fsyntax-only %s
+// RUN: %clang_cc1 -std=c++03 -fms-extensions -DDECLSPEC -fsyntax-only %s
+// RUN: %clang_cc1 -std=c++03 -fborland-extensions -DDECLSPEC -fsyntax-only %s
+// RUN: %clang_cc1 -std=c++03 -fms-extensions -fno-declspec -fsyntax-only %s
+// RUN: %clang_cc1 -std=c++03 -fborland-extensions -fno-declspec -fsyntax-only %s
+// RUN: %clang -std=c++03 -target i686-windows-msvc -DDECLSPEC -fsyntax-only %s
+// RUN: %clang -std=c++03 -target x86_64-scei-ps4 -DDECLSPEC -fsyntax-only %s
+// RUN: %clang -std=c++03 -target i686-windows-msvc -fno-declspec -fsyntax-only %s
+// RUN: %clang -std=c++03 -target x86_64-scei-ps4 -fno-declspec -fsyntax-only %s
 
 #define IS_KEYWORD(NAME) _Static_assert(!__is_identifier(NAME), #NAME)
 #define NOT_KEYWORD(NAME) _Static_assert(__is_identifier(NAME), #NAME)
@@ -12,6 +21,12 @@
 #define CONCEPTS_KEYWORD(NAME)  NOT_KEYWORD(NAME)
 #endif
 
+#ifdef DECLSPEC
+#define DECLSPEC_KEYWORD(NAME)  IS_KEYWORD(NAME)
+#else
+#define DECLSPEC_KEYWORD(NAME)  NOT_KEYWORD(NAME)
+#endif
+
 #ifdef CXX11
 #define CXX11_KEYWORD(NAME)  IS_KEYWORD(NAME)
 #define CXX11_TYPE(NAME) IS_TYPE(NAME)
@@ -38,6 +53,9 @@
 CONCEPTS_KEYWORD(concept);
 CONCEPTS_KEYWORD(requires);
 
+// __declspec extension
+DECLSPEC_KEYWORD(__declspec);
+
 // Clang extension
 IS_KEYWORD(__char16_t);
 IS_TYPE(__char16_t);
Index: test/Lexer/keywords_test.c
===
--- test/Lexer/keywords_test.c
+++ test/Lexer/keywords_test.c
@@ -9,6 +9,10 @@
 
 // RUN: %clang_cc1 -std=c99 -fms-extensions -E %s -o - \
 // RUN: | FileCheck --check-prefix=CHECK-MS-KEYWORDS %s
+// RUN: %clang_cc1 -std=c99 -fdeclspec -E %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-DECLSPEC-KEYWORD %s
+// RUN: %clang_cc1 -std=c99 -fms-extensions -fno-declspec -E %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-MS-KEYWORDS-WITHOUT-DECLSPEC %s
 
 void f() {
 // CHECK-NONE: int asm
@@ -22,8 +26,19 @@
 
 // CHECK-NONE: no_ms_wchar
 // CHECK-MS-KEYWORDS: has_ms_wchar
+// CHECK-MS-KEYWORDS-WITHOUT-DECLSPEC: has_ms_wchar
 #if __is_identifier(__wchar_t)
 void no_ms_wchar();
 #else
 void has_ms_wchar();
 #endif
+
+// CHECK-NONE: no_declspec
+// CHECK-MS-KEYWORDS: has_declspec
+// CHECK-MS-KEYWORDS-WITHOUT-DECLSPEC: no_declspec
+// CHECK-DECLSPEC-KEYWORD: has_declspec
+#if __is_identifier(__declspec)
+void no_declspec();
+#else
+void has_declspec();
+#endif
Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -532,9 +532,7 @@
 /// extended-decl-modifier extended-decl-modifier-seq
 void Parser::ParseMicrosoftDeclSpecs(ParsedAttributes ,
  SourceLocation *End) {
-  

Re: [PATCH] D13319: Eliminate __llvm_profile_register calls

2015-09-30 Thread David Li via cfe-commits
davidxl abandoned this revision.
davidxl added a comment.

Will split the patch into 3.


http://reviews.llvm.org/D13319



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


r248982 - Decorating virtual functions load with invariant.load

2015-09-30 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Wed Sep 30 22:50:41 2015
New Revision: 248982

URL: http://llvm.org/viewvc/llvm-project?rev=248982=rev
Log:
Decorating virtual functions load with invariant.load

http://reviews.llvm.org/D13279

Modified:
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=248982=248981=248982=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Wed Sep 30 22:50:41 2015
@@ -1609,7 +1609,16 @@ llvm::Value *ItaniumCXXABI::getVirtualFu
   uint64_t VTableIndex = 
CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
   llvm::Value *VFuncPtr =
   CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-  return CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+  auto *Inst = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+  // It's safe to add "invariant.load" without -fstrict-vtable-pointers, but it
+  // would not help in devirtualization.
+  if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+  CGM.getCodeGenOpts().StrictVTablePointers)
+Inst->setMetadata(llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+  return Inst;
 }
 
 llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(

Modified: cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp?rev=248982=248981=248982=diff
==
--- cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp Wed Sep 30 22:50:41 
2015
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - 
-fstrict-vtable-pointers -O1 | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@ namespace VirtualNoreturn {
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} align 8, !invariant.load 
![[EMPTY_NODE:[0-9]]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}


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


Re: [PATCH] D13319: Eliminate __llvm_profile_register calls

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


Comment at: lib/Driver/ToolChains.cpp:2191-2193
@@ +2190,5 @@
+
+  SmallString<128> Path(getDriver().ResourceDir);
+  llvm::sys::path::append(Path, "prf_data.x");
+  CmdArgs.push_back(Args.MakeArgString(Path));
+  return true;

Please add a driver test for this change.


http://reviews.llvm.org/D13319



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


r248974 - Module debugging: Emit Objective-C interfaces in their module scope when

2015-09-30 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Wed Sep 30 19:48:51 2015
New Revision: 248974

URL: http://llvm.org/viewvc/llvm-project?rev=248974=rev
Log:
Module debugging: Emit Objective-C interfaces in their module scope when
building a clang module.

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/test/Modules/ModuleDebugInfo.m

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=248974=248973=248974=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Sep 30 19:48:51 2015
@@ -1743,9 +1743,10 @@ llvm::DIType *CGDebugInfo::CreateTypeDef
   if (ID->getImplementation())
 Flags |= llvm::DINode::FlagObjcClassComplete;
 
+  llvm::DIScope *Mod = getParentModuleOrNull(ID);
   llvm::DICompositeType *RealDecl = DBuilder.createStructType(
-  Unit, ID->getName(), DefUnit, Line, Size, Align, Flags, nullptr,
-  llvm::DINodeArray(), RuntimeLang);
+  Mod ? Mod : Unit, ID->getName(), DefUnit, Line, Size, Align, Flags,
+  nullptr, llvm::DINodeArray(), RuntimeLang);
 
   QualType QTy(Ty, 0);
   TypeCache[QTy.getAsOpaquePtr()].reset(RealDecl);

Modified: cfe/trunk/test/Modules/ModuleDebugInfo.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/ModuleDebugInfo.m?rev=248974=248973=248974=diff
==
--- cfe/trunk/test/Modules/ModuleDebugInfo.m (original)
+++ cfe/trunk/test/Modules/ModuleDebugInfo.m Wed Sep 30 19:48:51 2015
@@ -7,6 +7,7 @@
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -x objective-c -fmodules -fmodule-format=obj 
-fimplicit-module-maps -DMODULES -fmodules-cache-path=%t %s -I %S/Inputs -I %t 
-emit-llvm -o %t.ll -mllvm -debug-only=pchcontainer &>%t-mod.ll
 // RUN: cat %t-mod.ll | FileCheck %s
+// RUN: cat %t-mod.ll | FileCheck %s --check-prefix=MODULE-CHECK
 
 // PCH:
 // RUN: %clang_cc1 -x objective-c -emit-pch -fmodule-format=obj -I %S/Inputs 
-o %t.pch %S/Inputs/DebugObjC.h -mllvm -debug-only=pchcontainer &>%t-pch.ll
@@ -18,9 +19,15 @@
 
 // CHECK: distinct !DICompileUnit(language: DW_LANG_ObjC
 // CHECK-SAME:isOptimized: false,
-// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "ObjCClass"
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type,
+// CHECK-SAME: name: "ObjCClass",
 // CHECK: !DIObjCProperty(name: "property",
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "ivar"
 // CHECK: !DISubprogram(name: "+[ObjCClass classMethod]"
 // CHECK: !DISubprogram(name: "-[ObjCClass instanceMethodWithInt:]"
 // CHECK: !DISubprogram(name: "-[ categoryMethod]"
+
+// MODULE-CHECK: !DICompositeType(tag: DW_TAG_structure_type,
+// MODULE-CHECK-SAME: name: "ObjCClass",
+// MODULE-CHECK-SAME: scope: ![[MODULE:[0-9]+]],
+// MODULE-CHECK: ![[MODULE]] = !DIModule(scope: null, name: "DebugObjC"


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


Re: [PATCH] D13318: Add a utility function to add target information to a command line

2015-09-30 Thread Eric Christopher via cfe-commits
echristo added a subscriber: echristo.
echristo added a comment.

This seems a little odd, could you explain in a bit more detail? Me not
understanding I imagine. :)

-eric


http://reviews.llvm.org/D13318



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


[PATCH] D13325: Fix crash in codegen on casting to `bool &`.

2015-09-30 Thread Alexey Bataev via cfe-commits
ABataev created this revision.
ABataev added a reviewer: rjmccall.
ABataev added a subscriber: cfe-commits.

Currently codegen crashes trying to emit casting to `bool &`. It happens 
because `bool` type is converted to `i1` and later then lvalue for reference is 
converted to `i1*`. But when codegen tries to load this lvalue it crashes 
trying to load value from this `i1*`.

http://reviews.llvm.org/D13325

Files:
  lib/CodeGen/CGExprScalar.cpp
  test/CodeGenCXX/cast-to-ref-bool.cpp

Index: lib/CodeGen/CGExprScalar.cpp
===
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -1369,7 +1369,7 @@
   case CK_LValueBitCast:
   case CK_ObjCObjectLValueCast: {
 Address Addr = EmitLValue(E).getAddress();
-Addr = Builder.CreateElementBitCast(Addr, ConvertType(DestTy));
+Addr = Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(DestTy));
 LValue LV = CGF.MakeAddrLValue(Addr, DestTy);
 return EmitLoadOfLValue(LV, CE->getExprLoc());
   }
Index: test/CodeGenCXX/cast-to-ref-bool.cpp
===
--- test/CodeGenCXX/cast-to-ref-bool.cpp
+++ test/CodeGenCXX/cast-to-ref-bool.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck 
%s
+
+// CHECK-LABEL: main
+int main(int argc, char **argv) {
+  // CHECK: load i8, i8* %
+  // CHECK-NEXT: trunc i8 %{{.+}} to i1
+  bool b = (bool &)argv[argc][1];
+  return b;
+}


Index: lib/CodeGen/CGExprScalar.cpp
===
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -1369,7 +1369,7 @@
   case CK_LValueBitCast:
   case CK_ObjCObjectLValueCast: {
 Address Addr = EmitLValue(E).getAddress();
-Addr = Builder.CreateElementBitCast(Addr, ConvertType(DestTy));
+Addr = Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(DestTy));
 LValue LV = CGF.MakeAddrLValue(Addr, DestTy);
 return EmitLoadOfLValue(LV, CE->getExprLoc());
   }
Index: test/CodeGenCXX/cast-to-ref-bool.cpp
===
--- test/CodeGenCXX/cast-to-ref-bool.cpp
+++ test/CodeGenCXX/cast-to-ref-bool.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck %s
+
+// CHECK-LABEL: main
+int main(int argc, char **argv) {
+  // CHECK: load i8, i8* %
+  // CHECK-NEXT: trunc i8 %{{.+}} to i1
+  bool b = (bool &)argv[argc][1];
+  return b;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13319: Eliminate __llvm_profile_register calls

2015-09-30 Thread Justin Bogner via cfe-commits
David Li  writes:
> davidxl created this revision.
> davidxl added reviewers: bogner, rsmith.
> davidxl added subscribers: cfe-commits, llvm-commits.
> Herald added subscribers: srhines, danalbert, tberghammer.
>
> With PGO, the instrumented binary needs to dump __llvm_prf_data,
> __llvm_prf_cnts, and __llvm_prf_names data sections. The runtime needs
> to figure out the start and end addresses of the sections. The way it
> is implemented for Linux is emit function calls during start up time
> to register the __llvm_profile_data variables created for the
> functions, and runtime library tracks the start and end.  On Darwin,
> special section symbol is used so this is avoided.
>
> This is not only inefficient, but also wastes lots of space in text.
>
> This patch proposes using linker script to solve the problem.  The
> changes in clang FE is basically refactoring. The core changes are in
> projects/compiler_rt/profile and llvm.

I think Phabricator did something really funny with these patches - I
see one patch that seems to reference files from three repos. Obviously
this can't be applied or anything. Can you attach the individual patches
please?

I haven't really looked at the changes, but at a high level, you'll want
to add an InstrProfilingPlatformLinux.c or InstrProfilingPlatformGnu.c
or something rather than changing *Other.c - we want that to be
available as a fall back on other platforms.

> http://reviews.llvm.org/D13319
>
> Files:
>   include/clang/Driver/ToolChain.h
>   lib/Driver/SanitizerArgs.cpp
>   lib/Driver/ToolChain.cpp
>   lib/Driver/ToolChains.cpp
>   lib/Driver/ToolChains.h
>   lib/Driver/Tools.cpp
>   lib/Transforms/Instrumentation/InstrProfiling.cpp
>   lib/profile/CMakeLists.txt
>   lib/profile/InstrProfilingPlatformOther.c
>   lib/profile/prf_data.x
>   test/Instrumentation/InstrProfiling/platform.ll
>
> Index: lib/profile/prf_data.x
> ===
> --- /dev/null
> +++ lib/profile/prf_data.x
> @@ -0,0 +1,8 @@
> +SECTIONS {
> +  __llvm_prf_data_start = ADDR(__llvm_prf_data);
> +  __llvm_prf_data_end = ADDR(__llvm_prf_data) + SIZEOF(__llvm_prf_data);
> +  __llvm_prf_cnts_start = ADDR(__llvm_prf_cnts);
> +  __llvm_prf_cnts_end = ADDR(__llvm_prf_cnts) + SIZEOF(__llvm_prf_cnts);
> +  __llvm_prf_names_start = ADDR(__llvm_prf_names);
> +  __llvm_prf_names_end = ADDR(__llvm_prf_names) + SIZEOF(__llvm_prf_names);
> +};
> Index: lib/profile/InstrProfilingPlatformOther.c
> ===
> --- lib/profile/InstrProfilingPlatformOther.c
> +++ lib/profile/InstrProfilingPlatformOther.c
> @@ -12,63 +12,35 @@
>  #if !defined(__APPLE__)
>  #include 
>  
> -static const __llvm_profile_data *DataFirst = NULL;
> -static const __llvm_profile_data *DataLast = NULL;
> -static const char *NamesFirst = NULL;
> -static const char *NamesLast = NULL;
> -static uint64_t *CountersFirst = NULL;
> -static uint64_t *CountersLast = NULL;
> -
> -/*!
> - * \brief Register an instrumented function.
> - *
> - * Calls to this are emitted by clang with -fprofile-instr-generate.  Such
> - * calls are only required (and only emitted) on targets where we haven't
> - * implemented linker magic to find the bounds of the sections.
> - */
> -__attribute__((visibility("hidden")))
> -void __llvm_profile_register_function(void *Data_) {
> -  /* TODO: Only emit this function if we can't use linker magic. */
> -  const __llvm_profile_data *Data = (__llvm_profile_data*)Data_;
> -  if (!DataFirst) {
> -DataFirst = Data;
> -DataLast = Data + 1;
> -NamesFirst = Data->Name;
> -NamesLast = Data->Name + Data->NameSize;
> -CountersFirst = Data->Counters;
> -CountersLast = Data->Counters + Data->NumCounters;
> -return;
> -  }
> -
> -#define UPDATE_FIRST(First, New) \
> -  First = New < First ? New : First
> -  UPDATE_FIRST(DataFirst, Data);
> -  UPDATE_FIRST(NamesFirst, Data->Name);
> -  UPDATE_FIRST(CountersFirst, Data->Counters);
> -#undef UPDATE_FIRST
> -
> -#define UPDATE_LAST(Last, New) \
> -  Last = New > Last ? New : Last
> -  UPDATE_LAST(DataLast, Data + 1);
> -  UPDATE_LAST(NamesLast, Data->Name + Data->NameSize);
> -  UPDATE_LAST(CountersLast, Data->Counters + Data->NumCounters);
> -#undef UPDATE_LAST
> -}
> +extern __llvm_profile_data __llvm_prf_data_start;
> +extern __llvm_profile_data __llvm_prf_data_end;
> +extern uint64_t __llvm_prf_cnts_start;
> +extern uint64_t __llvm_prf_cnts_end;
> +extern char __llvm_prf_names_start;
> +extern char __llvm_prf_names_end;
>  
>  __attribute__((visibility("hidden")))
>  const __llvm_profile_data *__llvm_profile_begin_data(void) {
> -  return DataFirst;
> +  return &__llvm_prf_data_start;
>  }
>  __attribute__((visibility("hidden")))
>  const __llvm_profile_data *__llvm_profile_end_data(void) {
> -  return DataLast;
> +  return &__llvm_prf_data_end;
> +}
> +__attribute__((visibility("hidden"))) const char *__llvm_profile_begin_names(
> +   

r248980 - Patch over a really horrible bug in our vector builtins that showed up

2015-09-30 Thread Chandler Carruth via cfe-commits
Author: chandlerc
Date: Wed Sep 30 21:21:34 2015
New Revision: 248980

URL: http://llvm.org/viewvc/llvm-project?rev=248980=rev
Log:
Patch over a really horrible bug in our vector builtins that showed up
recently when we started using direct conversion to model sign
extension. The __v16qi type we use for SSE v16i8 vectors is defined in
terms of 'char' which may or may not be signed! This causes us to
generate pmovsx and pmovzx depending on the setting of -funsigned-char.

This patch just forms an explicitly signed type and uses that to
formulate the sign extension. While this gets the correct behavior
(which we now verify with the enhanced test) this is just the tip of the
ice berg. Now that I know what to look for, I have found errors of this
sort *throughout* our vector code. Fortunately, this is the only
specific place where I know of users actively having their code
miscompiled by Clang due to this, so I'm keeping the fix for those users
minimal and targeted.

I'll be sending a proper email for discussion of how to fix these
systematically, what the implications are, and just how widely broken
this is... From what I can tell, we have never shipped a correct set of
builtin headers for x86 when users rely on -funsigned-char. Oops.

Modified:
cfe/trunk/lib/Headers/smmintrin.h
cfe/trunk/test/CodeGen/sse41-builtins.c

Modified: cfe/trunk/lib/Headers/smmintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/smmintrin.h?rev=248980=248979=248980=diff
==
--- cfe/trunk/lib/Headers/smmintrin.h (original)
+++ cfe/trunk/lib/Headers/smmintrin.h Wed Sep 30 21:21:34 2015
@@ -286,19 +286,34 @@ _mm_cmpeq_epi64(__m128i __V1, __m128i __
 static __inline__ __m128i __DEFAULT_FN_ATTRS
 _mm_cvtepi8_epi16(__m128i __V)
 {
-  return 
(__m128i)__builtin_convertvector(__builtin_shufflevector((__v16qi)__V, 
(__v16qi)__V, 0, 1, 2, 3, 4, 5, 6, 7), __v8hi);
+  /* We need a local definitively signed typedef similar to __v16qi even in the
+   * presence of __UNSIGNED_CHAR__.
+   * FIXME: __v16qi should almost certainly be definitively signed.
+   */
+  typedef signed char __signed_v16qi __attribute__((__vector_size__(16)));
+  return 
(__m128i)__builtin_convertvector(__builtin_shufflevector((__signed_v16qi)__V, 
(__signed_v16qi)__V, 0, 1, 2, 3, 4, 5, 6, 7), __v8hi);
 }
 
 static __inline__ __m128i __DEFAULT_FN_ATTRS
 _mm_cvtepi8_epi32(__m128i __V)
 {
-  return 
(__m128i)__builtin_convertvector(__builtin_shufflevector((__v16qi)__V, 
(__v16qi)__V, 0, 1, 2, 3), __v4si);
+  /* We need a local definitively signed typedef similar to __v16qi even in the
+   * presence of __UNSIGNED_CHAR__.
+   * FIXME: __v16qi should almost certainly be definitively signed.
+   */
+  typedef signed char __signed_v16qi __attribute__((__vector_size__(16)));
+  return 
(__m128i)__builtin_convertvector(__builtin_shufflevector((__signed_v16qi)__V, 
(__signed_v16qi)__V, 0, 1, 2, 3), __v4si);
 }
 
 static __inline__ __m128i __DEFAULT_FN_ATTRS
 _mm_cvtepi8_epi64(__m128i __V)
 {
-  return 
(__m128i)__builtin_convertvector(__builtin_shufflevector((__v16qi)__V, 
(__v16qi)__V, 0, 1), __v2di);
+  /* We need a local definitively signed typedef similar to __v16qi even in the
+   * presence of __UNSIGNED_CHAR__.
+   * FIXME: __v16qi should almost certainly be definitively signed.
+   */
+  typedef signed char __signed_v16qi __attribute__((__vector_size__(16)));
+  return 
(__m128i)__builtin_convertvector(__builtin_shufflevector((__signed_v16qi)__V, 
(__signed_v16qi)__V, 0, 1), __v2di);
 }
 
 static __inline__ __m128i __DEFAULT_FN_ATTRS

Modified: cfe/trunk/test/CodeGen/sse41-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/sse41-builtins.c?rev=248980=248979=248980=diff
==
--- cfe/trunk/test/CodeGen/sse41-builtins.c (original)
+++ cfe/trunk/test/CodeGen/sse41-builtins.c Wed Sep 30 21:21:34 2015
@@ -1,6 +1,8 @@
 // REQUIRES: x86-registered-target
 // RUN: %clang_cc1 %s -O0 -triple=x86_64-apple-darwin -target-feature +sse4.1 
-emit-llvm -o - -Werror | FileCheck %s
+// RUN: %clang_cc1 %s -O0 -triple=x86_64-apple-darwin -target-feature +sse4.1 
-fno-signed-char -emit-llvm -o - -Werror | FileCheck %s
 // RUN: %clang_cc1 %s -O0 -triple=x86_64-apple-darwin -target-feature +sse4.1 
-S -o - -Werror | FileCheck %s --check-prefix=CHECK-ASM
+// RUN: %clang_cc1 %s -O0 -triple=x86_64-apple-darwin -target-feature +sse4.1 
-fno-signed-char -S -o - -Werror | FileCheck %s --check-prefix=CHECK-ASM
 
 // Don't include mm_malloc.h, it's system specific.
 #define __MM_MALLOC_H


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


[PATCH] D13324: Fix the SSE4 byte sign extension in a cleaner way, and more thoroughly test that our intrinsics behave the same under -fsigned-char and -funsigned-char.

2015-09-30 Thread Chandler Carruth via cfe-commits
chandlerc created this revision.
chandlerc added a reviewer: rsmith.
chandlerc added a subscriber: cfe-commits.

This further testing uncovered that AVX-2 has a broken cmpgt for 8-bit
elements, and has for a long time. This is fixed in the same way as
SSE4 handles the case.

The other ISA extensions currently work correctly because they use
specific instruction intrinsics. As soon as they are rewritten in terms
of generic IR, they will need to add these special casts. I've added the
necessary testing to catch this however, so we shouldn't have to chase
it down again.

I considered changing the core typedef to be signed, but that seems like
a bad idea. Notably, it would be an ABI break if anyone is reaching into
the innards of the intrinsic headers and passing __v16qi on an API
boundary. I can't be completely confident that this wouldn't happen due
to a macro expanding in a lambda, etc., so it seems much better to leave
it alone. It also matches GCC's behavior exactly.

A fun side note is that for both GCC and Clang, -funsigned-char really
does change the semantics of __v16qi. To observe this, consider:

  % cat x.cc
  #include 
  #include 

  int main() {
__v16qi a = { 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
__v16qi b = _mm_set1_epi8(-1);
std::cout << (int)(a / b)[0] << ", " << (int)(a / b)[1] << '\n';
  }
  % clang++ -o x x.cc && ./x
  -1, 1
  % clang++ -funsigned-char -o x x.cc && ./x
  0, 1

However, while this may be surprising, both Clang and GCC agree.

http://reviews.llvm.org/D13324

Files:
  lib/Headers/avx2intrin.h
  lib/Headers/avxintrin.h
  lib/Headers/emmintrin.h
  lib/Headers/smmintrin.h
  test/CodeGen/avx2-builtins.c
  test/CodeGen/avx512bw-builtins.c
  test/CodeGen/avx512vlbw-builtins.c
  test/CodeGen/mmx-builtins.c
  test/CodeGen/sse42-builtins.c

Index: test/CodeGen/sse42-builtins.c
===
--- test/CodeGen/sse42-builtins.c
+++ test/CodeGen/sse42-builtins.c
@@ -1,12 +1,35 @@
 // REQUIRES: x86-registered-target
 // RUN: %clang_cc1 %s -O0 -triple=x86_64-apple-darwin -target-feature +sse4.2 -emit-llvm -o - -Werror | FileCheck %s
+// RUN: %clang_cc1 %s -O0 -triple=x86_64-apple-darwin -target-feature +sse4.2 -fno-signed-char -emit-llvm -o - -Werror | FileCheck %s
 // RUN: %clang_cc1 %s -O0 -triple=x86_64-apple-darwin -target-feature +sse4.2 -S -o - -Werror | FileCheck %s --check-prefix=CHECK-ASM
+// RUN: %clang_cc1 %s -O0 -triple=x86_64-apple-darwin -target-feature +sse4.2 -fno-signed-char -S -o - -Werror | FileCheck %s --check-prefix=CHECK-ASM
 
 // Don't include mm_malloc.h, it's system specific.
 #define __MM_MALLOC_H
 
 #include 
 
+__m128i test_mm_cmpgt_epi8(__m128i A, __m128i B) {
+  // CHECK-LABEL: test_mm_cmpgt_epi8
+  // CHECK: icmp sgt <16 x i8>
+  // CHECK-ASM: pcmpgtb %xmm{{.*}}, %xmm{{.*}}
+  return _mm_cmpgt_epi8(A, B);
+}
+
+__m128i test_mm_cmpgt_epi16(__m128i A, __m128i B) {
+  // CHECK-LABEL: test_mm_cmpgt_epi16
+  // CHECK: icmp sgt <8 x i16>
+  // CHECK-ASM: pcmpgtw %xmm{{.*}}, %xmm{{.*}}
+  return _mm_cmpgt_epi16(A, B);
+}
+
+__m128i test_mm_cmpgt_epi32(__m128i A, __m128i B) {
+  // CHECK-LABEL: test_mm_cmpgt_epi32
+  // CHECK: icmp sgt <4 x i32>
+  // CHECK-ASM: pcmpgtd %xmm{{.*}}, %xmm{{.*}}
+  return _mm_cmpgt_epi32(A, B);
+}
+
 __m128i test_mm_cmpgt_epi64(__m128i A, __m128i B) {
   // CHECK-LABEL: test_mm_cmpgt_epi64
   // CHECK: icmp sgt <2 x i64>
Index: test/CodeGen/mmx-builtins.c
===
--- test/CodeGen/mmx-builtins.c
+++ test/CodeGen/mmx-builtins.c
@@ -1,5 +1,6 @@
 // REQUIRES: x86-registered-target
 // RUN: %clang_cc1 %s -O3 -triple=x86_64-apple-darwin -target-feature +ssse3 -S -o - | FileCheck %s
+// RUN: %clang_cc1 %s -O3 -triple=x86_64-apple-darwin -target-feature +ssse3 -fno-signed-char -S -o - | FileCheck %s
 
 // FIXME: Disable inclusion of mm_malloc.h, our current implementation is broken
 // on win32 since we don't generally know how to find errno.h.
Index: test/CodeGen/avx512vlbw-builtins.c
===
--- test/CodeGen/avx512vlbw-builtins.c
+++ test/CodeGen/avx512vlbw-builtins.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -O0 -triple=x86_64-apple-darwin -ffreestanding -target-feature +avx512bw -target-feature +avx512vl -emit-llvm -o - -Werror | FileCheck %s
+// RUN: %clang_cc1 %s -O0 -triple=x86_64-apple-darwin -ffreestanding -target-feature +avx512bw -target-feature +avx512vl -fno-signed-char -emit-llvm -o - -Werror | FileCheck %s
 
 #include 
 
Index: test/CodeGen/avx512bw-builtins.c
===
--- test/CodeGen/avx512bw-builtins.c
+++ test/CodeGen/avx512bw-builtins.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -O0 -triple=x86_64-apple-darwin -ffreestanding -target-feature +avx512bw -emit-llvm -o - -Werror | FileCheck %s
+// RUN: %clang_cc1 %s -O0 -triple=x86_64-apple-darwin -ffreestanding -target-feature 

Re: r248980 - Patch over a really horrible bug in our vector builtins that showed up

2015-09-30 Thread Chandler Carruth via cfe-commits
Note that http://reviews.llvm.org/D13324 is the promised improved fix here,
awaiting review. =]
On Wed, Sep 30, 2015 at 7:23 PM Chandler Carruth via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: chandlerc
> Date: Wed Sep 30 21:21:34 2015
> New Revision: 248980
>
> URL: http://llvm.org/viewvc/llvm-project?rev=248980=rev
> Log:
> Patch over a really horrible bug in our vector builtins that showed up
> recently when we started using direct conversion to model sign
> extension. The __v16qi type we use for SSE v16i8 vectors is defined in
> terms of 'char' which may or may not be signed! This causes us to
> generate pmovsx and pmovzx depending on the setting of -funsigned-char.
>
> This patch just forms an explicitly signed type and uses that to
> formulate the sign extension. While this gets the correct behavior
> (which we now verify with the enhanced test) this is just the tip of the
> ice berg. Now that I know what to look for, I have found errors of this
> sort *throughout* our vector code. Fortunately, this is the only
> specific place where I know of users actively having their code
> miscompiled by Clang due to this, so I'm keeping the fix for those users
> minimal and targeted.
>
> I'll be sending a proper email for discussion of how to fix these
> systematically, what the implications are, and just how widely broken
> this is... From what I can tell, we have never shipped a correct set of
> builtin headers for x86 when users rely on -funsigned-char. Oops.
>
> Modified:
> cfe/trunk/lib/Headers/smmintrin.h
> cfe/trunk/test/CodeGen/sse41-builtins.c
>
> Modified: cfe/trunk/lib/Headers/smmintrin.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/smmintrin.h?rev=248980=248979=248980=diff
>
> ==
> --- cfe/trunk/lib/Headers/smmintrin.h (original)
> +++ cfe/trunk/lib/Headers/smmintrin.h Wed Sep 30 21:21:34 2015
> @@ -286,19 +286,34 @@ _mm_cmpeq_epi64(__m128i __V1, __m128i __
>  static __inline__ __m128i __DEFAULT_FN_ATTRS
>  _mm_cvtepi8_epi16(__m128i __V)
>  {
> -  return
> (__m128i)__builtin_convertvector(__builtin_shufflevector((__v16qi)__V,
> (__v16qi)__V, 0, 1, 2, 3, 4, 5, 6, 7), __v8hi);
> +  /* We need a local definitively signed typedef similar to __v16qi even
> in the
> +   * presence of __UNSIGNED_CHAR__.
> +   * FIXME: __v16qi should almost certainly be definitively signed.
> +   */
> +  typedef signed char __signed_v16qi __attribute__((__vector_size__(16)));
> +  return
> (__m128i)__builtin_convertvector(__builtin_shufflevector((__signed_v16qi)__V,
> (__signed_v16qi)__V, 0, 1, 2, 3, 4, 5, 6, 7), __v8hi);
>  }
>
>  static __inline__ __m128i __DEFAULT_FN_ATTRS
>  _mm_cvtepi8_epi32(__m128i __V)
>  {
> -  return
> (__m128i)__builtin_convertvector(__builtin_shufflevector((__v16qi)__V,
> (__v16qi)__V, 0, 1, 2, 3), __v4si);
> +  /* We need a local definitively signed typedef similar to __v16qi even
> in the
> +   * presence of __UNSIGNED_CHAR__.
> +   * FIXME: __v16qi should almost certainly be definitively signed.
> +   */
> +  typedef signed char __signed_v16qi __attribute__((__vector_size__(16)));
> +  return
> (__m128i)__builtin_convertvector(__builtin_shufflevector((__signed_v16qi)__V,
> (__signed_v16qi)__V, 0, 1, 2, 3), __v4si);
>  }
>
>  static __inline__ __m128i __DEFAULT_FN_ATTRS
>  _mm_cvtepi8_epi64(__m128i __V)
>  {
> -  return
> (__m128i)__builtin_convertvector(__builtin_shufflevector((__v16qi)__V,
> (__v16qi)__V, 0, 1), __v2di);
> +  /* We need a local definitively signed typedef similar to __v16qi even
> in the
> +   * presence of __UNSIGNED_CHAR__.
> +   * FIXME: __v16qi should almost certainly be definitively signed.
> +   */
> +  typedef signed char __signed_v16qi __attribute__((__vector_size__(16)));
> +  return
> (__m128i)__builtin_convertvector(__builtin_shufflevector((__signed_v16qi)__V,
> (__signed_v16qi)__V, 0, 1), __v2di);
>  }
>
>  static __inline__ __m128i __DEFAULT_FN_ATTRS
>
> Modified: cfe/trunk/test/CodeGen/sse41-builtins.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/sse41-builtins.c?rev=248980=248979=248980=diff
>
> ==
> --- cfe/trunk/test/CodeGen/sse41-builtins.c (original)
> +++ cfe/trunk/test/CodeGen/sse41-builtins.c Wed Sep 30 21:21:34 2015
> @@ -1,6 +1,8 @@
>  // REQUIRES: x86-registered-target
>  // RUN: %clang_cc1 %s -O0 -triple=x86_64-apple-darwin -target-feature
> +sse4.1 -emit-llvm -o - -Werror | FileCheck %s
> +// RUN: %clang_cc1 %s -O0 -triple=x86_64-apple-darwin -target-feature
> +sse4.1 -fno-signed-char -emit-llvm -o - -Werror | FileCheck %s
>  // RUN: %clang_cc1 %s -O0 -triple=x86_64-apple-darwin -target-feature
> +sse4.1 -S -o - -Werror | FileCheck %s --check-prefix=CHECK-ASM
> +// RUN: %clang_cc1 %s -O0 -triple=x86_64-apple-darwin -target-feature
> +sse4.1 -fno-signed-char -S -o - -Werror | FileCheck %s
> --check-prefix=CHECK-ASM
>
>  // Don't 

Re: [PATCH] D12979: Avoid inlining in exception handling context

2015-09-30 Thread Jun Bum Lim via cfe-commits
junbuml added a comment.

In this clang change, I added a state flag (bool IsColdRegion) in 
CodeGenFunction and set/reset the flag in EmitCXXThrowExpr(). In EmitCall(), 
the NoInline attribute would be added if IsColdRegion is true. As of now, this 
change only handles throw statements because I don't have any data / test for 
catch blocks yet.


http://reviews.llvm.org/D12979



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


Re: [PATCH] D12979: Avoid inlining in exception handling context

2015-09-30 Thread Jun Bum Lim via cfe-commits
junbuml edited subscribers, added: cfe-commits; removed: llvm-commits.
junbuml updated this revision to Diff 36107.

http://reviews.llvm.org/D12979

Files:
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGException.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGenCXX/throw-expressions.cpp

Index: test/CodeGenCXX/throw-expressions.cpp
===
--- test/CodeGenCXX/throw-expressions.cpp
+++ test/CodeGenCXX/throw-expressions.cpp
@@ -112,3 +112,14 @@
   // CHECK: ret i32* @val
   return cond ? val : ((throw "foo"));
 }
+
+// CHECK-LABEL: _Z5test9v
+// CHECK: invoke void @_ZN2EHC1Ev(%class.EH* %0) [[ATTR_NUM:#[0-9]+]]
+// CHECK: attributes [[ATTR_NUM]] = { cold noinline }
+class EH {
+public :
+  EH();
+};
+void test9() {
+  throw EH();
+}
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -283,6 +283,11 @@
   /// finally block or filter expression.
   bool IsOutlinedSEHHelper;
 
+  // True if the current insertion point is in cold regions (e.g., exception
+  // handling regions). As of now, this flag is ture only when handling throw
+  // statement.
+  bool IsColdRegion;
+
   const CodeGen::CGBlockInfo *BlockInfo;
   llvm::Value *BlockPointer;
 
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -44,7 +44,7 @@
   CapturedStmtInfo(nullptr),
   SanOpts(CGM.getLangOpts().Sanitize), IsSanitizerScope(false),
   CurFuncIsThunk(false), AutoreleaseResult(false), SawAsmBlock(false),
-  IsOutlinedSEHHelper(false),
+  IsOutlinedSEHHelper(false), IsColdRegion(false),
   BlockInfo(nullptr), BlockPointer(nullptr),
   LambdaThisCaptureField(nullptr), NormalCleanupDest(nullptr),
   NextCleanupDestIndex(1), FirstBlockInfo(nullptr), EHResumeBlock(nullptr),
Index: lib/CodeGen/CGException.cpp
===
--- lib/CodeGen/CGException.cpp
+++ lib/CodeGen/CGException.cpp
@@ -400,6 +400,11 @@
 
 void CodeGenFunction::EmitCXXThrowExpr(const CXXThrowExpr *E,
bool KeepInsertionPoint) {
+  // While handling the throw statement, inform that the insertion point is in
+  // cold regions so that we could perform cold region specific IR generation.
+  // For example, the NoInline attribute could be added in CallSites in throw
+  // statements.
+  IsColdRegion = true;
   if (const Expr *SubExpr = E->getSubExpr()) {
 QualType ThrowType = SubExpr->getType();
 if (ThrowType->isObjCObjectPointerType()) {
@@ -417,6 +422,9 @@
   // to leave ourselves at a valid insertion point.
   if (KeepInsertionPoint)
 EmitBlock(createBasicBlock("throw.cont"));
+
+  IsColdRegion = false;
+  // FIXME: Similarly, we could set IsColdRegion for catch blocks in ExitCXXTryStmt().
 }
 
 void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -3464,6 +3464,27 @@
 Attrs.addAttribute(getLLVMContext(), llvm::AttributeSet::FunctionIndex,
llvm::Attribute::NoInline);
 
+  // As of now, IsColdRegion is true only while handling throw statements.
+  // It might be reasonable to avoid inlining CallSites invoked in exception
+  // handling context so that we can reduce code size blow-up in EH regions
+  // as well as indirectly increase inline opportunities for unwinding
+  // functions containing exception handling code.
+  if (IsColdRegion) {
+// FIXME: We add both NoInline and Cold because the inline cold-threshold
+// is not tuned yet (r200898). As of now, considering that CallSites in
+// exception handling regions are very cold is not unreasonable even without
+// profiling, and avoiding inlining in exception handling region may not have
+// significant impacts on performance unless a program execution logic
+// really depends on exception handling flows. However, when the inline
+// cold-threshold is tuned, we may need to remove NoInline here so that we
+// can allow a trivial constructor to be inlined.
+Attrs =
+Attrs.addAttribute(getLLVMContext(), llvm::AttributeSet::FunctionIndex,
+   llvm::Attribute::NoInline);
+Attrs =
+Attrs.addAttribute(getLLVMContext(), llvm::AttributeSet::FunctionIndex,
+   llvm::Attribute::Cold);
+  }
   CS.setAttributes(Attrs);
   CS.setCallingConv(static_cast(CallingConv));
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D13326: [PGO]: Eliminate __llvm_profile_register calls for Linux (clang changes)

2015-09-30 Thread David Li via cfe-commits
davidxl created this revision.
davidxl added reviewers: rsmith, bogner.
davidxl added a subscriber: cfe-commits.
Herald added subscribers: srhines, danalbert, tberghammer.

This is the patch-1. Driver tests are also added. See 
http://reviews.llvm.org/D13319 for description.

http://reviews.llvm.org/D13326

Files:
  include/clang/Driver/ToolChain.h
  lib/Driver/SanitizerArgs.cpp
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains.cpp
  lib/Driver/ToolChains.h
  lib/Driver/Tools.cpp
  test/Driver/instrprof-ld.c

Index: test/Driver/instrprof-ld.c
===
--- test/Driver/instrprof-ld.c
+++ test/Driver/instrprof-ld.c
@@ -7,34 +7,42 @@
 // RUN:   | FileCheck --check-prefix=CHECK-LINUX-I386 %s
 //
 // CHECK-LINUX-I386: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-LINUX-I386: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-i386.a" {{.*}} "-lc"
+// CHECK-LINUX-I386:
+// "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-i386.a"
+// "{{.*}}/Inputs/resource_dir{{/|}}prf_data.x" {{.*}} "-lc"
+// CHECK-LINUX-I38 : "{{.*}}/Inputs/resource_dir{{/|}}prf_data.x"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-unknown-linux -fprofile-instr-generate \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LINUX-X86-64 %s
 //
 // CHECK-LINUX-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-LINUX-X86-64: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-x86_64.a" {{.*}} "-lc"
+// CHECK-LINUX-X86-64:
+// "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-x86_64.a"
+// "{{.*}}/Inputs/resource_dir{{/|}}prf_data.x" {{.*}} "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-unknown-linux -fprofile-instr-generate -nostdlib \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LINUX-NOSTDLIB-X86-64 %s
 //
 // CHECK-LINUX-NOSTDLIB-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-LINUX-NOSTDLIB-X86-64: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-x86_64.a"
+// CHECK-LINUX-NOSTDLIB-X86-64:
+// "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-x86_64.a"
+// "{{.*}}/Inputs/resource_dir{{/|}}prf_data.x"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-unknown-freebsd -fprofile-instr-generate \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
 // RUN: --sysroot=%S/Inputs/basic_freebsd64_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-FREEBSD-X86-64 %s
 //
 // CHECK-FREEBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-FREEBSD-X86-64: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
+// CHECK-FREEBSD-X86-64:
+// "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -shared \
@@ -44,7 +52,9 @@
 // RUN:   | FileCheck --check-prefix=CHECK-LINUX-I386-SHARED %s
 //
 // CHECK-LINUX-I386-SHARED: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-LINUX-I386-SHARED: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-i386.a" {{.*}} "-lc"
+// CHECK-LINUX-I386-SHARED:
+// "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-i386.a"
+// {{.*}} "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -shared \
@@ -54,7 +64,9 @@
 // RUN:   | FileCheck --check-prefix=CHECK-LINUX-X86-64-SHARED %s
 //
 // CHECK-LINUX-X86-64-SHARED: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-LINUX-X86-64-SHARED: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-x86_64.a" {{.*}} "-lc"
+// CHECK-LINUX-X86-64-SHARED:
+// "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-x86_64.a"
+// {{.*}} "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -shared \
@@ -64,28 +76,32 @@
 // RUN:   | FileCheck --check-prefix=CHECK-FREEBSD-X86-64-SHARED %s
 //
 // CHECK-FREEBSD-X86-64-SHARED: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-FREEBSD-X86-64-SHARED: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
+// CHECK-FREEBSD-X86-64-SHARED:
+// "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-apple-darwin14 -fprofile-instr-generate \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
 // 

Re: [PATCH] D13326: [PGO]: Eliminate __llvm_profile_register calls for Linux (clang changes)

2015-09-30 Thread David Li via cfe-commits
davidxl removed subscribers: tberghammer, danalbert, srhines.
davidxl updated this revision to Diff 36186.

http://reviews.llvm.org/D13326

Files:
  include/clang/Driver/ToolChain.h
  lib/Driver/SanitizerArgs.cpp
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains.cpp
  lib/Driver/ToolChains.h
  lib/Driver/Tools.cpp
  test/Driver/instrprof-ld.c

Index: test/Driver/instrprof-ld.c
===
--- test/Driver/instrprof-ld.c
+++ test/Driver/instrprof-ld.c
@@ -7,34 +7,41 @@
 // RUN:   | FileCheck --check-prefix=CHECK-LINUX-I386 %s
 //
 // CHECK-LINUX-I386: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-LINUX-I386: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-i386.a" {{.*}} "-lc"
+// CHECK-LINUX-I386:
+// "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-i386.a"
+// "{{.*}}/Inputs/resource_dir{{/|}}prf_data.x" {{.*}} "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-unknown-linux -fprofile-instr-generate \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LINUX-X86-64 %s
 //
 // CHECK-LINUX-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-LINUX-X86-64: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-x86_64.a" {{.*}} "-lc"
+// CHECK-LINUX-X86-64:
+// "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-x86_64.a"
+// "{{.*}}/Inputs/resource_dir{{/|}}prf_data.x" {{.*}} "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-unknown-linux -fprofile-instr-generate -nostdlib \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LINUX-NOSTDLIB-X86-64 %s
 //
 // CHECK-LINUX-NOSTDLIB-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-LINUX-NOSTDLIB-X86-64: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-x86_64.a"
+// CHECK-LINUX-NOSTDLIB-X86-64:
+// "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-x86_64.a"
+// "{{.*}}/Inputs/resource_dir{{/|}}prf_data.x"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-unknown-freebsd -fprofile-instr-generate \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
 // RUN: --sysroot=%S/Inputs/basic_freebsd64_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-FREEBSD-X86-64 %s
 //
 // CHECK-FREEBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-FREEBSD-X86-64: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
+// CHECK-FREEBSD-X86-64:
+// "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -shared \
@@ -44,7 +51,9 @@
 // RUN:   | FileCheck --check-prefix=CHECK-LINUX-I386-SHARED %s
 //
 // CHECK-LINUX-I386-SHARED: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-LINUX-I386-SHARED: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-i386.a" {{.*}} "-lc"
+// CHECK-LINUX-I386-SHARED:
+// "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-i386.a"
+// {{.*}} "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -shared \
@@ -54,7 +63,9 @@
 // RUN:   | FileCheck --check-prefix=CHECK-LINUX-X86-64-SHARED %s
 //
 // CHECK-LINUX-X86-64-SHARED: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-LINUX-X86-64-SHARED: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-x86_64.a" {{.*}} "-lc"
+// CHECK-LINUX-X86-64-SHARED:
+// "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-x86_64.a"
+// {{.*}} "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -shared \
@@ -64,28 +75,32 @@
 // RUN:   | FileCheck --check-prefix=CHECK-FREEBSD-X86-64-SHARED %s
 //
 // CHECK-FREEBSD-X86-64-SHARED: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-FREEBSD-X86-64-SHARED: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
+// CHECK-FREEBSD-X86-64-SHARED:
+// "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}freebsd{{/|}}libclang_rt.profile-x86_64.a"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-apple-darwin14 -fprofile-instr-generate \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
 // RUN:   | FileCheck --check-prefix=CHECK-DARWIN-X86-64 %s
 //
 // CHECK-DARWIN-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-DARWIN-X86-64: 

Re: [PATCH] D13249: Divide TraverseInitListExpr to a different function for each form.

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

+richard to tell us whether that comment is correct :)


http://reviews.llvm.org/D13249



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


RE: [PATCH] D13100: [mips] Separated mips specific -Wa options, so that they are not checked on other platforms.

2015-09-30 Thread Daniel Sanders via cfe-commits
Hi,

Sorry for the slow reply. I'm a bit behind on cfe-commits and it seems I 
dropped out of the CC list so it didn't land in my inbox.

Do you mean something like this?:
for (...) {
  ...

  switch (C.getDefaultToolChain().getArch()) {
  default:
break;
  case llvm::Triple::mips:
  case llvm::Triple::mipsel:
  case llvm::Triple::mips64:
  case llvm::Triple::mips64el:
if (Value == "--trap") {
  ...
  continue;
}
break;
  }

  if (Value == "-force_cpusubtype_ALL") {
...
continue;
  }

  ...

  D.Diag(diag::err_drv_unsupported_option_argument)
  << A->getOption().getName() << Value;
}

If so, that sounds good to me.
 
> -Original Message-
> From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf
> Of Joerg Sonnenberger via cfe-commits
> Sent: 24 September 2015 13:27
> To: cfe-commits@lists.llvm.org
> Subject: Re: [PATCH] D13100: [mips] Separated mips specific -Wa options, so
> that they are not checked on other platforms.
> 
> On Thu, Sep 24, 2015 at 10:22:29AM +, Daniel Sanders via cfe-commits
> wrote:
> > I'm thinking something like:
> 
> I think we really want to have an outer case, platform specific -Wa
> options are quite common. Only x86 is mostly getting by without them so
> far. I also think the switch is not that difficult to read.
> 
> Joerg
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13249: Divide TraverseInitListExpr to a different function for each form.

2015-09-30 Thread Manuel Klimek via cfe-commits
klimek added inline comments.


Comment at: include/clang/AST/RecursiveASTVisitor.h:2066-2089
@@ -2058,26 +2065,26 @@
 
-// InitListExpr is a tricky one, because we want to do all our work on
-// the syntactic form of the listexpr, but this method takes the
-// semantic form by default.  We can't use the macro helper because it
-// calls WalkUp*() on the semantic form, before our code can convert
-// to the syntactic form.
 template 
-bool RecursiveASTVisitor::TraverseInitListExpr(InitListExpr *S) {
+bool RecursiveASTVisitor::TraverseSyntacticInitListExpr(InitListExpr 
*S) {
   InitListExpr *Syn = S->isSemanticForm() ? S->getSyntacticForm() : S;
   if (Syn) {
 TRY_TO(WalkUpFromInitListExpr(Syn));
 // All we need are the default actions.  FIXME: use a helper function.
 for (Stmt *SubStmt : Syn->children()) {
   TRY_TO(TraverseStmt(SubStmt));
 }
   }
+  return true;
+}
+
+template 
+bool RecursiveASTVisitor::TraverseSemanticInitListExpr(InitListExpr 
*S) {
   InitListExpr *Sem = S->isSemanticForm() ? S : S->getSemanticForm();
   if (Sem) {
 TRY_TO(WalkUpFromInitListExpr(Sem));
 for (Stmt *SubStmt : Sem->children()) {
   TRY_TO(TraverseStmt(SubStmt));
 }
   }
   return true;
 }
 

Ok, I'd now pull out the first line of these functions into the 
TraverseInitListExpr, and then we only need one function here, right?


Comment at: include/clang/AST/RecursiveASTVisitor.h:2091-2095
@@ -2083,1 +2090,7 @@
 
+// InitListExpr is a tricky one, because we want to do all our work on
+// the syntactic form of the listexpr, but this method takes the
+// semantic form by default.  We can't use the macro helper because it
+// calls WalkUp*() on the semantic form, before our code can convert
+// to the syntactic form.
+//

I think we can remove this - I'm not sure it adds value.


http://reviews.llvm.org/D13249



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


Re: [PATCH] D12945: [PATCH] Add checker for objects that should not be value types

2015-09-30 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

In http://reviews.llvm.org/D12945#256509, @aaron.ballman wrote:

> I settled on "expression has opaque data structure type 'FILE'; type should 
> only be used as a pointer and not dereferenced" but we can tweak if that 
> still isn't quite right.


Seems good. Thank you!


http://reviews.llvm.org/D12945



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


r248905 - Fix FunctionParmPackExpr::Create() to take a ParmVarDecl* array.

2015-09-30 Thread James Y Knight via cfe-commits
Author: jyknight
Date: Wed Sep 30 09:04:23 2015
New Revision: 248905

URL: http://llvm.org/viewvc/llvm-project?rev=248905=rev
Log:
Fix FunctionParmPackExpr::Create() to take a ParmVarDecl* array.

FunctionParmPackExpr actually stores an array of ParmVarDecl* (and
accessors return that). But, the FunctionParmPackExpr::Create()
constructor accepted an array of Decl *s instead.

It was easy for this mismatch to occur without any obvious sign of
something wrong, since both the store and the access used independent
'reinterpet_cast(this+1)' calls.

Modified:
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/Sema/Template.h
cfe/trunk/lib/AST/ExprCXX.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=248905=248904=248905=diff
==
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Wed Sep 30 09:04:23 2015
@@ -3787,7 +3787,7 @@ class FunctionParmPackExpr : public Expr
 
   FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
SourceLocation NameLoc, unsigned NumParams,
-   Decl * const *Params);
+   ParmVarDecl *const *Params);
 
   friend class ASTReader;
   friend class ASTStmtReader;
@@ -3796,7 +3796,7 @@ public:
   static FunctionParmPackExpr *Create(const ASTContext , QualType T,
   ParmVarDecl *ParamPack,
   SourceLocation NameLoc,
-  ArrayRef Params);
+  ArrayRef Params);
   static FunctionParmPackExpr *CreateEmpty(const ASTContext ,
unsigned NumParams);
 

Modified: cfe/trunk/include/clang/Sema/Template.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Template.h?rev=248905=248904=248905=diff
==
--- cfe/trunk/include/clang/Sema/Template.h (original)
+++ cfe/trunk/include/clang/Sema/Template.h Wed Sep 30 09:04:23 2015
@@ -178,8 +178,8 @@ namespace clang {
   class LocalInstantiationScope {
   public:
 /// \brief A set of declarations.
-typedef SmallVector DeclArgumentPack;
-
+typedef SmallVector DeclArgumentPack;
+
   private:
 /// \brief Reference to the semantic analysis that is performing
 /// this template instantiation.
@@ -332,7 +332,7 @@ namespace clang {
 findInstantiationOf(const Decl *D);
 
 void InstantiatedLocal(const Decl *D, Decl *Inst);
-void InstantiatedLocalPackArg(const Decl *D, Decl *Inst);
+void InstantiatedLocalPackArg(const Decl *D, ParmVarDecl *Inst);
 void MakeInstantiatedLocalArgPack(const Decl *D);
 
 /// \brief Note that the given parameter pack has been partially 
substituted

Modified: cfe/trunk/lib/AST/ExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=248905=248904=248905=diff
==
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Wed Sep 30 09:04:23 2015
@@ -1468,19 +1468,19 @@ TemplateArgument SubstNonTypeTemplatePar
 FunctionParmPackExpr::FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
SourceLocation NameLoc,
unsigned NumParams,
-   Decl * const *Params)
-  : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary,
- true, true, true, true),
-ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) {
+   ParmVarDecl *const *Params)
+: Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary, true, true,
+   true, true),
+  ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) {
   if (Params)
 std::uninitialized_copy(Params, Params + NumParams,
-reinterpret_cast(this+1));
+reinterpret_cast(this + 1));
 }
 
 FunctionParmPackExpr *
 FunctionParmPackExpr::Create(const ASTContext , QualType T,
  ParmVarDecl *ParamPack, SourceLocation NameLoc,
- ArrayRef Params) {
+ ArrayRef Params) {
   return new (Context.Allocate(sizeof(FunctionParmPackExpr) +
sizeof(ParmVarDecl*) * Params.size()))
 FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data());

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=248905=248904=248905=diff

Re: [PATCH] D12945: [PATCH] Add checker for objects that should not be value types

2015-09-30 Thread Aaron Ballman via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

I settled on "expression has opaque data structure type 'FILE'; type should 
only be used as a pointer and not dereferenced" but we can tweak if that still 
isn't quite right.

Committed in r248907.

Thank you for the reviews!

~Aaron


http://reviews.llvm.org/D12945



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


[clang-tools-extra] r248907 - Adding a checker (misc-non-copyable-objects) that detects situations where a non-copyable C type is being dereferenced, such as FILE or pthread_mutex_t. Corresponds to th

2015-09-30 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Sep 30 09:09:38 2015
New Revision: 248907

URL: http://llvm.org/viewvc/llvm-project?rev=248907=rev
Log:
Adding a checker (misc-non-copyable-objects) that detects situations where a 
non-copyable C type is being dereferenced, such as FILE or pthread_mutex_t. 
Corresponds to the CERT C++ secure coding rule: 
https://www.securecoding.cert.org/confluence/display/c/FIO38-C.+Do+not+copy+a+FILE+object

Added:
clang-tools-extra/trunk/clang-tidy/misc/NonCopyableObjects.cpp
clang-tools-extra/trunk/clang-tidy/misc/NonCopyableObjects.h
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-non-copyable-objects.rst
clang-tools-extra/trunk/test/clang-tidy/misc-non-copyable-objects.c
clang-tools-extra/trunk/test/clang-tidy/misc-non-copyable-objects.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt?rev=248907=248906=248907=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt Wed Sep 30 09:09:38 
2015
@@ -13,6 +13,7 @@ add_clang_library(clangTidyMiscModule
   MoveConstructorInitCheck.cpp
   NewDeleteOverloadsCheck.cpp
   NoexceptMoveConstructorCheck.cpp
+  NonCopyableObjects.cpp
   SizeofContainerCheck.cpp
   StaticAssertCheck.cpp
   SwappedArgumentsCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp?rev=248907=248906=248907=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp Wed Sep 30 
09:09:38 2015
@@ -21,6 +21,7 @@
 #include "MoveConstructorInitCheck.h"
 #include "NewDeleteOverloadsCheck.h"
 #include "NoexceptMoveConstructorCheck.h"
+#include "NonCopyableObjects.h"
 #include "SizeofContainerCheck.h"
 #include "StaticAssertCheck.h"
 #include "SwappedArgumentsCheck.h"
@@ -58,8 +59,9 @@ public:
 "misc-new-delete-overloads");
 CheckFactories.registerCheck(
 "misc-noexcept-move-constructor");
-CheckFactories.registerCheck(
-"misc-sizeof-container");
+CheckFactories.registerCheck(
+"misc-non-copyable-objects");
+
CheckFactories.registerCheck("misc-sizeof-container");
 CheckFactories.registerCheck(
 "misc-static-assert");
 CheckFactories.registerCheck(

Added: clang-tools-extra/trunk/clang-tidy/misc/NonCopyableObjects.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/NonCopyableObjects.cpp?rev=248907=auto
==
--- clang-tools-extra/trunk/clang-tidy/misc/NonCopyableObjects.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/misc/NonCopyableObjects.cpp Wed Sep 30 
09:09:38 2015
@@ -0,0 +1,96 @@
+//===--- NonCopyableObjects.cpp - 
clang-tidy---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "NonCopyableObjects.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace {
+// FIXME: it would be good to make a list that is also user-configurable so 
that
+// users can add their own elements to the list. However, it may require some
+// extra thought since POSIX types and FILE types are usable in different ways.
+bool isPOSIXTypeName(StringRef ClassName) {
+  static const char *TypeNames[] = {
+"::pthread_cond_t",
+"::pthread_mutex_t",
+"pthread_cond_t",
+"pthread_mutex_t"
+  };
+  return std::binary_search(std::begin(TypeNames), std::end(TypeNames),
+ClassName);
+}
+
+bool isFILETypeName(StringRef ClassName) {
+  static const char *TypeNames[] = {
+"::FILE",
+"FILE",
+"std::FILE"
+  };
+  return std::binary_search(std::begin(TypeNames), std::end(TypeNames),
+ClassName);
+}
+
+AST_MATCHER(NamedDecl, isFILEType) {
+  return isFILETypeName(Node.getQualifiedNameAsString());
+}
+
+AST_MATCHER(NamedDecl, isPOSIXType) {
+  return isPOSIXTypeName(Node.getQualifiedNameAsString());
+}
+} // namespace
+
+namespace tidy {
+void NonCopyableObjectsCheck::registerMatchers(MatchFinder *Finder) {
+  // There are two ways to get 

r248906 - [OpenCL 2.0] Enable program scope variables, Section 6.5.1.

2015-09-30 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Wed Sep 30 09:08:20 2015
New Revision: 248906

URL: http://llvm.org/viewvc/llvm-project?rev=248906=rev
Log:
[OpenCL 2.0] Enable program scope variables, Section 6.5.1.

 - Remove virtual SC_OpenCLWorkGroupLocal storage type specifier
as it conflicts with static local variables now and prevents
diagnosing static local address space variables correctly.

 - Allow static local and global variables (OpenCL2.0 s6.8 and s6.5.1).

 - Improve diagnostics of allowed ASes for variables in different scopes:
(i) Global or static local variables have to be in global
or constant ASes (OpenCL1.2 s6.5, OpenCL2.0 s6.5.1);
(ii) Non-kernel function variables can't be declared in local
or constant ASes (OpenCL1.1 s6.5.2 and s6.5.3).

http://reviews.llvm.org/D13105


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/Specifiers.h
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Parser/opencl-storage-class.cl
cfe/trunk/test/SemaOpenCL/storageclass.cl
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=248906=248905=248906=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 30 09:08:20 
2015
@@ -7445,6 +7445,8 @@ def err_opencl_ptrptr_kernel_param : Err
   "kernel parameter cannot be declared as a pointer to a pointer">;
 def err_opencl_private_ptr_kernel_param : Error<
   "kernel parameter cannot be declared as a pointer to the __private address 
space">;
+def err_opencl_non_kernel_variable : Error<
+  "non-kernel function variable cannot be declared in %0 address space">;
 def err_static_function_scope : Error<
   "variables in function scope cannot be declared static">;
 def err_opencl_bitfields : Error<
@@ -7472,7 +7474,7 @@ def err_sampler_argument_required : Erro
 def err_wrong_sampler_addressspace: Error<
   "sampler type cannot be used with the __local and __global address space 
qualifiers">;
 def err_opencl_global_invalid_addr_space : Error<
-  "global variables must have a constant address space qualifier">;
+  "program scope variable must reside in %0 address space">;
 def err_opencl_no_main : Error<"%select{function|kernel}0 cannot be called 
'main'">;
 def err_opencl_kernel_attr :
   Error<"attribute %0 can only be applied to a kernel function">;

Modified: cfe/trunk/include/clang/Basic/Specifiers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Specifiers.h?rev=248906=248905=248906=diff
==
--- cfe/trunk/include/clang/Basic/Specifiers.h (original)
+++ cfe/trunk/include/clang/Basic/Specifiers.h Wed Sep 30 09:08:20 2015
@@ -178,7 +178,6 @@ namespace clang {
 SC_PrivateExtern,
 
 // These are only legal on variables.
-SC_OpenCLWorkGroupLocal,
 SC_Auto,
 SC_Register
   };

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=248906=248905=248906=diff
==
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Wed Sep 30 09:08:20 2015
@@ -1749,7 +1749,6 @@ const char *VarDecl::getStorageClassSpec
   case SC_None: break;
   case SC_Auto: return "auto";
   case SC_Extern:   return "extern";
-  case SC_OpenCLWorkGroupLocal: return "<>";
   case SC_PrivateExtern:return "__private_extern__";
   case SC_Register: return "register";
   case SC_Static:   return "static";

Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=248906=248905=248906=diff
==
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Wed Sep 30 09:08:20 2015
@@ -416,7 +416,7 @@ void DeclPrinter::VisitFunctionDecl(Func
 case SC_Extern: Out << "extern "; break;
 case SC_Static: Out << "static "; break;
 case SC_PrivateExtern: Out << "__private_extern__ "; break;
-case SC_Auto: case SC_Register: case SC_OpenCLWorkGroupLocal:
+case SC_Auto: case SC_Register:
   llvm_unreachable("invalid for functions");
 }
 

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=248906=248905=248906=diff
==
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Wed 

Re: [PATCH] D13100: [mips] Separated mips specific -Wa options, so that they are not checked on other platforms.

2015-09-30 Thread Joerg Sonnenberger via cfe-commits
On Wed, Sep 30, 2015 at 02:19:58PM +, Daniel Sanders via cfe-commits wrote:
> Hi,
> 
> Sorry for the slow reply. I'm a bit behind on cfe-commits and it seems I 
> dropped out of the CC list so it didn't land in my inbox.
> 
> Do you mean something like this?:
>   for (...) {
> ...
> 
> switch (C.getDefaultToolChain().getArch()) {
> default:
>   break;
> case llvm::Triple::mips:
> case llvm::Triple::mipsel:
> case llvm::Triple::mips64:
> case llvm::Triple::mips64el:
>   if (Value == "--trap") {
> ...
> continue;
>   }
>   break;
> }
>   
> if (Value == "-force_cpusubtype_ALL") {
>   ...
>   continue;
> }
> 
> ...
> 
> D.Diag(diag::err_drv_unsupported_option_argument)
> << A->getOption().getName() << Value;
>   }
> 
> If so, that sounds good to me.

Correct.

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


Re: [PATCH] D12979: Avoid inlining in exception handling context

2015-09-30 Thread hfin...@anl.gov via cfe-commits
hfinkel added a comment.

You should start a new differential for this, so that you can get a clean 
summary e-mail with a description sent to cfe-commits. There's some overlap, 
but you'll also get potentially-different reviewers here.


http://reviews.llvm.org/D12979



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


Re: [PATCH] D12793: Three new overflow builtins with generic argument types

2015-09-30 Thread David Grayson via cfe-commits
DavidEGrayson updated this revision to Diff 36117.
DavidEGrayson added a comment.

I changed the patch in two ways: it now returns ExprError() is the third 
argument is wrong (for consistency with the other argument checking code).  I 
removed an outdated comment for EncompassingIntegerType.

Thanks for reviewing this, John!  I think it is finally ready to be committed.  
Please let me know if I have to do anything else to get it committed.

This patch is still based on 248284, which is from 8 days ago.  Hopefully it 
can still be committed cleanly.


http://reviews.llvm.org/D12793

Files:
  docs/LanguageExtensions.rst
  include/clang/Basic/Builtins.def
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CGBuiltin.cpp
  lib/Sema/SemaChecking.cpp
  test/CodeGen/builtins-overflow-error.c
  test/CodeGen/builtins-overflow.c

Index: test/CodeGen/builtins-overflow.c
===
--- test/CodeGen/builtins-overflow.c
+++ test/CodeGen/builtins-overflow.c
@@ -11,7 +11,159 @@
 extern int IntErrorCode;
 extern long LongErrorCode;
 extern long long LongLongErrorCode;
+void overflowed(void);
 
+unsigned test_add_overflow_uint_uint_uint(unsigned x, unsigned y) {
+  // CHECK: @test_add_overflow_uint_uint_uint
+  // CHECK-NOT: ext
+  // CHECK: [[S:%.+]] = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %{{.+}}, i32 %{{.+}})
+  // CHECK-DAG: [[Q:%.+]] = extractvalue { i32, i1 } [[S]], 0
+  // CHECK-DAG: [[C:%.+]] = extractvalue { i32, i1 } [[S]], 1
+  // CHECK: store i32 [[Q]], i32* %r
+  // CHECK: br i1 [[C]]
+  unsigned r;
+  if (__builtin_add_overflow(x, y, ))
+overflowed();
+  return r;
+}
+
+int test_add_overflow_int_int_int(int x, int y) {
+  // CHECK: @test_add_overflow_int_int_int
+  // CHECK-NOT: ext
+  // CHECK: [[S:%.+]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %{{.+}}, i32 %{{.+}})
+  // CHECK-DAG: [[C:%.+]] = extractvalue { i32, i1 } [[S]], 1
+  // CHECK-DAG: [[Q:%.+]] = extractvalue { i32, i1 } [[S]], 0
+  // CHECK: store i32 [[Q]], i32* %r
+  // CHECK: br i1 [[C]]
+  int r;
+  if (__builtin_add_overflow(x, y, ))
+overflowed();
+  return r;
+}
+
+unsigned test_sub_overflow_uint_uint_uint(unsigned x, unsigned y) {
+  // CHECK: @test_sub_overflow_uint_uint_uint
+  // CHECK-NOT: ext
+  // CHECK: [[S:%.+]] = call { i32, i1 } @llvm.usub.with.overflow.i32(i32 %{{.+}}, i32 %{{.+}})
+  // CHECK-DAG: [[Q:%.+]] = extractvalue { i32, i1 } [[S]], 0
+  // CHECK-DAG: [[C:%.+]] = extractvalue { i32, i1 } [[S]], 1
+  // CHECK: store i32 [[Q]], i32* %r
+  // CHECK: br i1 [[C]]
+  unsigned r;
+  if (__builtin_sub_overflow(x, y, ))
+overflowed();
+  return r;
+}
+
+int test_sub_overflow_int_int_int(int x, int y) {
+  // CHECK: @test_sub_overflow_int_int_int
+  // CHECK-NOT: ext
+  // CHECK: [[S:%.+]] = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 %{{.+}}, i32 %{{.+}})
+  // CHECK-DAG: [[C:%.+]] = extractvalue { i32, i1 } [[S]], 1
+  // CHECK-DAG: [[Q:%.+]] = extractvalue { i32, i1 } [[S]], 0
+  // CHECK: store i32 [[Q]], i32* %r
+  // CHECK: br i1 [[C]]
+  int r;
+  if (__builtin_sub_overflow(x, y, ))
+overflowed();
+  return r;
+}
+
+unsigned test_mul_overflow_uint_uint_uint(unsigned x, unsigned y) {
+  // CHECK: @test_mul_overflow_uint_uint_uint
+  // CHECK-NOT: ext
+  // CHECK: [[S:%.+]] = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %{{.+}}, i32 %{{.+}})
+  // CHECK-DAG: [[Q:%.+]] = extractvalue { i32, i1 } [[S]], 0
+  // CHECK-DAG: [[C:%.+]] = extractvalue { i32, i1 } [[S]], 1
+  // CHECK: store i32 [[Q]], i32* %r
+  // CHECK: br i1 [[C]]
+  unsigned r;
+  if (__builtin_mul_overflow(x, y, ))
+overflowed();
+  return r;
+}
+
+int test_mul_overflow_int_int_int(int x, int y) {
+  // CHECK: @test_mul_overflow_int_int_int
+  // CHECK-NOT: ext
+  // CHECK: [[S:%.+]] = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %{{.+}}, i32 %{{.+}})
+  // CHECK-DAG: [[C:%.+]] = extractvalue { i32, i1 } [[S]], 1
+  // CHECK-DAG: [[Q:%.+]] = extractvalue { i32, i1 } [[S]], 0
+  // CHECK: store i32 [[Q]], i32* %r
+  // CHECK: br i1 [[C]]
+  int r;
+  if (__builtin_mul_overflow(x, y, ))
+overflowed();
+  return r;
+}
+
+int test_add_overflow_uint_int_int(unsigned x, int y) {
+  // CHECK: @test_add_overflow_uint_int_int
+  // CHECK: [[XE:%.+]] = zext i32 %{{.+}} to i33
+  // CHECK: [[YE:%.+]] = sext i32 %{{.+}} to i33
+  // CHECK: [[S:%.+]] = call { i33, i1 } @llvm.sadd.with.overflow.i33(i33 [[XE]], i33 [[YE]])
+  // CHECK-DAG: [[Q:%.+]] = extractvalue { i33, i1 } [[S]], 0
+  // CHECK-DAG: [[C1:%.+]] = extractvalue { i33, i1 } [[S]], 1
+  // CHECK: [[QT:%.+]] = trunc i33 [[Q]] to i32
+  // CHECK: [[QTE:%.+]] = sext i32 [[QT]] to i33
+  // CHECK: [[C2:%.+]] = icmp ne i33 [[Q]], [[QTE]]
+  // CHECK: [[C3:%.+]] = or i1 [[C1]], [[C2]]
+  // CHECK: store i32 [[QT]], i32* %r
+  // CHECK: br i1 [[C3]]
+  int r;
+  if (__builtin_add_overflow(x, y, ))
+overflowed();
+  return r;
+}
+
+_Bool test_add_overflow_uint_uint_bool(unsigned x, 

[PATCH] D13292: Add support for 'cbegin()' and 'cend()' on modernize-loop-convert.

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

This fixes https://llvm.org/bugs/show_bug.cgi?id=22196 .

Also add a non-trivially copyable type to fix some tests that were meant to be 
about using const-refs, but were changed in r248438.

http://reviews.llvm.org/D13292

Files:
  clang-tidy/modernize/LoopConvertCheck.cpp
  test/clang-tidy/Inputs/modernize-loop-convert/structures.h
  test/clang-tidy/modernize-loop-convert-basic.cpp

Index: test/clang-tidy/modernize-loop-convert-basic.cpp
===
--- test/clang-tidy/modernize-loop-convert-basic.cpp
+++ test/clang-tidy/modernize-loop-convert-basic.cpp
@@ -104,6 +104,14 @@
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto Elem : ConstArr)
   // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", Elem, Elem + Elem);
+
+  const NonTriviallyCopyable NonCopy[N]{};
+  for (int I = 0; I < N; ++I) {
+printf("2 * %d = %d\n", NonCopy[I].X, NonCopy[I].X + NonCopy[I].X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (const auto & Elem : NonCopy)
+  // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", Elem.X, Elem.X + Elem.X);
 }
 
 struct HasArr {
@@ -209,6 +217,13 @@
   // CHECK-FIXES: for (auto & P : *Ps)
   // CHECK-FIXES-NEXT: printf("s has value %d\n", P.X);
 
+  for (S::const_iterator It = Ss.cbegin(), E = Ss.cend(); It != E; ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto Elem : Ss)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", Elem.X);
+
   for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) {
 printf("s has value %d\n", It->X);
   }
@@ -459,8 +474,8 @@
 const int N = 6;
 dependent V;
 dependent *Pv;
-const dependent Constv;
-const dependent *Pconstv;
+const dependent Constv;
+const dependent *Pconstv;
 
 transparent Cv;
 
@@ -519,47 +534,47 @@
 void constness() {
   int Sum = 0;
   for (int I = 0, E = Constv.size(); I < E; ++I) {
-printf("Fibonacci number is %d\n", Constv[I]);
-Sum += Constv[I] + 2;
+printf("Fibonacci number is %d\n", Constv[I].X);
+Sum += Constv[I].X + 2;
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto Elem : Constv)
-  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem);
-  // CHECK-FIXES-NEXT: Sum += Elem + 2;
+  // CHECK-FIXES: for (const auto & Elem : Constv)
+  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem.X);
+  // CHECK-FIXES-NEXT: Sum += Elem.X + 2;
 
   for (int I = 0, E = Constv.size(); I < E; ++I) {
-printf("Fibonacci number is %d\n", Constv.at(I));
-Sum += Constv.at(I) + 2;
+printf("Fibonacci number is %d\n", Constv.at(I).X);
+Sum += Constv.at(I).X + 2;
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto Elem : Constv)
-  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem);
-  // CHECK-FIXES-NEXT: Sum += Elem + 2;
+  // CHECK-FIXES: for (const auto & Elem : Constv)
+  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem.X);
+  // CHECK-FIXES-NEXT: Sum += Elem.X + 2;
 
   for (int I = 0, E = Pconstv->size(); I < E; ++I) {
-printf("Fibonacci number is %d\n", Pconstv->at(I));
-Sum += Pconstv->at(I) + 2;
+printf("Fibonacci number is %d\n", Pconstv->at(I).X);
+Sum += Pconstv->at(I).X + 2;
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto Elem : *Pconstv)
-  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem);
-  // CHECK-FIXES-NEXT: Sum += Elem + 2;
+  // CHECK-FIXES: for (const auto & Elem : *Pconstv)
+  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem.X);
+  // CHECK-FIXES-NEXT: Sum += Elem.X + 2;
 
   // This test will fail if size() isn't called repeatedly, since it
   // returns unsigned int, and 0 is deduced to be signed int.
   // FIXME: Insert the necessary explicit conversion, or write out the types
   // explicitly.
   for (int I = 0; I < Pconstv->size(); ++I) {
-printf("Fibonacci number is %d\n", (*Pconstv).at(I));
-Sum += (*Pconstv)[I] + 2;
+printf("Fibonacci number is %d\n", (*Pconstv).at(I).X);
+Sum += (*Pconstv)[I].X + 2;
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto Elem : *Pconstv)
-  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem);
-  // CHECK-FIXES-NEXT: Sum += Elem + 2;
+  // CHECK-FIXES: for (const auto & Elem : *Pconstv)
+  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem.X);
+  // CHECK-FIXES-NEXT: Sum += Elem.X + 2;
 }
 
-void ConstRef(const dependent& ConstVRef) {
+void constRef(const dependent& ConstVRef) {
   int sum = 

r248912 - Alias "-ggdbN" to "-gN" options, fixing some incompatibilities.

2015-09-30 Thread Douglas Katzman via cfe-commits
Author: dougk
Date: Wed Sep 30 10:55:59 2015
New Revision: 248912

URL: http://llvm.org/viewvc/llvm-project?rev=248912=rev
Log:
Alias "-ggdbN" to "-gN" options, fixing some incompatibilities.

* assembling from a .s file mistook -ggdb0 for -g
* -ggdb1 is supposed to mean basically -g1, not -gN for N>1

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/debug-options-as.c
cfe/trunk/test/Driver/debug-options.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=248912=248911=248912=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Sep 30 10:55:59 2015
@@ -1109,14 +1109,16 @@ def gline_tables_only : Flag<["-"], "gli
   HelpText<"Emit debug line number tables only">, Flags<[CC1Option]>;
 def gmlt : Flag<["-"], "gmlt">, Alias;
 def g0 : Flag<["-"], "g0">, Group;
-def g1 : Flag<["-"], "g1">, Group;
+def g1 : Flag<["-"], "g1">, Group, Alias;
 def g2 : Flag<["-"], "g2">, Group;
 def g3 : Flag<["-"], "g3">, Group;
 def ggdb : Flag<["-"], "ggdb">, Group;
-def ggdb0 : Flag<["-"], "ggdb0">, Group;
-def ggdb1 : Flag<["-"], "ggdb1">, Group;
-def ggdb2 : Flag<["-"], "ggdb2">, Group;
-def ggdb3 : Flag<["-"], "ggdb3">, Group;
+def ggdb0 : Flag<["-"], "ggdb0">, Alias;
+// Redirect ggdb1 to , not ,
+// because aliases of aliases aren't allowed.
+def ggdb1 : Flag<["-"], "ggdb1">, Alias;
+def ggdb2 : Flag<["-"], "ggdb2">, Alias;
+def ggdb3 : Flag<["-"], "ggdb3">, Alias;
 def gdwarf_2 : Flag<["-"], "gdwarf-2">, Group,
   HelpText<"Generate source-level debug information with dwarf version 2">, 
Flags<[CC1Option,CC1AsOption]>;
 def gdwarf_3 : Flag<["-"], "gdwarf-3">, Group,

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=248912=248911=248912=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Sep 30 10:55:59 2015
@@ -3802,8 +3802,7 @@ void Clang::ConstructJob(Compilation ,
   Args.ClaimAllArgs(options::OPT_g_Group);
   Arg *SplitDwarfArg = Args.getLastArg(options::OPT_gsplit_dwarf);
   if (Arg *A = Args.getLastArg(options::OPT_g_Group)) {
-if ((A->getOption().matches(options::OPT_gline_tables_only) ||
- A->getOption().matches(options::OPT_g1)) &&
+if (A->getOption().matches(options::OPT_gline_tables_only) &&
 (!SplitDwarfArg || A->getIndex() > SplitDwarfArg->getIndex())) {
   // FIXME: we should support specifying dwarf version with
   // -gline-tables-only.
@@ -3819,8 +3818,7 @@ void Clang::ConstructJob(Compilation ,
A->getOption().matches(options::OPT_gdwarf_3) ||
A->getOption().matches(options::OPT_gdwarf_4)) {
   A->render(Args, CmdArgs);
-} else if (!A->getOption().matches(options::OPT_g0) &&
-   !A->getOption().matches(options::OPT_ggdb0)) {
+} else if (!A->getOption().matches(options::OPT_g0)) {
   // Default is dwarf-2 for Darwin, OpenBSD, FreeBSD and Solaris.
   const llvm::Triple  = getToolChain().getTriple();
   if (Triple.isOSDarwin() || Triple.getOS() == llvm::Triple::OpenBSD ||

Modified: cfe/trunk/test/Driver/debug-options-as.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/debug-options-as.c?rev=248912=248911=248912=diff
==
--- cfe/trunk/test/Driver/debug-options-as.c (original)
+++ cfe/trunk/test/Driver/debug-options-as.c Wed Sep 30 10:55:59 2015
@@ -7,10 +7,16 @@
 // SAVE: "-cc1as"
 // SAVE-NOT: "-g"
 
+// Make sure that '-ggdb0' is not accidentally mistaken for '-g'
+// RUN: %clang -### -ggdb0 -c -integrated-as -x assembler %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=GGDB0 %s
+//
+// GGDB0: "-cc1as"
+// GGDB0-NOT: "-g"
+
 // Check to make sure clang with -g on a .s file gets passed.
 // rdar://9275556
-// RUN: touch %t.s
-// RUN: %clang -### -c -integrated-as -g %t.s 2>&1 \
+// RUN: %clang -### -c -integrated-as -g -x assembler %s 2>&1 \
 // RUN:   | FileCheck %s
 //
 // CHECK: "-cc1as"
@@ -18,8 +24,7 @@
 
 // Check to make sure clang with -g on a .s file gets passed 
-dwarf-debug-producer.
 // rdar://12955296
-// RUN: touch %t.s
-// RUN: %clang -### -c -integrated-as -g %t.s 2>&1 \
+// RUN: %clang -### -c -integrated-as -g -x assembler %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=P %s
 //
 // P: "-cc1as"

Modified: cfe/trunk/test/Driver/debug-options.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/debug-options.c?rev=248912=248911=248912=diff
==
--- cfe/trunk/test/Driver/debug-options.c (original)
+++ cfe/trunk/test/Driver/debug-options.c Wed 

Re: [PATCH] D12251: Analyzer: Calculate field offset correctly

2015-09-30 Thread Ismail Pazarbasi via cfe-commits
ismailp updated this revision to Diff 36123.
ismailp added a comment.

- Don't try to calculate field offset for Objective-C instance variables
- Added test for Objective-C instance variables
- Added a non-null pointer in test


http://reviews.llvm.org/D12251

Files:
  lib/StaticAnalyzer/Core/Store.cpp
  test/Analysis/array-struct-region.cpp
  test/Analysis/ivars.m

Index: test/Analysis/ivars.m
===
--- test/Analysis/ivars.m
+++ test/Analysis/ivars.m
@@ -138,3 +138,8 @@
   int *x = >uniqueID;
   return *x; // expected-warning{{Dereference of null pointer (loaded from 
variable 'x')}}
 }
+
+void testFieldOffset() {
+  int *v = &((Root *)0x10)->uniqueID;
+  (void)v;
+}
Index: test/Analysis/array-struct-region.cpp
===
--- test/Analysis/array-struct-region.cpp
+++ test/Analysis/array-struct-region.cpp
@@ -106,6 +106,28 @@
 #endif
 }
 
+struct FieldOffset {
+  int firstField;
+  char secondField[63];
+  void *thirdField;
+};
+
+void testFieldOffsets() {
+  struct FieldOffset FO;
+  struct FieldOffset *PFONull = 0;
+  struct FieldOffset *PFOConstant = (struct FieldOffset *) 0x22;
+#if __cplusplus
+  struct FieldOffset *PFONew = new struct FieldOffset;
+#endif
+  clang_analyzer_eval((void *) != (void*)); // 
expected-warning{{TRUE}}
+  clang_analyzer_eval((void *) != (void*)); // 
expected-warning{{TRUE}}
+  clang_analyzer_eval((void *)>secondField != (void 
*)>thirdField); // expected-warning{{FALSE}}
+  clang_analyzer_eval((void *)>secondField == (void *)0); // 
expected-warning{{TRUE}}
+  clang_analyzer_eval((void *)>secondField != 
(void*)PFOConstant); // expected-warning{{TRUE}}
+#if __cplusplus
+  clang_analyzer_eval((void *)>secondField != (void *)); // 
expected-warning{{TRUE}}
+#endif
+}
 
 //
 // C++-only tests
Index: lib/StaticAnalyzer/Core/Store.cpp
===
--- lib/StaticAnalyzer/Core/Store.cpp
+++ lib/StaticAnalyzer/Core/Store.cpp
@@ -15,6 +15,7 @@
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/CharUnits.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 
@@ -401,12 +402,23 @@
 // These are anormal cases. Flag an undefined value.
 return UndefinedVal();
 
-  case loc::ConcreteIntKind:
-// While these seem funny, this can happen through casts.
-// FIXME: What we should return is the field offset.  For example,
-//  add the field offset to the integer value.  That way funny things
-//  like this work properly:  &(((struct foo *) 0xa)->f)
+  case loc::ConcreteIntKind: {
+// Don't allow field offset calculations, if base is null.
+if (!Base.isZeroConstant()) {
+  if (const auto *FD = dyn_cast(D)) {
+if (FD->getKind() != Decl::ObjCIvar) {
+  ASTContext  = D->getASTContext();
+  CharUnits CU = Ctx.toCharUnitsFromBits(Ctx.getFieldOffset(FD));
+  loc::ConcreteInt BasePtr = BaseL.castAs();
+  llvm::APSInt Offset(Ctx.getTypeSize(Ctx.VoidPtrTy));
+  Offset = CU.getQuantity();
+  Offset += BasePtr.getValue();
+  return svalBuilder.makeIntLocVal(Offset);
+}
+  }
+}
 return Base;
+  }
 
   default:
 llvm_unreachable("Unhandled Base.");


Index: test/Analysis/ivars.m
===
--- test/Analysis/ivars.m
+++ test/Analysis/ivars.m
@@ -138,3 +138,8 @@
   int *x = >uniqueID;
   return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}
 }
+
+void testFieldOffset() {
+  int *v = &((Root *)0x10)->uniqueID;
+  (void)v;
+}
Index: test/Analysis/array-struct-region.cpp
===
--- test/Analysis/array-struct-region.cpp
+++ test/Analysis/array-struct-region.cpp
@@ -106,6 +106,28 @@
 #endif
 }
 
+struct FieldOffset {
+  int firstField;
+  char secondField[63];
+  void *thirdField;
+};
+
+void testFieldOffsets() {
+  struct FieldOffset FO;
+  struct FieldOffset *PFONull = 0;
+  struct FieldOffset *PFOConstant = (struct FieldOffset *) 0x22;
+#if __cplusplus
+  struct FieldOffset *PFONew = new struct FieldOffset;
+#endif
+  clang_analyzer_eval((void *) != (void*)); // expected-warning{{TRUE}}
+  clang_analyzer_eval((void *) != (void*)); // expected-warning{{TRUE}}
+  clang_analyzer_eval((void *)>secondField != (void *)>thirdField); // expected-warning{{FALSE}}
+  clang_analyzer_eval((void *)>secondField == (void *)0); // expected-warning{{TRUE}}
+  clang_analyzer_eval((void *)>secondField != (void*)PFOConstant); // expected-warning{{TRUE}}
+#if __cplusplus
+  clang_analyzer_eval((void *)>secondField != (void *)); // expected-warning{{TRUE}}
+#endif
+}
 
 

Re: [PATCH] D12251: Analyzer: Calculate field offset correctly

2015-09-30 Thread Ismail Pazarbasi via cfe-commits
ismailp marked 3 inline comments as done.


Comment at: test/Analysis/array-struct-region.cpp:128
@@ +127,3 @@
+#if __cplusplus
+  clang_analyzer_eval((void *)>secondField != (void *)); // 
expected-warning{{TRUE}}
+#endif

I might be missing something, and would be very happy if you could explain why 
it is necessary to add `PFOConstant`.

At line 122, for example, where `` is always non-null. Likewise, I'd expect 
line 128 to be non-null, because `new` in this translation unit either throws 
-- in which case, we shouldn't be executing this line -- or succeeds -- in 
which case, `PFONew` is non-null.


http://reviews.llvm.org/D12251



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