[PATCH 1/2] fix clang -Wconstant-conversion with bit fields

2013-01-16 Thread Antoine Pelisse
clang incorrectly reports a constant conversion warning (implicit
truncation to bit field) when using the flag = ~FLAG form, because
~FLAG needs to be truncated.

Convert this form to flag = flag  ~FLAG fixes the issue as
the right operand now fits into the bit field.

Signed-off-by: Antoine Pelisse apeli...@gmail.com
---
I'm sorry about this fix, it really seems bad, yet it's one step closer
to warning-free clang compilation.

It seems quite clear to me that it's a bug in clang.

 bisect.c   | 2 +-
 builtin/checkout.c | 2 +-
 builtin/reflog.c   | 4 ++--
 commit.c   | 4 ++--
 revision.c | 8 
 upload-pack.c  | 4 ++--
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/bisect.c b/bisect.c
index bd1b7b5..34ac01d 100644
--- a/bisect.c
+++ b/bisect.c
@@ -63,7 +63,7 @@ static void clear_distance(struct commit_list *list)
 {
while (list) {
struct commit *commit = list-item;
-   commit-object.flags = ~COUNTED;
+   commit-object.flags = commit-object.flags  ~COUNTED;
list = list-next;
}
 }
diff --git a/builtin/checkout.c b/builtin/checkout.c
index a9c1b5a..2c83234 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -717,7 +717,7 @@ static void orphaned_commit_warning(struct commit *old, 
struct commit *new)
init_revisions(revs, NULL);
setup_revisions(0, NULL, revs, NULL);

-   object-flags = ~UNINTERESTING;
+   object-flags = object-flags  ~UNINTERESTING;
add_pending_object(revs, object, sha1_to_hex(object-sha1));

