]> granicus.if.org Git - clang/commitdiff
[OPENMP][CUDA]Do not emit warnings for variables in late-reported asm
authorAlexey Bataev <a.bataev@hotmail.com>
Tue, 26 Feb 2019 21:51:16 +0000 (21:51 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Tue, 26 Feb 2019 21:51:16 +0000 (21:51 +0000)
statements.

If the assembler instruction is not generated and the delayed diagnostic
is emitted, we may end up with extra warning message for variables used
in the asm statement. Since the asm statement is not built, the
variables may be left non-referenced and it may produce a warning about
a use of the non-initialized variables.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354928 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaStmtAsm.cpp
test/OpenMP/nvptx_asm_delayed_diags.c
test/Sema/asm.c
test/SemaCUDA/asm_delayed_diags.cu

index e1ea3b664631da24d561dc63d94514f2a91206d5..0d38f48aa5a51031967499883d1f47077b706c56 100644 (file)
@@ -262,10 +262,15 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
       OutputName = Names[i]->getName();
 
     TargetInfo::ConstraintInfo Info(Literal->getString(), OutputName);
-    if (!Context.getTargetInfo().validateOutputConstraint(Info))
-      return StmtResult(targetDiag(Literal->getBeginLoc(),
-                                   diag::err_asm_invalid_output_constraint)
-                        << Info.getConstraintStr());
+    if (!Context.getTargetInfo().validateOutputConstraint(Info)) {
+      targetDiag(Literal->getBeginLoc(),
+                 diag::err_asm_invalid_output_constraint)
+          << Info.getConstraintStr();
+      return new (Context)
+          GCCAsmStmt(Context, AsmLoc, IsSimple, IsVolatile, NumOutputs,
+                     NumInputs, Names, Constraints, Exprs.data(), AsmString,
+                     NumClobbers, Clobbers, RParenLoc);
+    }
 
     ExprResult ER = CheckPlaceholderExpr(Exprs[i]);
     if (ER.isInvalid())
@@ -318,10 +323,15 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
     }
 
     unsigned Size = Context.getTypeSize(OutputExpr->getType());
-    if (!Context.getTargetInfo().validateOutputSize(Literal->getString(), Size))
-      return StmtResult(targetDiag(OutputExpr->getBeginLoc(),
-                                   diag::err_asm_invalid_output_size)
-                        << Info.getConstraintStr());
+    if (!Context.getTargetInfo().validateOutputSize(Literal->getString(),
+                                                    Size)) {
+      targetDiag(OutputExpr->getBeginLoc(), diag::err_asm_invalid_output_size)
+          << Info.getConstraintStr();
+      return new (Context)
+          GCCAsmStmt(Context, AsmLoc, IsSimple, IsVolatile, NumOutputs,
+                     NumInputs, Names, Constraints, Exprs.data(), AsmString,
+                     NumClobbers, Clobbers, RParenLoc);
+    }
   }
 
   SmallVector<TargetInfo::ConstraintInfo, 4> InputConstraintInfos;
@@ -337,9 +347,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
     TargetInfo::ConstraintInfo Info(Literal->getString(), InputName);
     if (!Context.getTargetInfo().validateInputConstraint(OutputConstraintInfos,
                                                          Info)) {
-      return StmtResult(targetDiag(Literal->getBeginLoc(),
-                                   diag::err_asm_invalid_input_constraint)
-                        << Info.getConstraintStr());
+      targetDiag(Literal->getBeginLoc(), diag::err_asm_invalid_input_constraint)
+          << Info.getConstraintStr();
+      return new (Context)
+          GCCAsmStmt(Context, AsmLoc, IsSimple, IsVolatile, NumOutputs,
+                     NumInputs, Names, Constraints, Exprs.data(), AsmString,
+                     NumClobbers, Clobbers, RParenLoc);
     }
 
     ExprResult ER = CheckPlaceholderExpr(Exprs[i]);
@@ -423,10 +436,14 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
 
     StringRef Clobber = Literal->getString();
 
