[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[csmith-dev] Patch file for Int128 and unsigned int128.
Below is the patch file for int128 and unsigned int128.
It contains following command options:
1. --int128 for generating __int128
2. --no-int128 for disabling generation of __int128
3. --uint128 for generating unsigned __int128
4. --no-uint128 for disabling generation of unsigned __int128
5. --int128 --uint128 for generation of both __int128 and unsigned __int128
And can do several combination using first four commands.
Note- _int128 and unsigned _int128 are disabled by default.
In csmith codebase sometimes it happens that a larger integer value is returned than expected.
e.g.
int16_t function_1() {
// statements
return int32_t;
}
Will it cause integer overflow? As integer of 32 bit size is getting returned, while return type is of 16 bit.
diff --git a/src/CGOptions.cpp b/src/CGOptions.cpp
index 6c9d3dc..11469af 100644
--- a/src/CGOptions.cpp
+++ b/src/CGOptions.cpp
@@ -199,6 +199,8 @@ DEFINE_GETTER_SETTER_BOOL(const_struct_union_fields);
DEFINE_GETTER_SETTER_BOOL(lang_cpp);
DEFINE_GETTER_SETTER_BOOL(cpp11);
DEFINE_GETTER_SETTER_BOOL(fast_execution);
+DEFINE_GETTER_SETTER_BOOL(Int128);
+DEFINE_GETTER_SETTER_BOOL(UInt128);
void
CGOptions::set_default_builtin_kinds()
@@ -313,6 +315,8 @@ CGOptions::set_default_settings(void)
fast_execution(false);
set_default_builtin_kinds();
+ Int128(false);
+ UInt128(false);
}
// Add options necessary for cpp
diff --git a/src/CGOptions.h b/src/CGOptions.h
index ee7bb5e..df48731 100644
--- a/src/CGOptions.h
+++ b/src/CGOptions.h
@@ -253,6 +253,13 @@ public:
static bool uint8(void);
static bool uint8(bool p);
+ static bool Int128(void);
+ static bool Int128(bool p);
+
+ static bool UInt128(void);
+ static bool UInt128(bool p);
+
+
static bool enable_float(void);
static bool enable_float(bool p);
@@ -548,6 +555,8 @@ private:
static bool longlong_;
static bool int8_;
static bool uint8_;
+ static bool Int128_;
+ static bool UInt128_;
static bool enable_float_;
static bool strict_float_;
static bool pointers_;
diff --git a/src/Constant.cpp b/src/Constant.cpp
index 526c6cc..582ce7a 100644
--- a/src/Constant.cpp
+++ b/src/Constant.cpp
@@ -121,7 +121,13 @@ GenerateRandomIntConstant(void)
return val;
}
-
+static string
+GenerateRandomInt128Constant(void)
+{
+ string val;
+ val = "0x" + RandomHexDigits( 16 ) ;
+ return val;
+}
// --------------------------------------------------------------
static string
GenerateRandomShortConstant(void)
@@ -380,6 +386,8 @@ GenerateRandomConstant(const Type* type)
case eULong: v = GenerateRandomLongConstant(); break;
case eULongLong: v = GenerateRandomLongLongConstant(); break;
case eFloat: v = GenerateRandomFloatHexConstant(); break;
+ case eInt128: v = GenerateRandomInt128Constant(); break;
+ case eUInt128: v = GenerateRandomInt128Constant(); break;
// case eDouble: v = GenerateRandomFloatConstant(); break;
default:
assert(0 && "Unsupported type!");
diff --git a/src/Probabilities.cpp b/src/Probabilities.cpp
index beea841..c5581a2 100644
--- a/src/Probabilities.cpp
+++ b/src/Probabilities.cpp
@@ -677,6 +677,21 @@ Probabilities::set_default_simple_types_prob()
// We only use void for function's parameter, so
// disallow choosing void type from other places
SET_SINGLE_NAME("void_prob", Void, 0);
+ if (CGOptions::Int128()) {
+ SET_SINGLE_NAME("Int128_prob", Int128, 1);
+ }
+ else {
+ SET_SINGLE_NAME("Int128_prob", Int128, 0);
+ }
+
+ if (CGOptions::UInt128()) {
+ SET_SINGLE_NAME("UInt128_prob", UInt128, 1);
+ }
+ else {
+ SET_SINGLE_NAME("UInt128_prob", UInt128, 0);
+ }
+
+
if (CGOptions::int8()) {
SET_SINGLE_NAME("char_prob", Char, 1);
}
diff --git a/src/Probabilities.h b/src/Probabilities.h
index be483c5..7190b17 100644
--- a/src/Probabilities.h
+++ b/src/Probabilities.h
@@ -139,6 +139,8 @@ enum ProbName {
pULongProb,
pULongLongProb,
pFloatProb,
+ pUInt128Prob,
+ pInt128Prob,
// for safe math ops
pSafeOpsSizeProb,
diff --git a/src/RandomProgramGenerator.cpp b/src/RandomProgramGenerator.cpp
index a8eb615..a3cb543 100644
--- a/src/RandomProgramGenerator.cpp
+++ b/src/RandomProgramGenerator.cpp
@@ -170,6 +170,8 @@ static void print_help()
cout << " --longlong| --no-longlong: enable | disable long long (enabled by default)." << endl << endl;
cout << " --int8 | --no-int8: enable | disable int8_t (enabled by default)." << endl << endl;
cout << " --uint8 | --no-uint8: enable | disable uint8_t (enabled by default)." << endl << endl;
+ cout << " --int128 | --no-int128: enable | disable generate__int128 as datatype extension (disabled by default)." << endl << endl;
+ cout << " --uint128 | --no-uint128: enable | disable generate unsigned __int128 as datatype extension (disabled by default)." << endl << endl;
cout << " --float | --no-float: enable | disable float (disabled by default)." << endl << endl;
cout << " --main | --nomain: enable | disable to generate main function (enabled by default)." << endl << endl;
cout << " --math64 | --no-math64: enable | disable 64-bit math ops (enabled by default)." << endl << endl;
@@ -785,6 +787,27 @@ main(int argc, char **argv)
continue;
}
+ if (strcmp (argv[i], "--int128") == 0) {
+ CGOptions::Int128(true);
+ continue;
+ }
+
+ if (strcmp (argv[i], "--no-int128") == 0) {
+ CGOptions::Int128(false);
+ continue;
+ }
+
+ if (strcmp (argv[i], "--uint128") == 0) {
+ CGOptions::UInt128(true);
+ continue;
+ }
+
+ if (strcmp (argv[i], "--no-uint128") == 0) {
+ CGOptions::UInt128(false);
+ continue;
+ }
+
+
if (strcmp (argv[i], "--float") == 0) {
CGOptions::enable_float(true);
continue;
diff --git a/src/Type.cpp b/src/Type.cpp
index 73f7858..04625c0 100644
--- a/src/Type.cpp
+++ b/src/Type.cpp
@@ -430,6 +430,12 @@ Type::get_type_from_string(const string &type_string)
else if (type_string == "Float") {
return &Type::get_simple_type(eFloat);
}
+ else if (type_string == "Int128") {
+ return &Type::get_simple_type(eInt128);
+ }
+ else if (type_string == "UInt128") {
+ return &Type::get_simple_type(eUInt128);
+ }
assert(0 && "Unsupported type string!");
return NULL;
@@ -1424,6 +1430,8 @@ Type::to_unsigned(void) const
case eShort: return &get_simple_type(eUShort);
case eLong: return &get_simple_type(eULong);
case eLongLong: return &get_simple_type(eULongLong);
+ case eInt128: return &get_simple_type(eInt128);
+ case eUInt128: return &get_simple_type(eUInt128);
default:
break;
}
@@ -1581,16 +1589,18 @@ Type::SizeInBytes(void) const
switch (simple_type) {
case eVoid: return 0;
case eInt: return 4;
- case eShort: return 2;
+ case eShort: return 2;
case eChar: return 1;
case eLong: return 4;
- case eLongLong: return 8;
- case eUChar: return 1;
+ case eLongLong: return 8;
+ case eUChar: return 1;
case eUInt: return 4;
- case eUShort: return 2;
- case eULong: return 4;
- case eULongLong:return 8;
- case eFloat: return 4;
+ case eUShort: return 2;
+ case eULong: return 4;
+ case eULongLong: return 8;
+ case eFloat: return 4;
+ case eInt128: return 16;
+ case eUInt128: return 16;
// case eDouble: return 8;
}
break;
@@ -1720,10 +1730,21 @@ Type::Output(std::ostream &out) const
out << "void";
} else if (this->simple_type == eFloat) {
out << "float";
- } else {
+ }
+ else {
+ if(this->simple_type == eInt128){
+ out << "__int";
+ out << (SizeInBytes() * 8);
+ }
+ else if(this->simple_type == eUInt128){
+ out << "unsigned __int";
+ out << (SizeInBytes() * 8);
+ }
+ else{
out << (is_signed() ? "int" : "uint");
out << (SizeInBytes() * 8);
out << "_t";
+ }
}
break;
case ePointer: ptr_type->Output( out ); out << "*"; break;
diff --git a/src/Type.h b/src/Type.h
index 720f0b3..1e3294c 100644
--- a/src/Type.h
+++ b/src/Type.h
@@ -83,8 +83,10 @@ enum eSimpleType
eFloat,
// eDouble,
eULongLong,
+ eUInt128,
+ eInt128,
};
-#define MAX_SIMPLE_TYPES ((eSimpleType) (eULongLong+1))
+#define MAX_SIMPLE_TYPES ((eSimpleType) (eInt128+1))
enum eMatchType
{
diff --git a/src/VariableSelector.cpp b/src/VariableSelector.cpp
index 02ef82a..322a13b 100644
--- a/src/VariableSelector.cpp
+++ b/src/VariableSelector.cpp
@@ -553,6 +553,7 @@ VariableSelector::GenerateNewGlobal(Effect::Access access, const CGContext &cg_c
}
var_created = true;
return var;
+
}
Variable *