[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Feb 14 21:52:30 PST 2005



Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.222 -> 1.223
---
Log message:

Fix volatile load/store of pointers.  Consider this testcase:

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;
}





---
Diffs of the changes:  (+6 -6)

 Writer.cpp |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.222 llvm/lib/Target/CBackend/Writer.cpp:1.223
--- llvm/lib/Target/CBackend/Writer.cpp:1.222	Mon Feb 14 12:52:35 2005
+++ llvm/lib/Target/CBackend/Writer.cpp	Mon Feb 14 23:52:14 2005
@@ -1656,9 +1656,9 @@
 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::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 << ")";






More information about the llvm-commits mailing list