[clang] [lldb] [ASTImporter][lldb] Avoid implicit imports in VisitFieldDecl (PR #107828)

2024-09-17 Thread Andrew Savonichev via cfe-commits

asavonic wrote:

> Our idea is summarized in 
> https://discourse.llvm.org/t/rfc-lldb-more-reliable-completion-of-record-types/77442.
>  Basically the goal is to guarantee that a call to `getDefinition`, _will_ 
> fetch the definition. This is something that Clang already does, but we just 
> never implement (via `CompleteRedeclChain`). You're right that the "minimal 
> import" mode was implemented for perf. reasons. Though we should probably 
> revisit this. I think we can make LLDB use non-minimal import for record 
> types while keeping the number of transitive imports contained. It would 
> still require changes to the importer to be smarter about what we import, but 
> we wouldn't have these "complete but incomplete" types floating around.

Thanks a lot Michael. It's a lot of work to get the redesign ready, considering 
both functional and performance requirements.

In the meantime, should we merge this patch to fix at least some current 
problems?


https://github.com/llvm/llvm-project/pull/107828
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [ASTImporter][lldb] Avoid implicit imports in VisitFieldDecl (PR #107828)

2024-09-09 Thread Andrew Savonichev via cfe-commits

asavonic wrote:

Thanks Michael, I'm glad I'm not the only one seeing this problem.

> > If an implicit import happens between (2) and (3), it may indirectly bring 
> > the same field into the context. When (3) happens we add it again, 
> > duplicating the field and breaking the record. This is not detected until 
> > we crash later during layout computation:
> 
> And the LLDB test that was XFAILed, is a special case of exactly this problem 
> (summarized well in https://reviews.llvm.org/D102993).

Right, I saw this patch too. It tries to workaround the problem in LLDB, but 
seem to cause other issues. For example:
```
clang/lib/AST/ASTImporter.cpp:1933:
 Error clang::ASTNodeImporter::ImportDeclContext(DeclContext *, bool):
 Assertion `ToDC == ToD->getLexicalDeclContext() && 
ToDC->containsDecl(ToD)' failed.
```

> The more complete solution here is to make LLDB stop relying on this sort of 
> import-pattern. We've been told in the past that the ASTImporter just wasn't 
> designed for this use-case. Ideally, we'd remove the need for minimally 
> importing record types (instead we should just always use `IDK_Everything` 
> for importing definitions). In my opinion, adding complexity like this into 
> the ASTImporter just to support LLDB is going to make it a maintenance burden 
> on both. So I'd vote for trying to solve this properly (which is actually 
> something I've been working on, though I can't promise a timeline of when 
> this is supposed to land).

Oh, I think a redesign with this problem in mind would be great. 

As I understand it, minimal import is used in LLDB for performance reasons, so 
we don't waste time parsing and loading AST elements that we don't need. It 
sounds like a fine idea in general. Implicit imports of external sources in 
Clang, however, turn import process into a minefield, where you have no idea if 
a "pure" operation can cause a major change the target AST. "Complete" types 
are really incomplete, and there is no single point at which they are all 
guaranteed to be finalized.

Perhaps this approach was taken to minimize impact of external sources on the 
rest of Clang, to avoid introducing a concept of "not-fully-loaded-AST" 
everywhere. Understandable, but we have these issues now.

I don't know if I see the whole picture here. I might be wrong on some of these 
points or reasons behind them.

I'm curious what your plan is to address this problem.

> I do wonder whether there's something about the build configuration that 
> makes you hit this crash more likely in UE. Are you building with precompiled 
> headers by any chance? Or with `-flimit-debug-info`?

Unfortunately, I don't know. I'm using pre-built binaries downloaded from Epic.
PCHs are likely used, not sure about `-flimit-debug-info`.

> I'm actually looking at a similar crash at the moment for which I have a 
> reproducer. I'm trying to extract it into a smaller test-case.

Please let me know if you can get it. 

I reduced mine down to ~200KB of DWARF. It crashes on the same assertion in 
`RecordLayoutBuilder.cpp`, but this patch no longer helps. Perhaps there is 
another case of the issue, or the reduced DWARF is somehow invalid.

https://github.com/llvm/llvm-project/pull/107828
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [ASTImporter][lldb] Avoid implicit imports in VisitFieldDecl (PR #107828)

2024-09-09 Thread Andrew Savonichev via cfe-commits

https://github.com/asavonic created 
https://github.com/llvm/llvm-project/pull/107828

Fields from external sources are typically loaded implicitly by `RecordDecl` or 
`DeclContext` iterators and other functions (see LoadFieldsFromExternalStorage 
function and its uses). The assumption is that we only need to load such fields 
whenever a complete list of fields is necessary. However, there are cases where 
implicit loads are not expected and they may break AST importer logic.

In ASTNodeImporter::VisitFieldDecl:

  1) We first check that a field is not imported already.
  2) Then proceed to import it.
  3) Finally add it to the record with `setLexicalDeclContext` and 
`addDeclInternal`.

If an implicit import happens between (2) and (3), it may indirectly bring the 
same field into the context. When (3) happens we add it again, duplicating the 
field and breaking the record. This is not detected until we crash later during 
layout computation:

llvm/clang/lib/AST/RecordLayoutBuilder.cpp:81
Assertion `FieldOffsets.count(FD) && "Field does not have an external 
offset"' failed.

Detecting a possible duplication is difficult, especially considering that 
`addDeclInternal` may cause an implicit import as well.

The patch attempts to workaround this problem by triggering implicit imports 
before (1). However, it is hard to tell if it covers all the cases, because 
some of them are nested: `DeclContext::addHiddenDecl` calls 
`CXXRecordDecl::addedMember`, which calls `Type::isLiteralType` on a base type, 
which tries to iterate over fields and cause an implicit load.

It is quite tricky to get a reproducer for such problems, because they depend 
on order of imports of fields and records. Debugging Unreal Engine v5.3.2 with 
LLDB shows this problem once issue #90938 is fixed or workarounded. Only some 
UE classes are affected. Reducing it down to a LIT test is problematic due to 
size of libraries involved, and "flaky" nature of the problem.

TestCppReferenceToOuterClass shows an improvement with the patch, but it likely 
has no relation to the problem.

>From ee3a6a5b4eef069c5cef2820aeab5ab773df69a4 Mon Sep 17 00:00:00 2001
From: Andrew Savonichev 
Date: Mon, 9 Sep 2024 17:56:20 +0900
Subject: [PATCH] [ASTImporter][lldb] Avoid implicit imports in VisitFieldDecl

Fields from external sources are typically loaded implicitly by
`RecordDecl` or `DeclContext` iterators and other functions (see
LoadFieldsFromExternalStorage function and its uses). The assumption
is that we only need to load such fields whenever a complete list of
fields is necessary. However, there are cases where implicit loads are
not expected and they may break AST importer logic.

In ASTNodeImporter::VisitFieldDecl:

  1) We first check that a field is not imported already.
  2) Then proceed to import it.
  3) Finally add it to the record with `setLexicalDeclContext` and 
`addDeclInternal`.

If an implicit import happens between (2) and (3), it may indirectly
bring the same field into the context. When (3) happens we add it
again, duplicating the field and breaking the record. This is not
detected until we crash later during layout computation:

  llvm/clang/lib/AST/RecordLayoutBuilder.cpp:81
  Assertion `FieldOffsets.count(FD) && "Field does not have an external 
offset"' failed.

Detecting a possible duplication is difficult, especially considering
that `addDeclInternal` may cause an implicit import as well.

The patch attempts to workaround this problem by triggering implicit
imports before (1). However, it is hard to tell if it covers all the
cases, because some of them are nested: `DeclContext::addHiddenDecl`
calls `CXXRecordDecl::addedMember`, which calls `Type::isLiteralType`
on a base type, which tries to iterate over fields and cause an
implicit load.

It is quite tricky to get a reproducer for such problems, because they
depend on order of imports of fields and records. Debugging Unreal
Engine v5.3.2 with LLDB shows this problem once issue #90938 is fixed
or workarounded. Only some UE classes are affected. Reducing it down
to a LIT test is problematic due to size of libraries involved, and
"flaky" nature of the problem.

TestCppReferenceToOuterClass shows an improvement with the patch, but
it likely has no relation to the problem.
---
 clang/lib/AST/ASTImporter.cpp | 22 +--
 .../TestCppReferenceToOuterClass.py   |  1 -
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index c2fb7dddcfc637..6e48f21c57d9d6 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -4172,6 +4172,26 @@ ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl 
*D) {
   if (ToD)
 return ToD;
 
+  // Implicit imports of external fields may import the same field
+  // *after* we check for its presence with findDeclsInToCtx. If this
+  // happens we may import the field twice and break the record
+  // type.
+  //
+

[clang] 0a27622 - [NVPTX] Disable DWARF .file directory for PTX

2022-04-26 Thread Andrew Savonichev via cfe-commits

Author: Andrew Savonichev
Date: 2022-04-26T21:40:36+03:00
New Revision: 0a27622a1d625f179a17f3a22a547d50b042b76e

URL: 
https://github.com/llvm/llvm-project/commit/0a27622a1d625f179a17f3a22a547d50b042b76e
DIFF: 
https://github.com/llvm/llvm-project/commit/0a27622a1d625f179a17f3a22a547d50b042b76e.diff

LOG: [NVPTX] Disable DWARF .file directory for PTX

Default behavior for .file directory was changed in D105856, but
ptxas (CUDA 11.5 release) refuses to parse it:

$ llc -march=nvptx64 llvm/test/DebugInfo/NVPTX/debug-file-loc.ll
$ ptxas debug-file-loc.s
ptxas debug-file-loc.s, line 42; fatal   : Parsing error near
'"foo.h"': syntax error

Added a new field to MCAsmInfo to control default value of
UseDwarfDirectory. This value is used if -dwarf-directory command line
option is not specified.

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

Added: 
llvm/test/DebugInfo/NVPTX/dwarf-file-dir.ll

Modified: 
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/MC/MCAsmInfo.h
llvm/include/llvm/MC/MCTargetOptions.h
llvm/lib/CodeGen/LLVMTargetMachine.cpp
llvm/lib/MC/MCTargetOptions.cpp
llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
llvm/test/DebugInfo/NVPTX/dbg-declare-alloca.ll
llvm/test/DebugInfo/NVPTX/debug-file-loc-only.ll
llvm/test/DebugInfo/NVPTX/debug-file-loc.ll
llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll
llvm/tools/llc/llc.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index ed7bd8f838ee0..c802f74bb2db1 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -455,7 +455,10 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
   Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
   Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
   Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
-  Options.MCOptions.MCUseDwarfDirectory = !CodeGenOpts.NoDwarfDirectoryAsm;
+  Options.MCOptions.MCUseDwarfDirectory =
+  CodeGenOpts.NoDwarfDirectoryAsm
+  ? llvm::MCTargetOptions::DisableDwarfDirectory
+  : llvm::MCTargetOptions::EnableDwarfDirectory;
   Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
   Options.MCOptions.MCIncrementalLinkerCompatible =
   CodeGenOpts.IncrementalLinkerCompatible;

diff  --git a/llvm/include/llvm/MC/MCAsmInfo.h 
b/llvm/include/llvm/MC/MCAsmInfo.h
index 578518e6dc80a..08b5b3ebd355f 100644
--- a/llvm/include/llvm/MC/MCAsmInfo.h
+++ b/llvm/include/llvm/MC/MCAsmInfo.h
@@ -466,6 +466,10 @@ class MCAsmInfo {
   /// the .loc/.file directives. Defaults to true.
   bool UsesDwarfFileAndLocDirectives = true;
 
+  /// True if DWARF `.file directory' directive syntax is used by
+  /// default.
+  bool EnableDwarfFileDirectoryDefault = true;
+
   /// True if the target needs the DWARF section length in the header (if any)
   /// of the DWARF section in the assembly file. Defaults to true.
   bool DwarfSectionSizeRequired = true;
@@ -808,6 +812,10 @@ class MCAsmInfo {
 return DwarfSectionSizeRequired;
   }
 
