summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-c-like.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-02-26 22:19:53 +0000
committerGitHub <noreply@github.com>2020-02-26 22:19:53 +0000
commit46fd5fe81860ee6bd803f836ae78ceb9dc73ccae (patch)
tree867f20002dcbc19ebf32c45b41e13a19b8e31db7 /source/slang/slang-emit-c-like.cpp
parent7bce066cfc51296a538c7a7d325133d60e352494 (diff)
Fix for GCC C++ target - remove warning for int literal value. (#1244)
* Fix for GCC C++ target - remove warning for int literal value. * Comment around hack to negate -0x8000 0000 * Special case negation of literals in parser - to fix problems with errors on gcc. * Apply the literal integer 'fix' when doing negation of a literal.
Diffstat (limited to 'source/slang/slang-emit-c-like.cpp')
-rw-r--r--source/slang/slang-emit-c-like.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp
index 5f784cba3..538ef369a 100644
--- a/source/slang/slang-emit-c-like.cpp
+++ b/source/slang/slang-emit-c-like.cpp
@@ -783,8 +783,14 @@ void CLikeSourceEmitter::emitSimpleValueImpl(IRInst* inst)
// Why having a cast or having a suffix would make a difference though is not clear. It is also possible that the
// L suffix is just ignored, and the literal is really a 'non typed' int literal in C++.
+ // This little hack is needed for gcc that if we have the expression
+ // int(-0x80000000) we get the warning: warning : integer overflow in expression [-Woverflow]
+ // 0x80000000 and -0x80000000 mean the same thing when casted to 32 bit int, so we just flip the value here.
+ IRIntegerValue value = litInst->value.intVal;
+ value = (value == -0x80000000ll) ? -value : value;
+
m_writer->emit("int(");
- m_writer->emit(litInst->value.intVal);
+ m_writer->emit(value);
m_writer->emit(")");
return;
}