Commit 2173e1f457

Andrew Kelley <superjoe30@gmail.com>
2017-08-18 04:01:19
fix big integer shifting by large number
1 parent e63d864
Changed files (4)
src
std
special
compiler_rt
test
cases
src/bigint.cpp
@@ -826,7 +826,7 @@ void bigint_shl(BigInt *dest, const BigInt *op1, const BigInt *op2) {
     const uint64_t *op1_digits = bigint_ptr(op1);
     uint64_t shift_amt = bigint_as_unsigned(op2);
 
-    if (op1->digit_count == 1) {
+    if (op1->digit_count == 1 && shift_amt < 64) {
         dest->data.digit = op1_digits[0] << shift_amt;
         if (dest->data.digit > op1_digits[0]) {
             dest->digit_count = 1;
src/codegen.cpp
@@ -3852,6 +3852,10 @@ static void build_all_basic_blocks(CodeGen *g, FnTableEntry *fn) {
 static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef init_val,
     TypeTableEntry *type_entry)
 {
+    if (g->strip_debug_symbols) {
+        return;
+    }
+
     assert(var->gen_is_const);
     assert(type_entry);
 
@@ -3863,6 +3867,7 @@ static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef ini
         buf_ptr(&var->name), import->di_file,
         (unsigned)(var->decl_node->line + 1),
         type_entry->di_type, is_local_to_unit);
+
     // TODO ^^ make an actual global variable
 }
 
@@ -5127,6 +5132,12 @@ static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) {
                 case 64:
                     buf_init_from_str(out_buf, "double");
                     break;
+                case 80:
+                    buf_init_from_str(out_buf, "__float80");
+                    break;
+                case 128:
+                    buf_init_from_str(out_buf, "__float128");
+                    break;
                 default:
                     zig_unreachable();
             }
std/special/compiler_rt/comparetf2.zig
@@ -68,7 +68,6 @@ const GE_GREATER = c_int(1);
 const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED
 
 export fn __getf2(a: f128, b: f128) -> c_int {
-
     const aInt = @bitCast(srep_t, a);
     const bInt = @bitCast(srep_t, b);
     const aAbs = @bitCast(rep_t, aInt) & absMask;
test/cases/math.zig
@@ -313,6 +313,12 @@ test "big number multiplication" {
     }
 }
 
+test "big number shifting" {
+    comptime {
+        assert((u128(1) << 127) == 0x80000000000000000000000000000000);
+    }
+}
+
 test "f128" {
     test_f128();
     comptime test_f128();
@@ -327,4 +333,9 @@ fn test_f128() {
     assert(make_f128(1.0) > 0.9);
     assert(make_f128(1.0) >= 0.9);
     assert(make_f128(1.0) >= 1.0);
+    should_not_be_zero(1.0);
+}
+
+fn should_not_be_zero(x: f128) {
+    assert(x != 0.0);
 }