+  bool enableDwarfFileDirectoryDefault() const {
+return EnableDwarfFileDirectoryDefault;
+  }
+
   void addInitialFrameState(const MCCFIInstruction &Inst);
 
   const std::vector &getInitialFrameState() const {

diff  --git a/llvm/include/llvm/MC/MCTargetOptions.h 
b/llvm/include/llvm/MC/MCTargetOptions.h
index db50dc6749e2e..93712a6b7d44b 100644
--- a/llvm/include/llvm/MC/MCTargetOptions.h
+++ b/llvm/include/llvm/MC/MCTargetOptions.h
@@ -47,7 +47,6 @@ class MCTargetOptions {
   bool MCNoDeprecatedWarn : 1;
   bool MCNoTypeCheck : 1;
   bool MCSaveTempLabels : 1;
-  bool MCUseDwarfDirectory : 1;
   bool MCIncrementalLinkerCompatible : 1;
   bool ShowMCEncoding : 1;
   bool ShowMCInst : 1;
@@ -59,6 +58,17 @@ class MCTargetOptions {
   bool Dwarf64 : 1;
   int DwarfVersion = 0;
 
+  enum DwarfDirectory {
+// Force disable
+DisableDwarfDirectory,
+// Force enable, for assemblers that support
+// `.file fileno directory filename' syntax
+EnableDwarfDirectory,
+// Default is based on the target
+DefaultDwarfDirectory
+  };
+  DwarfDirectory MCUseDwarfDirectory;
+
   std::string ABIName;
   std::string AssemblyLanguage;
   std::string SplitDwarfFile;

diff  --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp 
b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
index 495efc6c05145..ee6c46212a68f 100644
--- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
@@ -165,13 +165,26 @@ Expected> 
LLVMTargetMachine::createMCStreamer(
 if (Options.MCOptions.ShowMCEncoding)
   MCE.reset(getTarget().createMCCodeEmitter(MII, Context));
 
+bool UseDwarfDirectory = false;
+switch (Options.MCOptions.MCUseDwarfDirectory) {
+case MCTargetOptions::DisableDwarfDirectory:
+  UseDwarfDirectory = false;
+  break;
+case MCTarge

[clang] a8083d4 - [X86][clang] Disable long double type for -mno-x87 option

2021-11-03 Thread Andrew Savonichev via cfe-commits

Author: Andrew Savonichev
Date: 2021-11-03T12:08:39+03:00
New Revision: a8083d42b1c346e21623a1d36d1f0cadd7801d83

URL: 
https://github.com/llvm/llvm-project/commit/a8083d42b1c346e21623a1d36d1f0cadd7801d83
DIFF: 
https://github.com/llvm/llvm-project/commit/a8083d42b1c346e21623a1d36d1f0cadd7801d83.diff

LOG: [X86][clang] Disable long double type for -mno-x87 option

This patch attempts to fix a compiler crash that occurs when long
double type is used with -mno-x87 compiler option.

The option disables x87 target feature, which in turn disables x87
registers, so CG cannot select them for x86_fp80 LLVM IR type. Long
double is lowered as x86_fp80 for some targets, so it leads to a
crash.

The option seems to contradict the SystemV ABI, which requires long
double to be represented as a 80-bit floating point, and it also
requires to use x87 registers.

To avoid that, `long double` type is disabled when -mno-x87 option is
set. In addition to that, `float` and `double` also use x87 registers
for return values on 32-bit x86, so they are disabled as well.

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

Added: 
clang/test/Sema/x86-no-x87.cpp
clang/test/Sema/x86_64-no-x87.cpp

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/TargetInfo.h
clang/lib/Basic/TargetInfo.cpp
clang/lib/Basic/Targets/X86.cpp
clang/lib/Basic/Targets/X86.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaSYCL/float128.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a67ef684f1e5c..fd5d7fb8168c6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10714,8 +10714,8 @@ def err_omp_invariant_or_linear_dependency : Error<
 def err_omp_wrong_dependency_iterator_type : Error<
   "expected an integer or a pointer type of the outer loop counter '%0' for 
non-rectangular nests">;
 def err_target_unsupported_type
-: Error<"%0 requires %select{|%2 bit size}1 %3 type support, but target "
-"'%4' does not support it">;
+: Error<"%0 requires %select{|%2 bit size}1 %3 %select{|return }4type 
support,"
+" but target '%5' does not support it">;
 def err_omp_lambda_capture_in_declare_target_not_to : Error<
   "variable captured in declare target region must appear in a to clause">;
 def err_omp_device_type_mismatch : Error<

diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 77a510462a65e..3e1e09417c661 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -203,6 +203,8 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   bool HasFloat16;
   bool HasBFloat16;
   bool HasIbm128;
+  bool HasLongDouble;
+  bool HasFPReturn;
   bool HasStrictFP;
 
   unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth;
@@ -601,6 +603,13 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   /// Determine whether the __ibm128 type is supported on this target.
   virtual bool hasIbm128Type() const { return HasIbm128; }
 
+  /// Determine whether the long double type is supported on this target.
+  virtual bool hasLongDoubleType() const { return HasLongDouble; }
+
+  /// Determine whether return of a floating point value is supported
+  /// on this target.
+  virtual bool hasFPReturn() const { return HasFPReturn; }
+
   /// Determine whether constrained floating point is supported on this target.
   virtual bool hasStrictFP() const { return HasStrictFP; }
 

diff  --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 76855b0c045c5..646bbe8b73873 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -37,6 +37,8 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : TargetOpts(), 
Triple(T) {
   HasIbm128 = false;
   HasFloat16 = false;
   HasBFloat16 = false;
+  HasLongDouble = true;
+  HasFPReturn = true;
   HasStrictFP = false;
   PointerWidth = PointerAlign = 32;
   BoolWidth = BoolAlign = 8;

diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index f40d8a6ed7312..454a7743dded3 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -338,6 +338,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasUINTR = true;
 } else if (Feature == "+crc32") {
   HasCRC32 = true;
+} else if (Feature == "+x87") {
+  HasX87 = true;
 }
 
 X86SSEEnum Level = llvm::StringSwitch(Feature)
@@ -379,6 +381,14 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
 
   SimdDefaultAlign =
   hasFeature("avx512f") ? 512 : hasFeature("avx") ? 256 : 128;
+
+  if (!HasX87) {
+if (LongDoubleFormat == &llvm::APFloat::x87DoubleExtended())
+  Has

[clang] 3dbcea8 - Reland [clang] Check unsupported types in expressions

2021-10-15 Thread Andrew Savonichev via cfe-commits

Author: Andrew Savonichev
Date: 2021-10-15T13:55:36+03:00
New Revision: 3dbcea8b957a5f0094f1d5a73b7a8ebebeedebb6

URL: 
https://github.com/llvm/llvm-project/commit/3dbcea8b957a5f0094f1d5a73b7a8ebebeedebb6
DIFF: 
https://github.com/llvm/llvm-project/commit/3dbcea8b957a5f0094f1d5a73b7a8ebebeedebb6.diff

LOG: Reland [clang] Check unsupported types in expressions

This was committed as ec6c847179fd, but then reverted after a failure
in: https://lab.llvm.org/buildbot/#/builders/84/builds/13983

I was not able to reproduce the problem, but I added an extra check
for a NULL QualType just in case.

Original comit message:

The patch adds missing diagnostics for cases like:

  float F3 = ((__float128)F1 * (__float128)F2) / 2.0f;

Sema::checkDeviceDecl (renamed to checkTypeSupport) is changed to work
with a type without the corresponding ValueDecl. It is also refactored
so that host diagnostics for unsupported types can be added here as
well.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/CodeGen/ibm128-unsupported.c
clang/test/OpenMP/nvptx_unsupported_type_messages.cpp
clang/test/SemaSYCL/float128.cpp
clang/test/SemaSYCL/int128.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1634c23db3d26..e0c36961a9124 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10713,8 +10713,8 @@ def err_omp_invariant_or_linear_dependency : Error<
   "expected loop invariant expression or ' * %0 + ' 
kind of expression">;
 def err_omp_wrong_dependency_iterator_type : Error<
   "expected an integer or a pointer type of the outer loop counter '%0' for 
non-rectangular nests">;
-def err_device_unsupported_type
-: Error<"%0 requires %select{|%2 bit size}1 %3 type support, but device "
+def err_target_unsupported_type
+: Error<"%0 requires %select{|%2 bit size}1 %3 type support, but target "
 "'%4' does not support it">;
 def err_omp_lambda_capture_in_declare_target_not_to : Error<
   "variable captured in declare target region must appear in a to clause">;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index ff759cc77ea53..4d5f9919ce9e6 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12219,9 +12219,9 @@ class Sema final {
 return targetDiag(Loc, PD.getDiagID(), FD) << PD;
   }
 
-  /// Check if the expression is allowed to be used in expressions for the
-  /// offloading devices.
-  void checkDeviceDecl(ValueDecl *D, SourceLocation Loc);
+  /// Check if the type is allowed to be used for the current target.
+  void checkTypeSupport(QualType Ty, SourceLocation Loc,
+ValueDecl *D = nullptr);
 
   enum CUDAFunctionTarget {
 CFT_Device,

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 88833f233adc1..9fae2243cbbf6 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1854,8 +1854,11 @@ Sema::SemaDiagnosticBuilder Sema::Diag(SourceLocation 
Loc, unsigned DiagID,
   return DB;
 }
 
-void Sema::checkDeviceDecl(ValueDecl *D, SourceLocation Loc) {
-  if (isUnevaluatedContext())
+void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
+  if (!LangOpts.SYCLIsDevice && !(LangOpts.OpenMP && LangOpts.OpenMPIsDevice))
+return;
+
+  if (isUnevaluatedContext() || Ty.isNull())
 return;
 
   Decl *C = cast(getCurLexicalContext());
@@ -1874,16 +1877,22 @@ void Sema::checkDeviceDecl(ValueDecl *D, SourceLocation 
Loc) {
 
   // Try to associate errors with the lexical context, if that is a function, 
or
   // the value declaration otherwise.
-  FunctionDecl *FD =
-  isa(C) ? cast(C) : dyn_cast(D);
+  FunctionDecl *FD = isa(C) ? cast(C)
+  : dyn_cast_or_null(D);
+
   auto CheckType = [&](QualType Ty) {
 if (Ty->isDependentType())
   return;
 
 if (Ty->isExtIntType()) {
   if (!Context.getTargetInfo().hasExtIntType()) {
-targetDiag(Loc, diag::err_device_unsupported_type, FD)
-<< D << false /*show bit size*/ << 0 /*bitsize*/
+PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
+if (D)
+  PD << D;
+else
+  PD << "expression";
+targetDiag(Loc, PD, FD)
+<< false /*show bit size*/ << 0 /*bitsize*/
 << Ty << Context.getTargetInfo().getTriple().str();
   }
   return;
@@ -1907,16 +1916,24 @@ void Sema::checkDeviceDecl(ValueDecl *D, SourceLocation 
Loc) {
 (Ty->isIntegerType() && Context.getTypeSize(Ty) == 128 &&
  !Con

[clang] 6377426 - Revert "[clang] Check unsupported types in expressions"

2021-09-13 Thread Andrew Savonichev via cfe-commits

Author: Andrew Savonichev
Date: 2021-09-13T15:34:21+03:00
New Revision: 6377426b4a326b52733065609a5d811afd2b8b1b

URL: 
https://github.com/llvm/llvm-project/commit/6377426b4a326b52733065609a5d811afd2b8b1b
DIFF: 
https://github.com/llvm/llvm-project/commit/6377426b4a326b52733065609a5d811afd2b8b1b.diff

LOG: Revert "[clang] Check unsupported types in expressions"

This reverts commit ec6c847179fd019acae4d97a18f9e7d3961a6fdf.

Fails on check-openmp:

/b/1/openmp-clang-x86_64-linux-debian/llvm.build/projects/openmp/runtime/test/lock/Output/omp_init_lock.c.tmp
--
Exit Code: -11

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/CodeGen/ibm128-unsupported.c
clang/test/OpenMP/nvptx_unsupported_type_messages.cpp
clang/test/SemaSYCL/float128.cpp
clang/test/SemaSYCL/int128.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9c739c3c1f250..824d9bf469360 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10688,8 +10688,8 @@ def err_omp_invariant_or_linear_dependency : Error<
   "expected loop invariant expression or ' * %0 + ' 
kind of expression">;
 def err_omp_wrong_dependency_iterator_type : Error<
   "expected an integer or a pointer type of the outer loop counter '%0' for 
non-rectangular nests">;
-def err_target_unsupported_type
-: Error<"%0 requires %select{|%2 bit size}1 %3 type support, but target "
+def err_device_unsupported_type
+: Error<"%0 requires %select{|%2 bit size}1 %3 type support, but device "
 "'%4' does not support it">;
 def err_omp_lambda_capture_in_declare_target_not_to : Error<
   "variable captured in declare target region must appear in a to clause">;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9e4175b6de811..710abeb1ea514 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12160,9 +12160,9 @@ class Sema final {
 return targetDiag(Loc, PD.getDiagID(), FD) << PD;
   }
 
-  /// Check if the type is allowed to be used for the current target.
-  void checkTypeSupport(QualType Ty, SourceLocation Loc,
-ValueDecl *D = nullptr);
+  /// Check if the expression is allowed to be used in expressions for the
+  /// offloading devices.
+  void checkDeviceDecl(ValueDecl *D, SourceLocation Loc);
 
   enum CUDAFunctionTarget {
 CFT_Device,

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index b23d92d101074..a9867697a4c31 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1852,10 +1852,7 @@ Sema::SemaDiagnosticBuilder Sema::Diag(SourceLocation 
Loc, unsigned DiagID,
   return DB;
 }
 
-void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
-  if (!LangOpts.SYCLIsDevice && !(LangOpts.OpenMP && LangOpts.OpenMPIsDevice))
-return;
-
+void Sema::checkDeviceDecl(ValueDecl *D, SourceLocation Loc) {
   if (isUnevaluatedContext())
 return;
 
@@ -1875,22 +1872,16 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation 
Loc, ValueDecl *D) {
 
   // Try to associate errors with the lexical context, if that is a function, 
or
   // the value declaration otherwise.
-  FunctionDecl *FD = isa(C) ? cast(C)
-  : dyn_cast_or_null(D);
-
+  FunctionDecl *FD =
+  isa(C) ? cast(C) : dyn_cast(D);
   auto CheckType = [&](QualType Ty) {
 if (Ty->isDependentType())
   return;
 
 if (Ty->isExtIntType()) {
   if (!Context.getTargetInfo().hasExtIntType()) {
-PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
-if (D)
-  PD << D;
-else
-  PD << "expression";
-targetDiag(Loc, PD, FD)
-<< false /*show bit size*/ << 0 /*bitsize*/
+targetDiag(Loc, diag::err_device_unsupported_type, FD)
+<< D << false /*show bit size*/ << 0 /*bitsize*/
 << Ty << Context.getTargetInfo().getTriple().str();
   }
   return;
@@ -1912,24 +1903,16 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation 
Loc, ValueDecl *D) {
 (Ty->isIntegerType() && Context.getTypeSize(Ty) == 128 &&
  !Context.getTargetInfo().hasInt128Type()) ||
 LongDoubleMismatched) {
-  PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
-  if (D)
-PD << D;
-  else
-PD << "expression";
-
-  if (targetDiag(Loc, PD, FD)
-  << true /*show bit size*/
+  if (targetDiag(Loc, diag::err_device_unsupported_type, FD)
+  << D << true /*show bit size*/
   << static_cast(Context.getTypeSize(Ty)) << Ty
-  << Context.getTa

[clang] ec6c847 - [clang] Check unsupported types in expressions

2021-09-13 Thread Andrew Savonichev via cfe-commits

Author: Andrew Savonichev
Date: 2021-09-13T14:59:37+03:00
New Revision: ec6c847179fd019acae4d97a18f9e7d3961a6fdf

URL: 
https://github.com/llvm/llvm-project/commit/ec6c847179fd019acae4d97a18f9e7d3961a6fdf
DIFF: 
https://github.com/llvm/llvm-project/commit/ec6c847179fd019acae4d97a18f9e7d3961a6fdf.diff

LOG: [clang] Check unsupported types in expressions

The patch adds missing diagnostics for cases like:

  float F3 = ((__float128)F1 * (__float128)F2) / 2.0f;

Sema::checkDeviceDecl (renamed to checkTypeSupport) is changed to work
with a type without the corresponding ValueDecl. It is also refactored
so that host diagnostics for unsupported types can be added here as
well.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/CodeGen/ibm128-unsupported.c
clang/test/OpenMP/nvptx_unsupported_type_messages.cpp
clang/test/SemaSYCL/float128.cpp
clang/test/SemaSYCL/int128.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 824d9bf469360..9c739c3c1f250 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10688,8 +10688,8 @@ def err_omp_invariant_or_linear_dependency : Error<
   "expected loop invariant expression or ' * %0 + ' 
kind of expression">;
 def err_omp_wrong_dependency_iterator_type : Error<
   "expected an integer or a pointer type of the outer loop counter '%0' for 
non-rectangular nests">;
-def err_device_unsupported_type
-: Error<"%0 requires %select{|%2 bit size}1 %3 type support, but device "
+def err_target_unsupported_type
+: Error<"%0 requires %select{|%2 bit size}1 %3 type support, but target "
 "'%4' does not support it">;
 def err_omp_lambda_capture_in_declare_target_not_to : Error<
   "variable captured in declare target region must appear in a to clause">;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 710abeb1ea514..9e4175b6de811 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12160,9 +12160,9 @@ class Sema final {
 return targetDiag(Loc, PD.getDiagID(), FD) << PD;
   }
 
-  /// Check if the expression is allowed to be used in expressions for the
-  /// offloading devices.
-  void checkDeviceDecl(ValueDecl *D, SourceLocation Loc);
+  /// Check if the type is allowed to be used for the current target.
+  void checkTypeSupport(QualType Ty, SourceLocation Loc,
+ValueDecl *D = nullptr);
 
   enum CUDAFunctionTarget {
 CFT_Device,

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index a9867697a4c31..b23d92d101074 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1852,7 +1852,10 @@ Sema::SemaDiagnosticBuilder Sema::Diag(SourceLocation 
Loc, unsigned DiagID,
   return DB;
 }
 
-void Sema::checkDeviceDecl(ValueDecl *D, SourceLocation Loc) {
+void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
+  if (!LangOpts.SYCLIsDevice && !(LangOpts.OpenMP && LangOpts.OpenMPIsDevice))
+return;
+
   if (isUnevaluatedContext())
 return;
 
@@ -1872,16 +1875,22 @@ void Sema::checkDeviceDecl(ValueDecl *D, SourceLocation 
Loc) {
 
   // Try to associate errors with the lexical context, if that is a function, 
or
   // the value declaration otherwise.
-  FunctionDecl *FD =
-  isa(C) ? cast(C) : dyn_cast(D);
+  FunctionDecl *FD = isa(C) ? cast(C)
+  : dyn_cast_or_null(D);
+
   auto CheckType = [&](QualType Ty) {
 if (Ty->isDependentType())
   return;
 
 if (Ty->isExtIntType()) {
   if (!Context.getTargetInfo().hasExtIntType()) {
-targetDiag(Loc, diag::err_device_unsupported_type, FD)
-<< D << false /*show bit size*/ << 0 /*bitsize*/
+PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
+if (D)
+  PD << D;
+else
+  PD << "expression";
+targetDiag(Loc, PD, FD)
+<< false /*show bit size*/ << 0 /*bitsize*/
 << Ty << Context.getTargetInfo().getTriple().str();
   }
   return;
@@ -1903,16 +1912,24 @@ void Sema::checkDeviceDecl(ValueDecl *D, SourceLocation 
Loc) {
 (Ty->isIntegerType() && Context.getTypeSize(Ty) == 128 &&
  !Context.getTargetInfo().hasInt128Type()) ||
 LongDoubleMismatched) {
-  if (targetDiag(Loc, diag::err_device_unsupported_type, FD)
-  << D << true /*show bit size*/
+  PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
+  if (D)
+PD << D;
+  else
+PD << "expression";
+
+  if (targetDiag(Loc, 

[clang] b31f41e - [Clang] Support a user-defined __dso_handle

2021-06-07 Thread Andrew Savonichev via cfe-commits

Author: Andrew Savonichev
Date: 2021-06-07T12:54:08+03:00
New Revision: b31f41e78b2722785f3df1da0d77dfcd68125d15

URL: 
https://github.com/llvm/llvm-project/commit/b31f41e78b2722785f3df1da0d77dfcd68125d15
DIFF: 
https://github.com/llvm/llvm-project/commit/b31f41e78b2722785f3df1da0d77dfcd68125d15.diff

LOG: [Clang] Support a user-defined __dso_handle

This fixes PR49198: Wrong usage of __dso_handle in user code leads to
a compiler crash.

When Init is an address of the global itself, we need to track it
across RAUW. Otherwise the initializer can be destroyed if the global
is replaced.

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

Added: 
clang/test/CodeGenCXX/dso-handle-custom.cpp

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 9b31ecdbd81a9..1f23ce7de52b7 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4284,7 +4284,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl 
*D,
   OpenMPRuntime->emitTargetGlobalVariable(D))
 return;
 
-  llvm::Constant *Init = nullptr;
+  llvm::TrackingVH Init;
   bool NeedsGlobalCtor = false;
   bool NeedsGlobalDtor =
   D->needsDestruction(getContext()) == QualType::DK_cxx_destructor;
@@ -4330,9 +4330,8 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl 
*D,
   } else {
 initializedGlobalDecl = GlobalDecl(D);
 emitter.emplace(*this);
-Init = emitter->tryEmitForInitializer(*InitDecl);
-
-if (!Init) {
+llvm::Constant *Initializer = emitter->tryEmitForInitializer(*InitDecl);
+if (!Initializer) {
   QualType T = InitExpr->getType();
   if (D->getType()->isReferenceType())
 T = D->getType();
@@ -4345,6 +4344,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl 
*D,
 Init = llvm::UndefValue::get(getTypes().ConvertType(T));
   }
 } else {
+  Init = Initializer;
   // We don't need an initializer, so remove the entry for the delayed
   // initializer position (just in case this entry was delayed) if we
   // also don't need to register a destructor.

diff  --git a/clang/test/CodeGenCXX/dso-handle-custom.cpp 
b/clang/test/CodeGenCXX/dso-handle-custom.cpp
new file mode 100644
index 0..a6bc34fe1c469
--- /dev/null
+++ b/clang/test/CodeGenCXX/dso-handle-custom.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fexceptions %s 
-o - | FileCheck %s --check-prefixes CHECK,CHECK-DEFAULT
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fexceptions %s 
-o - -DHIDDEN | FileCheck %s --check-prefixes CHECK,CHECK-HIDDEN
+
+class A {
+public:
+  ~A();
+} a;
+
+// CHECK-DEFAULT: @__dso_handle = global i8* bitcast (i8** @__dso_handle to 
i8*), align 8
+// CHECK-HIDDEN: @__dso_handle = hidden global i8* bitcast (i8** @__dso_handle 
to i8*), align 8
+// CHECK: define internal void @__cxx_global_var_init()
+// CHECK:   call i32 @__cxa_atexit({{.*}}, {{.*}}, i8* bitcast (i8** 
@__dso_handle to i8*))
+
+#ifdef HIDDEN
+void *__dso_handle __attribute__((__visibility__("hidden"))) = &__dso_handle;
+#else
+void *__dso_handle = &__dso_handle;
+#endif
+
+void use(void *);
+void use_dso_handle() {
+  use(__dso_handle);
+}



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


[clang] b451ecd - [Clang][AArch64] Disable rounding of return values for AArch64

2021-05-04 Thread Andrew Savonichev via cfe-commits

Author: Andrew Savonichev
Date: 2021-05-04T20:29:01+03:00
New Revision: b451ecd86e13ec6ef47caf37f62977645c4f748e

URL: 
https://github.com/llvm/llvm-project/commit/b451ecd86e13ec6ef47caf37f62977645c4f748e
DIFF: 
https://github.com/llvm/llvm-project/commit/b451ecd86e13ec6ef47caf37f62977645c4f748e.diff

LOG: [Clang][AArch64] Disable rounding of return values for AArch64

If a return value is explicitly rounded to 64 bits, an additional zext
instruction is emitted, and in some cases it prevents tail call
optimization.

As discussed in D100225, this rounding is not necessary and can be
disabled.

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

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp
clang/test/CodeGen/aarch64-varargs.c
clang/test/CodeGen/arm64-arguments.c
clang/test/CodeGen/arm64-microsoft-arguments.cpp
clang/test/CodeGen/attr-noundef.cpp
clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
clang/test/CodeGenCXX/trivial_abi.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 9577b61ca6d0..633b963965ed 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -5781,6 +5781,18 @@ ABIArgInfo AArch64ABIInfo::classifyReturnType(QualType 
RetTy,
 if (getTarget().isRenderScriptTarget()) {
   return coerceToIntArray(RetTy, getContext(), getVMContext());
 }
+
+if (Size <= 64 && getDataLayout().isLittleEndian()) {
+  // Composite types are returned in lower bits of a 64-bit register for 
LE,
+  // and in higher bits for BE. However, integer types are always returned
+  // in lower bits for both LE and BE, and they are not rounded up to
+  // 64-bits. We can skip rounding up of composite types for LE, but not 
for
+  // BE, otherwise composite types will be indistinguishable from integer
+  // types.
+  return ABIArgInfo::getDirect(
+  llvm::IntegerType::get(getVMContext(), Size));
+}
+
 unsigned Alignment = getContext().getTypeAlign(RetTy);
 Size = llvm::alignTo(Size, 64); // round up to multiple of 8 bytes
 

diff  --git a/clang/test/CodeGen/aarch64-varargs.c 
b/clang/test/CodeGen/aarch64-varargs.c
index b71ec4af7aca..908fb4ae5d10 100644
--- a/clang/test/CodeGen/aarch64-varargs.c
+++ b/clang/test/CodeGen/aarch64-varargs.c
@@ -473,7 +473,8 @@ typedef struct __attribute__((packed,aligned(2))) {
   int val;
 } underaligned_int_struct;
 underaligned_int_struct underaligned_int_struct_test() {
-// CHECK-LABEL: define{{.*}} i64 @underaligned_int_struct_test()
+// CHECK-LE-LABEL: define{{.*}} i32 @underaligned_int_struct_test()
+// CHECK-BE-LABEL: define{{.*}} i64 @underaligned_int_struct_test()
   return va_arg(the_list, underaligned_int_struct);
 // CHECK: [[GR_OFFS:%[a-z_0-9]+]] = load i32, i32* getelementptr inbounds 
(%struct.__va_list, %struct.__va_list* @the_list, i32 0, i32 3)
 // CHECK: [[EARLY_ONSTACK:%[a-z_0-9]+]] = icmp sge i32 [[GR_OFFS]], 0
@@ -675,7 +676,8 @@ typedef struct {
   int val __attribute__((packed,aligned(2)));
 } underaligned_int_struct_member;
 underaligned_int_struct_member underaligned_int_struct_member_test() {
-// CHECK-LABEL: define{{.*}} i64 @underaligned_int_struct_member_test()
+// CHECK-LE-LABEL: define{{.*}} i32 @underaligned_int_struct_member_test()
+// CHECK-BE-LABEL: define{{.*}} i64 @underaligned_int_struct_member_test()
   return va_arg(the_list, underaligned_int_struct_member);
 // CHECK: [[GR_OFFS:%[a-z_0-9]+]] = load i32, i32* getelementptr inbounds 
(%struct.__va_list, %struct.__va_list* @the_list, i32 0, i32 3)
 // CHECK: [[EARLY_ONSTACK:%[a-z_0-9]+]] = icmp sge i32 [[GR_OFFS]], 0

diff  --git a/clang/test/CodeGen/arm64-arguments.c 
b/clang/test/CodeGen/arm64-arguments.c
index a40e5365cc51..b362346aa8a8 100644
--- a/clang/test/CodeGen/arm64-arguments.c
+++ b/clang/test/CodeGen/arm64-arguments.c
@@ -1,33 +1,41 @@
-// RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -target-abi 
darwinpcs -ffreestanding -emit-llvm -w -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -target-abi 
darwinpcs -ffreestanding -emit-llvm -w -o - %s | FileCheck %s 
--check-prefixes=CHECK,CHECK-LE
+// RUN: %clang_cc1 -triple aarch64_be-none-linux-gnu -target-feature +neon 
-target-abi darwinpcs -ffreestanding -emit-llvm -w -o - %s | FileCheck %s 
--check-prefixes=CHECK,CHECK-BE
 
 // CHECK: define{{.*}} signext i8 @f0()
 char f0(void) {
   return 0;
 }
 
-// Struct as return type. Aggregates <= 16 bytes are passed directly and round
-// up to multiple of 8 bytes.
-// CHECK: define{{.*}} i64 @f1()
+// Struct as return type. Aggregates <= 16 bytes are passed directly. For BE,
+// return values are round up to 64 bits.
+//
+// CHECK-LE: define{{.*}} i8 @f1()
+// CHECK-BE: define{{.*}} i64 @f1()
 struct s1 { char f0; };
 struct s1 f1(void) {}
 
-// CHECK: define{{.*}} i6

r362398 - [OpenCL] Undefine cl_intel_planar_yuv extension

2019-06-03 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Mon Jun  3 06:02:43 2019
New Revision: 362398

URL: http://llvm.org/viewvc/llvm-project?rev=362398&view=rev
Log:
[OpenCL] Undefine cl_intel_planar_yuv extension

Summary:

Remove unnecessary definition (otherwise the extension will be defined
where it's not supposed to be defined).

Consider the code:

  #pragma OPENCL EXTENSION cl_intel_planar_yuv : begin
  // some declarations
  #pragma OPENCL EXTENSION cl_intel_planar_yuv : end

is enough for extension to become known for clang.

Patch by: Dmitry Sidorov 

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Tags: #clang

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

Modified:
cfe/trunk/lib/Headers/opencl-c.h
cfe/trunk/test/Headers/opencl-c-header.cl
cfe/trunk/test/SemaOpenCL/extension-begin.cl

Modified: cfe/trunk/lib/Headers/opencl-c.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c.h?rev=362398&r1=362397&r2=362398&view=diff
==
--- cfe/trunk/lib/Headers/opencl-c.h (original)
+++ cfe/trunk/lib/Headers/opencl-c.h Mon Jun  3 06:02:43 2019
@@ -22,9 +22,6 @@
 #endif //__OPENCL_C_VERSION__ < CL_VERSION_2_0
 
 #if __OPENCL_C_VERSION__ >= CL_VERSION_1_2
-#ifndef cl_intel_planar_yuv
-#define cl_intel_planar_yuv
-#endif // cl_intel_planar_yuv
 #pragma OPENCL EXTENSION cl_intel_planar_yuv : begin
 #pragma OPENCL EXTENSION cl_intel_planar_yuv : end
 #endif // __OPENCL_C_VERSION__ >= CL_VERSION_1_2

Modified: cfe/trunk/test/Headers/opencl-c-header.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/opencl-c-header.cl?rev=362398&r1=362397&r2=362398&view=diff
==
--- cfe/trunk/test/Headers/opencl-c-header.cl (original)
+++ cfe/trunk/test/Headers/opencl-c-header.cl Mon Jun  3 06:02:43 2019
@@ -77,9 +77,6 @@ void test_image3dwo(write_only image3d_t
 // OpenCL 1.2 onwards.
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
 // expected-no-diagnostics
-#ifndef cl_intel_planar_yuv
-#error "Missing cl_intel_planar_yuv define"
-#endif
 #else //__OPENCL_C_VERSION__
 // expected-warning@+2{{unknown OpenCL extension 'cl_intel_planar_yuv' - 
ignoring}}
 #endif //__OPENCL_C_VERSION__

Modified: cfe/trunk/test/SemaOpenCL/extension-begin.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/extension-begin.cl?rev=362398&r1=362397&r2=362398&view=diff
==
--- cfe/trunk/test/SemaOpenCL/extension-begin.cl (original)
+++ cfe/trunk/test/SemaOpenCL/extension-begin.cl Mon Jun  3 06:02:43 2019
@@ -16,6 +16,13 @@
 //
 // RUN: %clang_cc1 -cl-std=CL2.0 -DIMPLICIT_INCLUDE -include 
%S/extension-begin.h -triple spir-unknown-unknown -O0 -emit-llvm -o - -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t.modules %s -verify -pedantic
 
+#pragma OPENCL EXTENSION my_ext : enable
+#ifndef IMPLICIT_INCLUDE
+// expected-warning@-2 {{unknown OpenCL extension 'my_ext' - ignoring}}
+// expected-warning@+2 {{unknown OpenCL extension 'my_ext' - ignoring}}
+#endif // IMPLICIT_INCLUDE
+#pragma OPENCL EXTENSION my_ext : disable
+
 #ifndef IMPLICIT_INCLUDE
 #include "extension-begin.h"
 #endif // IMPLICIT_INCLUDE


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


r356571 - [OpenCL] Generate 'unroll.enable' metadata for __attribute__((opencl_unroll_hint))

2019-03-20 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Wed Mar 20 09:43:07 2019
New Revision: 356571

URL: http://llvm.org/viewvc/llvm-project?rev=356571&view=rev
Log:
[OpenCL] Generate 'unroll.enable' metadata for  
__attribute__((opencl_unroll_hint))

Summary:
[OpenCL] Generate 'unroll.enable' metadata for  
__attribute__((opencl_unroll_hint))

For both !{!"llvm.loop.unroll.enable"} and !{!"llvm.loop.unroll.full"} the 
unroller
will try to fully unroll a loop unless the trip count is not known at compile 
time.
In that case for '.full' metadata no unrolling will be processed, while for 
'.enable'
the loop will be partially unrolled with a heuristically chosen unroll factor.

See: docs/LanguageExtensions.rst

From 
https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/attributes-loopUnroll.html

__attribute__((opencl_unroll_hint))
for (int i=0; i<2; i++)
{
...
}

In the example above, the compiler will determine how much to unroll the loop.


Before the patch for  __attribute__((opencl_unroll_hint)) was generated metadata
!{!"llvm.loop.unroll.full"}, which limits ability of loop unroller to decide, 
how
much to unroll the loop.

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Subscribers: zzheng, dmgreen, jdoerfert, cfe-commits, asavonic, AlexeySotkin

Tags: #clang

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

Modified:
cfe/trunk/lib/CodeGen/CGLoopInfo.cpp
cfe/trunk/test/CodeGenOpenCL/unroll-hint.cl

Modified: cfe/trunk/lib/CodeGen/CGLoopInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGLoopInfo.cpp?rev=356571&r1=356570&r2=356571&view=diff
==
--- cfe/trunk/lib/CodeGen/CGLoopInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGLoopInfo.cpp Wed Mar 20 09:43:07 2019
@@ -208,13 +208,13 @@ void LoopInfoStack::push(BasicBlock *Hea
 // Translate opencl_unroll_hint attribute argument to
 // equivalent LoopHintAttr enums.
 // OpenCL v2.0 s6.11.5:
-// 0 - full unroll (no argument).
+// 0 - enable unroll (no argument).
 // 1 - disable unroll.
 // other positive integer n - unroll by n.
 if (OpenCLHint) {
   ValueInt = OpenCLHint->getUnrollHint();
   if (ValueInt == 0) {
-State = LoopHintAttr::Full;
+State = LoopHintAttr::Enable;
   } else if (ValueInt != 1) {
 Option = LoopHintAttr::UnrollCount;
 State = LoopHintAttr::Numeric;

Modified: cfe/trunk/test/CodeGenOpenCL/unroll-hint.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/unroll-hint.cl?rev=356571&r1=356570&r2=356571&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/unroll-hint.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/unroll-hint.cl Wed Mar 20 09:43:07 2019
@@ -18,12 +18,12 @@ void for_disable()
 // CHECK: br label %{{.*}}, !llvm.loop ![[FOR_DISABLE:.*]]
 }
 
-void for_full()
+void for_enable()
 {
-// CHECK-LABEL: for_full
+// CHECK-LABEL: for_enable
 __attribute__((opencl_unroll_hint))
 for( int i = 0; i < 1000; ++i);
-// CHECK: br label %{{.*}}, !llvm.loop ![[FOR_FULL:.*]]
+// CHECK: br label %{{.*}}, !llvm.loop ![[FOR_ENABLE:.*]]
 }
 
 /*** while ***/
@@ -45,13 +45,13 @@ void while_disable()
 // CHECK: br label %{{.*}}, !llvm.loop ![[WHILE_DISABLE:.*]]
 }
 
-void while_full()
+void while_enable()
 {
-// CHECK-LABEL: while_full
+// CHECK-LABEL: while_enable
 int i = 1000;
 __attribute__((opencl_unroll_hint))
 while(i-->0);
-// CHECK: br label %{{.*}}, !llvm.loop ![[WHILE_FULL:.*]]
+// CHECK: br label %{{.*}}, !llvm.loop ![[WHILE_ENABLE:.*]]
 }
 
 /*** do ***/
@@ -73,13 +73,13 @@ void do_disable()
 // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !llvm.loop 
![[DO_DISABLE:.*]]
 }
 
-void do_full()
+void do_enable()
 {
-// CHECK-LABEL: do_full
+// CHECK-LABEL: do_enable
 int i = 1000;
 __attribute__((opencl_unroll_hint))
 do {} while(i--> 0);
-// CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !llvm.loop 
![[DO_FULL:.*]]
+// CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !llvm.loop 
![[DO_ENABLE:.*]]
 }
 
 
@@ -87,11 +87,11 @@ void do_full()
 // CHECK: ![[COUNT]] =  !{!"llvm.loop.unroll.count", i32 8}
 // CHECK: ![[FOR_DISABLE]]   =  distinct !{![[FOR_DISABLE]],  ![[DISABLE:.*]]}
 // CHECK: ![[DISABLE]]   =  !{!"llvm.loop.unroll.disable"}
-// CHECK: ![[FOR_FULL]]  =  distinct !{![[FOR_FULL]],  ![[FULL:.*]]}
-// CHECK: ![[FULL]]  =  !{!"llvm.loop.unroll.full"}
+// CHECK: ![[FOR_ENABLE]]  =  distinct !{![[FOR_ENABLE]],  ![[ENABLE:.*]]}
+// CHECK: ![[ENABLE]]  =  !{!"llvm.loop.unroll.enable"}
 // CHECK: ![[WHILE_COUNT]]   =  distinct !{![[WHILE_COUNT]],![[COUNT]]}
 // CHECK: ![[WHILE_DISABLE]] =  distinct !{![[WHILE_DISABLE]],  ![[DISABLE]]}
-// CHECK: ![[WHILE_FULL]]=  distinct !{![[WHILE_FULL]], ![[FULL]]}
+// CHECK: ![[WHILE_ENABLE]]=  distinct !{![[

r354568 - [OpenCL] Simplify LLVM IR generated for OpenCL blocks

2019-02-21 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Thu Feb 21 03:02:10 2019
New Revision: 354568

URL: http://llvm.org/viewvc/llvm-project?rev=354568&view=rev
Log:
[OpenCL] Simplify LLVM IR generated for OpenCL blocks

Summary:
Emit direct call of block invoke functions when possible, i.e. in case the
block is not passed as a function argument.
Also doing some refactoring of `CodeGenFunction::EmitBlockCallExpr()`

Reviewers: Anastasia, yaxunl, svenvh

Reviewed By: Anastasia

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenCLRuntime.h
cfe/trunk/test/CodeGenOpenCL/blocks.cl
cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=354568&r1=354567&r2=354568&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Thu Feb 21 03:02:10 2019
@@ -1253,52 +1253,49 @@ RValue CodeGenFunction::EmitBlockCallExp
   ReturnValueSlot ReturnValue) {
   const BlockPointerType *BPT =
 E->getCallee()->getType()->getAs();
-
   llvm::Value *BlockPtr = EmitScalarExpr(E->getCallee());
-
-  // Get a pointer to the generic block literal.
-  // For OpenCL we generate generic AS void ptr to be able to reuse the same
-  // block definition for blocks with captures generated as private AS local
-  // variables and without captures generated as global AS program scope
-  // variables.
-  unsigned AddrSpace = 0;
-  if (getLangOpts().OpenCL)
-AddrSpace = getContext().getTargetAddressSpace(LangAS::opencl_generic);
-
-  llvm::Type *BlockLiteralTy =
-  llvm::PointerType::get(CGM.getGenericBlockLiteralType(), AddrSpace);
-
-  // Bitcast the callee to a block literal.
-  BlockPtr =
-  Builder.CreatePointerCast(BlockPtr, BlockLiteralTy, "block.literal");
-
-  // Get the function pointer from the literal.
-  llvm::Value *FuncPtr =
-  Builder.CreateStructGEP(CGM.getGenericBlockLiteralType(), BlockPtr,
-  CGM.getLangOpts().OpenCL ? 2 : 3);
-
-  // Add the block literal.
+  llvm::Type *GenBlockTy = CGM.getGenericBlockLiteralType();
+  llvm::Value *Func = nullptr;
+  QualType FnType = BPT->getPointeeType();
+  ASTContext &Ctx = getContext();
   CallArgList Args;
 
-  QualType VoidPtrQualTy = getContext().VoidPtrTy;
-  llvm::Type *GenericVoidPtrTy = VoidPtrTy;
   if (getLangOpts().OpenCL) {
-GenericVoidPtrTy = CGM.getOpenCLRuntime().getGenericVoidPointerType();
-VoidPtrQualTy =
-getContext().getPointerType(getContext().getAddrSpaceQualType(
-getContext().VoidTy, LangAS::opencl_generic));
-  }
+// For OpenCL, BlockPtr is already casted to generic block literal.
 
-  BlockPtr = Builder.CreatePointerCast(BlockPtr, GenericVoidPtrTy);
-  Args.add(RValue::get(BlockPtr), VoidPtrQualTy);
+// First argument of a block call is a generic block literal casted to
+// generic void pointer, i.e. i8 addrspace(4)*
+llvm::Value *BlockDescriptor = Builder.CreatePointerCast(
+BlockPtr, CGM.getOpenCLRuntime().getGenericVoidPointerType());
+QualType VoidPtrQualTy = Ctx.getPointerType(
+Ctx.getAddrSpaceQualType(Ctx.VoidTy, LangAS::opencl_generic));
+Args.add(RValue::get(BlockDescriptor), VoidPtrQualTy);
+// And the rest of the arguments.
+EmitCallArgs(Args, FnType->getAs(), E->arguments());
+
+// We *can* call the block directly unless it is a function argument.
+if (!isa(E->getCalleeDecl()))
+  Func = CGM.getOpenCLRuntime().getInvokeFunction(E->getCallee());
+else {
+  llvm::Value *FuncPtr = Builder.CreateStructGEP(GenBlockTy, BlockPtr, 2);
+  Func = Builder.CreateAlignedLoad(FuncPtr, getPointerAlign());
+}
+  } else {
+// Bitcast the block literal to a generic block literal.
+BlockPtr = Builder.CreatePointerCast(
+BlockPtr, llvm::PointerType::get(GenBlockTy, 0), "block.literal");
+// Get pointer to the block invoke function
+llvm::Value *FuncPtr = Builder.CreateStructGEP(GenBlockTy, BlockPtr, 3);
+
+// First argument is a block literal casted to a void pointer
+BlockPtr = Builder.CreatePointerCast(BlockPtr, VoidPtrTy);
+Args.add(RValue::get(BlockPtr), Ctx.VoidPtrTy);
+// And the rest of the arguments.
+EmitCallArgs(Args, FnType->getAs(), E->arguments());
 
-  QualType FnType = BPT->getPointeeType();
-
-  // And the rest of the arguments.
-  EmitCallArgs(Args, FnType->getAs(), E->arguments());
-
-  // Load the function.
-  llvm::Value *Func = Builder.CreateAlignedLoad(FuncPtr, getPointerAlign());
+// Load the function.
+Func = Builder.CreateAlignedLoad(FuncPtr, getPointerAlign());
+  }
 
   const FunctionType *FuncTy = FnType->castAs();
 

r348919 - [OpenCL] Fix for TBAA information of pointer after addresspacecast

2018-12-12 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Wed Dec 12 01:51:23 2018
New Revision: 348919

URL: http://llvm.org/viewvc/llvm-project?rev=348919&view=rev
Log:
[OpenCL] Fix for TBAA information of pointer after addresspacecast

Summary: When addresspacecast is generated resulting pointer should preserve 
TBAA information from original value.

Reviewers: rjmccall, yaxunl, Anastasia

Reviewed By: rjmccall

Subscribers: asavonic, kosarev, cfe-commits, llvm-commits

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

Added:
cfe/trunk/test/CodeGenOpenCLCXX/address-space-deduction2.cl
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=348919&r1=348918&r2=348919&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Dec 12 01:51:23 2018
@@ -4269,8 +4269,9 @@ LValue CodeGenFunction::EmitCastLValue(c
 QualType DestTy = getContext().getPointerType(E->getType());
 llvm::Value *V = getTargetHooks().performAddrSpaceCast(
 *this, LV.getPointer(), E->getSubExpr()->getType().getAddressSpace(),
-DestTy.getAddressSpace(), ConvertType(DestTy));
-return MakeNaturalAlignPointeeAddrLValue(V, DestTy);
+E->getType().getAddressSpace(), ConvertType(DestTy));
+return MakeAddrLValue(Address(V, LV.getAddress().getAlignment()),
+  E->getType(), LV.getBaseInfo(), LV.getTBAAInfo());
   }
   case CK_ObjCObjectLValueCast: {
 LValue LV = EmitLValue(E->getSubExpr());

Added: cfe/trunk/test/CodeGenOpenCLCXX/address-space-deduction2.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/address-space-deduction2.cl?rev=348919&view=auto
==
--- cfe/trunk/test/CodeGenOpenCLCXX/address-space-deduction2.cl (added)
+++ cfe/trunk/test/CodeGenOpenCLCXX/address-space-deduction2.cl Wed Dec 12 
01:51:23 2018
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -O0 -emit-llvm 
-o - | FileCheck %s
+
+class P {
+public:
+  P(const P &Rhs) = default;
+
+  long A;
+  long B;
+};
+
+void foo(__global P *GPtr) {
+// CHECK: call void @llvm.memcpy{{.*}}, {{.*}}, i32 16
+  P Val = GPtr[0];
+}
+
+struct __attribute__((packed)) A { int X; };
+int test(__global A *GPtr) {
+// CHECK: {{.*}} = load i32, {{.*}}, align 1
+  return static_cast<__generic A &>(*GPtr).X;
+}


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


r348752 - [OpenCL][CodeGen] Fix replacing memcpy with addrspacecast

2018-12-10 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Mon Dec 10 04:03:00 2018
New Revision: 348752

URL: http://llvm.org/viewvc/llvm-project?rev=348752&view=rev
Log:
[OpenCL][CodeGen] Fix replacing memcpy with addrspacecast

Summary:
If a function argument is byval and RV is located in default or alloca address 
space
an optimization of creating addrspacecast instead of memcpy is performed. That 
is
not correct for OpenCL, where that can lead to a situation of address space 
casting
from __private * to __global *. See an example below:

```
typedef struct {
  int x;
} MyStruct;

void foo(MyStruct val) {}

kernel void KernelOneMember(__global MyStruct* x) {
  foo (*x);
}
```

for this code clang generated following IR:
...
%0 = load %struct.MyStruct addrspace(1)*, %struct.MyStruct addrspace(1)**
%x.addr, align 4
%1 = addrspacecast %struct.MyStruct addrspace(1)* %0 to %struct.MyStruct*
...

So the optimization was disallowed for OpenCL if RV is located in an address 
space
different than that of the argument (0).


Reviewers: yaxunl, Anastasia

Reviewed By: Anastasia

Subscribers: cfe-commits, asavonic

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

Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/test/CodeGenOpenCL/addr-space-struct-arg.cl

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=348752&r1=348751&r2=348752&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Dec 10 04:03:00 2018
@@ -3958,15 +3958,28 @@ RValue CodeGenFunction::EmitCall(const C
 } else if (I->hasLValue()) {
   auto LV = I->getKnownLValue();
   auto AS = LV.getAddressSpace();
+
   if ((!ArgInfo.getIndirectByVal() &&
(LV.getAlignment() >=
-getContext().getTypeAlignInChars(I->Ty))) ||
-  (ArgInfo.getIndirectByVal() &&
-   ((AS != LangAS::Default && AS != LangAS::opencl_private &&
- AS != CGM.getASTAllocaAddressSpace() {
+getContext().getTypeAlignInChars(I->Ty {
+NeedCopy = true;
+  }
+  if (!getLangOpts().OpenCL) {
+if ((ArgInfo.getIndirectByVal() &&
+(AS != LangAS::Default &&
+ AS != CGM.getASTAllocaAddressSpace( {
+  NeedCopy = true;
+}
+  }
+  // For OpenCL even if RV is located in default or alloca address 
space
+  // we don't want to perform address space cast for it.
+  else if ((ArgInfo.getIndirectByVal() &&
+Addr.getType()->getAddressSpace() != IRFuncTy->
+  getParamType(FirstIRArg)->getPointerAddressSpace())) {
 NeedCopy = true;
   }
 }
+
 if (NeedCopy) {
   // Create an aligned temporary, and copy to it.
   Address AI = CreateMemTempWithoutCast(

Modified: cfe/trunk/test/CodeGenOpenCL/addr-space-struct-arg.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/addr-space-struct-arg.cl?rev=348752&r1=348751&r2=348752&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/addr-space-struct-arg.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/addr-space-struct-arg.cl Mon Dec 10 04:03:00 
2018
@@ -1,6 +1,9 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header 
-ffake-address-space-map -triple i686-pc-darwin | FileCheck -enable-var-scope 
-check-prefixes=COM,X86 %s
-// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -triple 
amdgcn | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN %s
-// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL2.0 -O0 
-finclude-default-header -triple amdgcn | FileCheck -enable-var-scope 
-check-prefixes=COM,AMDGCN,AMDGCN20 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -ffake-address-space-map -triple 
i686-pc-darwin | FileCheck -enable-var-scope -check-prefixes=COM,X86 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -triple amdgcn | FileCheck 
-enable-var-scope -check-prefixes=COM,AMDGCN %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL2.0 -O0 -triple amdgcn | 
FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN,AMDGCN20 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL1.2 -O0 -triple 
spir-unknown-unknown-unknown | FileCheck -enable-var-scope -check-prefixes=SPIR 
%s
+
+typedef int int2 __attribute__((ext_vector_type(2)));
 
 typedef struct {
   int cells[9];
@@ -130,6 +133,12 @@ kernel void KernelOneMember(struct Struc
   FuncOneMember(u);
 }
 
+// SPIR: call void @llvm.memcpy.p0i8.p1i8.i32
+// SPIR-NOT: addrspacecast
+kernel void KernelOneMemberSpir(global struct StructOneMember* u) {
+  FuncOneMember(*u);
+}
+
 // AMDGCN-LABEL: define amdgpu_kernel void @KernelLargeOneMember(
 // AMDGCN:  %[[U:.*]] = alloca %struct.LargeStructOneMember, align 8, 

r346392 - [OpenCL] Add support of cl_intel_device_side_avc_motion_estimation extension

2018-11-08 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Thu Nov  8 03:25:41 2018
New Revision: 346392

URL: http://llvm.org/viewvc/llvm-project?rev=346392&view=rev
Log:
[OpenCL] Add support of cl_intel_device_side_avc_motion_estimation extension

Summary:
Documentation can be found at 
https://www.khronos.org/registry/OpenCL/extensions/intel/cl_intel_device_side_avc_motion_estimation.txt

Patch by Kristina Bessonova


Reviewers: Anastasia, yaxunl, shafik

Reviewed By: Anastasia

Subscribers: arphaman, sidorovd, AlexeySotkin, krisb, bader, asavonic, 
cfe-commits

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

Added:
cfe/trunk/include/clang/Basic/OpenCLExtensionTypes.def
cfe/trunk/test/CodeGenOpenCL/intel-subgroups-avc-ext-types.cl
cfe/trunk/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Basic/OpenCLExtensions.def
cfe/trunk/include/clang/Sema/Initialization.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/include/clang/module.modulemap
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/lib/AST/NSAPI.cpp
cfe/trunk/lib/AST/PrintfFormatString.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/AST/TypeLoc.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/Headers/opencl-c.h
cfe/trunk/lib/Index/USRGeneration.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Serialization/ASTCommon.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/test/Headers/opencl-c-header.cl
cfe/trunk/test/Index/opencl-types.cl
cfe/trunk/test/SemaOpenCL/extension-version.cl
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/tools/libclang/CXType.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=346392&r1=346391&r2=346392&view=diff
==
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Thu Nov  8 03:25:41 2018
@@ -3297,7 +3297,21 @@ enum CXTypeKind {
 
   CXType_ObjCObject = 161,
   CXType_ObjCTypeParam = 162,
-  CXType_Attributed = 163
+  CXType_Attributed = 163,
+
+  CXType_OCLIntelSubgroupAVCMcePayload = 164,
+  CXType_OCLIntelSubgroupAVCImePayload = 165,
+  CXType_OCLIntelSubgroupAVCRefPayload = 166,
+  CXType_OCLIntelSubgroupAVCSicPayload = 167,
+  CXType_OCLIntelSubgroupAVCMceResult = 168,
+  CXType_OCLIntelSubgroupAVCImeResult = 169,
+  CXType_OCLIntelSubgroupAVCRefResult = 170,
+  CXType_OCLIntelSubgroupAVCSicResult = 171,
+  CXType_OCLIntelSubgroupAVCImeResultSingleRefStreamout = 172,
+  CXType_OCLIntelSubgroupAVCImeResultDualRefStreamout = 173,
+  CXType_OCLIntelSubgroupAVCImeSingleRefStreamin = 174,
+
+  CXType_OCLIntelSubgroupAVCImeDualRefStreamin = 175
 };
 
 /**

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=346392&r1=346391&r2=346392&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Thu Nov  8 03:25:41 2018
@@ -1062,6 +1062,9 @@ public:
   CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy;
   CanQualType OCLQueueTy, OCLReserveIDTy;
   CanQualType OMPArraySectionTy;
+#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
+  CanQualType Id##Ty;
+#include "clang/Basic/OpenCLExtensionTypes.def"
 
   // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand.
   mutable QualType AutoDeductTy; // Deduction against 'auto'.

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=346392&r1=346391&r2=346392&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Thu Nov  8 03:25:41 2018
@@ -2046,6 +2046,13 @@ public:
   bool isQueueT() const;// OpenCL queue_t
   bool isReserveIDT() const;// OpenCL reserve_id_t
 
+#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
+  bool is##Id##Type() const;
+#include "clang/Basic/OpenCLExtensionTypes.def"
+  // Type defined in cl_intel_device_side_avc_motion_estimation OpenCL 
extension
+  bool isOCLIntelSubgroupAVCType() const;
+  bool isOCLExtOpaqueType() const;  // Any OpenCL

r346338 - Revert r346326 [OpenCL] Add support of cl_intel_device_side_avc_motion_estimation

2018-11-07 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Wed Nov  7 10:34:19 2018
New Revision: 346338

URL: http://llvm.org/viewvc/llvm-project?rev=346338&view=rev
Log:
Revert r346326 [OpenCL] Add support of 
cl_intel_device_side_avc_motion_estimation

This patch breaks Index/opencl-types.cl LIT test:

Script:
--
: 'RUN: at line 1';   stage1/bin/c-index-test -test-print-type 
llvm/tools/clang/test/Index/opencl-types.cl -cl-std=CL2.0 | 
stage1/bin/FileCheck llvm/tools/clang/test/Index/opencl-types.cl
--
Command Output (stderr):
--
llvm/tools/clang/test/Index/opencl-types.cl:3:26: warning: unsupported OpenCL 
extension 'cl_khr_fp16' - ignoring [-Wignored-pragmas]
llvm/tools/clang/test/Index/opencl-types.cl:4:26: warning: unsupported OpenCL 
extension 'cl_khr_fp64' - ignoring [-Wignored-pragmas]
llvm/tools/clang/test/Index/opencl-types.cl:8:9: error: use of type 'double' 
requires cl_khr_fp64 extension to be enabled
llvm/tools/clang/test/Index/opencl-types.cl:11:8: error: declaring variable of 
type 'half' is not allowed
llvm/tools/clang/test/Index/opencl-types.cl:15:3: error: use of type 'double' 
requires cl_khr_fp64 extension to be enabled
llvm/tools/clang/test/Index/opencl-types.cl:16:3: error: use of type 'double4' 
(vector of 4 'double' values) requires cl_khr_fp64 extension to be enabled
llvm/tools/clang/test/Index/opencl-types.cl:26:26: warning: unsupported OpenCL 
extension 'cl_khr_gl_msaa_sharing' - ignoring [-Wignored-pragmas]
llvm/tools/clang/test/Index/opencl-types.cl:35:44: error: use of type 
'__read_only image2d_msaa_t' requires cl_khr_gl_msaa_sharing extension to be 
enabled
llvm/tools/clang/test/Index/opencl-types.cl:36:49: error: use of type 
'__read_only image2d_array_msaa_t' requires cl_khr_gl_msaa_sharing extension to 
be enabled
llvm/tools/clang/test/Index/opencl-types.cl:37:49: error: use of type 
'__read_only image2d_msaa_depth_t' requires cl_khr_gl_msaa_sharing extension to 
be enabled
llvm/tools/clang/test/Index/opencl-types.cl:38:54: error: use of type 
'__read_only image2d_array_msaa_depth_t' requires cl_khr_gl_msaa_sharing 
extension to be enabled


Removed:
cfe/trunk/include/clang/Basic/OpenCLExtensionTypes.def
cfe/trunk/test/CodeGenOpenCL/intel-subgroups-avc-ext-types.cl
cfe/trunk/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Basic/OpenCLExtensions.def
cfe/trunk/include/clang/Sema/Initialization.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/include/clang/module.modulemap
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/lib/AST/NSAPI.cpp
cfe/trunk/lib/AST/PrintfFormatString.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/AST/TypeLoc.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/Headers/opencl-c.h
cfe/trunk/lib/Index/USRGeneration.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Serialization/ASTCommon.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/test/Headers/opencl-c-header.cl
cfe/trunk/test/Index/opencl-types.cl
cfe/trunk/test/SemaOpenCL/extension-version.cl
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/tools/libclang/CXType.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=346338&r1=346337&r2=346338&view=diff
==
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Wed Nov  7 10:34:19 2018
@@ -3297,21 +3297,7 @@ enum CXTypeKind {
 
   CXType_ObjCObject = 161,
   CXType_ObjCTypeParam = 162,
-  CXType_Attributed = 163,
-
-  CXType_OCLIntelSubgroupAVCMcePayload = 164,
-  CXType_OCLIntelSubgroupAVCImePayload = 165,
-  CXType_OCLIntelSubgroupAVCRefPayload = 166,
-  CXType_OCLIntelSubgroupAVCSicPayload = 167,
-  CXType_OCLIntelSubgroupAVCMceResult = 168,
-  CXType_OCLIntelSubgroupAVCImeResult = 169,
-  CXType_OCLIntelSubgroupAVCRefResult = 170,
-  CXType_OCLIntelSubgroupAVCSicResult = 171,
-  CXType_OCLIntelSubgroupAVCImeResultSingleRefStreamout = 172,
-  CXType_OCLIntelSubgroupAVCImeResultDualRefStreamout = 173,
-  CXType_OCLIntelSubgroupAVCImeSingleRefStreamin = 174,
-
-  CXType_OCLIntelSubgroupAVCImeDualRefStreamin = 175
+  CXType_Attributed = 163
 };
 
 /**

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=346338&r1=346337&r2=346

r346326 - [OpenCL] Add support of cl_intel_device_side_avc_motion_estimation extension

2018-11-07 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Wed Nov  7 07:44:01 2018
New Revision: 346326

URL: http://llvm.org/viewvc/llvm-project?rev=346326&view=rev
Log:
[OpenCL] Add support of cl_intel_device_side_avc_motion_estimation extension

Summary:
Documentation can be found at 
https://www.khronos.org/registry/OpenCL/extensions/intel/cl_intel_device_side_avc_motion_estimation.txt

Patch by Kristina Bessonova


Reviewers: Anastasia, yaxunl, shafik

Reviewed By: Anastasia

Subscribers: arphaman, sidorovd, AlexeySotkin, krisb, bader, asavonic, 
cfe-commits

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

Added:
cfe/trunk/include/clang/Basic/OpenCLExtensionTypes.def
cfe/trunk/test/CodeGenOpenCL/intel-subgroups-avc-ext-types.cl
cfe/trunk/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Basic/OpenCLExtensions.def
cfe/trunk/include/clang/Sema/Initialization.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/include/clang/module.modulemap
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/lib/AST/NSAPI.cpp
cfe/trunk/lib/AST/PrintfFormatString.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/AST/TypeLoc.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/Headers/opencl-c.h
cfe/trunk/lib/Index/USRGeneration.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Serialization/ASTCommon.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/test/Headers/opencl-c-header.cl
cfe/trunk/test/Index/opencl-types.cl
cfe/trunk/test/SemaOpenCL/extension-version.cl
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/tools/libclang/CXType.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=346326&r1=346325&r2=346326&view=diff
==
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Wed Nov  7 07:44:01 2018
@@ -3297,7 +3297,21 @@ enum CXTypeKind {
 
   CXType_ObjCObject = 161,
   CXType_ObjCTypeParam = 162,
-  CXType_Attributed = 163
+  CXType_Attributed = 163,
+
+  CXType_OCLIntelSubgroupAVCMcePayload = 164,
+  CXType_OCLIntelSubgroupAVCImePayload = 165,
+  CXType_OCLIntelSubgroupAVCRefPayload = 166,
+  CXType_OCLIntelSubgroupAVCSicPayload = 167,
+  CXType_OCLIntelSubgroupAVCMceResult = 168,
+  CXType_OCLIntelSubgroupAVCImeResult = 169,
+  CXType_OCLIntelSubgroupAVCRefResult = 170,
+  CXType_OCLIntelSubgroupAVCSicResult = 171,
+  CXType_OCLIntelSubgroupAVCImeResultSingleRefStreamout = 172,
+  CXType_OCLIntelSubgroupAVCImeResultDualRefStreamout = 173,
+  CXType_OCLIntelSubgroupAVCImeSingleRefStreamin = 174,
+
+  CXType_OCLIntelSubgroupAVCImeDualRefStreamin = 175
 };
 
 /**

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=346326&r1=346325&r2=346326&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Wed Nov  7 07:44:01 2018
@@ -1062,6 +1062,9 @@ public:
   CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy;
   CanQualType OCLQueueTy, OCLReserveIDTy;
   CanQualType OMPArraySectionTy;
+#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
+  CanQualType Id##Ty;
+#include "clang/Basic/OpenCLExtensionTypes.def"
 
   // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand.
   mutable QualType AutoDeductTy; // Deduction against 'auto'.

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=346326&r1=346325&r2=346326&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Wed Nov  7 07:44:01 2018
@@ -2046,6 +2046,13 @@ public:
   bool isQueueT() const;// OpenCL queue_t
   bool isReserveIDT() const;// OpenCL reserve_id_t
 
+#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
+  bool is##Id##Type() const;
+#include "clang/Basic/OpenCLExtensionTypes.def"
+  // Type defined in cl_intel_device_side_avc_motion_estimation OpenCL 
extension
+  bool isOCLIntelSubgroupAVCType() const;
+  bool isOCLExtOpaqueType() const;  // Any OpenCL

r346311 - [OpenCL] Fix diagnostic message about overload candidates

2018-11-07 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Wed Nov  7 05:07:18 2018
New Revision: 346311

URL: http://llvm.org/viewvc/llvm-project?rev=346311&view=rev
Log:
[OpenCL] Fix diagnostic message about overload candidates

Summary:
I wonder if there are some extension which need to be disabled to get
overloadable candidate available.


Reviewers: asavonic, Anastasia

Reviewed By: Anastasia

Subscribers: yaxunl, sidorovd, cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/test/SemaOpenCL/extension-begin.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=346311&r1=346310&r2=346311&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Nov  7 05:07:18 
2018
@@ -3681,7 +3681,7 @@ def warn_diagnose_if_succeeded : Warning
 def note_ovl_candidate_disabled_by_function_cond_attr : Note<
 "candidate disabled: %0">;
 def note_ovl_candidate_disabled_by_extension : Note<
-"candidate unavailable as it requires OpenCL extension '%0' to be 
disabled">;
+"candidate unavailable as it requires OpenCL extension '%0' to be 
enabled">;
 def err_addrof_function_disabled_by_enable_if_attr : Error<
 "cannot take address of function %0 because it has one or more "
 "non-tautological enable_if conditions">;

Modified: cfe/trunk/test/SemaOpenCL/extension-begin.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/extension-begin.cl?rev=346311&r1=346310&r2=346311&view=diff
==
--- cfe/trunk/test/SemaOpenCL/extension-begin.cl (original)
+++ cfe/trunk/test/SemaOpenCL/extension-begin.cl Wed Nov  7 05:07:18 2018
@@ -40,7 +40,7 @@ void test_f2(void) {
   PointerOfA test_A_pointer; // expected-error {{use of type 'PointerOfA' (aka 
'const struct A *') requires my_ext extension to be enabled}}
   f(); // expected-error {{use of declaration 'f' requires my_ext extension to 
be enabled}}
   g(0); // expected-error {{no matching function for call to 'g'}}
-// expected-note@extension-begin.h:18 {{candidate unavailable as it 
requires OpenCL extension 'my_ext' to be disabled}}
+// expected-note@extension-begin.h:18 {{candidate unavailable as it 
requires OpenCL extension 'my_ext' to be enabled}}
 // expected-note@extension-begin.h:23 {{candidate function not viable: 
requires 0 arguments, but 1 was provided}}
 }
 


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


r345497 - [OpenCL] Fix serialization of OpenCLExtensionDecls

2018-10-29 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Mon Oct 29 04:14:01 2018
New Revision: 345497

URL: http://llvm.org/viewvc/llvm-project?rev=345497&view=rev
Log:
[OpenCL] Fix serialization of OpenCLExtensionDecls

Summary:
I recently discovered that adding the following code into `opencl-c.h` causes
failure of `test/Headers/opencl-c-header.cl`:
```
#pragma OPENCL EXTENSION cl_my_ext : begin
void cl_my_ext_foobarbaz();
#pragma OPENCL EXTENSIOn cl_my_ext : end
```

Clang crashes at the assertion is `ASTReader::getGlobalSubmoduleID()`:
```
assert(I != M.SubmoduleRemap.end() && "Invalid index into submodule index 
remap");
```

The root cause of the problem that to deserialize `OPENCL_EXTENSION_DECLS`
section `ASTReader` needs to deserialize a Decl contained in it. In turn,
deserializing a Decl requires information about whether this declaration is
part of a (sub)module, but this information is not read yet because it is
located further in a module file.

Reviewers: Anastasia, yaxunl, JDevlieghere

Reviewed By: Anastasia

Subscribers: sidorovd, cfe-commits, asavonic

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

Added:
cfe/trunk/test/SemaOpenCL/extension-begin.h
Modified:
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/test/SemaOpenCL/extension-begin.cl

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=345497&r1=345496&r2=345497&view=diff
==
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Mon Oct 29 04:14:01 2018
@@ -5014,13 +5014,16 @@ ASTFileSignature ASTWriter::WriteASTCore
   WriteFPPragmaOptions(SemaRef.getFPOptions());
   WriteOpenCLExtensions(SemaRef);
   WriteOpenCLExtensionTypes(SemaRef);
-  WriteOpenCLExtensionDecls(SemaRef);
   WriteCUDAPragmas(SemaRef);
 
   // If we're emitting a module, write out the submodule information.
   if (WritingModule)
 WriteSubmodules(WritingModule);
 
+  // We need to have information about submodules to correctly deserialize
+  // decls from OpenCLExtensionDecls block
+  WriteOpenCLExtensionDecls(SemaRef);
+
   Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes);
 
   // Write the record containing external, unnamed definitions.

Modified: cfe/trunk/test/SemaOpenCL/extension-begin.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/extension-begin.cl?rev=345497&r1=345496&r2=345497&view=diff
==
--- cfe/trunk/test/SemaOpenCL/extension-begin.cl (original)
+++ cfe/trunk/test/SemaOpenCL/extension-begin.cl Mon Oct 29 04:14:01 2018
@@ -1,37 +1,29 @@
 // Test this without pch.
-// RUN: %clang_cc1 %s -DHEADER -DHEADER_USER -triple spir-unknown-unknown 
-verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic 
-fsyntax-only
 
 // Test with pch.
-// RUN: %clang_cc1 %s -DHEADER -triple spir-unknown-unknown -emit-pch -o %t 
-verify -pedantic
-// RUN: %clang_cc1 %s -DHEADER_USER -triple spir-unknown-unknown -include-pch 
%t -fsyntax-only -verify -pedantic
+// RUN: %clang_cc1 -x cl %S/extension-begin.h -triple spir-unknown-unknown 
-emit-pch -o %t.pch -pedantic
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -include-pch %t.pch 
-DIMPLICIT_INCLUDE -DUSE_PCH -fsyntax-only -verify -pedantic
 
-#if defined(HEADER) && !defined(INCLUDED)
-#define INCLUDED 
-
-#pragma OPENCL EXTENSION all : begin // expected-warning {{expected 'disable' 
- ignoring}}
-#pragma OPENCL EXTENSION all : end // expected-warning {{expected 'disable' - 
ignoring}}
-
-#pragma OPENCL EXTENSION my_ext : begin 
-
-struct A {
-  int a;
-};
-
-typedef struct A TypedefOfA;
-typedef const TypedefOfA* PointerOfA;
-
-void f(void);
-
-__attribute__((overloadable)) void g(long x);
-
-#pragma OPENCL EXTENSION my_ext : end
-#pragma OPENCL EXTENSION my_ext : end // expected-warning {{OpenCL extension 
end directive mismatches begin directive - ignoring}}
-
-__attribute__((overloadable)) void g(void);
-
-#endif // defined(HEADER) && !defined(INCLUDED)
-
-#ifdef HEADER_USER
+// Test with modules
+// RUN: rm -rf %t.modules
+// RUN: mkdir -p %t.modules
+//
+// RUN: %clang_cc1 -cl-std=CL1.2 -DIMPLICIT_INCLUDE -include 
%S/extension-begin.h -triple spir-unknown-unknown -O0 -emit-llvm -o - -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t.modules %s -verify -pedantic
+//
+// RUN: rm -rf %t.modules
+// RUN: mkdir -p %t.modules
+//
+// RUN: %clang_cc1 -cl-std=CL2.0 -DIMPLICIT_INCLUDE -include 
%S/extension-begin.h -triple spir-unknown-unknown -O0 -emit-llvm -o - -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t.modules %s -verify -pedantic
+
+#ifndef IMPLICIT_INCLUDE
+#include "extension-begin.h"
+#endif // IMPLICIT_INCLUDE
+#ifndef USE_PCH
+// expected-warning@extension-begin.h:4 {{expected 'disable' - ignoring}}
+// expected-warning@extension-begin.h:5 {{expect

r345051 - [OpenCL] Remove PIPE_RESERVE_ID_VALID_BIT from opencl-c.h

2018-10-23 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Tue Oct 23 10:05:29 2018
New Revision: 345051

URL: http://llvm.org/viewvc/llvm-project?rev=345051&view=rev
Log:
[OpenCL] Remove PIPE_RESERVE_ID_VALID_BIT from opencl-c.h

Summary:
PIPE_RESERVE_ID_VALID_BIT is implementation defined, so lets not keep it in the 
header. 

Previously the topic was discussed here: https://reviews.llvm.org/D32896 

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Subscribers: cfe-commits, asavonic, bader

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

Modified:
cfe/trunk/lib/Headers/opencl-c.h

Modified: cfe/trunk/lib/Headers/opencl-c.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c.h?rev=345051&r1=345050&r2=345051&view=diff
==
--- cfe/trunk/lib/Headers/opencl-c.h (original)
+++ cfe/trunk/lib/Headers/opencl-c.h Tue Oct 23 10:05:29 2018
@@ -15715,7 +15715,6 @@ double __ovld __conv work_group_scan_inc
 
 // OpenCL v2.0 s6.13.16 - Pipe Functions
 #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
-#define PIPE_RESERVE_ID_VALID_BIT (1U << 30)
 #define CLK_NULL_RESERVE_ID (__builtin_astype(((void*)(__SIZE_MAX__)), 
reserve_id_t))
 bool __ovld is_valid_reserve_id(reserve_id_t reserve_id);
 #endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0


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


r345044 - [OpenCL] Add cl_intel_planar_yuv extension

2018-10-23 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Tue Oct 23 09:13:16 2018
New Revision: 345044

URL: http://llvm.org/viewvc/llvm-project?rev=345044&view=rev
Log:
[OpenCL] Add cl_intel_planar_yuv extension

Just adding a preprocessor #define for the extension.

Patch by Alexey Sotkin and Dmitry Sidorov

Phabricator review: https://reviews.llvm.org/D51402


Modified:
cfe/trunk/lib/Headers/opencl-c.h
cfe/trunk/test/Headers/opencl-c-header.cl

Modified: cfe/trunk/lib/Headers/opencl-c.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c.h?rev=345044&r1=345043&r2=345044&view=diff
==
--- cfe/trunk/lib/Headers/opencl-c.h (original)
+++ cfe/trunk/lib/Headers/opencl-c.h Tue Oct 23 09:13:16 2018
@@ -22,6 +22,14 @@
 #endif //cl_khr_3d_image_writes
 #endif //__OPENCL_C_VERSION__ < CL_VERSION_2_0
 
+#if __OPENCL_C_VERSION__ >= CL_VERSION_1_2
+#ifndef cl_intel_planar_yuv
+#define cl_intel_planar_yuv
+#endif // cl_intel_planar_yuv
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : begin
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : end
+#endif // __OPENCL_C_VERSION__ >= CL_VERSION_1_2
+
 #define __ovld __attribute__((overloadable))
 #define __conv __attribute__((convergent))
 

Modified: cfe/trunk/test/Headers/opencl-c-header.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/opencl-c-header.cl?rev=345044&r1=345043&r2=345044&view=diff
==
--- cfe/trunk/test/Headers/opencl-c-header.cl (original)
+++ cfe/trunk/test/Headers/opencl-c-header.cl Tue Oct 23 09:13:16 2018
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s| FileCheck %s
-// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -cl-std=CL1.1| 
FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify | FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.1| 
FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.2| 
FileCheck %s
 
 // Test including the default header as a module.
 // The module should be compiled only once and loaded from cache afterwards.
@@ -71,4 +72,16 @@ void test_image3dwo(write_only image3d_t
 }
 #endif //__OPENCL_C_VERSION__
 
+// Verify that non-builtin cl_intel_planar_yuv extension is defined from
+// OpenCL 1.2 onwards.
+#if (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
+// expected-no-diagnostics
+#ifndef cl_intel_planar_yuv
+#error "Missing cl_intel_planar_yuv define"
+#endif
+#else //__OPENCL_C_VERSION__
+// expected-warning@+2{{unknown OpenCL extension 'cl_intel_planar_yuv' - 
ignoring}}
+#endif //__OPENCL_C_VERSION__
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : enable
+
 // CHECK-MOD: Reading modules


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


r345038 - [OpenCL][NFC] Unify ZeroToOCL* cast types

2018-10-23 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Tue Oct 23 08:19:20 2018
New Revision: 345038

URL: http://llvm.org/viewvc/llvm-project?rev=345038&view=rev
Log:
[OpenCL][NFC] Unify ZeroToOCL* cast types

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Subscribers: asavonic, cfe-commits

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

Modified:
cfe/trunk/include/clang/AST/OperationKinds.def
cfe/trunk/include/clang/Sema/Initialization.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CGExprComplex.cpp
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp
cfe/trunk/lib/Sema/SemaCast.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp

Modified: cfe/trunk/include/clang/AST/OperationKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OperationKinds.def?rev=345038&r1=345037&r2=345038&view=diff
==
--- cfe/trunk/include/clang/AST/OperationKinds.def (original)
+++ cfe/trunk/include/clang/AST/OperationKinds.def Tue Oct 23 08:19:20 2018
@@ -322,11 +322,9 @@ CAST_OPERATION(CopyAndAutoreleaseBlockOb
 // callee of a call expression.
 CAST_OPERATION(BuiltinFnToFnPtr)
 
-// Convert a zero value for OpenCL event_t initialization.
-CAST_OPERATION(ZeroToOCLEvent)
-
-// Convert a zero value for OpenCL queue_t initialization.
-CAST_OPERATION(ZeroToOCLQueue)
+// Convert a zero value for OpenCL opaque types initialization (event_t,
+// queue_t, etc.)
+CAST_OPERATION(ZeroToOCLOpaqueType)
 
 // Convert a pointer to a different address space.
 CAST_OPERATION(AddressSpaceConversion)

Modified: cfe/trunk/include/clang/Sema/Initialization.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Initialization.h?rev=345038&r1=345037&r2=345038&view=diff
==
--- cfe/trunk/include/clang/Sema/Initialization.h (original)
+++ cfe/trunk/include/clang/Sema/Initialization.h Tue Oct 23 08:19:20 2018
@@ -893,11 +893,8 @@ public:
 /// Initialize an OpenCL sampler from an integer.
 SK_OCLSamplerInit,
 
-/// Initialize queue_t from 0.
-SK_OCLZeroQueue,
-
-/// Passing zero to a function where OpenCL event_t is expected.
-SK_OCLZeroEvent
+/// Initialize an opaque OpenCL type (event_t, queue_t, etc.) with zero
+SK_OCLZeroOpaqueType
   };
 
   /// A single step in the initialization sequence.
@@ -1334,12 +1331,9 @@ public:
   /// constant.
   void AddOCLSamplerInitStep(QualType T);
 
-  /// Add a step to initialize an OpenCL event_t from a NULL
-  /// constant.
-  void AddOCLZeroEventStep(QualType T);
-
-  /// Add a step to initialize an OpenCL queue_t from 0.
-  void AddOCLZeroQueueStep(QualType T);
+  /// Add a step to initialzie an OpenCL opaque type (event_t, queue_t, etc.)
+  /// from a zero constant.
+  void AddOCLZeroOpaqueTypeStep(QualType T);
 
   /// Add steps to unwrap a initializer list for a reference around a
   /// single element and rewrap it at the end.

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=345038&r1=345037&r2=345038&view=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Oct 23 08:19:20 2018
@@ -1641,8 +1641,7 @@ bool CastExpr::CastConsistency() const {
   case CK_ARCConsumeObject:
   case CK_ARCReclaimReturnedObject:
   case CK_ARCExtendBlockObject:
-  case CK_ZeroToOCLEvent:
-  case CK_ZeroToOCLQueue:
+  case CK_ZeroToOCLOpaqueType:
   case CK_IntToOCLSampler:
   case CK_FixedPointCast:
 assert(!getType()->isBooleanType() && "unheralded conversion to bool");

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=345038&r1=345037&r2=345038&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Oct 23 08:19:20 2018
@@ -9551,8 +9551,7 @@ bool IntExprEvaluator::VisitCastExpr(con
   case CK_IntegralComplexCast:
   case CK_IntegralComplexToFloatingComplex:
   case CK_BuiltinFnToFnPtr:
-  case CK_ZeroToOCLEvent:
-  case CK_ZeroToOCLQueue:
+  case CK_ZeroToOCLOpaqueType:
   case CK_NonAtomicToAtomic:
   case CK_AddressSpaceConversion:
   case CK_IntToOCLSampler:
@@ -10086,8 +10085,7 @@ bool ComplexExprEvaluator::VisitCastExpr
   case CK_ARCExtendBlockObject:
   case CK_CopyAndAutoreleaseBlockObject:
   case CK_BuiltinFnToFnPtr:
-  case CK_ZeroToOCLEvent:
-  case CK_ZeroToOCLQueue:
+  case CK_ZeroToOCLOpaqueType:
   case CK_NonAtomicToAtomic:
   case CK_

r344246 - [Sema][OpenCL] Improve diagnostics for not viable overloadable function candidates

2018-10-11 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Thu Oct 11 06:35:34 2018
New Revision: 344246

URL: http://llvm.org/viewvc/llvm-project?rev=344246&view=rev
Log:
[Sema][OpenCL] Improve diagnostics for not viable overloadable function 
candidates

Summary:
Allowed extension name (that ought to be disabled) printing in the note message.

This diagnostic was proposed here: https://reviews.llvm.org/D51341

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Subscribers: cfe-commits, asavonic, bader

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/SemaOpenCL/extension-begin.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=344246&r1=344245&r2=344246&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Oct 11 06:35:34 
2018
@@ -3674,7 +3674,7 @@ def warn_diagnose_if_succeeded : Warning
 def note_ovl_candidate_disabled_by_function_cond_attr : Note<
 "candidate disabled: %0">;
 def note_ovl_candidate_disabled_by_extension : Note<
-"candidate disabled due to OpenCL extension">;
+"candidate unavailable as it requires OpenCL extension '%0' to be 
disabled">;
 def err_addrof_function_disabled_by_enable_if_attr : Error<
 "cannot take address of function %0 because it has one or more "
 "non-tautological enable_if conditions">;

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=344246&r1=344245&r2=344246&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Oct 11 06:35:34 2018
@@ -8576,6 +8576,21 @@ public:
   llvm::StringRef getCurrentOpenCLExtension() const {
 return CurrOpenCLExtension;
   }
+
+  /// Check if a function declaration \p FD associates with any
+  /// extensions present in OpenCLDeclExtMap and if so return the
+  /// extension(s) name(s).
+  std::string getOpenCLExtensionsFromDeclExtMap(FunctionDecl *FD);
+
+  /// Check if a function type \p FT associates with any
+  /// extensions present in OpenCLTypeExtMap and if so return the
+  /// extension(s) name(s).
+  std::string getOpenCLExtensionsFromTypeExtMap(FunctionType *FT);
+
+  /// Find an extension in an appropriate extension map and return its name
+  template
+  std::string getOpenCLExtensionsFromExtMap(T* FT, MapT &Map);
+
   void setCurrentOpenCLExtension(llvm::StringRef Ext) {
 CurrOpenCLExtension = Ext;
   }

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=344246&r1=344245&r2=344246&view=diff
==
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Thu Oct 11 06:35:34 2018
@@ -1914,6 +1914,34 @@ void Sema::setCurrentOpenCLExtensionForD
   setOpenCLExtensionForDecl(D, CurrOpenCLExtension);
 }
 
+std::string Sema::getOpenCLExtensionsFromDeclExtMap(FunctionDecl *FD) {
+  if (!OpenCLDeclExtMap.empty())
+return getOpenCLExtensionsFromExtMap(FD, OpenCLDeclExtMap);
+
+  return "";
+}
+
+std::string Sema::getOpenCLExtensionsFromTypeExtMap(FunctionType *FT) {
+  if (!OpenCLTypeExtMap.empty())
+return getOpenCLExtensionsFromExtMap(FT, OpenCLTypeExtMap);
+
+  return "";
+}
+
+template 
+std::string Sema::getOpenCLExtensionsFromExtMap(T *FDT, MapT &Map) {
+  std::string ExtensionNames = "";
+  auto Loc = Map.find(FDT);
+
+  for (auto const& I : Loc->second) {
+ExtensionNames += I;
+ExtensionNames += " ";
+  }
+  ExtensionNames.pop_back();
+
+  return ExtensionNames;
+}
+
 bool Sema::isOpenCLDisabledDecl(Decl *FD) {
   auto Loc = OpenCLDeclExtMap.find(FD);
   if (Loc == OpenCLDeclExtMap.end())

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=344246&r1=344245&r2=344246&view=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Oct 11 06:35:34 2018
@@ -10242,7 +10242,8 @@ static void DiagnoseOpenCLExtensionDisab
   FunctionDecl *Callee = Cand->Function;
 
   S.Diag(Callee->getLocation(),
- diag::note_ovl_candidate_disabled_by_extension);
+ diag::note_ovl_candidate_disabled_by_extension)
+<< S.getOpenCLExtensionsFromDeclExtMap(Callee);
 }
 
 /// Generates a 'note' diagnostic for an overload candidate.  We've

Modified: cfe/trunk/test/SemaOpenCL/extension-begin.cl
URL: 
http://llvm

r342370 - [OpenCL] Allow blocks to capture arrays in OpenCL

2018-09-17 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Mon Sep 17 04:19:42 2018
New Revision: 342370

URL: http://llvm.org/viewvc/llvm-project?rev=342370&view=rev
Log:
[OpenCL] Allow blocks to capture arrays in OpenCL

Summary: Patch by Egor Churaev

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Subscribers: asavonic, bader, cfe-commits

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

Added:
cfe/trunk/test/SemaOpenCL/block-array-capturing.cl
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=342370&r1=342369&r2=342370&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Sep 17 04:19:42 2018
@@ -14627,8 +14627,10 @@ static bool captureInBlock(BlockScopeInf
   Expr *CopyExpr = nullptr;
   bool ByRef = false;
 
-  // Blocks are not allowed to capture arrays.
-  if (CaptureType->isArrayType()) {
+  // Blocks are not allowed to capture arrays, excepting OpenCL.
+  // OpenCL v2.0 s1.12.5 (revision 40): arrays are captured by reference
+  // (decayed to pointers).
+  if (!S.getLangOpts().OpenCL && CaptureType->isArrayType()) {
 if (BuildAndDiagnose) {
   S.Diag(Loc, diag::err_ref_array_type);
   S.Diag(Var->getLocation(), diag::note_previous_decl)

Added: cfe/trunk/test/SemaOpenCL/block-array-capturing.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/block-array-capturing.cl?rev=342370&view=auto
==
--- cfe/trunk/test/SemaOpenCL/block-array-capturing.cl (added)
+++ cfe/trunk/test/SemaOpenCL/block-array-capturing.cl Mon Sep 17 04:19:42 2018
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple spir64-unkown-unkown -emit-llvm 
%s -o -| FileCheck %s
+// expected-no-diagnostics
+
+typedef int (^block_t)();
+
+int block_typedef_kernel(global int* res) {
+  // CHECK: %{{.*}} = alloca <{ i32, i32, [3 x i32] }>
+  int a[3] = {1, 2, 3};
+  // CHECK: call void @llvm.memcpy{{.*}}
+  block_t b = ^() { return a[0]; };
+  return b();
+}
+
+// CHECK: define {{.*}} @__block_typedef_kernel_block_invoke
+// CHECK: %{{.*}} = getelementptr inbounds [3 x i32], [3 x i32] addrspace(4)* 
%{{.*}}, i64 0, i64 0
+// CHECK-NOT: call void @llvm.memcpy{{.*}}


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


r342367 - Merge two attribute diagnostics into one

2018-09-17 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Mon Sep 17 03:39:46 2018
New Revision: 342367

URL: http://llvm.org/viewvc/llvm-project?rev=342367&view=rev
Log:
Merge two attribute diagnostics into one

Summary:
Merged the recently added `err_attribute_argument_negative` diagnostic
with existing `err_attribute_requires_positive_integer` diagnostic:
the former allows only strictly positive integer, while the latter
also allows zero.

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaStmtAttr.cpp
cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=342367&r1=342366&r2=342367&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Sep 17 03:39:46 
2018
@@ -2498,7 +2498,8 @@ def err_attribute_invalid_vector_type :
 def err_attribute_bad_neon_vector_size : Error<
   "Neon vector size must be 64 or 128 bits">;
 def err_attribute_requires_positive_integer : Error<
-  "%0 attribute requires a positive integral compile time constant 
expression">;
+  "%0 attribute requires a %select{positive|non-negative}1 "
+  "integral compile time constant expression">;
 def err_attribute_requires_opencl_version : Error<
   "%0 attribute requires OpenCL version %1%select{| or above}2">;
 def warn_unsupported_target_attribute
@@ -2531,8 +2532,6 @@ def err_attribute_argument_type : Error<
   "constant|a string|an identifier}1">;
 def err_attribute_argument_outof_range : Error<
   "%0 attribute requires integer constant between %1 and %2 inclusive">;
-def err_attribute_argument_negative : Error<
-  "negative argument is not allowed for %0 attribute">;
 def err_init_priority_object_attr : Error<
   "can only use 'init_priority' attribute on file-scope definitions "
   "of objects of class type">;

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=342367&r1=342366&r2=342367&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Sep 17 03:39:46 2018
@@ -254,7 +254,8 @@ static bool checkUInt32Argument(Sema &S,
   }
 
   if (StrictlyUnsigned && I.isSigned() && I.isNegative()) {
-S.Diag(getAttrLoc(AI), diag::err_attribute_argument_negative) << AI;
+S.Diag(getAttrLoc(AI), diag::err_attribute_requires_positive_integer)
+<< AI << /*non-negative*/ 1;
 return false;
   }
 

Modified: cfe/trunk/lib/Sema/SemaStmtAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAttr.cpp?rev=342367&r1=342366&r2=342367&view=diff
==
--- cfe/trunk/lib/Sema/SemaStmtAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmtAttr.cpp Mon Sep 17 03:39:46 2018
@@ -304,7 +304,7 @@ static Attr *handleOpenCLUnrollHint(Sema
 if (Val <= 0) {
   S.Diag(A.getRange().getBegin(),
  diag::err_attribute_requires_positive_integer)
-  << A;
+  << A << /* positive */ 0;
   return nullptr;
 }
 UnrollFactor = Val;

Modified: cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl?rev=342367&r1=342366&r2=342367&view=diff
==
--- cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl Mon Sep 17 03:39:46 2018
@@ -38,8 +38,8 @@ __attribute__((intel_reqd_sub_group_size
 kernel __attribute__((intel_reqd_sub_group_size(0))) void kernel15(){} // 
expected-error {{'intel_reqd_sub_group_size' attribute must be greater than 0}}
 kernel __attribute__((intel_reqd_sub_group_size(8))) 
__attribute__((intel_reqd_sub_group_size(16))) void kernel16() {}  
//expected-warning{{attribute 'intel_reqd_sub_group_size' is already applied 
with different parameters}}
 
-__kernel __attribute__((work_group_size_hint(8,-16,32))) void neg1() {} 
//expected-error{{negative argument is not allowed for 'work_group_size_hint' 
attribute}}
-__kernel __attribute__((reqd_work_group_size(8,16,-32))) void neg2(){} // 
expected-error{{negative argument is not allowed for 'reqd_work_group_size' 
attribute}}
+__kernel __attribute__((work_group_size_hint(8,-16,32))) void neg1() {} 
//expected-error{{'work_group_size_hint' attribute requires a non-negative 
integral compile time constant expression}}
+__kernel __attribute__((reqd_work_gr

r341553 - [OpenCL] Relax diagnostics on OpenCL access qualifiers

2018-09-06 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Thu Sep  6 08:10:26 2018
New Revision: 341553

URL: http://llvm.org/viewvc/llvm-project?rev=341553&view=rev
Log:
[OpenCL] Relax diagnostics on OpenCL access qualifiers

Summary:
Emit warning for multiple access qualifiers if they do not conflict.

Patch by Alexey Bader

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Subscribers: asavonic, bader, cfe-commits

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

Modified:
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaOpenCL/access-qualifier.cl

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=341553&r1=341552&r2=341553&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Sep  6 08:10:26 2018
@@ -5900,10 +5900,16 @@ static void handleOpenCLAccessAttr(Sema
 
   // Check if there is only one access qualifier.
   if (D->hasAttr()) {
-S.Diag(AL.getLoc(), diag::err_opencl_multiple_access_qualifiers)
-<< D->getSourceRange();
-D->setInvalidDecl(true);
-return;
+if (D->getAttr()->getSemanticSpelling() ==
+AL.getSemanticSpelling()) {
+  S.Diag(AL.getLoc(), diag::warn_duplicate_declspec)
+  << AL.getName()->getName() << AL.getRange();
+} else {
+  S.Diag(AL.getLoc(), diag::err_opencl_multiple_access_qualifiers)
+  << D->getSourceRange();
+  D->setInvalidDecl(true);
+  return;
+}
   }
 
   // OpenCL v2.0 s6.6 - read_write can be used for image types to specify that 
an

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=341553&r1=341552&r2=341553&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Sep  6 08:10:26 2018
@@ -7105,23 +7105,43 @@ static void HandleOpenCLAccessAttr(QualT
   }
 
   if (const TypedefType* TypedefTy = CurType->getAs()) {
-QualType PointeeTy = TypedefTy->desugar();
-S.Diag(Attr.getLoc(), diag::err_opencl_multiple_access_qualifiers);
+QualType BaseTy = TypedefTy->desugar();
 
 std::string PrevAccessQual;
-switch (cast(PointeeTy.getTypePtr())->getKind()) {
-  #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
-case BuiltinType::Id:  \
-  PrevAccessQual = #Access;\
-  break;
-  #include "clang/Basic/OpenCLImageTypes.def"
-default:
-  assert(0 && "Unable to find corresponding image type.");
+if (BaseTy->isPipeType()) {
+  if (TypedefTy->getDecl()->hasAttr()) {
+OpenCLAccessAttr *Attr =
+TypedefTy->getDecl()->getAttr();
+PrevAccessQual = Attr->getSpelling();
+  } else {
+PrevAccessQual = "read_only";
+  }
+} else if (const BuiltinType* ImgType = BaseTy->getAs()) {
+
+  switch (ImgType->getKind()) {
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
+  case BuiltinType::Id:  \
+PrevAccessQual = #Access;\
+break;
+#include "clang/Basic/OpenCLImageTypes.def"
+  default:
+llvm_unreachable("Unable to find corresponding image type.");
+  }
+} else {
+  llvm_unreachable("unexpected type");
+}
+StringRef AttrName = Attr.getName()->getName();
+if (PrevAccessQual == AttrName.ltrim("_")) {
+  // Duplicated qualifiers
+  S.Diag(Attr.getLoc(), diag::warn_duplicate_declspec)
+ << AttrName << Attr.getRange();
+} else {
+  // Contradicting qualifiers
+  S.Diag(Attr.getLoc(), diag::err_opencl_multiple_access_qualifiers);
 }
 
 S.Diag(TypedefTy->getDecl()->getBeginLoc(),
-   diag::note_opencl_typedef_access_qualifier)
-<< PrevAccessQual;
+   diag::note_opencl_typedef_access_qualifier) << PrevAccessQual;
   } else if (CurType->isPipeType()) {
 if (Attr.getSemanticSpelling() == OpenCLAccessAttr::Keyword_write_only) {
   QualType ElemType = CurType->getAs()->getElementType();

Modified: cfe/trunk/test/SemaOpenCL/access-qualifier.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/access-qualifier.cl?rev=341553&r1=341552&r2=341553&view=diff
==
--- cfe/trunk/test/SemaOpenCL/access-qualifier.cl (original)
+++ cfe/trunk/test/SemaOpenCL/access-qualifier.cl Thu Sep  6 08:10:26 2018
@@ -60,7 +60,7 @@ kernel void k10(read_only Int img){} //
 
 kernel void k11(read_only write_only image1d_t i){} // 
expected-error{{multiple access qualifiers}}
 
-kernel void k12(read_only read_only image1d_t i){} // expected-error{{multi

Re: r341539 - [OpenCL] Disallow negative attribute arguments

2018-09-06 Thread Andrew Savonichev via cfe-commits
Hi Aaron,

> On Thu, Sep 6, 2018 at 7:54 AM, Andrew Savonichev via cfe-commits
>  wrote:
>> Author: asavonic
>> Date: Thu Sep  6 04:54:09 2018
>> New Revision: 341539
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=341539&view=rev
>> Log:
>> [OpenCL] Disallow negative attribute arguments
>>
>> [...]
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=341539&r1=341538&r2=341539&view=diff
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Sep  6 04:54:09 
>> 2018
>> @@ -2529,6 +2529,8 @@ def err_attribute_argument_type : Error<
>>"constant|a string|an identifier}1">;
>>  def err_attribute_argument_outof_range : Error<
>>"%0 attribute requires integer constant between %1 and %2 inclusive">;
>> +def err_attribute_argument_negative : Error<
>> +  "negative argument is not allowed for %0 attribute">;
>
> I don't think we need a new diagnostic here as we already have
> err_attribute_requires_positive_integer.

`err_attribute_requires_positive_integer' implies that a zero argument
is not allowed, while `err_attribute_argument_negative' should fire only
on a strictly negative argument.

I can merge these diagnostics into one (using %select), but I'm not sure
if it is appropriate.

-- 
Andrew


Joint Stock Company Intel A/O
Registered legal address: Krylatsky Hills Business Park,
17 Krylatskaya Str., Bldg 4, Moscow 121614,
Russian Federation

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

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


r341539 - [OpenCL] Disallow negative attribute arguments

2018-09-06 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Thu Sep  6 04:54:09 2018
New Revision: 341539

URL: http://llvm.org/viewvc/llvm-project?rev=341539&view=rev
Log:
[OpenCL] Disallow negative attribute arguments

Summary:
Negative arguments in kernel attributes are silently bitcast'ed to
unsigned, for example:

__attribute__((reqd_work_group_size(1, -1, 1)))
__kernel void k() {}

is a complete equivalent of:

__attribute__((reqd_work_group_size(1, 4294967294, 1)))
__kernel void k() {}

This is likely an error, so the patch forbids negative arguments in
several OpenCL attributes. Users who really want 4294967294 can still
use it as an unsigned representation.

Reviewers: Anastasia, yaxunl, bader

Reviewed By: Anastasia, yaxunl, bader

Subscribers: bader, cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=341539&r1=341538&r2=341539&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Sep  6 04:54:09 
2018
@@ -2529,6 +2529,8 @@ def err_attribute_argument_type : Error<
   "constant|a string|an identifier}1">;
 def err_attribute_argument_outof_range : Error<
   "%0 attribute requires integer constant between %1 and %2 inclusive">;
+def err_attribute_argument_negative : Error<
+  "negative argument is not allowed for %0 attribute">;
 def err_init_priority_object_attr : Error<
   "can only use 'init_priority' attribute on file-scope definitions "
   "of objects of class type">;

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=341539&r1=341538&r2=341539&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Sep  6 04:54:09 2018
@@ -227,9 +227,13 @@ static SourceLocation getAttrLoc(const P
 
 /// If Expr is a valid integer constant, get the value of the integer
 /// expression and return success or failure. May output an error.
+///
+/// Negative argument is implicitly converted to unsigned, unless
+/// \p StrictlyUnsigned is true.
 template 
 static bool checkUInt32Argument(Sema &S, const AttrInfo &AI, const Expr *Expr,
-uint32_t &Val, unsigned Idx = UINT_MAX) {
+uint32_t &Val, unsigned Idx = UINT_MAX,
+bool StrictlyUnsigned = false) {
   llvm::APSInt I(32);
   if (Expr->isTypeDependent() || Expr->isValueDependent() ||
   !Expr->isIntegerConstantExpr(I, S.Context)) {
@@ -249,6 +253,11 @@ static bool checkUInt32Argument(Sema &S,
 return false;
   }
 
+  if (StrictlyUnsigned && I.isSigned() && I.isNegative()) {
+S.Diag(getAttrLoc(AI), diag::err_attribute_argument_negative) << AI;
+return false;
+  }
+
   Val = (uint32_t)I.getZExtValue();
   return true;
 }
@@ -2766,7 +2775,8 @@ static void handleWorkGroupSize(Sema &S,
   uint32_t WGSize[3];
   for (unsigned i = 0; i < 3; ++i) {
 const Expr *E = AL.getArgAsExpr(i);
-if (!checkUInt32Argument(S, AL, E, WGSize[i], i))
+if (!checkUInt32Argument(S, AL, E, WGSize[i], i,
+ /*StrictlyUnsigned=*/true))
   return;
 if (WGSize[i] == 0) {
   S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero)

Modified: cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl?rev=341539&r1=341538&r2=341539&view=diff
==
--- cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl Thu Sep  6 04:54:09 2018
@@ -37,3 +37,10 @@ kernel __attribute__((reqd_work_group_si
 __attribute__((intel_reqd_sub_group_size(8))) void kernel14(){} // 
expected-error {{attribute 'intel_reqd_sub_group_size' can only be applied to 
an OpenCL kernel}}
 kernel __attribute__((intel_reqd_sub_group_size(0))) void kernel15(){} // 
expected-error {{'intel_reqd_sub_group_size' attribute must be greater than 0}}
 kernel __attribute__((intel_reqd_sub_group_size(8))) 
__attribute__((intel_reqd_sub_group_size(16))) void kernel16() {}  
//expected-warning{{attribute 'intel_reqd_sub_group_size' is already applied 
with different parameters}}
+
+__kernel __attribute__((work_group_size_hint(8,-16,32))) void neg1() {} 
//expected-error{{negative argument is not allowed for 'work_group_size_hint' 
attribute}}
+__kernel __attribute__((reqd_work_group_size(8,16,-32))) 

[PATCH] D23712: [OpenCL] Override supported OpenCL extensions with -cl-ext option

2016-10-24 Thread Andrew Savonichev via cfe-commits
asavonic updated this revision to Diff 75568.
asavonic added a comment.

- Fix comments and code formatting


https://reviews.llvm.org/D23712

Files:
  include/clang/Basic/OpenCLOptions.h
  include/clang/Basic/TargetInfo.h
  include/clang/Basic/TargetOptions.h
  include/clang/Driver/CC1Options.td
  lib/Basic/Targets.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/SemaOpenCL/extensions.cl

Index: test/SemaOpenCL/extensions.cl
===
--- test/SemaOpenCL/extensions.cl
+++ test/SemaOpenCL/extensions.cl
@@ -2,7 +2,26 @@
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1
 
 // Test with a target not supporting fp64.
-// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
+
+// Test with some extensions enabled or disabled by cmd-line args
+//
+// Target does not support fp64 and fp16 - override it
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+cl_khr_fp64,+cl_khr_fp16
+//
+// Disable or enable all extensions
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -DNOFP64 -DNOFP16
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-cl_khr_fp64 -DNOFP64
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=-all,+cl_khr_fp64 -DNOFP16
+//
+// Concatenating
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64 -cl-ext=+cl_khr_fp64  -DNOFP16
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64,+cl_khr_fp64  -DNOFP16
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64 -cl-ext=+cl_khr_fp16 -cl-ext=-cl_khr_fp64 -DNOFP64
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64,-cl_khr_fp64,+cl_khr_fp16 -DNOFP64
+
+
 
 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}}
   double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
@@ -14,6 +33,11 @@
 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}}
 #endif
 
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+#ifdef NOFP16
+// expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp16' - ignoring}}
+#endif
+
 void f2(void) {
   double d;
 #ifdef NOFP64
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2349,6 +2349,7 @@
   // Use the default target triple if unspecified.
   if (Opts.Triple.empty())
 Opts.Triple = llvm::sys::getDefaultTargetTriple();
+  Opts.OpenCLExtensionsAsWritten = Args.getAllArgValues(OPT_cl_ext_EQ);
 }
 
 bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -8676,6 +8676,7 @@
 return nullptr;
 
   Target->setSupportedOpenCLOpts();
+  Target->setOpenCLExtensionOpts();
 
   if (!Target->validateTarget(Diags))
 return nullptr;
Index: include/clang/Driver/CC1Options.td
===
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -685,6 +685,13 @@
   HelpText<"include a detailed record of preprocessing actions">;
 
 //===--===//
+// OpenCL Options
+//===--===//
+
+def cl_ext_EQ : CommaJoined<["-"], "cl-ext=">,
+  HelpText<"OpenCL only. Enable or disable OpenCL extensions. The argument is a comma-separated sequence of one or more extension names, each prefixed by '+' or '-'.">;
+
+//===--===//
 // CUDA Options
 //===--===//
 
Index: include/clang/Basic/TargetOptions.h
===
--- include/clang/Basic/TargetOptions.h
+++ include/clang/Basic/TargetOptions.h
@@ -58,6 +58,10 @@
 
   /// Supported OpenCL extensions and optional core features.
   OpenCLOptions SupportedOpenCLOptions;
+
+  /// \brief The list of OpenCL extensions to enable or disable, as written on
+  /// the command line.
+  std::vector OpenCLExtensionsAsW

[PATCH] D23712: [OpenCL] Override supported OpenCL extensions with -cl-ext option

2016-10-04 Thread Andrew Savonichev via cfe-commits
asavonic updated this revision to Diff 73443.
asavonic added a comment.

- Describe OpenCLOptions::set() function
- Move -cl-ext option to cc1
- Reword -cl-ext option help
- Move -cl-ext handling out of target-specific code
- Add two more test cases regarding -cl-ext option


https://reviews.llvm.org/D23712

Files:
  include/clang/Basic/OpenCLOptions.h
  include/clang/Basic/TargetInfo.h
  include/clang/Basic/TargetOptions.h
  include/clang/Driver/CC1Options.td
  lib/Basic/Targets.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/SemaOpenCL/extensions.cl

Index: test/SemaOpenCL/extensions.cl
===
--- test/SemaOpenCL/extensions.cl
+++ test/SemaOpenCL/extensions.cl
@@ -2,7 +2,26 @@
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1
 
 // Test with a target not supporting fp64.
-// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
+
+// Test with some extensions enabled or disabled by cmd-line args
+//
+// Target does not support fp64 and fp16 - override it
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+cl_khr_fp64,+cl_khr_fp16
+//
+// Disable or enable all extensions
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -DNOFP64 -DNOFP16
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-cl_khr_fp64 -DNOFP64
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=-all,+cl_khr_fp64 -DNOFP16
+//
+// Concatenating
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64 -cl-ext=+cl_khr_fp64  -DNOFP16
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64,+cl_khr_fp64  -DNOFP16
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64 -cl-ext=+cl_khr_fp16 -cl-ext=-cl_khr_fp64 -DNOFP64
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64,-cl_khr_fp64,+cl_khr_fp16 -DNOFP64
+
+
 
 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}}
   double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
@@ -14,6 +33,11 @@
 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}}
 #endif
 
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+#ifdef NOFP16
+// expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp16' - ignoring}}
+#endif
+
 void f2(void) {
   double d;
 #ifdef NOFP64
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2349,6 +2349,7 @@
   // Use the default target triple if unspecified.
   if (Opts.Triple.empty())
 Opts.Triple = llvm::sys::getDefaultTargetTriple();
+  Opts.OpenCLExtensionsAsWritten = Args.getAllArgValues(OPT_cl_ext_EQ);
 }
 
 bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -8676,6 +8676,7 @@
 return nullptr;
 
   Target->setSupportedOpenCLOpts();
+  Target->setOpenCLExtensionOpts();
 
   if (!Target->validateTarget(Diags))
 return nullptr;
Index: include/clang/Driver/CC1Options.td
===
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -685,6 +685,13 @@
   HelpText<"include a detailed record of preprocessing actions">;
 
 //===--===//
+// OpenCL Options
+//===--===//
+
+def cl_ext_EQ : CommaJoined<["-"], "cl-ext=">,
+  HelpText<"OpenCL only. Enable or disable OpenCL extensions. The argument is a comma-separated sequence of one or more extension names, each prefixed by '+' or '-'.">;
+
+//===--===//
 // CUDA Options
 //===--===//
 
Index: include/clang/Basic/TargetOptions.h
===
--- include/clang/Basic/TargetOptions.h
+++ include/clang/Basic/TargetOptions.h
@@ -58,6 +58,10 @@
 
   /// Supported OpenCL extensions and optional core features.
   OpenCLOption

Re: [PATCH] D23712: [OpenCL] Override supported OpenCL extensions with -cl-ext option

2016-09-22 Thread Andrew Savonichev via cfe-commits
asavonic marked 3 inline comments as done.


Comment at: include/clang/Basic/OpenCLOptions.h:39
@@ +38,3 @@
+
+  void set(llvm::StringRef Ext, bool Enable = true) {
+assert(!Ext.empty() && "Extension is empty.");

yaxunl wrote:
> It seems Enable should be a local variable.
This argument is used when `Ext` is not prefixed by '+' or '-'.


https://reviews.llvm.org/D23712



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


Re: [PATCH] D23712: [OpenCL] Override supported OpenCL extensions with -cl-ext option

2016-09-22 Thread Andrew Savonichev via cfe-commits
asavonic updated this revision to Diff 72143.
asavonic added a comment.
Herald added a subscriber: yaxunl.

Add more test cases and fix minor issues


https://reviews.llvm.org/D23712

Files:
  include/clang/Basic/OpenCLOptions.h
  include/clang/Basic/TargetInfo.h
  include/clang/Basic/TargetOptions.h
  include/clang/Driver/Options.td
  lib/Basic/Targets.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/SemaOpenCL/extensions.cl

Index: test/SemaOpenCL/extensions.cl
===
--- test/SemaOpenCL/extensions.cl
+++ test/SemaOpenCL/extensions.cl
@@ -2,7 +2,24 @@
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1
 
 // Test with a target not supporting fp64.
-// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
+
+// Test with some extensions enabled or disabled by cmd-line args
+//
+// Target does not support fp64 and fp16 - override it
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+cl_khr_fp64,+cl_khr_fp16
+//
+// Disable or enable all extensions
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -DNOFP64 -DNOFP16
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-cl_khr_fp64 -DNOFP64
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=-all,+cl_khr_fp64 -DNOFP16
+//
+// Concatenating
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64 -cl-ext=+cl_khr_fp16 -cl-ext=-cl_khr_fp64 -DNOFP64
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64,-cl_khr_fp64,+cl_khr_fp16 -DNOFP64
+
+
 
 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}}
   double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
@@ -14,6 +31,11 @@
 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}}
 #endif
 
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+#ifdef NOFP16
+// expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp16' - ignoring}}
+#endif
+
 void f2(void) {
   double d;
 #ifdef NOFP64
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2349,6 +2349,7 @@
   // Use the default target triple if unspecified.
   if (Opts.Triple.empty())
 Opts.Triple = llvm::sys::getDefaultTargetTriple();
+  Opts.OpenCLExtensionsAsWritten = Args.getAllArgValues(OPT_cl_ext_EQ);
 }
 
 bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -1878,6 +1878,8 @@
 Opts.cl_khr_global_int32_extended_atomics = 1;
 Opts.cl_khr_local_int32_base_atomics = 1;
 Opts.cl_khr_local_int32_extended_atomics = 1;
+
+setOpenCLExtensionOpts();
   }
 };
 
@@ -2163,6 +2165,7 @@
   Opts.cl_amd_media_ops = 1;
   Opts.cl_amd_media_ops2 = 1;
 }
+setOpenCLExtensionOpts();
   }
 
   LangAS::ID getOpenCLImageAddrSpace() const override {
@@ -2855,6 +2858,7 @@
 
   void setSupportedOpenCLOpts() override {
 getSupportedOpenCLOpts().setAll();
+setOpenCLExtensionOpts();
   }
 };
 
@@ -8029,6 +8033,7 @@
 // Assume all OpenCL extensions and optional core features are supported
 // for SPIR since it is a generic target.
 getSupportedOpenCLOpts().setAll();
+setOpenCLExtensionOpts();
   }
 };
 
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -391,6 +391,8 @@
   HelpText<"OpenCL only. Allow denormals to be flushed to zero.">;
 def cl_fp32_correctly_rounded_divide_sqrt : Flag<["-"], "cl-fp32-correctly-rounded-divide-sqrt">, Group, Flags<[CC1Option]>,
   HelpText<"OpenCL only. Specify that single precision floating-point divide and sqrt used in the program source are correctly rounded.">;
+def cl_ext_EQ : CommaJoined<["-"], "cl-ext=">, Group, Flags<[CC1Option]>,
+  HelpText<"OpenCL only. Enable or disable specific OpenCL extensions separated by comma. Use 'all' for all extensions.">;
 def client__name : JoinedOrSeparate<["-"], "client_name">;
 def combine : Flag<["-", "--"], "combine">, Flags<[DriverOption, Unsupported]>;
 def compatibility__version : JoinedOrSeparate<["-"], "compatibility_

Re: [PATCH] D23712: [OpenCL] Override supported OpenCL extensions with -cl-ext option

2016-09-20 Thread Andrew Savonichev via cfe-commits
asavonic added a comment.

Hi @Anastasia,

Sorry for my late reply.

> > > What would be the use case to override the supported extensions for the 
> > > end user?

> 

> > 

> 

> > 

> 

> > Some extensions may be supported by the platform in general, but not by the

> 

> >  specific version of the OpenCL runtime.

> 

> 

> Would triple not be suitable in this case, because they include OS/RT 
> information?


This can be achieved with a custom triple, yes, but it is not a flexible 
solution. 
We need to create a triple for every combination of extensions. If we want to 
change it, we need to modify the clang source code and recompile it.

I think it is better to have a default set of extensions (from target triple) 
and allow user to tweak it without creating one more triple.

So instead of:

  clang -cc1 -triple spir-unknown-intel-skl-nofp64-nofp16 <...>

we could write:

  clang -cc1 -triple spir-unknown-unknown -cl-ext=-cl_khr_fp64,-cl_khr_fp16 
<...>

Both have the same result, but the latter one is more flexible and it can be 
changed without changing the clang code.


https://reviews.llvm.org/D23712



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


Re: [PATCH] D23712: [OpenCL] Override supported OpenCL extensions with -cl-ext option

2016-08-24 Thread Andrew Savonichev via cfe-commits
asavonic added a comment.

In https://reviews.llvm.org/D23712#520818, @Anastasia wrote:

> What would be the use case to override the supported extensions for the end 
> user?


Some extensions may be supported by the platform in general, but not by the
specific version of the OpenCL runtime.

For example, when the platform supports fp64, the OpenCL runtime may not have a
fp64 built-ins implementation. In this case it is better to disable fp64 by the
compiler, rather than get a link error.

Actually, the use case is similar to the -target-feature option, which allows to
control supported CPU features, e.g enable or disable some instruction set.


https://reviews.llvm.org/D23712



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


Re: [PATCH] D23712: [OpenCL] Override supported OpenCL extensions with -cl-ext option

2016-08-19 Thread Andrew Savonichev via cfe-commits
asavonic updated this revision to Diff 68677.
asavonic added a comment.

- Remove unused test case


https://reviews.llvm.org/D23712

Files:
  include/clang/Basic/OpenCLOptions.h
  include/clang/Basic/TargetInfo.h
  include/clang/Basic/TargetOptions.h
  include/clang/Driver/Options.td
  lib/Basic/Targets.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/SemaOpenCL/extensions.cl

Index: test/SemaOpenCL/extensions.cl
===
--- test/SemaOpenCL/extensions.cl
+++ test/SemaOpenCL/extensions.cl
@@ -2,7 +2,20 @@
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1
 
 // Test with a target not supporting fp64.
-// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
+
+// Test with some extensions enabled or disabled by cmd-line args
+//
+// Target does not support fp64 and fp16 - override it
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+cl_khr_fp64,+cl_khr_fp16
+//
+// Disable or enable all extensions
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -DNOFP64 -DNOFP16
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-cl_khr_fp64 -DNOFP64
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=-all,+cl_khr_fp64 -DNOFP16
+
+
 
 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}}
   double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
@@ -14,6 +27,11 @@
 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}}
 #endif
 
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+#ifdef NOFP16
+// expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp16' - ignoring}}
+#endif
+
 void f2(void) {
   double d;
 #ifdef NOFP64
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2316,6 +2316,7 @@
   // Use the default target triple if unspecified.
   if (Opts.Triple.empty())
 Opts.Triple = llvm::sys::getDefaultTargetTriple();
+  Opts.OpenCLExtensionsAsWritten = Args.getAllArgValues(OPT_cl_ext_EQ);
 }
 
 bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -1874,6 +1874,8 @@
 Opts.cl_khr_global_int32_extended_atomics = 1;
 Opts.cl_khr_local_int32_base_atomics = 1;
 Opts.cl_khr_local_int32_extended_atomics = 1;
+
+setOpenCLExtensionOpts();
   }
 };
 
@@ -2157,6 +2159,7 @@
   Opts.cl_amd_media_ops = 1;
   Opts.cl_amd_media_ops2 = 1;
 }
+setOpenCLExtensionOpts();
   }
 
   LangAS::ID getOpenCLImageAddrSpace() const override {
@@ -2848,6 +2851,7 @@
 
   void setSupportedOpenCLOpts() override {
 getSupportedOpenCLOpts().setAll();
+setOpenCLExtensionOpts();
   }
 };
 
@@ -8007,6 +8011,7 @@
 // Assume all OpenCL extensions and optional core features are supported
 // for SPIR since it is a generic target.
 getSupportedOpenCLOpts().setAll();
+setOpenCLExtensionOpts();
   }
 };
 
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -391,6 +391,8 @@
   HelpText<"OpenCL only. Allow denormals to be flushed to zero.">;
 def cl_fp32_correctly_rounded_divide_sqrt : Flag<["-"], "cl-fp32-correctly-rounded-divide-sqrt">, Group, Flags<[CC1Option]>,
   HelpText<"OpenCL only. Specify that single precision floating-point divide and sqrt used in the program source are correctly rounded.">;
+def cl_ext_EQ : CommaJoined<["-"], "cl-ext=">, Group, Flags<[CC1Option]>,
+  HelpText<"OpenCL only. Enable or disable specific OpenCL extensions.">;
 def client__name : JoinedOrSeparate<["-"], "client_name">;
 def combine : Flag<["-", "--"], "combine">, Flags<[DriverOption, Unsupported]>;
 def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">;
Index: include/clang/Basic/TargetOptions.h
===
--- include/clang/Basic/TargetOptions.h
+++ include/clang/Basic/TargetOptions.h
@@ -58,6 +58,10 @@
 
   /// Supported OpenCL extensions and optional core features.
   OpenCLOptions SupportedOpenCLOptions;
+
+  /// \brief The list of OpenCL extensions to enable or disable, as written on
+  /// the command line.
+  std::v

[PATCH] D23712: [OpenCL] Override supported OpenCL extensions with -cl-ext option

2016-08-19 Thread Andrew Savonichev via cfe-commits
asavonic created this revision.
asavonic added a reviewer: Anastasia.
asavonic added a subscriber: cfe-commits.

This patch adds a command line option '-cl-ext' to control a set of
supported OpenCL extensions. Option accepts a comma-separated list
of extensions prefixed with '+' or '-'.

It can be used together with a target triple to override support for some
extensions:

  // spir target supports all extensions, but we want to disable fp64
  clang -cc1 -triple spir-unknown-unknown -cl-ext=-cl_khr_fp64

Special 'all' extension allows to enable or disable all possible
extensions:

  // only fp64 will be supported
  clang -cc1 -triple spir-unknown-unknown -cl-ext=-all,+cl_khr_fp64

https://reviews.llvm.org/D23712

Files:
  include/clang/Basic/OpenCLOptions.h
  include/clang/Basic/TargetInfo.h
  include/clang/Basic/TargetOptions.h
  include/clang/Driver/Options.td
  lib/Basic/Targets.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/SemaOpenCL/extensions.cl

Index: test/SemaOpenCL/extensions.cl
===
--- test/SemaOpenCL/extensions.cl
+++ test/SemaOpenCL/extensions.cl
@@ -2,7 +2,20 @@
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1
 
 // Test with a target not supporting fp64.
-// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
+
+// Test with some extensions enabled or disabled by cmd-line args
+//
+// Target does not support fp64 and fp16 - override it
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+cl_khr_fp64,+cl_khr_fp16
+//
+// Disable or enable all extensions
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -DNOFP64 -DNOFP16
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-cl_khr_fp64 -DNOFP64
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=-all,+cl_khr_fp64 -DNOFP16
+
+
 
 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}}
   double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
@@ -14,6 +27,11 @@
 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}}
 #endif
 
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+#ifdef NOFP16
+// expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp16' - ignoring}}
+#endif
+
 void f2(void) {
   double d;
 #ifdef NOFP64
@@ -34,3 +52,13 @@
 void f3(void) {
   double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
 }
+
+#ifdef CL_EXT_OPT
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable // expected-warning{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}}
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : disable
+void f4(__global half* h) {
+  *h = 4.h; // expected-error{{half precision constant requires cl_khr_fp16}}
+}
+#endif
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2316,6 +2316,7 @@
   // Use the default target triple if unspecified.
   if (Opts.Triple.empty())
 Opts.Triple = llvm::sys::getDefaultTargetTriple();
+  Opts.OpenCLExtensionsAsWritten = Args.getAllArgValues(OPT_cl_ext_EQ);
 }
 
 bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -1874,6 +1874,8 @@
 Opts.cl_khr_global_int32_extended_atomics = 1;
 Opts.cl_khr_local_int32_base_atomics = 1;
 Opts.cl_khr_local_int32_extended_atomics = 1;
+
+setOpenCLExtensionOpts();
   }
 };
 
@@ -2157,6 +2159,7 @@
   Opts.cl_amd_media_ops = 1;
   Opts.cl_amd_media_ops2 = 1;
 }
+setOpenCLExtensionOpts();
   }
 
   LangAS::ID getOpenCLImageAddrSpace() const override {
@@ -2848,6 +2851,7 @@
 
   void setSupportedOpenCLOpts() override {
 getSupportedOpenCLOpts().setAll();
+setOpenCLExtensionOpts();
   }
 };
 
@@ -8007,6 +8011,7 @@
 // Assume all OpenCL extensions and optional core features are supported
 // for SPIR since it is a generic target.
 getSupportedOpenCLOpts().setAll();
+setOpenCLExtensionOpts();
   }
 };
 
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -391,6 +391,8 @@
   HelpText<"OpenCL only. Allow denormals to be flushed to zero.">;

Re: [PATCH] D20948: [OpenCL] Fix access qualifiers handling for typedefs

2016-07-08 Thread Andrew Savonichev via cfe-commits
asavonic updated this revision to Diff 63222.
asavonic added a comment.

Change diagnostic wording


http://reviews.llvm.org/D20948

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/AttributeList.h
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCL/kernel-arg-info.cl
  test/SemaOpenCL/access-qualifier.cl
  test/SemaOpenCL/invalid-access-qualifier.cl

Index: test/SemaOpenCL/invalid-access-qualifier.cl
===
--- test/SemaOpenCL/invalid-access-qualifier.cl
+++ /dev/null
@@ -1,14 +0,0 @@
-// RUN: %clang_cc1 -verify %s
-// RUN: %clang_cc1 -verify -cl-std=CL2.0 -DCL20 %s
-
-void test1(read_only int i){} // expected-error{{access qualifier can only be used for pipe and image type}}
-
-void test2(read_only write_only image1d_t i){} // expected-error{{multiple access qualifiers}}
-
-void test3(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}}
-
-#ifdef CL20
-void test4(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'pipe int'}}
-#else
-void test4(__read_write image1d_t i) {} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' earlier than OpenCL version 2.0}}
-#endif
Index: test/SemaOpenCL/access-qualifier.cl
===
--- /dev/null
+++ test/SemaOpenCL/access-qualifier.cl
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL1.2 %s
+// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL2.0 %s
+
+typedef image1d_t img1d_ro_default; // expected-note {{previously declared 'read_only' here}}
+
+typedef write_only image1d_t img1d_wo; // expected-note {{previously declared 'write_only' here}}
+typedef read_only image1d_t img1d_ro;
+
+#if __OPENCL_C_VERSION__ >= 200
+typedef read_write image1d_t img1d_rw;
+#endif
+
+typedef int Int;
+typedef read_only int IntRO; // expected-error {{access qualifier can only be used for pipe and image type}}
+
+
+void myWrite(write_only image1d_t); // expected-note {{passing argument to parameter here}} expected-note {{passing argument to parameter here}}
+void myRead(read_only image1d_t); // expected-note {{passing argument to parameter here}}
+
+#if __OPENCL_C_VERSION__ >= 200
+void myReadWrite(read_write image1d_t);
+#else
+void myReadWrite(read_write image1d_t); // expected-error {{access qualifier 'read_write' can not be used for '__read_write image1d_t' prior to OpenCL version 2.0}}
+#endif
+
+
+kernel void k1(img1d_wo img) {
+  myRead(img); // expected-error {{passing 'img1d_wo' (aka '__write_only image1d_t') to parameter of incompatible type '__read_only image1d_t'}}
+}
+
+kernel void k2(img1d_ro img) {
+  myWrite(img); // expected-error {{passing 'img1d_ro' (aka '__read_only image1d_t') to parameter of incompatible type '__write_only image1d_t'}}
+}
+
+kernel void k3(img1d_wo img) {
+  myWrite(img);
+}
+
+#if __OPENCL_C_VERSION__ >= 200
+kernel void k4(img1d_rw img) {
+  myReadWrite(img);
+}
+#endif
+
+kernel void k5(img1d_ro_default img) {
+  myWrite(img); // expected-error {{passing 'img1d_ro_default' (aka '__read_only image1d_t') to parameter of incompatible type '__write_only image1d_t'}}
+}
+
+kernel void k6(img1d_ro img) {
+  myRead(img);
+}
+
+kernel void k7(read_only img1d_wo img){} // expected-error {{multiple access qualifiers}}
+
+kernel void k8(write_only img1d_ro_default img){} // expected-error {{multiple access qualifiers}}
+
+kernel void k9(read_only int i){} // expected-error{{access qualifier can only be used for pipe and image type}}
+
+kernel void k10(read_only Int img){} // expected-error {{access qualifier can only be used for pipe and image type}}
+
+kernel void k11(read_only write_only image1d_t i){} // expected-error{{multiple access qualifiers}}
+
+kernel void k12(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}}
+
+#if __OPENCL_C_VERSION__ >= 200
+kernel void k13(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'pipe int'}}
+#else
+kernel void k13(__read_write image1d_t i){} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' prior to OpenCL version 2.0}}
+#endif
Index: test/CodeGenOpenCL/kernel-arg-info.cl
===
--- test/CodeGenOpenCL/kernel-arg-info.cl
+++ test/CodeGenOpenCL/kernel-arg-info.cl
@@ -49,7 +49,7 @@
 // ARGINFO: !kernel_arg_name ![[MD46:[0-9]+]]
 
 typedef image1d_t myImage;
-kernel void foo5(read_only myImage img1, write_only image1d_t img2) {
+kernel void foo5(myImage img1, write_only image1d_t img2) {
 }
 // CHECK: define spir_kernel void @foo5{{[^!]+}}
 // CHECK: !kernel_arg_addr_space ![[MD41:[0-9]+]]
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/Se

Re: [PATCH] D20948: [OpenCL] Fix access qualifiers handling for typedefs

2016-07-08 Thread Andrew Savonichev via cfe-commits
asavonic marked an inline comment as done.


Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2509-2510
@@ -2508,4 +2508,4 @@
   "functions, methods, and parameters|classes|enums|variables|methods|"
-  "fields and global variables|structs|variables and typedefs|thread-local 
variables|"
-  "variables and fields|variables, data members and tag types|"
+  "fields and global variables|structs|parameters and typedefs|variables and 
typedefs|"
+  "thread-local variables|variables and fields|variables, data members and tag 
types|"
   "types and namespaces|Objective-C interfaces|methods and properties|"

Yes, because I added "ExpectedParameterOrTypedef" diagnostic to support access 
qualifiers in typedef decl.


http://reviews.llvm.org/D20948



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


Re: [PATCH] D20948: [OpenCL] Fix access qualifiers handling for typedefs

2016-07-08 Thread Andrew Savonichev via cfe-commits
asavonic marked 2 inline comments as done.
asavonic added a comment.

http://reviews.llvm.org/D20948



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


Re: [PATCH] D20948: [OpenCL] Fix access qualifiers handling for typedefs

2016-07-07 Thread Andrew Savonichev via cfe-commits
asavonic marked 4 inline comments as done.
asavonic added a comment.

http://reviews.llvm.org/D20948



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


Re: [PATCH] D20948: [OpenCL] Fix access qualifiers handling for typedefs

2016-07-07 Thread Andrew Savonichev via cfe-commits
asavonic updated this revision to Diff 63073.
asavonic added a comment.

Merged invalid-access-qualifier.cl and images-typedef.cl tests, fixed
code style issues.


http://reviews.llvm.org/D20948

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/AttributeList.h
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCL/kernel-arg-info.cl
  test/SemaOpenCL/access-qualifier.cl
  test/SemaOpenCL/invalid-access-qualifier.cl

Index: test/SemaOpenCL/invalid-access-qualifier.cl
===
--- test/SemaOpenCL/invalid-access-qualifier.cl
+++ /dev/null
@@ -1,14 +0,0 @@
-// RUN: %clang_cc1 -verify %s
-// RUN: %clang_cc1 -verify -cl-std=CL2.0 -DCL20 %s
-
-void test1(read_only int i){} // expected-error{{access qualifier can only be used for pipe and image type}}
-
-void test2(read_only write_only image1d_t i){} // expected-error{{multiple access qualifiers}}
-
-void test3(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}}
-
-#ifdef CL20
-void test4(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'pipe int'}}
-#else
-void test4(__read_write image1d_t i) {} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' earlier than OpenCL version 2.0}}
-#endif
Index: test/SemaOpenCL/access-qualifier.cl
===
--- /dev/null
+++ test/SemaOpenCL/access-qualifier.cl
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL1.2 %s
+// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL2.0 %s
+
+typedef image1d_t img1d_ro_default; // expected-note {{previously declared 'read_only' here}}
+
+typedef write_only image1d_t img1d_wo; // expected-note {{previously declared 'write_only' here}}
+typedef read_only image1d_t img1d_ro;
+
+#if __OPENCL_C_VERSION__ >= 200
+  typedef read_write image1d_t img1d_rw;
+#endif
+
+typedef int Int;
+typedef read_only int IntRO; // expected-error {{access qualifier can only be used for pipe and image type}}
+
+
+void myWrite(write_only image1d_t); // expected-note {{passing argument to parameter here}} expected-note {{passing argument to parameter here}}
+void myRead(read_only image1d_t); // expected-note {{passing argument to parameter here}}
+
+#if __OPENCL_C_VERSION__ >= 200
+void myReadWrite(read_write image1d_t);
+#else
+void myReadWrite(read_write image1d_t); // expected-error {{access qualifier 'read_write' can not be used for '__read_write image1d_t' earlier than OpenCL version 2.0}}
+#endif
+
+
+kernel void k1(img1d_wo img) {
+  myRead(img); // expected-error {{passing 'img1d_wo' (aka '__write_only image1d_t') to parameter of incompatible type '__read_only image1d_t'}}
+}
+
+kernel void k2(img1d_ro img) {
+  myWrite(img); // expected-error {{passing 'img1d_ro' (aka '__read_only image1d_t') to parameter of incompatible type '__write_only image1d_t'}}
+}
+
+kernel void k3(img1d_wo img) {
+  myWrite(img);
+}
+
+#if __OPENCL_C_VERSION__ >= 200
+kernel void k4(img1d_rw img) {
+  myReadWrite(img);
+}
+#endif
+
+kernel void k5(img1d_ro_default img) {
+  myWrite(img); // expected-error {{passing 'img1d_ro_default' (aka '__read_only image1d_t') to parameter of incompatible type '__write_only image1d_t'}}
+}
+
+kernel void k6(img1d_ro img) {
+  myRead(img);
+}
+
+kernel void k7(read_only img1d_wo img){} // expected-error {{multiple access qualifiers}}
+
+kernel void k8(write_only img1d_ro_default img){} // expected-error {{multiple access qualifiers}}
+
+kernel void k9(read_only int i){} // expected-error{{access qualifier can only be used for pipe and image type}}
+
+kernel void k10(read_only Int img){} // expected-error {{access qualifier can only be used for pipe and image type}}
+
+kernel void k11(read_only write_only image1d_t i){} // expected-error{{multiple access qualifiers}}
+
+kernel void k12(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}}
+
+#if __OPENCL_C_VERSION__ >= 200
+kernel void k13(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'pipe int'}}
+#else
+kernel void k13(__read_write image1d_t i){} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' earlier than OpenCL version 2.0}}
+#endif
Index: test/CodeGenOpenCL/kernel-arg-info.cl
===
--- test/CodeGenOpenCL/kernel-arg-info.cl
+++ test/CodeGenOpenCL/kernel-arg-info.cl
@@ -49,7 +49,7 @@
 // ARGINFO: !kernel_arg_name ![[MD46:[0-9]+]]
 
 typedef image1d_t myImage;