for_each_ref(add_pending_uninteresting_ref, revs);
diff --git a/builtin/reflog.c b/builtin/reflog.c
index b3c9e27..3079c81 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -170,7 +170,7 @@ static int commit_is_complete(struct commit *commit)
}
/* clear flags from the objects we traversed */
for (i = 0; i  found.nr; i++)
-   found.objects[i].item-flags = ~STUDYING;
+   found.objects[i].item-flags = found.objects[i].item-flags  
~STUDYING;
if (is_incomplete)
commit-object.flags |= INCOMPLETE;
else {
@@ -229,7 +229,7 @@ static void mark_reachable(struct expire_reflog_cb *cb)
struct commit_list *leftover = NULL;

for (pending = cb-mark_list; pending; pending = pending-next)
-   pending-item-object.flags = ~REACHABLE;
+   pending-item-object.flags = pending-item-object.flags  
~REACHABLE;

pending = cb-mark_list;
while (pending) {
diff --git a/commit.c b/commit.c
index e8eb0ae..800779d 100644
--- a/commit.c
+++ b/commit.c
@@ -883,7 +883,7 @@ struct commit_list *reduce_heads(struct commit_list *heads)

/* Uniquify */
for (p = heads; p; p = p-next)
-   p-item-object.flags = ~STALE;
+   p-item-object.flags = p-item-object.flags  ~STALE;
for (p = heads, num_head = 0; p; p = p-next) {
if (p-item-object.flags  STALE)
continue;
@@ -894,7 +894,7 @@ struct commit_list *reduce_heads(struct commit_list *heads)
for (p = heads, i = 0; p; p = p-next) {
if (p-item-object.flags  STALE) {
array[i++] = p-item;
-   p-item-object.flags = ~STALE;
+   p-item-object.flags = p-item-object.flags  ~STALE;
}
}
num_head = remove_redundant(array, num_head);
diff --git a/revision.c b/revision.c
index d7562ee..ed1c16d 100644
--- a/revision.c
+++ b/revision.c
@@ -787,9 +787,9 @@ static void limit_to_ancestry(struct commit_list *bottom, 
struct commit_list *li

/* We are done with the TMP_MARK */
for (p = list; p; p = p-next)
-   p-item-object.flags = ~TMP_MARK;
+   p-item-object.flags = p-item-object.flags  ~TMP_MARK;
for (p = bottom; p; p = p-next)
-   p-item-object.flags = ~TMP_MARK;
+   p-item-object.flags = p-item-object.flags  ~TMP_MARK;
free_commit_list(rlist);
 }

@@ -1948,7 +1948,7 @@ static int remove_duplicate_parents(struct commit *commit)
/* count them while clearing the temporary mark */
surviving_parents = 0;
for (p = commit-parents; p; p = p-next) {
-   p-item-object.flags = ~TMP_MARK;
+   p-item-object.flags = p-item-object.flags  ~TMP_MARK;
surviving_parents++;
}
return surviving_parents;
@@ -2378,7 +2378,7 @@ static struct commit *get_revision_1(struct rev_info 
*revs)

if (revs-reflog_info) {
fake_reflog_parent(revs-reflog_info, commit);
-   commit-object.flags = ~(ADDED | SEEN | SHOWN);
+   commit-object.flags = commit-object.flags  ~(ADDED | 
SEEN | SHOWN);
}

/*
diff --git a/upload-pack.c b/upload-pack.c
index 7c05b15..74d8f0e 100644
--- 

Re: [PATCH 1/2] fix clang -Wconstant-conversion with bit fields

2013-01-16 Thread John Keeping
On Wed, Jan 16, 2013 at 11:47:22PM +0100, Antoine Pelisse wrote:
 clang incorrectly reports a constant conversion warning (implicit
 truncation to bit field) when using the flag = ~FLAG form, because
 ~FLAG needs to be truncated.
 
 Convert this form to flag = flag  ~FLAG fixes the issue as
 the right operand now fits into the bit field.
 
 Signed-off-by: Antoine Pelisse apeli...@gmail.com
 ---
 I'm sorry about this fix, it really seems bad, yet it's one step closer
 to warning-free clang compilation.
 
 It seems quite clear to me that it's a bug in clang.

Which version of clang did you see this with?  I don't get these
warnings with clang 3.2.


John
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] fix clang -Wconstant-conversion with bit fields

2013-01-16 Thread Antoine Pelisse
On Thu, Jan 17, 2013 at 12:08 AM, John Keeping j...@keeping.me.uk wrote:
 On Wed, Jan 16, 2013 at 11:47:22PM +0100, Antoine Pelisse wrote:
 clang incorrectly reports a constant conversion warning (implicit
 truncation to bit field) when using the flag = ~FLAG form, because
 ~FLAG needs to be truncated.
 Which version of clang did you see this with?  I don't get these
 warnings with clang 3.2.

Ubuntu clang version 3.0-6ubuntu3 (tags/RELEASE_30/final) (based on LLVM 3.0)

It's good to know it's been fixed !
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] fix clang -Wconstant-conversion with bit fields

2013-01-16 Thread Antoine Pelisse
So I guess we should drop this patch, it's probably not worth it,
especially if it's been fixed already by clang.

On Thu, Jan 17, 2013 at 12:09 AM, Antoine Pelisse apeli...@gmail.com wrote:
 On Thu, Jan 17, 2013 at 12:08 AM, John Keeping j...@keeping.me.uk wrote:
 On Wed, Jan 16, 2013 at 11:47:22PM +0100, Antoine Pelisse wrote:
 clang incorrectly reports a constant conversion warning (implicit
 truncation to bit field) when using the flag = ~FLAG form, because
 ~FLAG needs to be truncated.
 Which version of clang did you see this with?  I don't get these
 warnings with clang 3.2.

 Ubuntu clang version 3.0-6ubuntu3 (tags/RELEASE_30/final) (based on LLVM 3.0)

 It's good to know it's been fixed !
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] fix clang -Wconstant-conversion with bit fields

2013-01-16 Thread Junio C Hamano
Antoine Pelisse apeli...@gmail.com writes:

 clang incorrectly reports a constant conversion warning (implicit
 truncation to bit field) when using the flag = ~FLAG form, because
 ~FLAG needs to be truncated.

 Convert this form to flag = flag  ~FLAG fixes the issue as
 the right operand now fits into the bit field.

If the clang incorrectly reports is already recognised by clang
folks as a bug to be fixed in clang, I'd rather not to take this
patch.

I do not think it is reasonable to expect people to remember that
they have to write flags = ~TO_DROP in a longhand whenever they
are adding new code that needs to do bit-fields, so even if this
patch makes clang silent for the _current_ code, it will not stay
that way.  Something like

#define FLIP_BIT_CLR(fld,bit) do { \
typeof(fld) *x = (fld); \
*x = *x  (~(bit)); \
} while (0)

may be more palapable but not by a large margin.

Yuck.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] fix clang -Wconstant-conversion with bit fields

2013-01-16 Thread Junio C Hamano
Junio C Hamano gits...@pobox.com writes:

 Antoine Pelisse apeli...@gmail.com writes:

 clang incorrectly reports a constant conversion warning (implicit
 truncation to bit field) when using the flag = ~FLAG form, because
 ~FLAG needs to be truncated.

 Convert this form to flag = flag  ~FLAG fixes the issue as
 the right operand now fits into the bit field.

 If the clang incorrectly reports is already recognised by clang
 folks as a bug to be fixed in clang, I'd rather not to take this
 patch.

 I do not think it is reasonable to expect people to remember that
 they have to write flags = ~TO_DROP in a longhand whenever they
 are adding new code that needs to do bit-fields, so even if this
 patch makes clang silent for the _current_ code, it will not stay
 that way.  Something like

 #define FLIP_BIT_CLR(fld,bit) do { \
   typeof(fld) *x = (fld); \
 *x = *x  (~(bit)); \
 } while (0)

 may be more palapable but not by a large margin.

 Yuck.

Double yuck.  I meant palatable.

In any case, I see somebody reports that more recent clang does not
have this bug in the near-by message, so let's forget about this
issue.

Thanks.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html