-    if (!Context.getTargetInfo().isValidClobber(Clobber))
-      return StmtResult(targetDiag(Literal->getBeginLoc(),
-                                   diag::err_asm_unknown_register_name)
-                        << Clobber);
+    if (!Context.getTargetInfo().isValidClobber(Clobber)) {
+      targetDiag(Literal->getBeginLoc(), diag::err_asm_unknown_register_name)
+          << Clobber;
+      return new (Context)
+          GCCAsmStmt(Context, AsmLoc, IsSimple, IsVolatile, NumOutputs,
+                     NumInputs, Names, Constraints, Exprs.data(), AsmString,
+                     NumClobbers, Clobbers, RParenLoc);
+    }
   }
 
   GCCAsmStmt *NS =
@@ -437,10 +454,11 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
   // have.
   SmallVector<GCCAsmStmt::AsmStringPiece, 8> Pieces;
   unsigned DiagOffs;
-  if (unsigned DiagID = NS->AnalyzeAsmString(Pieces, Context, DiagOffs))
-    return StmtResult(
-        targetDiag(getLocationOfStringLiteralByte(AsmString, DiagOffs), DiagID)
-        << AsmString->getSourceRange());
+  if (unsigned DiagID = NS->AnalyzeAsmString(Pieces, Context, DiagOffs)) {
+    targetDiag(getLocationOfStringLiteralByte(AsmString, DiagOffs), DiagID)
+        << AsmString->getSourceRange();
+    return NS;
+  }
 
   // Validate constraints and modifiers.
   for (unsigned i = 0, e = Pieces.size(); i != e; ++i) {
@@ -496,13 +514,14 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
     TargetInfo::ConstraintInfo &Info = OutputConstraintInfos[i];
     StringRef ConstraintStr = Info.getConstraintStr();
     unsigned AltCount = ConstraintStr.count(',') + 1;
-    if (NumAlternatives == ~0U)
+    if (NumAlternatives == ~0U) {
       NumAlternatives = AltCount;
-    else if (NumAlternatives != AltCount)
-      return StmtResult(
-          targetDiag(NS->getOutputExpr(i)->getBeginLoc(),
-                     diag::err_asm_unexpected_constraint_alternatives)
-          << NumAlternatives << AltCount);
+    } else if (NumAlternatives != AltCount) {
+      targetDiag(NS->getOutputExpr(i)->getBeginLoc(),
+                 diag::err_asm_unexpected_constraint_alternatives)
+          << NumAlternatives << AltCount;
+      return NS;
+    }
   }
   SmallVector<size_t, 4> InputMatchedToOutput(OutputConstraintInfos.size(),
                                               ~0U);
@@ -510,13 +529,14 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
     TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i];
     StringRef ConstraintStr = Info.getConstraintStr();
     unsigned AltCount = ConstraintStr.count(',') + 1;
-    if (NumAlternatives == ~0U)
+    if (NumAlternatives == ~0U) {
       NumAlternatives = AltCount;
-    else if (NumAlternatives != AltCount)
-      return StmtResult(
-          targetDiag(NS->getInputExpr(i)->getBeginLoc(),
-                     diag::err_asm_unexpected_constraint_alternatives)
-          << NumAlternatives << AltCount);
+    } else if (NumAlternatives != AltCount) {
+      targetDiag(NS->getInputExpr(i)->getBeginLoc(),
+                 diag::err_asm_unexpected_constraint_alternatives)
+          << NumAlternatives << AltCount;
+      return NS;
+    }
 
     // If this is a tied constraint, verify that the output and input have
     // either exactly the same type, or that they are int/ptr operands with the
@@ -534,11 +554,10 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
       targetDiag(NS->getInputExpr(i)->getBeginLoc(),
                  diag::err_asm_input_duplicate_match)
           << TiedTo;
-      return StmtResult(
-          targetDiag(
-              NS->getInputExpr(InputMatchedToOutput[TiedTo])->getBeginLoc(),
-              diag::note_asm_input_duplicate_first)
-          << TiedTo);
+      targetDiag(NS->getInputExpr(InputMatchedToOutput[TiedTo])->getBeginLoc(),
+                 diag::note_asm_input_duplicate_first)
+          << TiedTo;
+      return NS;
     }
     InputMatchedToOutput[TiedTo] = i;
 
