[AVR] Fix incorrectly-calculated AVRMCExpr evaluations
authorDylan McKay <me@dylanmckay.io>
Mon, 11 Dec 2017 11:01:19 +0000 (11:01 +0000)
committerDylan McKay <me@dylanmckay.io>
Mon, 11 Dec 2017 11:01:19 +0000 (11:01 +0000)
This has been broken since r320009.

llvm-svn: 320347

llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp

index fdd43dd5ee1ed30fe998675ff3356e209fe92451..4e13e7adf395f85b3a3e3532f06a489279928be2 100644 (file)
@@ -102,6 +102,7 @@ int64_t AVRMCExpr::evaluateAsInt64(int64_t Value) const {
 
   switch (Kind) {
   case AVRMCExpr::VK_AVR_LO8:
+    Value &= 0xff;
     break;
   case AVRMCExpr::VK_AVR_HI8:
     Value &= 0xff00;
@@ -116,27 +117,23 @@ int64_t AVRMCExpr::evaluateAsInt64(int64_t Value) const {
     Value >>= 24;
     break;
   case AVRMCExpr::VK_AVR_PM_LO8:
+  case AVRMCExpr::VK_AVR_LO8_GS:
+    Value >>= 1; // Program memory addresses must always be shifted by one.
     Value &= 0xff;
-    Value >>= 1;
     break;
   case AVRMCExpr::VK_AVR_PM_HI8:
+  case AVRMCExpr::VK_AVR_HI8_GS:
+    Value >>= 1; // Program memory addresses must always be shifted by one.
     Value &= 0xff00;
-    Value >>= 9;
+    Value >>= 8;
     break;
   case AVRMCExpr::VK_AVR_PM_HH8:
+    Value >>= 1; // Program memory addresses must always be shifted by one.
     Value &= 0xff0000;
-    Value >>= 17;
-    break;
-  case AVRMCExpr::VK_AVR_LO8_GS:
-    Value &= 0xff;
-    Value >>= 1;
-    break;
-  case AVRMCExpr::VK_AVR_HI8_GS:
-    Value &= 0xff00;
-    Value >>= 9;
+    Value >>= 16;
     break;
   case AVRMCExpr::VK_AVR_GS:
-    Value >>= 1;
+    Value >>= 1; // Program memory addresses must always be shifted by one.
     break;
 
   case AVRMCExpr::VK_AVR_None: