Skip to content

Commit 1a8b3f1

Browse files
committedMay 6, 2015
[OPENMP] Fix for http://llvm.org/PR23387: clang fails to compile magick/attribute.c
Allow to use variables with 'register' storage class as loop control variables in OpenMP loop based constructs. llvm-svn: 236571
1 parent 1d28544 commit 1a8b3f1

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
 

‎clang/lib/Sema/SemaOpenMP.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D, bool FromParent) {
426426
// in a Construct, C/C++, predetermined, p.1]
427427
// Variables appearing in threadprivate directives are threadprivate.
428428
if (D->getTLSKind() != VarDecl::TLS_None ||
429-
D->getStorageClass() == SC_Register) {
429+
(D->getStorageClass() == SC_Register && D->hasAttr<AsmLabelAttr>() &&
430+
!D->isLocalVarDecl())) {
430431
DVar.CKind = OMPC_threadprivate;
431432
return DVar;
432433
}
@@ -885,7 +886,8 @@ Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) {
885886

886887
// Check if this is a TLS variable.
887888
if (VD->getTLSKind() != VarDecl::TLS_None ||
888-
VD->getStorageClass() == SC_Register) {
889+
(VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() &&
890+
!VD->isLocalVarDecl())) {
889891
Diag(ILoc, diag::err_omp_var_thread_local)
890892
<< VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1);
891893
bool IsDecl =

‎clang/test/OpenMP/for_loop_messages.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ static int sii;
1313
#pragma omp threadprivate(sii) // expected-note {{defined as threadprivate or thread local}}
1414
static int globalii;
1515

16+
register int reg0 __asm__("0"); // expected-note {{loop iteration variable is predetermined as linear}}
17+
1618
int test_iteration_spaces() {
1719
const int N = 100;
1820
float a[N], b[N], c[N];
1921
int ii, jj, kk;
2022
float fii;
2123
double dii;
24+
register int reg; // expected-warning {{'register' storage class specifier is deprecated}}
2225
#pragma omp parallel
2326
#pragma omp for
2427
for (int i = 0; i < 10; i += 1) {
@@ -311,6 +314,21 @@ int test_iteration_spaces() {
311314
c[sii] = a[sii];
312315
}
313316

317+
#pragma omp parallel
318+
{
319+
// expected-error@+2 {{loop iteration variable in the associated loop of 'omp for' directive may not be threadprivate or thread local, predetermined as private}}
320+
#pragma omp for
321+
for (reg0 = 0; reg0 < 10; reg0 += 1)
322+
c[reg0] = a[reg0];
323+
}
324+
325+
#pragma omp parallel
326+
{
327+
#pragma omp for
328+
for (reg = 0; reg < 10; reg += 1)
329+
c[reg] = a[reg];
330+
}
331+
314332
#pragma omp parallel
315333
{
316334
#pragma omp for

0 commit comments

Comments
 (0)
Please sign in to comment.