@@ -623,10 +642,10 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
       continue;
     }
 
-    return StmtResult(targetDiag(InputExpr->getBeginLoc(),
-                                 diag::err_asm_tying_incompatible_types)
-                      << InTy << OutTy << OutputExpr->getSourceRange()
-                      << InputExpr->getSourceRange());
+    targetDiag(InputExpr->getBeginLoc(), diag::err_asm_tying_incompatible_types)
+        << InTy << OutTy << OutputExpr->getSourceRange()
+        << InputExpr->getSourceRange();
+    return NS;
   }
 
   // Check for conflicts between clobber list and input or output lists
@@ -634,8 +653,7 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
       getClobberConflictLocation(Exprs, Constraints, Clobbers, NumClobbers,
                                  Context.getTargetInfo(), Context);
   if (ConstraintLoc.isValid())
-    return StmtResult(
-        targetDiag(ConstraintLoc, diag::error_inoutput_conflict_with_clobber));
+    targetDiag(ConstraintLoc, diag::error_inoutput_conflict_with_clobber);
 
   return NS;
 }
index b3adc8ea00a25c7daaaa8eed4902388bafbbdacf..fa6128b60bdac8952167011b5eedaf09605b90f4 100644 (file)
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -fopenmp -x c -triple i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm-bc %s -o %t-x86-host.bc
-// RUN: %clang_cc1 -verify -fopenmp -x c -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -fsyntax-only
-// RUN: %clang_cc1 -verify -DDIAGS -DIMMEDIATE -fopenmp -x c -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -fsyntax-only
-// RUN: %clang_cc1 -verify -DDIAGS -DDELAYED -fopenmp -x c -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -fsyntax-only
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -fsyntax-only -Wuninitialized
+// RUN: %clang_cc1 -verify -DDIAGS -DIMMEDIATE -fopenmp -x c -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -fsyntax-only -Wuninitialized
+// RUN: %clang_cc1 -verify -DDIAGS -DDELAYED -fopenmp -x c -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -fsyntax-only -Wuninitialized
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
 
index 04b7cb19eb83a2d0672d0518d4269ace543ac155..67da197426cd59ba1f2b9b2228993daf0b2a0d91 100644 (file)
@@ -249,7 +249,7 @@ void fn6() {
     int a;
   __asm__(""
             : "=rm"(a), "=rm"(a)
-            : "11m"(a)) // expected-error {{invalid input constraint '11m' in asm}}
+            : "11m"(a)); // expected-error {{invalid input constraint '11m' in asm}}
 }
 
 // PR14269
index 20c5c4480e4dc26776779264f87c6043672b48c7..457054f608fab4855c86e7b4d5a3311266b46736 100644 (file)
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -DHOST -triple x86_64-unknown-linux-gnu
-// RUN: %clang_cc1 -fsyntax-only -verify %s -DHOST -DHOST_USED -triple x86_64-unknown-linux-gnu
-// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -verify %s -DDEVICE_NOT_USED -triple nvptx-unknown-cuda
-// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -verify %s -DDEVICE -triple nvptx-unknown-cuda
-// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -verify %s -DDEVICE -DDEVICE_USED -triple nvptx-unknown-cuda
+// RUN: %clang_cc1 -fsyntax-only -verify %s -DHOST -triple x86_64-unknown-linux-gnu -Wuninitialized
+// RUN: %clang_cc1 -fsyntax-only -verify %s -DHOST -DHOST_USED -triple x86_64-unknown-linux-gnu -Wuninitialized
+// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -verify %s -DDEVICE_NOT_USED -triple nvptx-unknown-cuda -Wuninitialized
+// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -verify %s -DDEVICE -triple nvptx-unknown-cuda -Wuninitialized
+// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -verify %s -DDEVICE -DDEVICE_USED -triple nvptx-unknown-cuda -Wuninitialized
 
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target