mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 16:47:28 +01:00
cgen: omit consecutive Wconversion gcc pragmas
This commit is contained in:
1 parent
fab0dd534a
commit
cc9ee184d0
3 files changed
+25
-393
No files matched your search
@@ -237,6 +237,16 @@ func (b *buffer) writeb(x byte) { *b = append(*b, x)
|
||||
func (b *buffer) writes(s string) { *b = append(*b, s...) }
|
||||
func (b *buffer) writex(s []byte) { *b = append(*b, s...) }
|
||||
|
||||
func (b *buffer) undoWrites(s string) bool {
|
||||
nb := len(*b)
|
||||
ns := len(s)
|
||||
if (nb < ns) || (string((*b)[nb-ns:]) != s) {
|
||||
return false
|
||||
}
|
||||
*b = (*b)[:nb-ns]
|
||||
return true
|
||||
}
|
||||
|
||||
func expandBangInsert(b *buffer, s string, m map[string]func(*buffer) error) error {
|
||||
for {
|
||||
remaining := ""
|
||||
|
||||
@@ -183,14 +183,23 @@ func (g *gen) writeStatementAssign1(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const disableWconversion0 = "" +
|
||||
"#if defined(__GNUC__)\n" +
|
||||
"#pragma GCC diagnostic push\n" +
|
||||
"#pragma GCC diagnostic ignored \"-Wconversion\"\n" +
|
||||
"#endif\n"
|
||||
|
||||
const disableWconversion1 = "" +
|
||||
"#if defined(__GNUC__)\n" +
|
||||
"#pragma GCC diagnostic pop\n" +
|
||||
"#endif\n"
|
||||
|
||||
// "x += 1" triggers -Wconversion, if x is smaller than an int (i.e. a
|
||||
// uint8_t or a uint16_t). This is arguably a clang/gcc bug, but in any
|
||||
// case, we work around it in Wuffs.
|
||||
if disableWconversion {
|
||||
b.writes("#if defined(__GNUC__)\n")
|
||||
b.writes("#pragma GCC diagnostic push\n")
|
||||
b.writes("#pragma GCC diagnostic ignored \"-Wconversion\"\n")
|
||||
b.writes("#endif\n")
|
||||
if disableWconversion && !b.undoWrites(disableWconversion1) {
|
||||
b.writes(disableWconversion0)
|
||||
}
|
||||
|
||||
n := len(*b)
|
||||
@@ -213,9 +222,7 @@ func (g *gen) writeStatementAssign1(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr
|
||||
}
|
||||
|
||||
if disableWconversion {
|
||||
b.writes("#if defined(__GNUC__)\n")
|
||||
b.writes("#pragma GCC diagnostic pop\n")
|
||||
b.writes("#endif\n")
|
||||
b.writes(disableWconversion1)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in new issue
Block a user