Fix volatile load/store of pointers. Consider this testcase:
authorChris Lattner <sabre@nondot.org>
Tue, 15 Feb 2005 05:52:14 +0000 (05:52 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 15 Feb 2005 05:52:14 +0000 (05:52 +0000)
void %test(int** %P) {
  %A = volatile load int** %P
  ret void
}

void %test2(int*** %Q) {
  %P = load int*** %Q
  volatile store int** %P, int*** %Q
  ret void
}

instead of emitting:

void test(int **l1_P) {
  int *l2_A;

  l2_A = (int **((volatile int **)l1_P));
  return;
}
void test2(int ***l2_Q) {
  int **l1_P;

  l1_P = *l2_Q;
  *((volatile int ***)l2_Q) = l1_P;
  return;
}

... which is loading/storing volatile pointers, not through volatile pointers,
emit this (which is right):

void test(int **l1_P) {
  int *l3_A;

  l3_A = *((int * volatile*)l1_P);
  return;
}
void test2(int ***l2_Q) {
  int **l1_P;

  l1_P = *l2_Q;
  *((int ** volatile*)l2_Q) = l1_P;
  return;
}

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

lib/Target/CBackend/CBackend.cpp
lib/Target/CBackend/Writer.cpp

index acb7736e45f3d5190a89cadf7cc561cd4fe7150b..46f03357960bc1a5498b04f9f30f73b8fc4ced67 100644 (file)
@@ -1656,9 +1656,9 @@ void CWriter::printIndexingExpression(Value *Ptr, gep_type_iterator I,
 void CWriter::visitLoadInst(LoadInst &I) {
   Out << '*';
   if (I.isVolatile()) {
-    Out << "((volatile ";
-    printType(Out, I.getOperand(0)->getType());
-    Out << ")";
+    Out << "((";
+    printType(Out, I.getType());
+    Out << " volatile*)";
   }
 
   writeOperand(I.getOperand(0));
@@ -1670,9 +1670,9 @@ void CWriter::visitLoadInst(LoadInst &I) {
 void CWriter::visitStoreInst(StoreInst &I) {
   Out << '*';
   if (I.isVolatile()) {
-    Out << "((volatile ";
-    printType(Out, I.getPointerOperand()->getType());
-    Out << ")";
+    Out << "((";
+    printType(Out, I.getOperand(0)->getType());
+    Out << " volatile*)";
   }
   writeOperand(I.getPointerOperand());
   if (I.isVolatile()) Out << ")";
index acb7736e45f3d5190a89cadf7cc561cd4fe7150b..46f03357960bc1a5498b04f9f30f73b8fc4ced67 100644 (file)
@@ -1656,9 +1656,9 @@ void CWriter::printIndexingExpression(Value *Ptr, gep_type_iterator I,
 void CWriter::visitLoadInst(LoadInst &I) {
   Out << '*';
   if (I.isVolatile()) {
-    Out << "((volatile ";
-    printType(Out, I.getOperand(0)->getType());
-    Out << ")";
+    Out << "((";
+    printType(Out, I.getType());
+    Out << " volatile*)";
   }
 
   writeOperand(I.getOperand(0));
@@ -1670,9 +1670,9 @@ void CWriter::visitLoadInst(LoadInst &I) {
 void CWriter::visitStoreInst(StoreInst &I) {
   Out << '*';
   if (I.isVolatile()) {
-    Out << "((volatile ";
-    printType(Out, I.getPointerOperand()->getType());
-    Out << ")";
+    Out << "((";
+    printType(Out, I.getOperand(0)->getType());
+    Out << " volatile*)";
   }
   writeOperand(I.getPointerOperand());
   if (I.isVolatile()) Out << ")";