-kernel void foo5(read_only myImage img1, write_only image1d_t img2) {
+kernel void foo5(myImage img1, write_only image1d_t img2) {
 }
 // CHECK: define spir_kernel void @foo5{{[^!]+}}
 // CHECK: !kernel_arg_addr_space ![[MD41:[0-9]+]]
Index: lib/Sema/SemaType.cpp

Re: [PATCH] D20948: [OpenCL] Fix access qualifiers handling for typedefs

2016-06-07 Thread Andrew Savonichev via cfe-commits
asavonic updated this revision to Diff 59890.
asavonic added a comment.

- Cleanup images-typedef.cl
- Fix typo in SemaType.cpp
- Change diagnostic: error when access qualifier applied to a typedef


http://reviews.llvm.org/D20948

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/AttributeList.h
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCL/kernel-arg-info.cl
  test/SemaOpenCL/images-typedef.cl

Index: test/SemaOpenCL/images-typedef.cl
===
--- /dev/null
+++ test/SemaOpenCL/images-typedef.cl
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+typedef image1d_t img1d_ro_default; // expected-note {{previously declared 'read_only' here}}
+
+typedef write_only image1d_t img1d_wo; // expected-note {{previously declared 'write_only' here}}
+typedef read_only image1d_t img1d_ro;
+
+#if __OPENCL_C_VERSION__ >= 200
+  typedef read_write image1d_t img1d_rw;
+#endif
+
+typedef int Int;
+typedef read_only int IntRO; // expected-error {{access qualifier can only be used for pipe and image type}}
+
+
+void myWrite(write_only image1d_t); // expected-note {{passing argument to parameter here}} expected-note {{passing argument to parameter here}}
+void myRead(read_only image1d_t); // expected-note {{passing argument to parameter here}}
+
+kernel void k1(img1d_wo img) {
+  myRead(img); // expected-error {{passing 'img1d_wo' (aka '__write_only image1d_t') to parameter of incompatible type '__read_only image1d_t'}}
+}
+
+kernel void k2(img1d_ro img) {
+  myWrite(img); // expected-error {{passing 'img1d_ro' (aka '__read_only image1d_t') to parameter of incompatible type '__write_only image1d_t'}}
+}
+
+kernel void k3(img1d_wo img) {
+  myWrite(img);
+}
+
+#if __OPENCL_C_VERSION__ >= 200
+  kernel void k4(img1d_rw img) {
+myWrite(img);
+myRead(img);
+  }
+#endif
+
+kernel void k5(img1d_ro_default img) {
+  myWrite(img); // expected-error {{passing 'img1d_ro_default' (aka '__read_only image1d_t') to parameter of incompatible type '__write_only image1d_t'}}
+}
+
+kernel void k6(img1d_ro img) {
+  myRead(img);
+}
+
+kernel void k7(read_only img1d_wo img) { // expected-error {{multiple access qualifiers}}
+}
+
+kernel void k8(write_only img1d_ro_default img) { // expected-error {{multiple access qualifiers}}
+}
+
+kernel void k9(read_only Int img) { // expected-error {{access qualifier can only be used for pipe and image type}}
+}
Index: test/CodeGenOpenCL/kernel-arg-info.cl
===
--- test/CodeGenOpenCL/kernel-arg-info.cl
+++ test/CodeGenOpenCL/kernel-arg-info.cl
@@ -46,7 +46,7 @@
 // NO-ARGINFO-NOT: !{!"kernel_arg_name", !"X", !"Y"}
 
 typedef image1d_t myImage;
-kernel void foo5(read_only myImage img1, write_only image1d_t img2) {
+kernel void foo5(myImage img1, write_only image1d_t img2) {
 }
 // CHECK:  !{!"kernel_arg_access_qual", !"read_only", !"write_only"}
 // CHECK:  !{!"kernel_arg_type", !"myImage", !"image1d_t"}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -6472,12 +6472,31 @@
 /// Handle OpenCL Access Qualifier Attribute.
 static void HandleOpenCLAccessAttr(QualType &CurType, const AttributeList &Attr,
Sema &S) {
-  // OpenCL v2.0 s6.6 - Access qualifier can used only for image and pipe type.
+  // OpenCL v2.0 s6.6 - Access qualifier can be used only for image and pipe type.
   if (!(CurType->isImageType() || CurType->isPipeType())) {
 S.Diag(Attr.getLoc(), diag::err_opencl_invalid_access_qualifier);
 Attr.setInvalid();
 return;
   }
+
+  if (const TypedefType* TypedefTy = CurType->getAs()) {
+QualType PointeeTy = TypedefTy->desugar();
+S.Diag(Attr.getLoc(), diag::err_opencl_multiple_access_qualifiers);
+
+std::string PrevAccessQual;
+switch (cast(PointeeTy.getTypePtr())->getKind()) {
+  #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
+	case BuiltinType::Id:	   \
+	  PrevAccessQual = #Access;   \
+	  break;
+  #include "clang/Basic/OpenCLImageTypes.def"
+default:
+  assert(0 && "unable to find corresponding image type");
+}
+
+S.Diag(TypedefTy->getDecl()->getLocStart(),
+	   diag::note_opencl_typedef_access_qualifier) << PrevAccessQual;
+  }
 }
 
 static void processTypeAttrs(TypeProcessingState &state, QualType &type,
Index: include/clang/Sema/AttributeList.h
===
--- include/clang/Sema/AttributeList.h
+++ include/clang/Sema/AttributeList.h
@@ -881,6 +881,7 @@
   ExpectedMethod,
   ExpectedFieldOrGlobalVar,
   ExpectedStruct,
+  ExpectedParameterOrTypedef,
   ExpectedVariableOrTypedef,
   ExpectedTLSVar,
   ExpectedVariableOrField,
Index: include/clang/Basic/DiagnosticSemaKinds.td
==

Re: [PATCH] D20948: [OpenCL] Fix access qualifiers handling for typedefs

2016-06-07 Thread Andrew Savonichev via cfe-commits
asavonic updated this revision to Diff 59893.
asavonic marked 3 inline comments as done.
asavonic added a comment.

- Fix images-typedef.cl for OpenCL 2.0


http://reviews.llvm.org/D20948

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/AttributeList.h
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCL/kernel-arg-info.cl
  test/SemaOpenCL/images-typedef.cl

Index: test/SemaOpenCL/images-typedef.cl
===
--- /dev/null
+++ test/SemaOpenCL/images-typedef.cl
@@ -0,0 +1,58 @@
+// RUN: %clang_cc1 -verify -pedantic -fsyntax-only %s
+// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL2.0 %s
+
+typedef image1d_t img1d_ro_default; // expected-note {{previously declared 'read_only' here}}
+
+typedef write_only image1d_t img1d_wo; // expected-note {{previously declared 'write_only' here}}
+typedef read_only image1d_t img1d_ro;
+
+#if __OPENCL_C_VERSION__ >= 200
+  typedef read_write image1d_t img1d_rw;
+#endif
+
+typedef int Int;
+typedef read_only int IntRO; // expected-error {{access qualifier can only be used for pipe and image type}}
+
+
+void myWrite(write_only image1d_t); // expected-note {{passing argument to parameter here}} expected-note {{passing argument to parameter here}}
+void myRead(read_only image1d_t); // expected-note {{passing argument to parameter here}}
+
+#if __OPENCL_C_VERSION__ >= 200
+  void myReadWrite(read_write image1d_t);
+#endif
+
+
+kernel void k1(img1d_wo img) {
+  myRead(img); // expected-error {{passing 'img1d_wo' (aka '__write_only image1d_t') to parameter of incompatible type '__read_only image1d_t'}}
+}
+
+kernel void k2(img1d_ro img) {
+  myWrite(img); // expected-error {{passing 'img1d_ro' (aka '__read_only image1d_t') to parameter of incompatible type '__write_only image1d_t'}}
+}
+
+kernel void k3(img1d_wo img) {
+  myWrite(img);
+}
+
+#if __OPENCL_C_VERSION__ >= 200
+  kernel void k4(img1d_rw img) {
+myReadWrite(img);
+  }
+#endif
+
+kernel void k5(img1d_ro_default img) {
+  myWrite(img); // expected-error {{passing 'img1d_ro_default' (aka '__read_only image1d_t') to parameter of incompatible type '__write_only image1d_t'}}
+}
+
+kernel void k6(img1d_ro img) {
+  myRead(img);
+}
+
+kernel void k7(read_only img1d_wo img) { // expected-error {{multiple access qualifiers}}
+}
+
+kernel void k8(write_only img1d_ro_default img) { // expected-error {{multiple access qualifiers}}
+}
+
+kernel void k9(read_only Int img) { // expected-error {{access qualifier can only be used for pipe and image type}}
+}
Index: test/CodeGenOpenCL/kernel-arg-info.cl
===
--- test/CodeGenOpenCL/kernel-arg-info.cl
+++ test/CodeGenOpenCL/kernel-arg-info.cl
@@ -46,7 +46,7 @@
 // NO-ARGINFO-NOT: !{!"kernel_arg_name", !"X", !"Y"}
 
 typedef image1d_t myImage;
-kernel void foo5(read_only myImage img1, write_only image1d_t img2) {
+kernel void foo5(myImage img1, write_only image1d_t img2) {
 }
 // CHECK:  !{!"kernel_arg_access_qual", !"read_only", !"write_only"}
 // CHECK:  !{!"kernel_arg_type", !"myImage", !"image1d_t"}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -6472,12 +6472,31 @@
 /// Handle OpenCL Access Qualifier Attribute.
 static void HandleOpenCLAccessAttr(QualType &CurType, const AttributeList &Attr,
Sema &S) {
-  // OpenCL v2.0 s6.6 - Access qualifier can used only for image and pipe type.
+  // OpenCL v2.0 s6.6 - Access qualifier can be used only for image and pipe type.
   if (!(CurType->isImageType() || CurType->isPipeType())) {
 S.Diag(Attr.getLoc(), diag::err_opencl_invalid_access_qualifier);
 Attr.setInvalid();
 return;
   }
+
+  if (const TypedefType* TypedefTy = CurType->getAs()) {
+QualType PointeeTy = TypedefTy->desugar();
+S.Diag(Attr.getLoc(), diag::err_opencl_multiple_access_qualifiers);
+
+std::string PrevAccessQual;
+switch (cast(PointeeTy.getTypePtr())->getKind()) {
+  #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
+	case BuiltinType::Id:	   \
+	  PrevAccessQual = #Access;   \
+	  break;
+  #include "clang/Basic/OpenCLImageTypes.def"
+default:
+  assert(0 && "unable to find corresponding image type");
+}
+
+S.Diag(TypedefTy->getDecl()->getLocStart(),
+	   diag::note_opencl_typedef_access_qualifier) << PrevAccessQual;
+  }
 }
 
 static void processTypeAttrs(TypeProcessingState &state, QualType &type,
Index: include/clang/Sema/AttributeList.h
===
--- include/clang/Sema/AttributeList.h
+++ include/clang/Sema/AttributeList.h
@@ -881,6 +881,7 @@
   ExpectedMethod,
   ExpectedFieldOrGlobalVar,
   ExpectedStruct,
+  ExpectedParameterOrTypedef,
   ExpectedVariableOrTypedef,
   ExpectedTLSVar,
   ExpectedVariableOrField,
Index: i

Re: [PATCH] D20948: [OpenCL] Fix access qualifiers handling for typedefs

2016-06-07 Thread Andrew Savonichev via cfe-commits
asavonic added inline comments.


Comment at: test/SemaOpenCL/images-typedef.cl:40
@@ +39,3 @@
+  myWrite(img); // expected-error {{passing 'img1d_ro_default' (aka 
'__read_only image1d_t') to parameter of incompatible type '__write_only 
image1d_t'}}
+}
+

No, but write_only qualifer was just silently ignored and img had a read_only 
type.

I changed the diagnostic, it should be better now:

  typedef write_only image1d_t img1d_wo; // note: previously declared 
'write_only' here
  kernel void k7(read_only img1d_wo img){} // error: multiple access qualifiers


Comment at: test/SemaOpenCL/images-typedef.cl:43
@@ +42,3 @@
+kernel void k6(img1d_ro img) {
+  myRead(img);
+}

In this case we should rename merged test to just 'access-qualifier.cl', since 
images-typedef.cl contains positive test cases too. Is it ok?


http://reviews.llvm.org/D20948



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