len = strlen(s) + 1;
d = malloc(len);
strcpy(d,s); // ---> memcpy(d,s, len);
Details
Diff Detail
Event Timeline
What does the malloc have to do with this transform? The transform here is just strcpy(d, s) -> memcpy(d, s, strlen(s)+1), where strlen(s) is free because we can CSE it with the previous call. I guess in general, you can transform strcpy(malloc(strlen(s)+1), s) to strdup, but that's not what you're doing.
Also, you're making the same mistake *again*: you're not checking whether the string is modified between the strlen and the strcpy.
Ah yes, sure (why I still think that if value comes from malloc, it cannot modified between, sigh, sorry) :/
Too bad that helper function "isModifiedBetween" cannot be used here.
But with these transformations (malloc-memset, malloc-strcpy), arent we just transforming part of InstCombine to DSE? Are all these transformations legal there, I mean the right place for them?
If yes, I could rework this patch for DSE after some time.