aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-08-19 01:32:15 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-08-19 01:43:43 -0400
commit987768778a67538299f84a6ab7ff0ca65f69d2ac (patch)
tree2e7551d76bf9a3e6d242a961eacf7c81aab6025f /src/analyze.cpp
parent558ece8f6f1889bc4773432c16cdf96a54ec1431 (diff)
downloadzig-987768778a67538299f84a6ab7ff0ca65f69d2ac.tar.gz
zig-987768778a67538299f84a6ab7ff0ca65f69d2ac.zip
bit shifting safety
* add u3, u4, u5, u6, u7 and i3, i4, i5, i6, i7 * shift operations shift amount parameter type is integer with log2 bit width of other param - This enforces not violating undefined behavior on shift amount >= bit width with the type system * clean up math.log, math.ln, math.log2, math.log10 closes #403
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 263c04f6e4..b7616151c5 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -3076,16 +3076,26 @@ void semantic_analyze(CodeGen *g) {
TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
size_t index;
- if (size_in_bits == 8) {
+ if (size_in_bits == 3) {
index = 0;
- } else if (size_in_bits == 16) {
+ } else if (size_in_bits == 4) {
index = 1;
- } else if (size_in_bits == 32) {
+ } else if (size_in_bits == 5) {
index = 2;
- } else if (size_in_bits == 64) {
+ } else if (size_in_bits == 6) {
index = 3;
- } else if (size_in_bits == 128) {
+ } else if (size_in_bits == 7) {
index = 4;
+ } else if (size_in_bits == 8) {
+ index = 5;
+ } else if (size_in_bits == 16) {
+ index = 6;
+ } else if (size_in_bits == 32) {
+ index = 7;
+ } else if (size_in_bits == 64) {
+ index = 8;
+ } else if (size_in_bits == 128) {
+ index = 9;
} else {
return nullptr;
}